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 _0xa630=['Project\x20%s\x20not\x20found','voice','callysquare','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','[LICENSE]','./server','listening','xml2json','lodash','moment','../../config/logger','../../config/license/util','./rpc','./mailRpc','./graph','./vertices','defaults','agi','127.0.0.1','nextTick','stack','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','name','message','error','[%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','calleridname','dnid','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','callerid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','mxGraphModel','root','agicommand','hasOwnProperty','retry','mxCell','isArray','length','target','addEdge','source','value','getSquareProject','createSquareReport','then','catch','indexOf','agi_','inspect','debug','variables','stringify','timeout','evtHangup','production','start','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','traverseBFS','clear','vertex','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','code','result','isUndefined','toString','finally','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','agicommand\x20not\x20found','[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s','close','Project\x20%s\x20not\x20published','continueAt'];(function(_0x1f90ee,_0x1e2df9){var _0x49ef50=function(_0x729b70){while(--_0x729b70){_0x1f90ee['push'](_0x1f90ee['shift']());}};_0x49ef50(++_0x1e2df9);}(_0xa630,0xbe));var _0x0a63=function(_0x47811d,_0xadf716){_0x47811d=_0x47811d-0x0;var _0x1ba6cc=_0xa630[_0x47811d];return _0x1ba6cc;};'use strict';var parser=require(_0x0a63('0x0'));var _=require(_0x0a63('0x1'));var syncho=require('syncho');var util=require('util');var moment=require(_0x0a63('0x2'));var config=require('../../config/environment');var logger=require(_0x0a63('0x3'))('agi');var utilLicense=require(_0x0a63('0x4'));var rpc=require(_0x0a63('0x5'));var mailRpc=require(_0x0a63('0x6'));var Graph=require(_0x0a63('0x7'));var Vertices=require(_0x0a63('0x8'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config['agi']=_[_0x0a63('0x9')](config[_0x0a63('0xa')],{'ip':_0x0a63('0xb'),'port':0x11dd});function connectionHandler(_0x41d21d){process[_0x0a63('0xc')](function(){syncho(function(){try{setChannelVariables(_0x41d21d);agiHandler(_0x41d21d);}catch(_0x2a1bd7){logger['error'](_0x2a1bd7[_0x0a63('0xd')]);}});});}function listeningHandler(){console[_0x0a63('0xe')](_0x0a63('0xf'),config[_0x0a63('0xa')][_0x0a63('0x10')]);logger[_0x0a63('0x11')](util[_0x0a63('0x12')](_0x0a63('0x13'),config[_0x0a63('0xa')]['ip'],config[_0x0a63('0xa')]['port']));}function errorHandler(_0x345f56){if(_0x345f56&&_0x345f56[_0x0a63('0x14')]&&_0x345f56[_0x0a63('0x15')]){logger[_0x0a63('0x16')](util['format'](_0x0a63('0x17'),_0x345f56['name'],_0x345f56[_0x0a63('0x15')]));}else{logger[_0x0a63('0x16')](util[_0x0a63('0x12')](_0x0a63('0x18'),_0x345f56[_0x0a63('0xd')]));}}function closeHandler(){logger[_0x0a63('0x11')](util[_0x0a63('0x12')](_0x0a63('0x19'),this['arg_1'],this[_0x0a63('0x1a')],this['callerid'],this[_0x0a63('0x1b')],this[_0x0a63('0x1c')]));try{createSquareReport(this);}catch(_0x36a9e8){logger[_0x0a63('0x16')](_0x36a9e8[_0x0a63('0xd')]);}}function timeoutHandler(){logger[_0x0a63('0x11')](util[_0x0a63('0x12')](_0x0a63('0x1d'),this[_0x0a63('0x1e')],this[_0x0a63('0x1a')],this[_0x0a63('0x1f')],this['dnid'],this['uniqueid']));}function hangupHandler(){logger[_0x0a63('0x11')](util['format'](_0x0a63('0x20'),this['arg_1'],this[_0x0a63('0x1a')],this[_0x0a63('0x1f')],this[_0x0a63('0x1b')],this[_0x0a63('0x1c')]));this['evtHangup']=!![];}function getRoot(_0x398a16){return parser['toJson'](_0x398a16,{'object':!![]})[_0x0a63('0x21')][_0x0a63('0x22')];}function addVertex(_0x1bf64a,_0x20c114,_0x343273){_0x20c114[_0x0a63('0x23')]=_0x343273;if(_0x20c114[_0x0a63('0x24')](_0x0a63('0x25'))){_0x20c114['maxRetry']=parseInt(_0x20c114['retry'],0xa);}_0x1bf64a['addVertex'](_['omit'](_0x20c114,_0x0a63('0x26')));}function initGraph(_0x4916b1,_0x496c93){var _0x2133cf=new Graph();for(var _0x1d5448 in _0x4916b1){if(_0x4916b1[_0x0a63('0x24')](_0x1d5448)){if(_[_0x0a63('0x27')](_0x4916b1[_0x1d5448])){for(var _0x52e7ef=0x0;_0x52e7ef<_0x4916b1[_0x1d5448][_0x0a63('0x28')];_0x52e7ef+=0x1){addVertex(_0x2133cf,_0x4916b1[_0x1d5448][_0x52e7ef],_0x1d5448);}}else{addVertex(_0x2133cf,_0x4916b1[_0x1d5448],_0x1d5448);}}}for(var _0x498371=0x0;_0x498371<_0x496c93[_0x0a63('0x28')];_0x498371+=0x1){if(_0x496c93[_0x498371]['source']&&_0x496c93[_0x498371][_0x0a63('0x29')]){_0x2133cf[_0x0a63('0x2a')](_0x496c93[_0x498371][_0x0a63('0x2b')],_0x496c93[_0x498371][_0x0a63('0x29')],_0x496c93[_0x498371][_0x0a63('0x2c')]);}}return _0x2133cf;}function getSquareProject(_0x4577b6,_0x23fcf3){rpc[_0x0a63('0x2d')](_0x4577b6)['then'](function(_0x58cc71){_0x23fcf3(null,_0x58cc71);})['catch'](function(_0x151cb6){_0x23fcf3(null,_0x151cb6);});}function createSquareReport(_0xc8caf6,_0x30cebd){rpc[_0x0a63('0x2e')](_0xc8caf6)[_0x0a63('0x2f')](function(_0x53a46b){if(_0x30cebd){_0x30cebd(null,_0x53a46b);}})[_0x0a63('0x30')](function(_0x2884f1){if(_0x30cebd){_0x30cebd(null,_0x2884f1);}});}function setChannelVariables(_0x33a717){for(var _0x46fb40 in _0x33a717){if(_0x33a717['hasOwnProperty'](_0x46fb40)){if(_0x46fb40[_0x0a63('0x31')](_0x0a63('0x32'))===0x0){_0x33a717[_0x46fb40['substring'](0x4)]=_0x33a717[_0x46fb40];delete _0x33a717[_0x46fb40];}}}}function getLogFromObject(_0x4a7145){return util[_0x0a63('0x33')](_0x4a7145,{'showHidden':![],'depth':null});}function agiHandler(_0x51d959){var _0x5708fc,_0x3bd154,_0x3fd128,_0x58201a,_0xfd1e09;logger[_0x0a63('0x34')](_0x0a63('0x35'),JSON[_0x0a63('0x36')](_0x51d959,null,0x2));logger[_0x0a63('0x11')](util['format']('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x51d959[_0x0a63('0x1e')],_0x51d959[_0x0a63('0x1a')],_0x51d959[_0x0a63('0x1f')],_0x51d959[_0x0a63('0x1b')],_0x51d959[_0x0a63('0x1c')]));_0x51d959['on'](_0x0a63('0x16'),errorHandler);_0x51d959['on']('close',closeHandler);_0x51d959['on'](_0x0a63('0x37'),timeoutHandler);_0x51d959[_0x0a63('0x38')]=![];_0x51d959['on']('hangup',hangupHandler);var _0xf9c6ea=getSquareProject['sync'](null,_0x51d959['arg_1']);if(_0xf9c6ea){if(_0xf9c6ea[_0x0a63('0x39')]){_0x5708fc=getRoot(_0xf9c6ea[_0x0a63('0x39')]);if(_0x5708fc&&_0x5708fc[_0x0a63('0x3a')]){logger['debug'](_0x0a63('0x22'),JSON[_0x0a63('0x36')](_0x5708fc,null,0x2));_0x51d959[_0x0a63('0x3b')]=moment()[_0x0a63('0x12')](_0x0a63('0x3c'));_0x3bd154=initGraph(_[_0x0a63('0x3d')](_0x5708fc,_0x0a63('0x26')),_0x5708fc['mxCell']);_0x3fd128=new Vertices(_0x51d959,rpc,mailRpc);logger[_0x0a63('0x11')](util[_0x0a63('0x12')](_0x0a63('0x3e'),_0x51d959['arg_1'],_0x51d959['calleridname'],_0x51d959[_0x0a63('0x1f')],_0x51d959['dnid'],_0x51d959[_0x0a63('0x1c')]));_0x3bd154[_0x0a63('0x3f')](_0x5708fc[_0x0a63('0x3a')]['id'],function(_0x5c7b78){try{_0x5c7b78=_0x3fd128[_0x0a63('0x40')](_0x5c7b78);logger[_0x0a63('0x34')](_0x0a63('0x41'),JSON[_0x0a63('0x36')](_0x5c7b78,null,0x2));if(_0x5c7b78['agicommand']===_0x0a63('0x42')){logger[_0x0a63('0x11')](_0x0a63('0x43'));_0x51d959[_0x0a63('0x44')]=_0x5c7b78[_0x0a63('0x44')]||_0x51d959[_0x0a63('0x44')];_0x51d959['extension']=_0x5c7b78[_0x0a63('0x45')];_0x51d959[_0x0a63('0x46')]=_0x5c7b78[_0x0a63('0x46')]?_0x5c7b78[_0x0a63('0x46')]-0x1:0x1;return null;}else if(_0x5c7b78&&_0x3fd128[_0x5c7b78[_0x0a63('0x23')]]){_0xfd1e09=_0x3fd128[_0x5c7b78[_0x0a63('0x23')]](_0x5c7b78);logger[_0x0a63('0x11')](_0x0a63('0x47'),JSON[_0x0a63('0x36')](_0xfd1e09,null,0x2));if(_0xfd1e09&&_0xfd1e09[_0x0a63('0x48')]===AGI_CODE_SUCCESS&&_0xfd1e09[_0x0a63('0x49')]!==AGI_RESULT_ERROR&&!_0x51d959[_0x0a63('0x38')]){logger[_0x0a63('0x34')](_0x0a63('0x47'),getLogFromObject(_0xfd1e09));return _[_0x0a63('0x4a')](_0xfd1e09[_0x0a63('0x49')])?null:_0xfd1e09[_0x0a63('0x49')][_0x0a63('0x4b')]();}else{logger['error'](_0x0a63('0x47'),getLogFromObject(_0xfd1e09));return null;}}else{logger['error']('agicommand\x20not\x20found');return null;}}catch(_0xd9eddc){logger[_0x0a63('0x16')](_0xd9eddc[_0x0a63('0xd')]);return null;}});if(_0x5708fc[_0x0a63('0x4c')]){logger[_0x0a63('0x11')](util[_0x0a63('0x12')](_0x0a63('0x4d'),_0x51d959[_0x0a63('0x1e')],_0x51d959[_0x0a63('0x1a')],_0x51d959[_0x0a63('0x1f')],_0x51d959[_0x0a63('0x1b')],_0x51d959[_0x0a63('0x1c')]));_0x3bd154[_0x0a63('0x3f')](_0x5708fc[_0x0a63('0x4c')]['id'],function(_0x459d1c){try{_0x459d1c=_0x3fd128[_0x0a63('0x40')](_0x459d1c);logger[_0x0a63('0x34')](_0x0a63('0x41'),JSON[_0x0a63('0x36')](_0x459d1c,null,0x2));if(_0x459d1c&&_0x3fd128[_0x459d1c[_0x0a63('0x23')]]){_0xfd1e09=_0x3fd128[_0x459d1c['agicommand']](_0x459d1c);if(_0xfd1e09){logger[_0x0a63('0x34')](_0x0a63('0x47'),getLogFromObject(_0xfd1e09));return _['isUndefined'](_0xfd1e09['result'])?null:_0xfd1e09['result']['toString']();}else{logger[_0x0a63('0x16')](_0x0a63('0x47'),getLogFromObject(_0xfd1e09));return null;}}else{logger['error'](_0x0a63('0x4e'));return null;}}catch(_0x59c367){logger[_0x0a63('0x16')](_0x59c367[_0x0a63('0xd')]);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',_0x51d959[_0x0a63('0x1e')],_0x51d959[_0x0a63('0x1a')],_0x51d959[_0x0a63('0x1f')],_0x51d959[_0x0a63('0x1b')],_0x51d959[_0x0a63('0x1c')]));logger['info'](util[_0x0a63('0x12')](_0x0a63('0x4f'),_0x51d959[_0x0a63('0x44')],_0x51d959[_0x0a63('0x45')],parseInt(_0x51d959[_0x0a63('0x46')],0xa)+0x1));_0x51d959['continueAt'](_0x51d959[_0x0a63('0x44')],_0x51d959[_0x0a63('0x45')],parseInt(_0x51d959[_0x0a63('0x46')],0xa)+0x1);_0x51d959[_0x0a63('0x50')]();}}else{logger['error'](util[_0x0a63('0x12')](_0x0a63('0x51'),_0x51d959[_0x0a63('0x1e')]));_0x51d959[_0x0a63('0x52')](_0x51d959[_0x0a63('0x44')],_0x51d959[_0x0a63('0x45')],parseInt(_0x51d959['priority'],0xa)+0x1);_0x51d959[_0x0a63('0x50')]();}}else{logger[_0x0a63('0x16')](util[_0x0a63('0x12')](_0x0a63('0x53'),_0x51d959['arg_1']));_0x51d959['continueAt'](_0x51d959[_0x0a63('0x44')],_0x51d959[_0x0a63('0x45')],parseInt(_0x51d959[_0x0a63('0x46')],0xa)+0x1);_0x51d959[_0x0a63('0x50')]();}}function main(){var _0x12c3e5;return utilLicense['getLicense']()['then'](function(_0x58b3a8){if(_0x58b3a8){if(_0x58b3a8[_0x0a63('0x54')]){if(_0x58b3a8['callysquare']&&_0x58b3a8[_0x0a63('0x55')]>0x0){logger[_0x0a63('0x11')](util[_0x0a63('0x12')]('[LICENSE]\x20CHANNELS:\x20%s',_0x58b3a8['callysquare']));_0x12c3e5=_0x58b3a8[_0x0a63('0x55')];}else{logger[_0x0a63('0x11')](_0x0a63('0x56'));}}else{logger[_0x0a63('0x11')](_0x0a63('0x57'));_0x12c3e5=-0x1;}}})[_0x0a63('0x30')](function(_0x21502e){logger[_0x0a63('0x16')](_0x0a63('0x58'),_0x21502e[_0x0a63('0xd')]);})[_0x0a63('0x4c')](function(){var _0x345b1d=require(_0x0a63('0x59'))(config[_0x0a63('0xa')]['port'],config['agi']['ip'],_0x12c3e5);_0x345b1d['on'](_0x0a63('0x16'),errorHandler);_0x345b1d['on'](_0x0a63('0x5a'),listeningHandler);_0x345b1d['on']('connection',connectionHandler);_0x345b1d['on'](_0x0a63('0x50'),closeHandler);});}main();