Built motion from commit (unavailable).|2.5.3
[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 _0x9b67=['calleridname','callerid','dnid','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','evtHangup','mxGraphModel','root','hasOwnProperty','retry','maxRetry','mxCell','length','target','addEdge','value','getSquareProject','then','catch','createSquareReport','indexOf','agi_','substring','inspect','variables','stringify','[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','close','timeout','hangup','sync','debug','joinAt','YYYY-MM-DD\x20HH:mm:ss','omit','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','start','clear','vertex','agicommand','gotoc','context','extension','priority','response','code','result','toString','agicommand\x20not\x20found','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','isUndefined','continueAt','Project\x20%s\x20not\x20published','Project\x20%s\x20not\x20found','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','[LICENSE]','finally','./server','listening','connection','xml2json','lodash','syncho','util','moment','../../config/logger','agi','./mailRpc','./graph','./vertices','defaults','127.0.0.1','nextTick','error','stack','log','port','info','format','message','[%s]\x20%s','name','[ERROR]\x20%s','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s'];(function(_0x9b3efc,_0x577a0d){var _0x200f05=function(_0x15ad7c){while(--_0x15ad7c){_0x9b3efc['push'](_0x9b3efc['shift']());}};_0x200f05(++_0x577a0d);}(_0x9b67,0xf6));var _0x79b6=function(_0x3d32b3,_0x49677e){_0x3d32b3=_0x3d32b3-0x0;var _0x1b5913=_0x9b67[_0x3d32b3];return _0x1b5913;};'use strict';var parser=require(_0x79b6('0x0'));var _=require(_0x79b6('0x1'));var syncho=require(_0x79b6('0x2'));var util=require(_0x79b6('0x3'));var moment=require(_0x79b6('0x4'));var config=require('../../config/environment');var logger=require(_0x79b6('0x5'))(_0x79b6('0x6'));var utilLicense=require('../../config/license/util');var rpc=require('./rpc');var mailRpc=require(_0x79b6('0x7'));var Graph=require(_0x79b6('0x8'));var Vertices=require(_0x79b6('0x9'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config[_0x79b6('0x6')]=_[_0x79b6('0xa')](config[_0x79b6('0x6')],{'ip':_0x79b6('0xb'),'port':0x11dd});function connectionHandler(_0x58ae2d){process[_0x79b6('0xc')](function(){syncho(function(){try{setChannelVariables(_0x58ae2d);agiHandler(_0x58ae2d);}catch(_0x107e4b){logger[_0x79b6('0xd')](_0x107e4b[_0x79b6('0xe')]);}});});}function listeningHandler(){console[_0x79b6('0xf')]('Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!',config[_0x79b6('0x6')][_0x79b6('0x10')]);logger[_0x79b6('0x11')](util[_0x79b6('0x12')]('[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d',config['agi']['ip'],config[_0x79b6('0x6')][_0x79b6('0x10')]));}function errorHandler(_0x303cfb){if(_0x303cfb&&_0x303cfb['name']&&_0x303cfb[_0x79b6('0x13')]){logger[_0x79b6('0xd')](util[_0x79b6('0x12')](_0x79b6('0x14'),_0x303cfb[_0x79b6('0x15')],_0x303cfb[_0x79b6('0x13')]));}else{logger[_0x79b6('0xd')](util[_0x79b6('0x12')](_0x79b6('0x16'),_0x303cfb[_0x79b6('0xe')]));}}function closeHandler(){logger[_0x79b6('0x11')](util[_0x79b6('0x12')](_0x79b6('0x17'),this['arg_1'],this[_0x79b6('0x18')],this[_0x79b6('0x19')],this[_0x79b6('0x1a')],this[_0x79b6('0x1b')]));try{createSquareReport(this);}catch(_0x2a8788){logger[_0x79b6('0xd')](_0x2a8788[_0x79b6('0xe')]);}}function timeoutHandler(){logger[_0x79b6('0x11')](util[_0x79b6('0x12')](_0x79b6('0x1c'),this[_0x79b6('0x1d')],this[_0x79b6('0x18')],this[_0x79b6('0x19')],this['dnid'],this[_0x79b6('0x1b')]));}function hangupHandler(){logger['info'](util[_0x79b6('0x12')]('[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0x79b6('0x1d')],this[_0x79b6('0x18')],this[_0x79b6('0x19')],this['dnid'],this[_0x79b6('0x1b')]));this[_0x79b6('0x1e')]=!![];}function getRoot(_0x53208a){return parser['toJson'](_0x53208a,{'object':!![]})[_0x79b6('0x1f')][_0x79b6('0x20')];}function addVertex(_0x9bd2cc,_0x268826,_0x3b2a2a){_0x268826['agicommand']=_0x3b2a2a;if(_0x268826[_0x79b6('0x21')](_0x79b6('0x22'))){_0x268826[_0x79b6('0x23')]=parseInt(_0x268826[_0x79b6('0x22')],0xa);}_0x9bd2cc['addVertex'](_['omit'](_0x268826,_0x79b6('0x24')));}function initGraph(_0x2d16b2,_0x37b01b){var _0xc25c99=new Graph();for(var _0x4adf15 in _0x2d16b2){if(_0x2d16b2[_0x79b6('0x21')](_0x4adf15)){if(_['isArray'](_0x2d16b2[_0x4adf15])){for(var _0x400542=0x0;_0x400542<_0x2d16b2[_0x4adf15][_0x79b6('0x25')];_0x400542+=0x1){addVertex(_0xc25c99,_0x2d16b2[_0x4adf15][_0x400542],_0x4adf15);}}else{addVertex(_0xc25c99,_0x2d16b2[_0x4adf15],_0x4adf15);}}}for(var _0x302596=0x0;_0x302596<_0x37b01b[_0x79b6('0x25')];_0x302596+=0x1){if(_0x37b01b[_0x302596]['source']&&_0x37b01b[_0x302596][_0x79b6('0x26')]){_0xc25c99[_0x79b6('0x27')](_0x37b01b[_0x302596]['source'],_0x37b01b[_0x302596][_0x79b6('0x26')],_0x37b01b[_0x302596][_0x79b6('0x28')]);}}return _0xc25c99;}function getSquareProject(_0x1b1f2b,_0x4f47dc){rpc[_0x79b6('0x29')](_0x1b1f2b)[_0x79b6('0x2a')](function(_0x53b2f5){_0x4f47dc(null,_0x53b2f5);})[_0x79b6('0x2b')](function(_0x11057e){_0x4f47dc(null,_0x11057e);});}function createSquareReport(_0x27f680,_0x40ab0c){rpc[_0x79b6('0x2c')](_0x27f680)[_0x79b6('0x2a')](function(_0x572a2a){if(_0x40ab0c){_0x40ab0c(null,_0x572a2a);}})[_0x79b6('0x2b')](function(_0x10408a){if(_0x40ab0c){_0x40ab0c(null,_0x10408a);}});}function setChannelVariables(_0x34c1fd){for(var _0x489962 in _0x34c1fd){if(_0x34c1fd['hasOwnProperty'](_0x489962)){if(_0x489962[_0x79b6('0x2d')](_0x79b6('0x2e'))===0x0){_0x34c1fd[_0x489962[_0x79b6('0x2f')](0x4)]=_0x34c1fd[_0x489962];delete _0x34c1fd[_0x489962];}}}}function getLogFromObject(_0x2022eb){return util[_0x79b6('0x30')](_0x2022eb,{'showHidden':![],'depth':null});}function agiHandler(_0x31ebd9){var _0x5f4b90,_0x4ac3b9,_0x3bf55d,_0x498e83,_0xe7a4d;logger['debug'](_0x79b6('0x31'),JSON[_0x79b6('0x32')](_0x31ebd9,null,0x2));logger['info'](util[_0x79b6('0x12')](_0x79b6('0x33'),_0x31ebd9['arg_1'],_0x31ebd9[_0x79b6('0x18')],_0x31ebd9['callerid'],_0x31ebd9[_0x79b6('0x1a')],_0x31ebd9[_0x79b6('0x1b')]));_0x31ebd9['on'](_0x79b6('0xd'),errorHandler);_0x31ebd9['on'](_0x79b6('0x34'),closeHandler);_0x31ebd9['on'](_0x79b6('0x35'),timeoutHandler);_0x31ebd9[_0x79b6('0x1e')]=![];_0x31ebd9['on'](_0x79b6('0x36'),hangupHandler);var _0x276eb5=getSquareProject[_0x79b6('0x37')](null,_0x31ebd9[_0x79b6('0x1d')]);if(_0x276eb5){if(_0x276eb5['production']){_0x5f4b90=getRoot(_0x276eb5['production']);if(_0x5f4b90&&_0x5f4b90['start']){logger[_0x79b6('0x38')](_0x79b6('0x20'),JSON['stringify'](_0x5f4b90,null,0x2));_0x31ebd9[_0x79b6('0x39')]=moment()['format'](_0x79b6('0x3a'));_0x4ac3b9=initGraph(_[_0x79b6('0x3b')](_0x5f4b90,_0x79b6('0x24')),_0x5f4b90['mxCell']);_0x3bf55d=new Vertices(_0x31ebd9,rpc,mailRpc);logger[_0x79b6('0x11')](util['format'](_0x79b6('0x3c'),_0x31ebd9[_0x79b6('0x1d')],_0x31ebd9[_0x79b6('0x18')],_0x31ebd9[_0x79b6('0x19')],_0x31ebd9[_0x79b6('0x1a')],_0x31ebd9['uniqueid']));_0x4ac3b9['traverseBFS'](_0x5f4b90[_0x79b6('0x3d')]['id'],function(_0x48ae49){try{_0x48ae49=_0x3bf55d[_0x79b6('0x3e')](_0x48ae49);logger[_0x79b6('0x38')](_0x79b6('0x3f'),JSON[_0x79b6('0x32')](_0x48ae49,null,0x2));if(_0x48ae49[_0x79b6('0x40')]===_0x79b6('0x41')){logger[_0x79b6('0x11')]('gotoc\x20block\x20stop\x20traverse\x20BFS');_0x31ebd9[_0x79b6('0x42')]=_0x48ae49[_0x79b6('0x42')]||_0x31ebd9[_0x79b6('0x42')];_0x31ebd9[_0x79b6('0x43')]=_0x48ae49['extension'];_0x31ebd9[_0x79b6('0x44')]=_0x48ae49['priority']?_0x48ae49['priority']-0x1:0x1;return null;}else if(_0x48ae49&&_0x3bf55d[_0x48ae49[_0x79b6('0x40')]]){_0xe7a4d=_0x3bf55d[_0x48ae49[_0x79b6('0x40')]](_0x48ae49);logger[_0x79b6('0x11')](_0x79b6('0x45'),JSON[_0x79b6('0x32')](_0xe7a4d,null,0x2));if(_0xe7a4d&&_0xe7a4d[_0x79b6('0x46')]===AGI_CODE_SUCCESS&&_0xe7a4d[_0x79b6('0x47')]!==AGI_RESULT_ERROR&&!_0x31ebd9[_0x79b6('0x1e')]){logger['debug'](_0x79b6('0x45'),getLogFromObject(_0xe7a4d));return _['isUndefined'](_0xe7a4d['result'])?null:_0xe7a4d[_0x79b6('0x47')][_0x79b6('0x48')]();}else{logger[_0x79b6('0xd')](_0x79b6('0x45'),getLogFromObject(_0xe7a4d));return null;}}else{logger[_0x79b6('0xd')](_0x79b6('0x49'));return null;}}catch(_0x2b9b30){logger[_0x79b6('0xd')](_0x2b9b30[_0x79b6('0xe')]);return null;}});if(_0x5f4b90['finally']){logger[_0x79b6('0x11')](util[_0x79b6('0x12')](_0x79b6('0x4a'),_0x31ebd9[_0x79b6('0x1d')],_0x31ebd9[_0x79b6('0x18')],_0x31ebd9['callerid'],_0x31ebd9[_0x79b6('0x1a')],_0x31ebd9[_0x79b6('0x1b')]));_0x4ac3b9['traverseBFS'](_0x5f4b90['finally']['id'],function(_0xb9c74d){try{_0xb9c74d=_0x3bf55d[_0x79b6('0x3e')](_0xb9c74d);logger[_0x79b6('0x38')](_0x79b6('0x3f'),JSON[_0x79b6('0x32')](_0xb9c74d,null,0x2));if(_0xb9c74d&&_0x3bf55d[_0xb9c74d[_0x79b6('0x40')]]){_0xe7a4d=_0x3bf55d[_0xb9c74d[_0x79b6('0x40')]](_0xb9c74d);if(_0xe7a4d){logger[_0x79b6('0x38')](_0x79b6('0x45'),getLogFromObject(_0xe7a4d));return _[_0x79b6('0x4b')](_0xe7a4d[_0x79b6('0x47')])?null:_0xe7a4d[_0x79b6('0x47')][_0x79b6('0x48')]();}else{logger[_0x79b6('0xd')](_0x79b6('0x45'),getLogFromObject(_0xe7a4d));return null;}}else{logger[_0x79b6('0xd')](_0x79b6('0x49'));return null;}}catch(_0x14fa5c){logger[_0x79b6('0xd')](_0x14fa5c['stack']);return null;}});}logger['info'](util['format']('[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x31ebd9['arg_1'],_0x31ebd9[_0x79b6('0x18')],_0x31ebd9[_0x79b6('0x19')],_0x31ebd9[_0x79b6('0x1a')],_0x31ebd9[_0x79b6('0x1b')]));logger[_0x79b6('0x11')](util[_0x79b6('0x12')]('[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s',_0x31ebd9[_0x79b6('0x42')],_0x31ebd9[_0x79b6('0x43')],parseInt(_0x31ebd9['priority'],0xa)+0x1));_0x31ebd9[_0x79b6('0x4c')](_0x31ebd9['context'],_0x31ebd9[_0x79b6('0x43')],parseInt(_0x31ebd9['priority'],0xa)+0x1);_0x31ebd9['close']();}}else{logger[_0x79b6('0xd')](util[_0x79b6('0x12')](_0x79b6('0x4d'),_0x31ebd9[_0x79b6('0x1d')]));_0x31ebd9[_0x79b6('0x4c')](_0x31ebd9[_0x79b6('0x42')],_0x31ebd9['extension'],parseInt(_0x31ebd9['priority'],0xa)+0x1);_0x31ebd9[_0x79b6('0x34')]();}}else{logger[_0x79b6('0xd')](util['format'](_0x79b6('0x4e'),_0x31ebd9[_0x79b6('0x1d')]));_0x31ebd9[_0x79b6('0x4c')](_0x31ebd9[_0x79b6('0x42')],_0x31ebd9[_0x79b6('0x43')],parseInt(_0x31ebd9[_0x79b6('0x44')],0xa)+0x1);_0x31ebd9[_0x79b6('0x34')]();}}function main(){var _0x479605;return utilLicense[_0x79b6('0x4f')]()[_0x79b6('0x2a')](function(_0x56385e){if(_0x56385e){if(_0x56385e[_0x79b6('0x50')]){if(_0x56385e['callysquare']&&_0x56385e[_0x79b6('0x51')]>0x0){logger['info'](util['format'](_0x79b6('0x52'),_0x56385e[_0x79b6('0x51')]));_0x479605=_0x56385e[_0x79b6('0x51')];}else{logger[_0x79b6('0x11')](_0x79b6('0x53'));}}else{logger[_0x79b6('0x11')](_0x79b6('0x54'));_0x479605=-0x1;}}})['catch'](function(_0x537a02){logger[_0x79b6('0xd')](_0x79b6('0x55'),_0x537a02[_0x79b6('0xe')]);})[_0x79b6('0x56')](function(){var _0x10b129=require(_0x79b6('0x57'))(config[_0x79b6('0x6')][_0x79b6('0x10')],config[_0x79b6('0x6')]['ip'],_0x479605);_0x10b129['on'](_0x79b6('0xd'),errorHandler);_0x10b129['on'](_0x79b6('0x58'),listeningHandler);_0x10b129['on'](_0x79b6('0x59'),connectionHandler);_0x10b129['on']('close',closeHandler);});}main();