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 _0xc306=['value','getSquareProject','catch','createSquareReport','then','indexOf','substring','inspect','debug','variables','stringify','close','timeout','hangup','sync','production','SQUAREROOT','joinAt','YYYY-MM-DD\x20HH:mm:ss','omit','vertices','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','LOOP\x20through\x20graph','traverseBFS','clear','VERTEX','gotoc','context','extension','priority','vresponse','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','[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','continueAt','Project\x20%s\x20not\x20published','Project\x20%s\x20not\x20found','getLicense','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20VOICE\x20IS\x20DISABLED','[LICENSE]','listening','connection','xml2json','syncho','util','moment','../../config/environment','../../config/logger','../../config/license/util','./mailRpc','./graph','./vertices','agi','defaults','127.0.0.1','nextTick','error','log','port','name','message','format','[ERROR]\x20%s','stack','info','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','calleridname','callerid','dnid','uniqueid','[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','toJson','mxGraphModel','root','agicommand','hasOwnProperty','retry','maxRetry','addVertex','mxCell','length','source','target','addEdge'];(function(_0x10b67e,_0x440062){var _0x2d688a=function(_0x4e9982){while(--_0x4e9982){_0x10b67e['push'](_0x10b67e['shift']());}};_0x2d688a(++_0x440062);}(_0xc306,0x1a9));var _0x6c30=function(_0x2ff56a,_0x305966){_0x2ff56a=_0x2ff56a-0x0;var _0x18a66d=_0xc306[_0x2ff56a];return _0x18a66d;};'use strict';var parser=require(_0x6c30('0x0'));var _=require('lodash');var syncho=require(_0x6c30('0x1'));var util=require(_0x6c30('0x2'));var moment=require(_0x6c30('0x3'));var config=require(_0x6c30('0x4'));var logger=require(_0x6c30('0x5'))('agi');var utilLicense=require(_0x6c30('0x6'));var rpc=require('./rpc');var mailRpc=require(_0x6c30('0x7'));var Graph=require(_0x6c30('0x8'));var Vertices=require(_0x6c30('0x9'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config[_0x6c30('0xa')]=_[_0x6c30('0xb')](config[_0x6c30('0xa')],{'ip':_0x6c30('0xc'),'port':0x11dd});function connectionHandler(_0x4e0017){process[_0x6c30('0xd')](function(){syncho(function(){try{setChannelVariables(_0x4e0017);agiHandler(_0x4e0017);}catch(_0x3f937a){logger[_0x6c30('0xe')](_0x3f937a['stack']);}});});}function listeningHandler(){console[_0x6c30('0xf')]('Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!',config['agi'][_0x6c30('0x10')]);logger['info'](util['format']('[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d',config[_0x6c30('0xa')]['ip'],config[_0x6c30('0xa')][_0x6c30('0x10')]));}function errorHandler(_0x4db908){if(_0x4db908&&_0x4db908[_0x6c30('0x11')]&&_0x4db908['message']){logger[_0x6c30('0xe')](util['format']('[%s]\x20%s',_0x4db908[_0x6c30('0x11')],_0x4db908[_0x6c30('0x12')]));}else{logger['error'](util[_0x6c30('0x13')](_0x6c30('0x14'),_0x4db908[_0x6c30('0x15')]));}}function closeHandler(){logger[_0x6c30('0x16')](util['format'](_0x6c30('0x17'),this[_0x6c30('0x18')],this[_0x6c30('0x19')],this[_0x6c30('0x1a')],this[_0x6c30('0x1b')],this[_0x6c30('0x1c')]));try{createSquareReport(this);}catch(_0x439581){logger[_0x6c30('0xe')](_0x439581[_0x6c30('0x15')]);}}function timeoutHandler(){logger[_0x6c30('0x16')](util['format'](_0x6c30('0x1d'),this[_0x6c30('0x18')],this[_0x6c30('0x19')],this[_0x6c30('0x1a')],this[_0x6c30('0x1b')],this['uniqueid']));}function hangupHandler(){logger[_0x6c30('0x16')](util[_0x6c30('0x13')](_0x6c30('0x1e'),this[_0x6c30('0x18')],this[_0x6c30('0x19')],this[_0x6c30('0x1a')],this['dnid'],this['uniqueid']));this[_0x6c30('0x1f')]=!![];}function getRoot(_0x4688fa){return parser[_0x6c30('0x20')](_0x4688fa,{'object':!![]})[_0x6c30('0x21')][_0x6c30('0x22')];}function addVertex(_0x34ddb6,_0x17c025,_0x726de6){_0x17c025[_0x6c30('0x23')]=_0x726de6;if(_0x17c025[_0x6c30('0x24')](_0x6c30('0x25'))){_0x17c025[_0x6c30('0x26')]=parseInt(_0x17c025[_0x6c30('0x25')],0xa);}_0x34ddb6[_0x6c30('0x27')](_['omit'](_0x17c025,_0x6c30('0x28')));}function initGraph(_0x1152f3,_0x56f3eb){var _0x190693=new Graph();for(var _0x6fc3f8 in _0x1152f3){if(_0x1152f3[_0x6c30('0x24')](_0x6fc3f8)){if(_['isArray'](_0x1152f3[_0x6fc3f8])){for(var _0x2706ae=0x0;_0x2706ae<_0x1152f3[_0x6fc3f8][_0x6c30('0x29')];_0x2706ae+=0x1){addVertex(_0x190693,_0x1152f3[_0x6fc3f8][_0x2706ae],_0x6fc3f8);}}else{addVertex(_0x190693,_0x1152f3[_0x6fc3f8],_0x6fc3f8);}}}for(var _0x3471dc=0x0;_0x3471dc<_0x56f3eb[_0x6c30('0x29')];_0x3471dc+=0x1){if(_0x56f3eb[_0x3471dc][_0x6c30('0x2a')]&&_0x56f3eb[_0x3471dc][_0x6c30('0x2b')]){_0x190693[_0x6c30('0x2c')](_0x56f3eb[_0x3471dc][_0x6c30('0x2a')],_0x56f3eb[_0x3471dc]['target'],_0x56f3eb[_0x3471dc][_0x6c30('0x2d')]);}}return _0x190693;}function getSquareProject(_0x2ff96a,_0x231ec0){rpc[_0x6c30('0x2e')](_0x2ff96a)['then'](function(_0x5b0990){_0x231ec0(null,_0x5b0990);})[_0x6c30('0x2f')](function(_0x53551f){_0x231ec0(null,_0x53551f);});}function createSquareReport(_0x29bc69,_0x428f61){rpc[_0x6c30('0x30')](_0x29bc69)[_0x6c30('0x31')](function(_0x2a14f7){if(_0x428f61){_0x428f61(null,_0x2a14f7);}})[_0x6c30('0x2f')](function(_0x16dd6f){if(_0x428f61){_0x428f61(null,_0x16dd6f);}});}function setChannelVariables(_0x27ddc4){for(var _0x4ec2a9 in _0x27ddc4){if(_0x27ddc4[_0x6c30('0x24')](_0x4ec2a9)){if(_0x4ec2a9[_0x6c30('0x32')]('agi_')===0x0){_0x27ddc4[_0x4ec2a9[_0x6c30('0x33')](0x4)]=_0x27ddc4[_0x4ec2a9];delete _0x27ddc4[_0x4ec2a9];}}}}function getLogFromObject(_0x1e9997){return util[_0x6c30('0x34')](_0x1e9997,{'showHidden':![],'depth':null});}function agiHandler(_0x4cf1c5){var _0x57153e,_0x11612c,_0x4c5a45,_0x5e852c,_0x5d1f3e;logger[_0x6c30('0x35')](_0x6c30('0x36'),JSON[_0x6c30('0x37')](_0x4cf1c5,null,0x2));logger[_0x6c30('0x16')](util[_0x6c30('0x13')]('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x4cf1c5['arg_1'],_0x4cf1c5[_0x6c30('0x19')],_0x4cf1c5['callerid'],_0x4cf1c5['dnid'],_0x4cf1c5[_0x6c30('0x1c')]));_0x4cf1c5['on'](_0x6c30('0xe'),errorHandler);_0x4cf1c5['on'](_0x6c30('0x38'),closeHandler);_0x4cf1c5['on'](_0x6c30('0x39'),timeoutHandler);_0x4cf1c5[_0x6c30('0x1f')]=![];_0x4cf1c5['on'](_0x6c30('0x3a'),hangupHandler);var _0x472664=getSquareProject[_0x6c30('0x3b')](null,_0x4cf1c5[_0x6c30('0x18')]);if(_0x472664){if(_0x472664[_0x6c30('0x3c')]){_0x57153e=getRoot(_0x472664[_0x6c30('0x3c')]);console[_0x6c30('0xf')](_0x6c30('0x3d'),_0x57153e);if(_0x57153e&&_0x57153e['start']){logger[_0x6c30('0x35')](_0x6c30('0x22'),JSON[_0x6c30('0x37')](_0x57153e,null,0x2));_0x4cf1c5[_0x6c30('0x3e')]=moment()[_0x6c30('0x13')](_0x6c30('0x3f'));_0x11612c=initGraph(_[_0x6c30('0x40')](_0x57153e,_0x6c30('0x28')),_0x57153e[_0x6c30('0x28')]);_0x4c5a45=new Vertices(_0x4cf1c5,rpc,mailRpc);console['log'](_0x6c30('0x41'),_0x4c5a45);logger[_0x6c30('0x16')](util[_0x6c30('0x13')](_0x6c30('0x42'),_0x4cf1c5[_0x6c30('0x18')],_0x4cf1c5['calleridname'],_0x4cf1c5[_0x6c30('0x1a')],_0x4cf1c5[_0x6c30('0x1b')],_0x4cf1c5[_0x6c30('0x1c')]));console[_0x6c30('0xf')](_0x6c30('0x43'));_0x11612c[_0x6c30('0x44')](_0x57153e['start']['id'],function(_0x3e29a1){try{_0x3e29a1=_0x4c5a45[_0x6c30('0x45')](_0x3e29a1);logger['debug']('vertex',JSON[_0x6c30('0x37')](_0x3e29a1,null,0x2));console[_0x6c30('0xf')](_0x6c30('0x46'),_0x3e29a1);if(_0x3e29a1[_0x6c30('0x23')]===_0x6c30('0x47')){logger[_0x6c30('0x16')]('gotoc\x20block\x20stop\x20traverse\x20BFS');_0x4cf1c5[_0x6c30('0x48')]=_0x3e29a1['context']||_0x4cf1c5[_0x6c30('0x48')];_0x4cf1c5[_0x6c30('0x49')]=_0x3e29a1[_0x6c30('0x49')];_0x4cf1c5['priority']=_0x3e29a1[_0x6c30('0x4a')]?_0x3e29a1[_0x6c30('0x4a')]-0x1:0x1;return null;}else if(_0x3e29a1&&_0x4c5a45[_0x3e29a1['agicommand']]){_0x5d1f3e=_0x4c5a45[_0x3e29a1[_0x6c30('0x23')]](_0x3e29a1);console[_0x6c30('0xf')](_0x6c30('0x4b'),_0x5d1f3e);logger['info'](_0x6c30('0x4c'),JSON['stringify'](_0x5d1f3e,null,0x2));if(_0x5d1f3e&&_0x5d1f3e['code']===AGI_CODE_SUCCESS&&_0x5d1f3e['result']!==AGI_RESULT_ERROR&&!_0x4cf1c5[_0x6c30('0x1f')]){logger[_0x6c30('0x35')](_0x6c30('0x4c'),getLogFromObject(_0x5d1f3e));return _[_0x6c30('0x4d')](_0x5d1f3e['result'])?null:_0x5d1f3e[_0x6c30('0x4e')][_0x6c30('0x4f')]();}else{logger[_0x6c30('0xe')](_0x6c30('0x4c'),getLogFromObject(_0x5d1f3e));return null;}}else{logger['error'](_0x6c30('0x50'));return null;}}catch(_0x20891a){logger[_0x6c30('0xe')](_0x20891a[_0x6c30('0x15')]);return null;}});if(_0x57153e[_0x6c30('0x51')]){logger[_0x6c30('0x16')](util['format'](_0x6c30('0x52'),_0x4cf1c5[_0x6c30('0x18')],_0x4cf1c5[_0x6c30('0x19')],_0x4cf1c5['callerid'],_0x4cf1c5['dnid'],_0x4cf1c5['uniqueid']));_0x11612c[_0x6c30('0x44')](_0x57153e[_0x6c30('0x51')]['id'],function(_0x1c02c2){try{_0x1c02c2=_0x4c5a45[_0x6c30('0x45')](_0x1c02c2);logger[_0x6c30('0x35')]('vertex',JSON[_0x6c30('0x37')](_0x1c02c2,null,0x2));if(_0x1c02c2&&_0x4c5a45[_0x1c02c2[_0x6c30('0x23')]]){_0x5d1f3e=_0x4c5a45[_0x1c02c2[_0x6c30('0x23')]](_0x1c02c2);if(_0x5d1f3e){logger[_0x6c30('0x35')](_0x6c30('0x4c'),getLogFromObject(_0x5d1f3e));return _[_0x6c30('0x4d')](_0x5d1f3e[_0x6c30('0x4e')])?null:_0x5d1f3e[_0x6c30('0x4e')][_0x6c30('0x4f')]();}else{logger[_0x6c30('0xe')](_0x6c30('0x4c'),getLogFromObject(_0x5d1f3e));return null;}}else{logger['error'](_0x6c30('0x50'));return null;}}catch(_0x29f9d0){logger[_0x6c30('0xe')](_0x29f9d0[_0x6c30('0x15')]);return null;}});}logger[_0x6c30('0x16')](util[_0x6c30('0x13')](_0x6c30('0x53'),_0x4cf1c5[_0x6c30('0x18')],_0x4cf1c5[_0x6c30('0x19')],_0x4cf1c5['callerid'],_0x4cf1c5[_0x6c30('0x1b')],_0x4cf1c5[_0x6c30('0x1c')]));logger['info'](util[_0x6c30('0x13')]('[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s',_0x4cf1c5[_0x6c30('0x48')],_0x4cf1c5['extension'],parseInt(_0x4cf1c5[_0x6c30('0x4a')],0xa)+0x1));_0x4cf1c5[_0x6c30('0x54')](_0x4cf1c5[_0x6c30('0x48')],_0x4cf1c5[_0x6c30('0x49')],parseInt(_0x4cf1c5[_0x6c30('0x4a')],0xa)+0x1);_0x4cf1c5[_0x6c30('0x38')]();}}else{logger[_0x6c30('0xe')](util[_0x6c30('0x13')](_0x6c30('0x55'),_0x4cf1c5[_0x6c30('0x18')]));_0x4cf1c5[_0x6c30('0x54')](_0x4cf1c5['context'],_0x4cf1c5['extension'],parseInt(_0x4cf1c5['priority'],0xa)+0x1);_0x4cf1c5[_0x6c30('0x38')]();}}else{logger['error'](util['format'](_0x6c30('0x56'),_0x4cf1c5[_0x6c30('0x18')]));_0x4cf1c5[_0x6c30('0x54')](_0x4cf1c5[_0x6c30('0x48')],_0x4cf1c5[_0x6c30('0x49')],parseInt(_0x4cf1c5['priority'],0xa)+0x1);_0x4cf1c5[_0x6c30('0x38')]();}}function main(){var _0x5d7432;return utilLicense[_0x6c30('0x57')]()[_0x6c30('0x31')](function(_0x11df70){if(_0x11df70){if(_0x11df70['voice']){if(_0x11df70[_0x6c30('0x58')]&&_0x11df70[_0x6c30('0x58')]>0x0){logger[_0x6c30('0x16')](util[_0x6c30('0x13')](_0x6c30('0x59'),_0x11df70[_0x6c30('0x58')]));_0x5d7432=_0x11df70[_0x6c30('0x58')];}else{logger[_0x6c30('0x16')]('[LICENSE]\x20CHANNELS:\x20UNLIMITED');}}else{logger[_0x6c30('0x16')](_0x6c30('0x5a'));_0x5d7432=-0x1;}}})[_0x6c30('0x2f')](function(_0x33cbf8){logger[_0x6c30('0xe')](_0x6c30('0x5b'),_0x33cbf8['stack']);})['finally'](function(){var _0x115efb=require('./server')(config[_0x6c30('0xa')][_0x6c30('0x10')],config[_0x6c30('0xa')]['ip'],_0x5d7432);_0x115efb['on'](_0x6c30('0xe'),errorHandler);_0x115efb['on'](_0x6c30('0x5c'),listeningHandler);_0x115efb['on'](_0x6c30('0x5d'),connectionHandler);_0x115efb['on'](_0x6c30('0x38'),closeHandler);});}main();