Built motion from commit 639a1a7f.|2.6.19
[motion2.git] / server / services / agi / index.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x5145=['[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED','catch','[LICENSE]','finally','./server','listening','connection','lodash','syncho','util','../../config/environment','../../config/logger','agi','../../config/license/util','./project','./events','defaults','projectUpdate','nextTick','findIndex','deleted','splice','push','error','stack','log','port','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','name','message','[%s]\x20%s','[ERROR]\x20%s','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','calleridname','callerid','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','dnid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','createSquareReport','then','hasOwnProperty','indexOf','agi_','debug','variables','stringify','[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','close','timeout','find','production','initialize','voice','callysquare'];(function(_0x28a91b,_0x47acb5){var _0x39a46c=function(_0x412b60){while(--_0x412b60){_0x28a91b['push'](_0x28a91b['shift']());}};_0x39a46c(++_0x47acb5);}(_0x5145,0x1ac));var _0x5514=function(_0x922c24,_0x149ee1){_0x922c24=_0x922c24-0x0;var _0x2590b7=_0x5145[_0x922c24];return _0x2590b7;};'use strict';var _=require(_0x5514('0x0'));var syncho=require(_0x5514('0x1'));var util=require(_0x5514('0x2'));var config=require(_0x5514('0x3'));var logger=require(_0x5514('0x4'))(_0x5514('0x5'));var utilLicense=require(_0x5514('0x6'));var rpc=require('./rpc');var Project=require(_0x5514('0x7'));var AGIEmitter=require(_0x5514('0x8'))['EventEmitter'];var projects=[];config[_0x5514('0x5')]=_[_0x5514('0x9')](config[_0x5514('0x5')],{'ip':'127.0.0.1','port':0x11dd});AGIEmitter['on'](_0x5514('0xa'),projectUpdateHandler);function connectionHandler(_0x42006c){process[_0x5514('0xb')](function(){syncho(function(){try{setChannelVariables(_0x42006c);agiHandler(_0x42006c);}catch(_0xb12cc6){logger['error'](_0xb12cc6['stack']);}});});}function projectUpdateHandler(_0x29d0f0){try{var _0x4efa20=_[_0x5514('0xc')](projects,['id',_0x29d0f0['id']]);if(_0x4efa20>-0x1){if(_0x29d0f0[_0x5514('0xd')]===!![]){projects[_0x5514('0xe')](_0x4efa20,0x1);}else{projects[_0x4efa20]=_0x29d0f0;}}else{projects[_0x5514('0xf')](_0x29d0f0);}}catch(_0x1d22ea){logger[_0x5514('0x10')](_0x1d22ea[_0x5514('0x11')]);}}function listeningHandler(){console[_0x5514('0x12')]('Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!',config[_0x5514('0x5')][_0x5514('0x13')]);logger[_0x5514('0x14')](util[_0x5514('0x15')](_0x5514('0x16'),config[_0x5514('0x5')]['ip'],config[_0x5514('0x5')][_0x5514('0x13')]));}function errorHandler(_0x19f9d9){if(_0x19f9d9&&_0x19f9d9[_0x5514('0x17')]&&_0x19f9d9[_0x5514('0x18')]){logger[_0x5514('0x10')](util[_0x5514('0x15')](_0x5514('0x19'),_0x19f9d9[_0x5514('0x17')],_0x19f9d9[_0x5514('0x18')]));}else{logger[_0x5514('0x10')](util['format'](_0x5514('0x1a'),_0x19f9d9['stack']));}}function closeHandler(){logger[_0x5514('0x14')](util[_0x5514('0x15')](_0x5514('0x1b'),this[_0x5514('0x1c')],this[_0x5514('0x1d')],this[_0x5514('0x1e')],this['dnid'],this[_0x5514('0x1f')]));try{createSquareReport(this);}catch(_0x4f39a1){logger['error'](_0x4f39a1['stack']);}}function timeoutHandler(){logger[_0x5514('0x14')](util[_0x5514('0x15')](_0x5514('0x20'),this[_0x5514('0x1c')],this[_0x5514('0x1d')],this[_0x5514('0x1e')],this[_0x5514('0x21')],this[_0x5514('0x1f')]));}function hangupHandler(){logger[_0x5514('0x14')](util[_0x5514('0x15')](_0x5514('0x22'),this[_0x5514('0x1c')],this[_0x5514('0x1d')],this['callerid'],this[_0x5514('0x21')],this[_0x5514('0x1f')]));this[_0x5514('0x23')]=!![];}function createSquareReport(_0x2bf01d,_0x45a0b4){rpc[_0x5514('0x24')](_0x2bf01d)[_0x5514('0x25')](function(_0x40158d){if(_0x45a0b4){_0x45a0b4(null,_0x40158d);}})['catch'](function(_0x11a0e4){if(_0x45a0b4){_0x45a0b4(null,_0x11a0e4);}});}function setChannelVariables(_0x21fb8d){for(var _0x73fe3 in _0x21fb8d){if(_0x21fb8d[_0x5514('0x26')](_0x73fe3)){if(_0x73fe3[_0x5514('0x27')](_0x5514('0x28'))===0x0){_0x21fb8d[_0x73fe3['substring'](0x4)]=_0x21fb8d[_0x73fe3];delete _0x21fb8d[_0x73fe3];}}}}function agiHandler(_0x4b79e5){logger[_0x5514('0x29')](_0x5514('0x2a'),JSON[_0x5514('0x2b')](_0x4b79e5,null,0x2));logger[_0x5514('0x14')](util['format'](_0x5514('0x2c'),_0x4b79e5[_0x5514('0x1c')],_0x4b79e5[_0x5514('0x1d')],_0x4b79e5[_0x5514('0x1e')],_0x4b79e5[_0x5514('0x21')],_0x4b79e5[_0x5514('0x1f')]));_0x4b79e5['on']('error',errorHandler);_0x4b79e5['on'](_0x5514('0x2d'),closeHandler);_0x4b79e5['on'](_0x5514('0x2e'),timeoutHandler);_0x4b79e5[_0x5514('0x23')]=![];_0x4b79e5['on']('hangup',hangupHandler);var _0x4ebbc3=_[_0x5514('0x2f')](projects,[_0x5514('0x17'),_0x4b79e5[_0x5514('0x1c')]]);if(!_0x4ebbc3)return Project['handleNotFound'](_0x4b79e5);if(!_0x4ebbc3[_0x5514('0x30')])return Project['handleUnpublished'](_0x4b79e5);return Project[_0x5514('0x31')](_0x4ebbc3,_0x4b79e5);}function main(){var _0xb2a37e;return utilLicense['getLicense']()[_0x5514('0x25')](function(_0x2521f7){if(!_0x2521f7)return;if(_0x2521f7[_0x5514('0x32')]){if(_0x2521f7[_0x5514('0x33')]&&_0x2521f7[_0x5514('0x33')]>0x0){logger[_0x5514('0x14')](util[_0x5514('0x15')](_0x5514('0x34'),_0x2521f7[_0x5514('0x33')]));_0xb2a37e=_0x2521f7[_0x5514('0x33')];}else{logger[_0x5514('0x14')](_0x5514('0x35'));}}else{logger[_0x5514('0x14')]('[LICENSE]\x20VOICE\x20IS\x20DISABLED');_0xb2a37e=-0x1;}})[_0x5514('0x25')](function(){return Project['getAll']();})['then'](function(_0x270e83){projects=_0x270e83;return;})[_0x5514('0x36')](function(_0x33a90b){logger[_0x5514('0x10')](_0x5514('0x37'),_0x33a90b['stack']);})[_0x5514('0x38')](function(){var _0x5dab9b=require(_0x5514('0x39'))(config[_0x5514('0x5')][_0x5514('0x13')],config[_0x5514('0x5')]['ip'],_0xb2a37e);_0x5dab9b['on']('error',errorHandler);_0x5dab9b['on'](_0x5514('0x3a'),listeningHandler);_0x5dab9b['on'](_0x5514('0x3b'),connectionHandler);_0x5dab9b['on'](_0x5514('0x2d'),closeHandler);});}main();