Built motion from commit (unavailable).|2.5.28
[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 _0x98a8=['context','extension','priority','code','result','response','isUndefined','toString','finally','agicommand\x20not\x20found','[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s','close','Project\x20%s\x20not\x20published','continueAt','Project\x20%s\x20not\x20found','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','./server','listening','xml2json','lodash','syncho','util','moment','../../config/environment','../../config/logger','../../config/license/util','./rpc','./mailRpc','./graph','./vertices','defaults','127.0.0.1','nextTick','error','stack','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','agi','port','info','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','name','message','format','[ERROR]\x20%s','arg_1','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','calleridname','toJson','mxGraphModel','root','agicommand','hasOwnProperty','retry','maxRetry','addVertex','mxCell','isArray','length','source','target','value','getSquareProject','then','catch','createSquareReport','substring','inspect','debug','variables','stringify','timeout','evtHangup','hangup','production','joinAt','omit','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','clear','vertex','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS'];(function(_0x4d2f00,_0x4e94d5){var _0x2d7b7f=function(_0x18fa08){while(--_0x18fa08){_0x4d2f00['push'](_0x4d2f00['shift']());}};_0x2d7b7f(++_0x4e94d5);}(_0x98a8,0x12c));var _0x898a=function(_0x162627,_0x4cb5e3){_0x162627=_0x162627-0x0;var _0x34f6d5=_0x98a8[_0x162627];return _0x34f6d5;};'use strict';var parser=require(_0x898a('0x0'));var _=require(_0x898a('0x1'));var syncho=require(_0x898a('0x2'));var util=require(_0x898a('0x3'));var moment=require(_0x898a('0x4'));var config=require(_0x898a('0x5'));var logger=require(_0x898a('0x6'))('agi');var utilLicense=require(_0x898a('0x7'));var rpc=require(_0x898a('0x8'));var mailRpc=require(_0x898a('0x9'));var Graph=require(_0x898a('0xa'));var Vertices=require(_0x898a('0xb'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config['agi']=_[_0x898a('0xc')](config['agi'],{'ip':_0x898a('0xd'),'port':0x11dd});function connectionHandler(_0x4fbce5){process[_0x898a('0xe')](function(){syncho(function(){try{setChannelVariables(_0x4fbce5);agiHandler(_0x4fbce5);}catch(_0x283c5){logger[_0x898a('0xf')](_0x283c5[_0x898a('0x10')]);}});});}function listeningHandler(){console[_0x898a('0x11')](_0x898a('0x12'),config[_0x898a('0x13')][_0x898a('0x14')]);logger[_0x898a('0x15')](util['format'](_0x898a('0x16'),config['agi']['ip'],config[_0x898a('0x13')]['port']));}function errorHandler(_0x25d7f2){if(_0x25d7f2&&_0x25d7f2[_0x898a('0x17')]&&_0x25d7f2[_0x898a('0x18')]){logger['error'](util['format']('[%s]\x20%s',_0x25d7f2[_0x898a('0x17')],_0x25d7f2[_0x898a('0x18')]));}else{logger[_0x898a('0xf')](util[_0x898a('0x19')](_0x898a('0x1a'),_0x25d7f2[_0x898a('0x10')]));}}function closeHandler(){logger['info'](util[_0x898a('0x19')]('[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0x898a('0x1b')],this['calleridname'],this[_0x898a('0x1c')],this['dnid'],this[_0x898a('0x1d')]));try{createSquareReport(this);}catch(_0x56f8f9){logger[_0x898a('0xf')](_0x56f8f9[_0x898a('0x10')]);}}function timeoutHandler(){logger[_0x898a('0x15')](util['format'](_0x898a('0x1e'),this['arg_1'],this['calleridname'],this[_0x898a('0x1c')],this[_0x898a('0x1f')],this['uniqueid']));}function hangupHandler(){logger['info'](util[_0x898a('0x19')](_0x898a('0x20'),this[_0x898a('0x1b')],this[_0x898a('0x21')],this[_0x898a('0x1c')],this[_0x898a('0x1f')],this[_0x898a('0x1d')]));this['evtHangup']=!![];}function getRoot(_0x247cfc){return parser[_0x898a('0x22')](_0x247cfc,{'object':!![]})[_0x898a('0x23')][_0x898a('0x24')];}function addVertex(_0x30495a,_0x310bfa,_0x4e254d){_0x310bfa[_0x898a('0x25')]=_0x4e254d;if(_0x310bfa[_0x898a('0x26')](_0x898a('0x27'))){_0x310bfa[_0x898a('0x28')]=parseInt(_0x310bfa[_0x898a('0x27')],0xa);}_0x30495a[_0x898a('0x29')](_['omit'](_0x310bfa,_0x898a('0x2a')));}function initGraph(_0x51d501,_0x513c6b){var _0x53ddb2=new Graph();for(var _0x3678be in _0x51d501){if(_0x51d501[_0x898a('0x26')](_0x3678be)){if(_[_0x898a('0x2b')](_0x51d501[_0x3678be])){for(var _0x40b3db=0x0;_0x40b3db<_0x51d501[_0x3678be][_0x898a('0x2c')];_0x40b3db+=0x1){addVertex(_0x53ddb2,_0x51d501[_0x3678be][_0x40b3db],_0x3678be);}}else{addVertex(_0x53ddb2,_0x51d501[_0x3678be],_0x3678be);}}}for(var _0x2efde2=0x0;_0x2efde2<_0x513c6b[_0x898a('0x2c')];_0x2efde2+=0x1){if(_0x513c6b[_0x2efde2][_0x898a('0x2d')]&&_0x513c6b[_0x2efde2][_0x898a('0x2e')]){_0x53ddb2['addEdge'](_0x513c6b[_0x2efde2]['source'],_0x513c6b[_0x2efde2]['target'],_0x513c6b[_0x2efde2][_0x898a('0x2f')]);}}return _0x53ddb2;}function getSquareProject(_0x62fe93,_0x3b7704){rpc[_0x898a('0x30')](_0x62fe93)[_0x898a('0x31')](function(_0x560000){_0x3b7704(null,_0x560000);})[_0x898a('0x32')](function(_0xf74645){_0x3b7704(null,_0xf74645);});}function createSquareReport(_0x18773a,_0x4287da){rpc[_0x898a('0x33')](_0x18773a)[_0x898a('0x31')](function(_0x494127){if(_0x4287da){_0x4287da(null,_0x494127);}})[_0x898a('0x32')](function(_0x17a5f3){if(_0x4287da){_0x4287da(null,_0x17a5f3);}});}function setChannelVariables(_0x26eead){for(var _0x17a980 in _0x26eead){if(_0x26eead[_0x898a('0x26')](_0x17a980)){if(_0x17a980['indexOf']('agi_')===0x0){_0x26eead[_0x17a980[_0x898a('0x34')](0x4)]=_0x26eead[_0x17a980];delete _0x26eead[_0x17a980];}}}}function getLogFromObject(_0x1e2fd4){return util[_0x898a('0x35')](_0x1e2fd4,{'showHidden':![],'depth':null});}function agiHandler(_0x4de9bf){var _0x105477,_0x339eb4,_0x5eafc7,_0x2d3b3a,_0x41cd46;logger[_0x898a('0x36')](_0x898a('0x37'),JSON[_0x898a('0x38')](_0x4de9bf,null,0x2));logger['info'](util[_0x898a('0x19')]('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x4de9bf['arg_1'],_0x4de9bf[_0x898a('0x21')],_0x4de9bf['callerid'],_0x4de9bf[_0x898a('0x1f')],_0x4de9bf['uniqueid']));_0x4de9bf['on'](_0x898a('0xf'),errorHandler);_0x4de9bf['on']('close',closeHandler);_0x4de9bf['on'](_0x898a('0x39'),timeoutHandler);_0x4de9bf[_0x898a('0x3a')]=![];_0x4de9bf['on'](_0x898a('0x3b'),hangupHandler);var _0x50c0e4=getSquareProject['sync'](null,_0x4de9bf['arg_1']);if(_0x50c0e4){if(_0x50c0e4[_0x898a('0x3c')]){_0x105477=getRoot(_0x50c0e4[_0x898a('0x3c')]);if(_0x105477&&_0x105477['start']){logger[_0x898a('0x36')](_0x898a('0x24'),JSON[_0x898a('0x38')](_0x105477,null,0x2));_0x4de9bf[_0x898a('0x3d')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x339eb4=initGraph(_[_0x898a('0x3e')](_0x105477,_0x898a('0x2a')),_0x105477['mxCell']);_0x5eafc7=new Vertices(_0x4de9bf,rpc,mailRpc);logger['info'](util[_0x898a('0x19')](_0x898a('0x3f'),_0x4de9bf[_0x898a('0x1b')],_0x4de9bf[_0x898a('0x21')],_0x4de9bf['callerid'],_0x4de9bf[_0x898a('0x1f')],_0x4de9bf[_0x898a('0x1d')]));_0x339eb4['traverseBFS'](_0x105477['start']['id'],function(_0x48cc85){try{_0x48cc85=_0x5eafc7[_0x898a('0x40')](_0x48cc85);logger[_0x898a('0x36')](_0x898a('0x41'),JSON[_0x898a('0x38')](_0x48cc85,null,0x2));if(_0x48cc85[_0x898a('0x25')]===_0x898a('0x42')){logger[_0x898a('0x15')](_0x898a('0x43'));_0x4de9bf[_0x898a('0x44')]=_0x48cc85[_0x898a('0x44')]||_0x4de9bf[_0x898a('0x44')];_0x4de9bf[_0x898a('0x45')]=_0x48cc85[_0x898a('0x45')];_0x4de9bf[_0x898a('0x46')]=_0x48cc85[_0x898a('0x46')]?_0x48cc85['priority']-0x1:0x1;return null;}else if(_0x48cc85&&_0x5eafc7[_0x48cc85[_0x898a('0x25')]]){_0x41cd46=_0x5eafc7[_0x48cc85[_0x898a('0x25')]](_0x48cc85);logger[_0x898a('0x15')]('response',JSON[_0x898a('0x38')](_0x41cd46,null,0x2));if(_0x41cd46&&_0x41cd46[_0x898a('0x47')]===AGI_CODE_SUCCESS&&_0x41cd46[_0x898a('0x48')]!==AGI_RESULT_ERROR&&!_0x4de9bf[_0x898a('0x3a')]){logger[_0x898a('0x36')](_0x898a('0x49'),getLogFromObject(_0x41cd46));return _[_0x898a('0x4a')](_0x41cd46[_0x898a('0x48')])?null:_0x41cd46['result'][_0x898a('0x4b')]();}else{logger[_0x898a('0xf')](_0x898a('0x49'),getLogFromObject(_0x41cd46));return null;}}else{logger[_0x898a('0xf')]('agicommand\x20not\x20found');return null;}}catch(_0x3d5fba){logger[_0x898a('0xf')](_0x3d5fba['stack']);return null;}});if(_0x105477[_0x898a('0x4c')]){logger['info'](util[_0x898a('0x19')]('[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x4de9bf['arg_1'],_0x4de9bf[_0x898a('0x21')],_0x4de9bf['callerid'],_0x4de9bf[_0x898a('0x1f')],_0x4de9bf[_0x898a('0x1d')]));_0x339eb4['traverseBFS'](_0x105477[_0x898a('0x4c')]['id'],function(_0x304bd8){try{_0x304bd8=_0x5eafc7['clear'](_0x304bd8);logger[_0x898a('0x36')](_0x898a('0x41'),JSON[_0x898a('0x38')](_0x304bd8,null,0x2));if(_0x304bd8&&_0x5eafc7[_0x304bd8[_0x898a('0x25')]]){_0x41cd46=_0x5eafc7[_0x304bd8['agicommand']](_0x304bd8);if(_0x41cd46){logger[_0x898a('0x36')](_0x898a('0x49'),getLogFromObject(_0x41cd46));return _['isUndefined'](_0x41cd46[_0x898a('0x48')])?null:_0x41cd46[_0x898a('0x48')]['toString']();}else{logger[_0x898a('0xf')]('response',getLogFromObject(_0x41cd46));return null;}}else{logger[_0x898a('0xf')](_0x898a('0x4d'));return null;}}catch(_0x32ccb9){logger['error'](_0x32ccb9[_0x898a('0x10')]);return null;}});}logger[_0x898a('0x15')](util[_0x898a('0x19')](_0x898a('0x4e'),_0x4de9bf['arg_1'],_0x4de9bf[_0x898a('0x21')],_0x4de9bf['callerid'],_0x4de9bf[_0x898a('0x1f')],_0x4de9bf[_0x898a('0x1d')]));logger[_0x898a('0x15')](util['format'](_0x898a('0x4f'),_0x4de9bf[_0x898a('0x44')],_0x4de9bf[_0x898a('0x45')],parseInt(_0x4de9bf['priority'],0xa)+0x1));_0x4de9bf['continueAt'](_0x4de9bf[_0x898a('0x44')],_0x4de9bf[_0x898a('0x45')],parseInt(_0x4de9bf[_0x898a('0x46')],0xa)+0x1);_0x4de9bf[_0x898a('0x50')]();}}else{logger[_0x898a('0xf')](util[_0x898a('0x19')](_0x898a('0x51'),_0x4de9bf[_0x898a('0x1b')]));_0x4de9bf[_0x898a('0x52')](_0x4de9bf[_0x898a('0x44')],_0x4de9bf[_0x898a('0x45')],parseInt(_0x4de9bf['priority'],0xa)+0x1);_0x4de9bf[_0x898a('0x50')]();}}else{logger[_0x898a('0xf')](util['format'](_0x898a('0x53'),_0x4de9bf['arg_1']));_0x4de9bf['continueAt'](_0x4de9bf[_0x898a('0x44')],_0x4de9bf[_0x898a('0x45')],parseInt(_0x4de9bf[_0x898a('0x46')],0xa)+0x1);_0x4de9bf['close']();}}function main(){var _0x556fd8;return utilLicense[_0x898a('0x54')]()[_0x898a('0x31')](function(_0x515725){if(_0x515725){if(_0x515725[_0x898a('0x55')]){if(_0x515725[_0x898a('0x56')]&&_0x515725['callysquare']>0x0){logger[_0x898a('0x15')](util[_0x898a('0x19')](_0x898a('0x57'),_0x515725['callysquare']));_0x556fd8=_0x515725[_0x898a('0x56')];}else{logger[_0x898a('0x15')](_0x898a('0x58'));}}else{logger[_0x898a('0x15')](_0x898a('0x59'));_0x556fd8=-0x1;}}})[_0x898a('0x32')](function(_0x4cd6fa){logger[_0x898a('0xf')]('[LICENSE]',_0x4cd6fa[_0x898a('0x10')]);})[_0x898a('0x4c')](function(){var _0x15b203=require(_0x898a('0x5a'))(config[_0x898a('0x13')][_0x898a('0x14')],config[_0x898a('0x13')]['ip'],_0x556fd8);_0x15b203['on'](_0x898a('0xf'),errorHandler);_0x15b203['on'](_0x898a('0x5b'),listeningHandler);_0x15b203['on']('connection',connectionHandler);_0x15b203['on'](_0x898a('0x50'),closeHandler);});}main();