Built motion from commit (unavailable).|2.5.31
[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 _0xf725=['inspect','debug','stringify','[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','close','timeout','hangup','sync','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','vertex','gotoc','context','extension','priority','response','code','result','isUndefined','agicommand\x20not\x20found','finally','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','toString','[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','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20%s','[LICENSE]\x20VOICE\x20IS\x20DISABLED','listening','connection','xml2json','lodash','syncho','util','moment','../../config/environment','../../config/logger','agi','../../config/license/util','./rpc','./graph','./vertices','defaults','127.0.0.1','error','stack','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','port','message','[%s]\x20%s','name','arg_1','callerid','dnid','calleridname','uniqueid','evtHangup','toJson','mxGraphModel','root','agicommand','hasOwnProperty','retry','addVertex','mxCell','isArray','length','source','addEdge','target','value','getSquareProject','catch','createSquareReport','then','indexOf','substring'];(function(_0x3b9b2e,_0x1d3afe){var _0x3e1a74=function(_0x1d5439){while(--_0x1d5439){_0x3b9b2e['push'](_0x3b9b2e['shift']());}};_0x3e1a74(++_0x1d3afe);}(_0xf725,0x7e));var _0x5f72=function(_0x3d611a,_0x215cf1){_0x3d611a=_0x3d611a-0x0;var _0x57182f=_0xf725[_0x3d611a];return _0x57182f;};'use strict';var parser=require(_0x5f72('0x0'));var _=require(_0x5f72('0x1'));var syncho=require(_0x5f72('0x2'));var util=require(_0x5f72('0x3'));var moment=require(_0x5f72('0x4'));var config=require(_0x5f72('0x5'));var logger=require(_0x5f72('0x6'))(_0x5f72('0x7'));var utilLicense=require(_0x5f72('0x8'));var rpc=require(_0x5f72('0x9'));var mailRpc=require('./mailRpc');var Graph=require(_0x5f72('0xa'));var Vertices=require(_0x5f72('0xb'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config[_0x5f72('0x7')]=_[_0x5f72('0xc')](config[_0x5f72('0x7')],{'ip':_0x5f72('0xd'),'port':0x11dd});function connectionHandler(_0x158aa3){process['nextTick'](function(){syncho(function(){try{setChannelVariables(_0x158aa3);agiHandler(_0x158aa3);}catch(_0x499e28){logger[_0x5f72('0xe')](_0x499e28[_0x5f72('0xf')]);}});});}function listeningHandler(){console['log'](_0x5f72('0x10'),config[_0x5f72('0x7')]['port']);logger[_0x5f72('0x11')](util[_0x5f72('0x12')](_0x5f72('0x13'),config[_0x5f72('0x7')]['ip'],config[_0x5f72('0x7')][_0x5f72('0x14')]));}function errorHandler(_0x1446f1){if(_0x1446f1&&_0x1446f1['name']&&_0x1446f1[_0x5f72('0x15')]){logger[_0x5f72('0xe')](util[_0x5f72('0x12')](_0x5f72('0x16'),_0x1446f1[_0x5f72('0x17')],_0x1446f1['message']));}else{logger[_0x5f72('0xe')](util['format']('[ERROR]\x20%s',_0x1446f1[_0x5f72('0xf')]));}}function closeHandler(){logger['info'](util[_0x5f72('0x12')]('[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0x5f72('0x18')],this['calleridname'],this[_0x5f72('0x19')],this[_0x5f72('0x1a')],this['uniqueid']));try{createSquareReport(this);}catch(_0xea99d5){logger[_0x5f72('0xe')](_0xea99d5[_0x5f72('0xf')]);}}function timeoutHandler(){logger['info'](util['format']('[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0x5f72('0x18')],this[_0x5f72('0x1b')],this[_0x5f72('0x19')],this[_0x5f72('0x1a')],this[_0x5f72('0x1c')]));}function hangupHandler(){logger[_0x5f72('0x11')](util[_0x5f72('0x12')]('[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0x5f72('0x18')],this[_0x5f72('0x1b')],this[_0x5f72('0x19')],this[_0x5f72('0x1a')],this[_0x5f72('0x1c')]));this[_0x5f72('0x1d')]=!![];}function getRoot(_0x30235e){return parser[_0x5f72('0x1e')](_0x30235e,{'object':!![]})[_0x5f72('0x1f')][_0x5f72('0x20')];}function addVertex(_0x21c7d2,_0x530009,_0x433935){_0x530009[_0x5f72('0x21')]=_0x433935;if(_0x530009[_0x5f72('0x22')](_0x5f72('0x23'))){_0x530009['maxRetry']=parseInt(_0x530009[_0x5f72('0x23')],0xa);}_0x21c7d2[_0x5f72('0x24')](_['omit'](_0x530009,_0x5f72('0x25')));}function initGraph(_0x3bb0a6,_0x347723){var _0x521174=new Graph();for(var _0x58ff77 in _0x3bb0a6){if(_0x3bb0a6[_0x5f72('0x22')](_0x58ff77)){if(_[_0x5f72('0x26')](_0x3bb0a6[_0x58ff77])){for(var _0x3936ed=0x0;_0x3936ed<_0x3bb0a6[_0x58ff77][_0x5f72('0x27')];_0x3936ed+=0x1){addVertex(_0x521174,_0x3bb0a6[_0x58ff77][_0x3936ed],_0x58ff77);}}else{addVertex(_0x521174,_0x3bb0a6[_0x58ff77],_0x58ff77);}}}for(var _0x1c3d8f=0x0;_0x1c3d8f<_0x347723[_0x5f72('0x27')];_0x1c3d8f+=0x1){if(_0x347723[_0x1c3d8f][_0x5f72('0x28')]&&_0x347723[_0x1c3d8f]['target']){_0x521174[_0x5f72('0x29')](_0x347723[_0x1c3d8f]['source'],_0x347723[_0x1c3d8f][_0x5f72('0x2a')],_0x347723[_0x1c3d8f][_0x5f72('0x2b')]);}}return _0x521174;}function getSquareProject(_0x7cce31,_0x3c5dbb){rpc[_0x5f72('0x2c')](_0x7cce31)['then'](function(_0x502057){_0x3c5dbb(null,_0x502057);})[_0x5f72('0x2d')](function(_0x15f7ac){_0x3c5dbb(null,_0x15f7ac);});}function createSquareReport(_0x25ab30,_0x3112ad){rpc[_0x5f72('0x2e')](_0x25ab30)[_0x5f72('0x2f')](function(_0x1d56de){if(_0x3112ad){_0x3112ad(null,_0x1d56de);}})['catch'](function(_0x4c6909){if(_0x3112ad){_0x3112ad(null,_0x4c6909);}});}function setChannelVariables(_0x2d4bbe){for(var _0x336e19 in _0x2d4bbe){if(_0x2d4bbe[_0x5f72('0x22')](_0x336e19)){if(_0x336e19[_0x5f72('0x30')]('agi_')===0x0){_0x2d4bbe[_0x336e19[_0x5f72('0x31')](0x4)]=_0x2d4bbe[_0x336e19];delete _0x2d4bbe[_0x336e19];}}}}function getLogFromObject(_0x2e247a){return util[_0x5f72('0x32')](_0x2e247a,{'showHidden':![],'depth':null});}function agiHandler(_0x2581df){var _0x3a7aaa,_0x2c19eb,_0x59f276,_0x4a55a1,_0x11299c;logger[_0x5f72('0x33')]('variables',JSON[_0x5f72('0x34')](_0x2581df,null,0x2));logger[_0x5f72('0x11')](util[_0x5f72('0x12')](_0x5f72('0x35'),_0x2581df[_0x5f72('0x18')],_0x2581df[_0x5f72('0x1b')],_0x2581df[_0x5f72('0x19')],_0x2581df[_0x5f72('0x1a')],_0x2581df[_0x5f72('0x1c')]));_0x2581df['on'](_0x5f72('0xe'),errorHandler);_0x2581df['on'](_0x5f72('0x36'),closeHandler);_0x2581df['on'](_0x5f72('0x37'),timeoutHandler);_0x2581df[_0x5f72('0x1d')]=![];_0x2581df['on'](_0x5f72('0x38'),hangupHandler);var _0x52fab3=getSquareProject[_0x5f72('0x39')](null,_0x2581df['arg_1']);if(_0x52fab3){if(_0x52fab3['production']){_0x3a7aaa=getRoot(_0x52fab3[_0x5f72('0x3a')]);if(_0x3a7aaa&&_0x3a7aaa[_0x5f72('0x3b')]){logger[_0x5f72('0x33')](_0x5f72('0x20'),JSON[_0x5f72('0x34')](_0x3a7aaa,null,0x2));_0x2581df[_0x5f72('0x3c')]=moment()['format'](_0x5f72('0x3d'));_0x2c19eb=initGraph(_[_0x5f72('0x3e')](_0x3a7aaa,_0x5f72('0x25')),_0x3a7aaa[_0x5f72('0x25')]);_0x59f276=new Vertices(_0x2581df,rpc,mailRpc);logger[_0x5f72('0x11')](util[_0x5f72('0x12')](_0x5f72('0x3f'),_0x2581df[_0x5f72('0x18')],_0x2581df[_0x5f72('0x1b')],_0x2581df[_0x5f72('0x19')],_0x2581df[_0x5f72('0x1a')],_0x2581df[_0x5f72('0x1c')]));_0x2c19eb[_0x5f72('0x40')](_0x3a7aaa[_0x5f72('0x3b')]['id'],function(_0xefdf17){try{_0xefdf17=_0x59f276['clear'](_0xefdf17);logger['debug'](_0x5f72('0x41'),JSON['stringify'](_0xefdf17,null,0x2));if(_0xefdf17['agicommand']===_0x5f72('0x42')){logger[_0x5f72('0x11')]('gotoc\x20block\x20stop\x20traverse\x20BFS');_0x2581df[_0x5f72('0x43')]=_0xefdf17[_0x5f72('0x43')]||_0x2581df['context'];_0x2581df[_0x5f72('0x44')]=_0xefdf17[_0x5f72('0x44')];_0x2581df[_0x5f72('0x45')]=_0xefdf17[_0x5f72('0x45')]?_0xefdf17['priority']-0x1:0x1;return null;}else if(_0xefdf17&&_0x59f276[_0xefdf17['agicommand']]){_0x11299c=_0x59f276[_0xefdf17[_0x5f72('0x21')]](_0xefdf17);logger[_0x5f72('0x11')](_0x5f72('0x46'),JSON[_0x5f72('0x34')](_0x11299c,null,0x2));if(_0x11299c&&_0x11299c[_0x5f72('0x47')]===AGI_CODE_SUCCESS&&_0x11299c[_0x5f72('0x48')]!==AGI_RESULT_ERROR&&!_0x2581df[_0x5f72('0x1d')]){logger['debug'](_0x5f72('0x46'),getLogFromObject(_0x11299c));return _[_0x5f72('0x49')](_0x11299c[_0x5f72('0x48')])?null:_0x11299c[_0x5f72('0x48')]['toString']();}else{logger[_0x5f72('0xe')](_0x5f72('0x46'),getLogFromObject(_0x11299c));return null;}}else{logger[_0x5f72('0xe')](_0x5f72('0x4a'));return null;}}catch(_0x5a84fe){logger[_0x5f72('0xe')](_0x5a84fe[_0x5f72('0xf')]);return null;}});if(_0x3a7aaa[_0x5f72('0x4b')]){logger[_0x5f72('0x11')](util['format'](_0x5f72('0x4c'),_0x2581df[_0x5f72('0x18')],_0x2581df['calleridname'],_0x2581df[_0x5f72('0x19')],_0x2581df[_0x5f72('0x1a')],_0x2581df['uniqueid']));_0x2c19eb[_0x5f72('0x40')](_0x3a7aaa[_0x5f72('0x4b')]['id'],function(_0x31bb61){try{_0x31bb61=_0x59f276['clear'](_0x31bb61);logger[_0x5f72('0x33')](_0x5f72('0x41'),JSON[_0x5f72('0x34')](_0x31bb61,null,0x2));if(_0x31bb61&&_0x59f276[_0x31bb61[_0x5f72('0x21')]]){_0x11299c=_0x59f276[_0x31bb61['agicommand']](_0x31bb61);if(_0x11299c){logger[_0x5f72('0x33')](_0x5f72('0x46'),getLogFromObject(_0x11299c));return _[_0x5f72('0x49')](_0x11299c[_0x5f72('0x48')])?null:_0x11299c['result'][_0x5f72('0x4d')]();}else{logger[_0x5f72('0xe')](_0x5f72('0x46'),getLogFromObject(_0x11299c));return null;}}else{logger[_0x5f72('0xe')]('agicommand\x20not\x20found');return null;}}catch(_0x16a452){logger['error'](_0x16a452[_0x5f72('0xf')]);return null;}});}logger[_0x5f72('0x11')](util[_0x5f72('0x12')](_0x5f72('0x4e'),_0x2581df[_0x5f72('0x18')],_0x2581df[_0x5f72('0x1b')],_0x2581df[_0x5f72('0x19')],_0x2581df[_0x5f72('0x1a')],_0x2581df[_0x5f72('0x1c')]));logger[_0x5f72('0x11')](util['format'](_0x5f72('0x4f'),_0x2581df[_0x5f72('0x43')],_0x2581df[_0x5f72('0x44')],parseInt(_0x2581df[_0x5f72('0x45')],0xa)+0x1));_0x2581df[_0x5f72('0x50')](_0x2581df['context'],_0x2581df[_0x5f72('0x44')],parseInt(_0x2581df[_0x5f72('0x45')],0xa)+0x1);_0x2581df[_0x5f72('0x36')]();}}else{logger[_0x5f72('0xe')](util[_0x5f72('0x12')]('Project\x20%s\x20not\x20published',_0x2581df['arg_1']));_0x2581df[_0x5f72('0x50')](_0x2581df[_0x5f72('0x43')],_0x2581df[_0x5f72('0x44')],parseInt(_0x2581df['priority'],0xa)+0x1);_0x2581df[_0x5f72('0x36')]();}}else{logger[_0x5f72('0xe')](util[_0x5f72('0x12')]('Project\x20%s\x20not\x20found',_0x2581df[_0x5f72('0x18')]));_0x2581df[_0x5f72('0x50')](_0x2581df['context'],_0x2581df['extension'],parseInt(_0x2581df[_0x5f72('0x45')],0xa)+0x1);_0x2581df['close']();}}function main(){var _0x5cc147;return utilLicense[_0x5f72('0x51')]()[_0x5f72('0x2f')](function(_0x1b9cab){if(_0x1b9cab){if(_0x1b9cab[_0x5f72('0x52')]){if(_0x1b9cab[_0x5f72('0x53')]&&_0x1b9cab[_0x5f72('0x53')]>0x0){logger[_0x5f72('0x11')](util['format'](_0x5f72('0x54'),_0x1b9cab['callysquare']));_0x5cc147=_0x1b9cab[_0x5f72('0x53')];}else{logger[_0x5f72('0x11')]('[LICENSE]\x20CHANNELS:\x20UNLIMITED');}}else{logger[_0x5f72('0x11')](_0x5f72('0x55'));_0x5cc147=-0x1;}}})[_0x5f72('0x2d')](function(_0x39036d){logger[_0x5f72('0xe')]('[LICENSE]',_0x39036d[_0x5f72('0xf')]);})[_0x5f72('0x4b')](function(){var _0x14e20b=require('./server')(config[_0x5f72('0x7')][_0x5f72('0x14')],config[_0x5f72('0x7')]['ip'],_0x5cc147);_0x14e20b['on'](_0x5f72('0xe'),errorHandler);_0x14e20b['on'](_0x5f72('0x56'),listeningHandler);_0x14e20b['on'](_0x5f72('0x57'),connectionHandler);_0x14e20b['on'](_0x5f72('0x36'),closeHandler);});}main();