Built motion from commit (unavailable).|2.5.4
[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 _0x5584=['start','root','joinAt','YYYY-MM-DD\x20HH:mm:ss','clear','vertex','agicommand','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','code','result','isUndefined','toString','agicommand\x20not\x20found','finally','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','traverseBFS','stack','[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','Project\x20%s\x20not\x20published','continueAt','Project\x20%s\x20not\x20found','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20VOICE\x20IS\x20DISABLED','[LICENSE]','./server','connection','xml2json','lodash','util','moment','../../config/logger','../../config/license/util','./rpc','./mailRpc','./vertices','agi','defaults','error','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','info','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','name','message','format','[%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','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','callerid','dnid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','toJson','mxGraphModel','retry','maxRetry','addVertex','omit','mxCell','hasOwnProperty','length','source','target','value','getSquareProject','then','catch','createSquareReport','agi_','inspect','debug','variables','stringify','close','timeout','hangup','sync','production','SQUAREROOT'];(function(_0xa6cc5c,_0x239c99){var _0x44803d=function(_0x515b6e){while(--_0x515b6e){_0xa6cc5c['push'](_0xa6cc5c['shift']());}};_0x44803d(++_0x239c99);}(_0x5584,0x1e8));var _0x4558=function(_0x5e47ec,_0x4b1d36){_0x5e47ec=_0x5e47ec-0x0;var _0x55f1cf=_0x5584[_0x5e47ec];return _0x55f1cf;};'use strict';var parser=require(_0x4558('0x0'));var _=require(_0x4558('0x1'));var syncho=require('syncho');var util=require(_0x4558('0x2'));var moment=require(_0x4558('0x3'));var config=require('../../config/environment');var logger=require(_0x4558('0x4'))('agi');var utilLicense=require(_0x4558('0x5'));var rpc=require(_0x4558('0x6'));var mailRpc=require(_0x4558('0x7'));var Graph=require('./graph');var Vertices=require(_0x4558('0x8'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config[_0x4558('0x9')]=_[_0x4558('0xa')](config['agi'],{'ip':'127.0.0.1','port':0x11dd});function connectionHandler(_0x49099a){process['nextTick'](function(){syncho(function(){try{setChannelVariables(_0x49099a);agiHandler(_0x49099a);}catch(_0x162481){logger[_0x4558('0xb')](_0x162481['stack']);}});});}function listeningHandler(){console[_0x4558('0xc')](_0x4558('0xd'),config[_0x4558('0x9')][_0x4558('0xe')]);logger[_0x4558('0xf')](util['format'](_0x4558('0x10'),config[_0x4558('0x9')]['ip'],config[_0x4558('0x9')][_0x4558('0xe')]));}function errorHandler(_0xc81bd9){if(_0xc81bd9&&_0xc81bd9[_0x4558('0x11')]&&_0xc81bd9[_0x4558('0x12')]){logger[_0x4558('0xb')](util[_0x4558('0x13')](_0x4558('0x14'),_0xc81bd9['name'],_0xc81bd9['message']));}else{logger['error'](util[_0x4558('0x13')](_0x4558('0x15'),_0xc81bd9['stack']));}}function closeHandler(){logger[_0x4558('0xf')](util[_0x4558('0x13')](_0x4558('0x16'),this[_0x4558('0x17')],this[_0x4558('0x18')],this['callerid'],this['dnid'],this[_0x4558('0x19')]));try{createSquareReport(this);}catch(_0x32b153){logger[_0x4558('0xb')](_0x32b153['stack']);}}function timeoutHandler(){logger[_0x4558('0xf')](util['format'](_0x4558('0x1a'),this[_0x4558('0x17')],this[_0x4558('0x18')],this[_0x4558('0x1b')],this[_0x4558('0x1c')],this[_0x4558('0x19')]));}function hangupHandler(){logger[_0x4558('0xf')](util['format'](_0x4558('0x1d'),this['arg_1'],this[_0x4558('0x18')],this[_0x4558('0x1b')],this[_0x4558('0x1c')],this[_0x4558('0x19')]));this[_0x4558('0x1e')]=!![];}function getRoot(_0x13dca5){return parser[_0x4558('0x1f')](_0x13dca5,{'object':!![]})[_0x4558('0x20')]['root'];}function addVertex(_0x4e099a,_0x242a6e,_0x229dc7){_0x242a6e['agicommand']=_0x229dc7;if(_0x242a6e['hasOwnProperty'](_0x4558('0x21'))){_0x242a6e[_0x4558('0x22')]=parseInt(_0x242a6e['retry'],0xa);}_0x4e099a[_0x4558('0x23')](_[_0x4558('0x24')](_0x242a6e,_0x4558('0x25')));}function initGraph(_0x96ea8,_0x366f77){var _0x2bdd7f=new Graph();for(var _0x374e36 in _0x96ea8){if(_0x96ea8[_0x4558('0x26')](_0x374e36)){if(_['isArray'](_0x96ea8[_0x374e36])){for(var _0x230868=0x0;_0x230868<_0x96ea8[_0x374e36][_0x4558('0x27')];_0x230868+=0x1){addVertex(_0x2bdd7f,_0x96ea8[_0x374e36][_0x230868],_0x374e36);}}else{addVertex(_0x2bdd7f,_0x96ea8[_0x374e36],_0x374e36);}}}for(var _0x4ad71c=0x0;_0x4ad71c<_0x366f77[_0x4558('0x27')];_0x4ad71c+=0x1){if(_0x366f77[_0x4ad71c][_0x4558('0x28')]&&_0x366f77[_0x4ad71c][_0x4558('0x29')]){_0x2bdd7f['addEdge'](_0x366f77[_0x4ad71c][_0x4558('0x28')],_0x366f77[_0x4ad71c][_0x4558('0x29')],_0x366f77[_0x4ad71c][_0x4558('0x2a')]);}}return _0x2bdd7f;}function getSquareProject(_0x1916e6,_0x13985f){rpc[_0x4558('0x2b')](_0x1916e6)[_0x4558('0x2c')](function(_0x36ee7a){_0x13985f(null,_0x36ee7a);})[_0x4558('0x2d')](function(_0x1e11a9){_0x13985f(null,_0x1e11a9);});}function createSquareReport(_0x205d86,_0x206714){rpc[_0x4558('0x2e')](_0x205d86)[_0x4558('0x2c')](function(_0x71f0c7){if(_0x206714){_0x206714(null,_0x71f0c7);}})[_0x4558('0x2d')](function(_0x4cf82f){if(_0x206714){_0x206714(null,_0x4cf82f);}});}function setChannelVariables(_0x3c33a3){for(var _0x51aaf6 in _0x3c33a3){if(_0x3c33a3[_0x4558('0x26')](_0x51aaf6)){if(_0x51aaf6['indexOf'](_0x4558('0x2f'))===0x0){_0x3c33a3[_0x51aaf6['substring'](0x4)]=_0x3c33a3[_0x51aaf6];delete _0x3c33a3[_0x51aaf6];}}}}function getLogFromObject(_0x3babbf){return util[_0x4558('0x30')](_0x3babbf,{'showHidden':![],'depth':null});}function agiHandler(_0x32dcda){var _0x3edf16,_0x1acd44,_0x549d0b,_0x15271b,_0x36e4e1;logger[_0x4558('0x31')](_0x4558('0x32'),JSON[_0x4558('0x33')](_0x32dcda,null,0x2));logger[_0x4558('0xf')](util[_0x4558('0x13')]('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x32dcda[_0x4558('0x17')],_0x32dcda[_0x4558('0x18')],_0x32dcda[_0x4558('0x1b')],_0x32dcda['dnid'],_0x32dcda[_0x4558('0x19')]));_0x32dcda['on'](_0x4558('0xb'),errorHandler);_0x32dcda['on'](_0x4558('0x34'),closeHandler);_0x32dcda['on'](_0x4558('0x35'),timeoutHandler);_0x32dcda[_0x4558('0x1e')]=![];_0x32dcda['on'](_0x4558('0x36'),hangupHandler);var _0x1fca1e=getSquareProject[_0x4558('0x37')](null,_0x32dcda['arg_1']);if(_0x1fca1e){if(_0x1fca1e[_0x4558('0x38')]){_0x3edf16=getRoot(_0x1fca1e['production']);console['log'](_0x4558('0x39'),_0x3edf16);if(_0x3edf16&&_0x3edf16[_0x4558('0x3a')]){logger[_0x4558('0x31')](_0x4558('0x3b'),JSON[_0x4558('0x33')](_0x3edf16,null,0x2));_0x32dcda[_0x4558('0x3c')]=moment()[_0x4558('0x13')](_0x4558('0x3d'));_0x1acd44=initGraph(_['omit'](_0x3edf16,_0x4558('0x25')),_0x3edf16[_0x4558('0x25')]);_0x549d0b=new Vertices(_0x32dcda,rpc,mailRpc);logger[_0x4558('0xf')](util[_0x4558('0x13')]('[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x32dcda['arg_1'],_0x32dcda['calleridname'],_0x32dcda[_0x4558('0x1b')],_0x32dcda[_0x4558('0x1c')],_0x32dcda[_0x4558('0x19')]));_0x1acd44['traverseBFS'](_0x3edf16[_0x4558('0x3a')]['id'],function(_0x1c7b60){try{_0x1c7b60=_0x549d0b[_0x4558('0x3e')](_0x1c7b60);logger[_0x4558('0x31')](_0x4558('0x3f'),JSON[_0x4558('0x33')](_0x1c7b60,null,0x2));if(_0x1c7b60[_0x4558('0x40')]==='gotoc'){logger[_0x4558('0xf')](_0x4558('0x41'));_0x32dcda['context']=_0x1c7b60[_0x4558('0x42')]||_0x32dcda[_0x4558('0x42')];_0x32dcda['extension']=_0x1c7b60[_0x4558('0x43')];_0x32dcda[_0x4558('0x44')]=_0x1c7b60['priority']?_0x1c7b60[_0x4558('0x44')]-0x1:0x1;return null;}else if(_0x1c7b60&&_0x549d0b[_0x1c7b60['agicommand']]){_0x36e4e1=_0x549d0b[_0x1c7b60[_0x4558('0x40')]](_0x1c7b60);logger[_0x4558('0xf')](_0x4558('0x45'),JSON['stringify'](_0x36e4e1,null,0x2));if(_0x36e4e1&&_0x36e4e1[_0x4558('0x46')]===AGI_CODE_SUCCESS&&_0x36e4e1[_0x4558('0x47')]!==AGI_RESULT_ERROR&&!_0x32dcda['evtHangup']){logger[_0x4558('0x31')](_0x4558('0x45'),getLogFromObject(_0x36e4e1));return _[_0x4558('0x48')](_0x36e4e1[_0x4558('0x47')])?null:_0x36e4e1[_0x4558('0x47')][_0x4558('0x49')]();}else{logger[_0x4558('0xb')](_0x4558('0x45'),getLogFromObject(_0x36e4e1));return null;}}else{logger[_0x4558('0xb')](_0x4558('0x4a'));return null;}}catch(_0x61d674){logger['error'](_0x61d674['stack']);return null;}});if(_0x3edf16[_0x4558('0x4b')]){logger['info'](util[_0x4558('0x13')](_0x4558('0x4c'),_0x32dcda[_0x4558('0x17')],_0x32dcda[_0x4558('0x18')],_0x32dcda[_0x4558('0x1b')],_0x32dcda[_0x4558('0x1c')],_0x32dcda[_0x4558('0x19')]));_0x1acd44[_0x4558('0x4d')](_0x3edf16[_0x4558('0x4b')]['id'],function(_0x3b0486){try{_0x3b0486=_0x549d0b[_0x4558('0x3e')](_0x3b0486);logger['debug'](_0x4558('0x3f'),JSON[_0x4558('0x33')](_0x3b0486,null,0x2));if(_0x3b0486&&_0x549d0b[_0x3b0486['agicommand']]){_0x36e4e1=_0x549d0b[_0x3b0486[_0x4558('0x40')]](_0x3b0486);if(_0x36e4e1){logger['debug']('response',getLogFromObject(_0x36e4e1));return _[_0x4558('0x48')](_0x36e4e1[_0x4558('0x47')])?null:_0x36e4e1[_0x4558('0x47')][_0x4558('0x49')]();}else{logger[_0x4558('0xb')](_0x4558('0x45'),getLogFromObject(_0x36e4e1));return null;}}else{logger['error'](_0x4558('0x4a'));return null;}}catch(_0x15e3a5){logger[_0x4558('0xb')](_0x15e3a5[_0x4558('0x4e')]);return null;}});}logger[_0x4558('0xf')](util['format'](_0x4558('0x4f'),_0x32dcda[_0x4558('0x17')],_0x32dcda[_0x4558('0x18')],_0x32dcda[_0x4558('0x1b')],_0x32dcda[_0x4558('0x1c')],_0x32dcda[_0x4558('0x19')]));logger[_0x4558('0xf')](util[_0x4558('0x13')]('[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s',_0x32dcda[_0x4558('0x42')],_0x32dcda[_0x4558('0x43')],parseInt(_0x32dcda['priority'],0xa)+0x1));_0x32dcda['continueAt'](_0x32dcda[_0x4558('0x42')],_0x32dcda[_0x4558('0x43')],parseInt(_0x32dcda[_0x4558('0x44')],0xa)+0x1);_0x32dcda['close']();}}else{logger[_0x4558('0xb')](util[_0x4558('0x13')](_0x4558('0x50'),_0x32dcda[_0x4558('0x17')]));_0x32dcda[_0x4558('0x51')](_0x32dcda['context'],_0x32dcda[_0x4558('0x43')],parseInt(_0x32dcda[_0x4558('0x44')],0xa)+0x1);_0x32dcda[_0x4558('0x34')]();}}else{logger[_0x4558('0xb')](util[_0x4558('0x13')](_0x4558('0x52'),_0x32dcda[_0x4558('0x17')]));_0x32dcda['continueAt'](_0x32dcda['context'],_0x32dcda[_0x4558('0x43')],parseInt(_0x32dcda[_0x4558('0x44')],0xa)+0x1);_0x32dcda[_0x4558('0x34')]();}}function main(){var _0x3f0b81;return utilLicense[_0x4558('0x53')]()[_0x4558('0x2c')](function(_0x519f8f){if(_0x519f8f){if(_0x519f8f[_0x4558('0x54')]){if(_0x519f8f['callysquare']&&_0x519f8f[_0x4558('0x55')]>0x0){logger[_0x4558('0xf')](util[_0x4558('0x13')](_0x4558('0x56'),_0x519f8f[_0x4558('0x55')]));_0x3f0b81=_0x519f8f[_0x4558('0x55')];}else{logger[_0x4558('0xf')]('[LICENSE]\x20CHANNELS:\x20UNLIMITED');}}else{logger[_0x4558('0xf')](_0x4558('0x57'));_0x3f0b81=-0x1;}}})[_0x4558('0x2d')](function(_0x567199){logger[_0x4558('0xb')](_0x4558('0x58'),_0x567199[_0x4558('0x4e')]);})[_0x4558('0x4b')](function(){var _0x3e6c14=require(_0x4558('0x59'))(config['agi'][_0x4558('0xe')],config[_0x4558('0x9')]['ip'],_0x3f0b81);_0x3e6c14['on']('error',errorHandler);_0x3e6c14['on']('listening',listeningHandler);_0x3e6c14['on'](_0x4558('0x5a'),connectionHandler);_0x3e6c14['on'](_0x4558('0x34'),closeHandler);});}main();