Built motion from commit 3e059bc2.|2.5.32
[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 _0x9e3a=['omit','mxCell','isArray','length','source','addEdge','value','getSquareProject','then','createSquareReport','catch','indexOf','agi_','substring','debug','stringify','close','timeout','hangup','production','start','joinAt','YYYY-MM-DD\x20HH:mm:ss','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','traverseBFS','vertex','agicommand','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','isUndefined','result','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','clear','[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','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]','listening','connection','xml2json','lodash','syncho','util','moment','../../config/logger','agi','./mailRpc','./vertices','127.0.0.1','error','stack','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','port','name','message','[ERROR]\x20%s','arg_1','callerid','dnid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','calleridname','uniqueid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','toJson','mxGraphModel','root','hasOwnProperty','retry','maxRetry'];(function(_0x5d7919,_0x57510e){var _0x2ed755=function(_0x296567){while(--_0x296567){_0x5d7919['push'](_0x5d7919['shift']());}};_0x2ed755(++_0x57510e);}(_0x9e3a,0x195));var _0xa9e3=function(_0x2526c0,_0x1224f5){_0x2526c0=_0x2526c0-0x0;var _0x1e0829=_0x9e3a[_0x2526c0];return _0x1e0829;};'use strict';var parser=require(_0xa9e3('0x0'));var _=require(_0xa9e3('0x1'));var syncho=require(_0xa9e3('0x2'));var util=require(_0xa9e3('0x3'));var moment=require(_0xa9e3('0x4'));var config=require('../../config/environment');var logger=require(_0xa9e3('0x5'))(_0xa9e3('0x6'));var utilLicense=require('../../config/license/util');var rpc=require('./rpc');var mailRpc=require(_0xa9e3('0x7'));var Graph=require('./graph');var Vertices=require(_0xa9e3('0x8'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config[_0xa9e3('0x6')]=_['defaults'](config[_0xa9e3('0x6')],{'ip':_0xa9e3('0x9'),'port':0x11dd});function connectionHandler(_0x1b7103){process['nextTick'](function(){syncho(function(){try{setChannelVariables(_0x1b7103);agiHandler(_0x1b7103);}catch(_0x4f4ed8){logger[_0xa9e3('0xa')](_0x4f4ed8[_0xa9e3('0xb')]);}});});}function listeningHandler(){console[_0xa9e3('0xc')](_0xa9e3('0xd'),config[_0xa9e3('0x6')]['port']);logger[_0xa9e3('0xe')](util[_0xa9e3('0xf')](_0xa9e3('0x10'),config[_0xa9e3('0x6')]['ip'],config['agi'][_0xa9e3('0x11')]));}function errorHandler(_0x5a76de){if(_0x5a76de&&_0x5a76de[_0xa9e3('0x12')]&&_0x5a76de[_0xa9e3('0x13')]){logger['error'](util[_0xa9e3('0xf')]('[%s]\x20%s',_0x5a76de[_0xa9e3('0x12')],_0x5a76de['message']));}else{logger[_0xa9e3('0xa')](util[_0xa9e3('0xf')](_0xa9e3('0x14'),_0x5a76de['stack']));}}function closeHandler(){logger[_0xa9e3('0xe')](util[_0xa9e3('0xf')]('[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0xa9e3('0x15')],this['calleridname'],this[_0xa9e3('0x16')],this[_0xa9e3('0x17')],this['uniqueid']));try{createSquareReport(this);}catch(_0x3c1d5f){logger[_0xa9e3('0xa')](_0x3c1d5f[_0xa9e3('0xb')]);}}function timeoutHandler(){logger[_0xa9e3('0xe')](util[_0xa9e3('0xf')](_0xa9e3('0x18'),this[_0xa9e3('0x15')],this[_0xa9e3('0x19')],this[_0xa9e3('0x16')],this[_0xa9e3('0x17')],this[_0xa9e3('0x1a')]));}function hangupHandler(){logger[_0xa9e3('0xe')](util[_0xa9e3('0xf')](_0xa9e3('0x1b'),this['arg_1'],this[_0xa9e3('0x19')],this[_0xa9e3('0x16')],this[_0xa9e3('0x17')],this[_0xa9e3('0x1a')]));this[_0xa9e3('0x1c')]=!![];}function getRoot(_0x2c3d50){return parser[_0xa9e3('0x1d')](_0x2c3d50,{'object':!![]})[_0xa9e3('0x1e')][_0xa9e3('0x1f')];}function addVertex(_0x4e34ec,_0x593942,_0x1f2848){_0x593942['agicommand']=_0x1f2848;if(_0x593942[_0xa9e3('0x20')](_0xa9e3('0x21'))){_0x593942[_0xa9e3('0x22')]=parseInt(_0x593942['retry'],0xa);}_0x4e34ec['addVertex'](_[_0xa9e3('0x23')](_0x593942,_0xa9e3('0x24')));}function initGraph(_0x223fb6,_0x473e7a){var _0x2d4948=new Graph();for(var _0x8ce6d2 in _0x223fb6){if(_0x223fb6['hasOwnProperty'](_0x8ce6d2)){if(_[_0xa9e3('0x25')](_0x223fb6[_0x8ce6d2])){for(var _0x5367f8=0x0;_0x5367f8<_0x223fb6[_0x8ce6d2][_0xa9e3('0x26')];_0x5367f8+=0x1){addVertex(_0x2d4948,_0x223fb6[_0x8ce6d2][_0x5367f8],_0x8ce6d2);}}else{addVertex(_0x2d4948,_0x223fb6[_0x8ce6d2],_0x8ce6d2);}}}for(var _0x57f709=0x0;_0x57f709<_0x473e7a[_0xa9e3('0x26')];_0x57f709+=0x1){if(_0x473e7a[_0x57f709][_0xa9e3('0x27')]&&_0x473e7a[_0x57f709]['target']){_0x2d4948[_0xa9e3('0x28')](_0x473e7a[_0x57f709][_0xa9e3('0x27')],_0x473e7a[_0x57f709]['target'],_0x473e7a[_0x57f709][_0xa9e3('0x29')]);}}return _0x2d4948;}function getSquareProject(_0x516978,_0x8079e1){rpc[_0xa9e3('0x2a')](_0x516978)[_0xa9e3('0x2b')](function(_0x3345d4){_0x8079e1(null,_0x3345d4);})['catch'](function(_0xea45a8){_0x8079e1(null,_0xea45a8);});}function createSquareReport(_0x4962eb,_0x4d1e89){rpc[_0xa9e3('0x2c')](_0x4962eb)[_0xa9e3('0x2b')](function(_0x3f2a7b){if(_0x4d1e89){_0x4d1e89(null,_0x3f2a7b);}})[_0xa9e3('0x2d')](function(_0x26f5dd){if(_0x4d1e89){_0x4d1e89(null,_0x26f5dd);}});}function setChannelVariables(_0x1758a6){for(var _0x2312d8 in _0x1758a6){if(_0x1758a6[_0xa9e3('0x20')](_0x2312d8)){if(_0x2312d8[_0xa9e3('0x2e')](_0xa9e3('0x2f'))===0x0){_0x1758a6[_0x2312d8[_0xa9e3('0x30')](0x4)]=_0x1758a6[_0x2312d8];delete _0x1758a6[_0x2312d8];}}}}function getLogFromObject(_0x2337a0){return util['inspect'](_0x2337a0,{'showHidden':![],'depth':null});}function agiHandler(_0x1e291e){var _0xecc73f,_0x43dc0b,_0x14cf7a,_0x38a681,_0x101e58;logger[_0xa9e3('0x31')]('variables',JSON[_0xa9e3('0x32')](_0x1e291e,null,0x2));logger[_0xa9e3('0xe')](util[_0xa9e3('0xf')]('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x1e291e[_0xa9e3('0x15')],_0x1e291e[_0xa9e3('0x19')],_0x1e291e[_0xa9e3('0x16')],_0x1e291e[_0xa9e3('0x17')],_0x1e291e['uniqueid']));_0x1e291e['on'](_0xa9e3('0xa'),errorHandler);_0x1e291e['on'](_0xa9e3('0x33'),closeHandler);_0x1e291e['on'](_0xa9e3('0x34'),timeoutHandler);_0x1e291e[_0xa9e3('0x1c')]=![];_0x1e291e['on'](_0xa9e3('0x35'),hangupHandler);var _0xd9b6c1=getSquareProject['sync'](null,_0x1e291e[_0xa9e3('0x15')]);if(_0xd9b6c1){if(_0xd9b6c1[_0xa9e3('0x36')]){_0xecc73f=getRoot(_0xd9b6c1[_0xa9e3('0x36')]);if(_0xecc73f&&_0xecc73f[_0xa9e3('0x37')]){logger['debug'](_0xa9e3('0x1f'),JSON[_0xa9e3('0x32')](_0xecc73f,null,0x2));_0x1e291e[_0xa9e3('0x38')]=moment()[_0xa9e3('0xf')](_0xa9e3('0x39'));_0x43dc0b=initGraph(_[_0xa9e3('0x23')](_0xecc73f,_0xa9e3('0x24')),_0xecc73f['mxCell']);_0x14cf7a=new Vertices(_0x1e291e,rpc,mailRpc);logger[_0xa9e3('0xe')](util[_0xa9e3('0xf')](_0xa9e3('0x3a'),_0x1e291e['arg_1'],_0x1e291e['calleridname'],_0x1e291e[_0xa9e3('0x16')],_0x1e291e[_0xa9e3('0x17')],_0x1e291e[_0xa9e3('0x1a')]));_0x43dc0b[_0xa9e3('0x3b')](_0xecc73f[_0xa9e3('0x37')]['id'],function(_0x341263){try{_0x341263=_0x14cf7a['clear'](_0x341263);logger['debug'](_0xa9e3('0x3c'),JSON[_0xa9e3('0x32')](_0x341263,null,0x2));if(_0x341263[_0xa9e3('0x3d')]==='gotoc'){logger['info'](_0xa9e3('0x3e'));_0x1e291e[_0xa9e3('0x3f')]=_0x341263[_0xa9e3('0x3f')]||_0x1e291e[_0xa9e3('0x3f')];_0x1e291e[_0xa9e3('0x40')]=_0x341263['extension'];_0x1e291e[_0xa9e3('0x41')]=_0x341263[_0xa9e3('0x41')]?_0x341263[_0xa9e3('0x41')]-0x1:0x1;return null;}else if(_0x341263&&_0x14cf7a[_0x341263['agicommand']]){_0x101e58=_0x14cf7a[_0x341263['agicommand']](_0x341263);logger['info'](_0xa9e3('0x42'),JSON[_0xa9e3('0x32')](_0x101e58,null,0x2));if(_0x101e58&&_0x101e58['code']===AGI_CODE_SUCCESS&&_0x101e58['result']!==AGI_RESULT_ERROR&&!_0x1e291e[_0xa9e3('0x1c')]){logger[_0xa9e3('0x31')](_0xa9e3('0x42'),getLogFromObject(_0x101e58));return _[_0xa9e3('0x43')](_0x101e58[_0xa9e3('0x44')])?null:_0x101e58[_0xa9e3('0x44')][_0xa9e3('0x45')]();}else{logger[_0xa9e3('0xa')](_0xa9e3('0x42'),getLogFromObject(_0x101e58));return null;}}else{logger['error'](_0xa9e3('0x46'));return null;}}catch(_0x241b6d){logger['error'](_0x241b6d[_0xa9e3('0xb')]);return null;}});if(_0xecc73f[_0xa9e3('0x47')]){logger[_0xa9e3('0xe')](util[_0xa9e3('0xf')](_0xa9e3('0x48'),_0x1e291e[_0xa9e3('0x15')],_0x1e291e[_0xa9e3('0x19')],_0x1e291e[_0xa9e3('0x16')],_0x1e291e[_0xa9e3('0x17')],_0x1e291e[_0xa9e3('0x1a')]));_0x43dc0b['traverseBFS'](_0xecc73f[_0xa9e3('0x47')]['id'],function(_0x283a9d){try{_0x283a9d=_0x14cf7a[_0xa9e3('0x49')](_0x283a9d);logger['debug'](_0xa9e3('0x3c'),JSON[_0xa9e3('0x32')](_0x283a9d,null,0x2));if(_0x283a9d&&_0x14cf7a[_0x283a9d[_0xa9e3('0x3d')]]){_0x101e58=_0x14cf7a[_0x283a9d[_0xa9e3('0x3d')]](_0x283a9d);if(_0x101e58){logger['debug']('response',getLogFromObject(_0x101e58));return _[_0xa9e3('0x43')](_0x101e58[_0xa9e3('0x44')])?null:_0x101e58[_0xa9e3('0x44')][_0xa9e3('0x45')]();}else{logger[_0xa9e3('0xa')]('response',getLogFromObject(_0x101e58));return null;}}else{logger[_0xa9e3('0xa')]('agicommand\x20not\x20found');return null;}}catch(_0x4078b7){logger[_0xa9e3('0xa')](_0x4078b7['stack']);return null;}});}logger['info'](util[_0xa9e3('0xf')](_0xa9e3('0x4a'),_0x1e291e[_0xa9e3('0x15')],_0x1e291e[_0xa9e3('0x19')],_0x1e291e[_0xa9e3('0x16')],_0x1e291e[_0xa9e3('0x17')],_0x1e291e[_0xa9e3('0x1a')]));logger[_0xa9e3('0xe')](util[_0xa9e3('0xf')](_0xa9e3('0x4b'),_0x1e291e[_0xa9e3('0x3f')],_0x1e291e[_0xa9e3('0x40')],parseInt(_0x1e291e[_0xa9e3('0x41')],0xa)+0x1));_0x1e291e[_0xa9e3('0x4c')](_0x1e291e[_0xa9e3('0x3f')],_0x1e291e[_0xa9e3('0x40')],parseInt(_0x1e291e[_0xa9e3('0x41')],0xa)+0x1);_0x1e291e[_0xa9e3('0x33')]();}}else{logger[_0xa9e3('0xa')](util[_0xa9e3('0xf')](_0xa9e3('0x4d'),_0x1e291e[_0xa9e3('0x15')]));_0x1e291e[_0xa9e3('0x4c')](_0x1e291e[_0xa9e3('0x3f')],_0x1e291e[_0xa9e3('0x40')],parseInt(_0x1e291e[_0xa9e3('0x41')],0xa)+0x1);_0x1e291e[_0xa9e3('0x33')]();}}else{logger[_0xa9e3('0xa')](util[_0xa9e3('0xf')](_0xa9e3('0x4e'),_0x1e291e[_0xa9e3('0x15')]));_0x1e291e[_0xa9e3('0x4c')](_0x1e291e[_0xa9e3('0x3f')],_0x1e291e['extension'],parseInt(_0x1e291e[_0xa9e3('0x41')],0xa)+0x1);_0x1e291e[_0xa9e3('0x33')]();}}function main(){var _0x552190;return utilLicense[_0xa9e3('0x4f')]()[_0xa9e3('0x2b')](function(_0x336f6c){if(_0x336f6c){if(_0x336f6c[_0xa9e3('0x50')]){if(_0x336f6c[_0xa9e3('0x51')]&&_0x336f6c[_0xa9e3('0x51')]>0x0){logger[_0xa9e3('0xe')](util[_0xa9e3('0xf')](_0xa9e3('0x52'),_0x336f6c[_0xa9e3('0x51')]));_0x552190=_0x336f6c['callysquare'];}else{logger['info'](_0xa9e3('0x53'));}}else{logger[_0xa9e3('0xe')](_0xa9e3('0x54'));_0x552190=-0x1;}}})[_0xa9e3('0x2d')](function(_0x4d6399){logger[_0xa9e3('0xa')](_0xa9e3('0x55'),_0x4d6399[_0xa9e3('0xb')]);})[_0xa9e3('0x47')](function(){var _0x311b50=require('./server')(config[_0xa9e3('0x6')][_0xa9e3('0x11')],config[_0xa9e3('0x6')]['ip'],_0x552190);_0x311b50['on']('error',errorHandler);_0x311b50['on'](_0xa9e3('0x56'),listeningHandler);_0x311b50['on'](_0xa9e3('0x57'),connectionHandler);_0x311b50['on'](_0xa9e3('0x33'),closeHandler);});}main();