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 _0x6071=['SQUAREROOT','start','root','joinAt','YYYY-MM-DD\x20HH:mm:ss','traverseBFS','clear','vertex','agicommand','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','code','result','response','finally','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','toString','agicommand\x20not\x20found','[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\x20found','getLicense','voice','callysquare','[LICENSE]\x20CHANNELS:\x20UNLIMITED','[LICENSE]\x20VOICE\x20IS\x20DISABLED','[LICENSE]','listening','connection','xml2json','lodash','syncho','util','moment','../../config/environment','../../config/logger','./graph','./vertices','agi','127.0.0.1','nextTick','error','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!','port','format','name','message','[%s]\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','callerid','dnid','uniqueid','calleridname','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','toJson','mxGraphModel','hasOwnProperty','retry','maxRetry','addVertex','mxCell','isArray','length','source','addEdge','target','value','getSquareProject','then','createSquareReport','catch','agi_','inspect','debug','variables','stringify','close','timeout','evtHangup','sync','production','log'];(function(_0x127a8a,_0x32efa4){var _0x374563=function(_0xc2e790){while(--_0xc2e790){_0x127a8a['push'](_0x127a8a['shift']());}};_0x374563(++_0x32efa4);}(_0x6071,0x1de));var _0x1607=function(_0xd444e7,_0x986904){_0xd444e7=_0xd444e7-0x0;var _0x171580=_0x6071[_0xd444e7];return _0x171580;};'use strict';var parser=require(_0x1607('0x0'));var _=require(_0x1607('0x1'));var syncho=require(_0x1607('0x2'));var util=require(_0x1607('0x3'));var moment=require(_0x1607('0x4'));var config=require(_0x1607('0x5'));var logger=require(_0x1607('0x6'))('agi');var utilLicense=require('../../config/license/util');var rpc=require('./rpc');var mailRpc=require('./mailRpc');var Graph=require(_0x1607('0x7'));var Vertices=require(_0x1607('0x8'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config['agi']=_['defaults'](config[_0x1607('0x9')],{'ip':_0x1607('0xa'),'port':0x11dd});function connectionHandler(_0x56ea02){process[_0x1607('0xb')](function(){syncho(function(){try{setChannelVariables(_0x56ea02);agiHandler(_0x56ea02);}catch(_0x5190ed){logger[_0x1607('0xc')](_0x5190ed['stack']);}});});}function listeningHandler(){console['log'](_0x1607('0xd'),config[_0x1607('0x9')][_0x1607('0xe')]);logger['info'](util[_0x1607('0xf')]('[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d',config[_0x1607('0x9')]['ip'],config[_0x1607('0x9')][_0x1607('0xe')]));}function errorHandler(_0xcabe27){if(_0xcabe27&&_0xcabe27[_0x1607('0x10')]&&_0xcabe27[_0x1607('0x11')]){logger['error'](util['format'](_0x1607('0x12'),_0xcabe27[_0x1607('0x10')],_0xcabe27[_0x1607('0x11')]));}else{logger[_0x1607('0xc')](util[_0x1607('0xf')]('[ERROR]\x20%s',_0xcabe27[_0x1607('0x13')]));}}function closeHandler(){logger[_0x1607('0x14')](util[_0x1607('0xf')](_0x1607('0x15'),this[_0x1607('0x16')],this['calleridname'],this[_0x1607('0x17')],this[_0x1607('0x18')],this[_0x1607('0x19')]));try{createSquareReport(this);}catch(_0x19dd5d){logger[_0x1607('0xc')](_0x19dd5d[_0x1607('0x13')]);}}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['arg_1'],this[_0x1607('0x1a')],this[_0x1607('0x17')],this[_0x1607('0x18')],this['uniqueid']));}function hangupHandler(){logger[_0x1607('0x14')](util['format'](_0x1607('0x1b'),this[_0x1607('0x16')],this[_0x1607('0x1a')],this[_0x1607('0x17')],this[_0x1607('0x18')],this[_0x1607('0x19')]));this['evtHangup']=!![];}function getRoot(_0xb6149){return parser[_0x1607('0x1c')](_0xb6149,{'object':!![]})[_0x1607('0x1d')]['root'];}function addVertex(_0x3378b9,_0x286051,_0x2daef9){_0x286051['agicommand']=_0x2daef9;if(_0x286051[_0x1607('0x1e')](_0x1607('0x1f'))){_0x286051[_0x1607('0x20')]=parseInt(_0x286051[_0x1607('0x1f')],0xa);}_0x3378b9[_0x1607('0x21')](_['omit'](_0x286051,_0x1607('0x22')));}function initGraph(_0x45dbbf,_0x251f59){var _0x15e79b=new Graph();for(var _0xe298f5 in _0x45dbbf){if(_0x45dbbf[_0x1607('0x1e')](_0xe298f5)){if(_[_0x1607('0x23')](_0x45dbbf[_0xe298f5])){for(var _0x27c916=0x0;_0x27c916<_0x45dbbf[_0xe298f5][_0x1607('0x24')];_0x27c916+=0x1){addVertex(_0x15e79b,_0x45dbbf[_0xe298f5][_0x27c916],_0xe298f5);}}else{addVertex(_0x15e79b,_0x45dbbf[_0xe298f5],_0xe298f5);}}}for(var _0x102f25=0x0;_0x102f25<_0x251f59['length'];_0x102f25+=0x1){if(_0x251f59[_0x102f25][_0x1607('0x25')]&&_0x251f59[_0x102f25]['target']){_0x15e79b[_0x1607('0x26')](_0x251f59[_0x102f25][_0x1607('0x25')],_0x251f59[_0x102f25][_0x1607('0x27')],_0x251f59[_0x102f25][_0x1607('0x28')]);}}return _0x15e79b;}function getSquareProject(_0x27ab8d,_0x587ed3){rpc[_0x1607('0x29')](_0x27ab8d)[_0x1607('0x2a')](function(_0xe74000){_0x587ed3(null,_0xe74000);})['catch'](function(_0x526fdf){_0x587ed3(null,_0x526fdf);});}function createSquareReport(_0x172ccf,_0x5ad542){rpc[_0x1607('0x2b')](_0x172ccf)[_0x1607('0x2a')](function(_0x221b23){if(_0x5ad542){_0x5ad542(null,_0x221b23);}})[_0x1607('0x2c')](function(_0x2c816c){if(_0x5ad542){_0x5ad542(null,_0x2c816c);}});}function setChannelVariables(_0x4c3968){for(var _0x359ac1 in _0x4c3968){if(_0x4c3968[_0x1607('0x1e')](_0x359ac1)){if(_0x359ac1['indexOf'](_0x1607('0x2d'))===0x0){_0x4c3968[_0x359ac1['substring'](0x4)]=_0x4c3968[_0x359ac1];delete _0x4c3968[_0x359ac1];}}}}function getLogFromObject(_0x492d80){return util[_0x1607('0x2e')](_0x492d80,{'showHidden':![],'depth':null});}function agiHandler(_0x3d11c7){var _0x65d934,_0x499acd,_0x217e88,_0x35e5e8,_0x2e7d8f;logger[_0x1607('0x2f')](_0x1607('0x30'),JSON[_0x1607('0x31')](_0x3d11c7,null,0x2));logger[_0x1607('0x14')](util[_0x1607('0xf')]('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x3d11c7[_0x1607('0x16')],_0x3d11c7['calleridname'],_0x3d11c7[_0x1607('0x17')],_0x3d11c7[_0x1607('0x18')],_0x3d11c7['uniqueid']));_0x3d11c7['on'](_0x1607('0xc'),errorHandler);_0x3d11c7['on'](_0x1607('0x32'),closeHandler);_0x3d11c7['on'](_0x1607('0x33'),timeoutHandler);_0x3d11c7[_0x1607('0x34')]=![];_0x3d11c7['on']('hangup',hangupHandler);var _0x38585d=getSquareProject[_0x1607('0x35')](null,_0x3d11c7[_0x1607('0x16')]);if(_0x38585d){if(_0x38585d['production']){_0x65d934=getRoot(_0x38585d[_0x1607('0x36')]);console[_0x1607('0x37')](_0x1607('0x38'),_0x65d934);if(_0x65d934&&_0x65d934[_0x1607('0x39')]){logger['debug'](_0x1607('0x3a'),JSON[_0x1607('0x31')](_0x65d934,null,0x2));_0x3d11c7[_0x1607('0x3b')]=moment()[_0x1607('0xf')](_0x1607('0x3c'));_0x499acd=initGraph(_['omit'](_0x65d934,'mxCell'),_0x65d934[_0x1607('0x22')]);_0x217e88=new Vertices(_0x3d11c7,rpc,mailRpc);logger[_0x1607('0x14')](util[_0x1607('0xf')]('[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x3d11c7[_0x1607('0x16')],_0x3d11c7[_0x1607('0x1a')],_0x3d11c7['callerid'],_0x3d11c7[_0x1607('0x18')],_0x3d11c7[_0x1607('0x19')]));_0x499acd[_0x1607('0x3d')](_0x65d934[_0x1607('0x39')]['id'],function(_0xd13ccb){try{_0xd13ccb=_0x217e88[_0x1607('0x3e')](_0xd13ccb);logger[_0x1607('0x2f')](_0x1607('0x3f'),JSON[_0x1607('0x31')](_0xd13ccb,null,0x2));if(_0xd13ccb[_0x1607('0x40')]===_0x1607('0x41')){logger[_0x1607('0x14')](_0x1607('0x42'));_0x3d11c7[_0x1607('0x43')]=_0xd13ccb[_0x1607('0x43')]||_0x3d11c7[_0x1607('0x43')];_0x3d11c7['extension']=_0xd13ccb[_0x1607('0x44')];_0x3d11c7[_0x1607('0x45')]=_0xd13ccb[_0x1607('0x45')]?_0xd13ccb[_0x1607('0x45')]-0x1:0x1;return null;}else if(_0xd13ccb&&_0x217e88[_0xd13ccb['agicommand']]){_0x2e7d8f=_0x217e88[_0xd13ccb['agicommand']](_0xd13ccb);logger[_0x1607('0x14')]('response',JSON[_0x1607('0x31')](_0x2e7d8f,null,0x2));if(_0x2e7d8f&&_0x2e7d8f[_0x1607('0x46')]===AGI_CODE_SUCCESS&&_0x2e7d8f[_0x1607('0x47')]!==AGI_RESULT_ERROR&&!_0x3d11c7['evtHangup']){logger[_0x1607('0x2f')]('response',getLogFromObject(_0x2e7d8f));return _['isUndefined'](_0x2e7d8f['result'])?null:_0x2e7d8f[_0x1607('0x47')]['toString']();}else{logger[_0x1607('0xc')](_0x1607('0x48'),getLogFromObject(_0x2e7d8f));return null;}}else{logger[_0x1607('0xc')]('agicommand\x20not\x20found');return null;}}catch(_0x6cddd0){logger['error'](_0x6cddd0[_0x1607('0x13')]);return null;}});if(_0x65d934[_0x1607('0x49')]){logger[_0x1607('0x14')](util[_0x1607('0xf')](_0x1607('0x4a'),_0x3d11c7[_0x1607('0x16')],_0x3d11c7[_0x1607('0x1a')],_0x3d11c7[_0x1607('0x17')],_0x3d11c7[_0x1607('0x18')],_0x3d11c7['uniqueid']));_0x499acd[_0x1607('0x3d')](_0x65d934[_0x1607('0x49')]['id'],function(_0x405b40){try{_0x405b40=_0x217e88[_0x1607('0x3e')](_0x405b40);logger[_0x1607('0x2f')](_0x1607('0x3f'),JSON['stringify'](_0x405b40,null,0x2));if(_0x405b40&&_0x217e88[_0x405b40['agicommand']]){_0x2e7d8f=_0x217e88[_0x405b40['agicommand']](_0x405b40);if(_0x2e7d8f){logger[_0x1607('0x2f')](_0x1607('0x48'),getLogFromObject(_0x2e7d8f));return _['isUndefined'](_0x2e7d8f['result'])?null:_0x2e7d8f[_0x1607('0x47')][_0x1607('0x4b')]();}else{logger[_0x1607('0xc')](_0x1607('0x48'),getLogFromObject(_0x2e7d8f));return null;}}else{logger['error'](_0x1607('0x4c'));return null;}}catch(_0x25a56b){logger[_0x1607('0xc')](_0x25a56b[_0x1607('0x13')]);return null;}});}logger['info'](util['format'](_0x1607('0x4d'),_0x3d11c7[_0x1607('0x16')],_0x3d11c7[_0x1607('0x1a')],_0x3d11c7[_0x1607('0x17')],_0x3d11c7[_0x1607('0x18')],_0x3d11c7[_0x1607('0x19')]));logger['info'](util[_0x1607('0xf')](_0x1607('0x4e'),_0x3d11c7[_0x1607('0x43')],_0x3d11c7['extension'],parseInt(_0x3d11c7[_0x1607('0x45')],0xa)+0x1));_0x3d11c7[_0x1607('0x4f')](_0x3d11c7[_0x1607('0x43')],_0x3d11c7['extension'],parseInt(_0x3d11c7[_0x1607('0x45')],0xa)+0x1);_0x3d11c7[_0x1607('0x32')]();}}else{logger[_0x1607('0xc')](util[_0x1607('0xf')]('Project\x20%s\x20not\x20published',_0x3d11c7[_0x1607('0x16')]));_0x3d11c7[_0x1607('0x4f')](_0x3d11c7[_0x1607('0x43')],_0x3d11c7['extension'],parseInt(_0x3d11c7[_0x1607('0x45')],0xa)+0x1);_0x3d11c7[_0x1607('0x32')]();}}else{logger[_0x1607('0xc')](util[_0x1607('0xf')](_0x1607('0x50'),_0x3d11c7[_0x1607('0x16')]));_0x3d11c7[_0x1607('0x4f')](_0x3d11c7[_0x1607('0x43')],_0x3d11c7[_0x1607('0x44')],parseInt(_0x3d11c7[_0x1607('0x45')],0xa)+0x1);_0x3d11c7[_0x1607('0x32')]();}}function main(){var _0x628d5;return utilLicense[_0x1607('0x51')]()[_0x1607('0x2a')](function(_0x1f3237){if(_0x1f3237){if(_0x1f3237[_0x1607('0x52')]){if(_0x1f3237[_0x1607('0x53')]&&_0x1f3237[_0x1607('0x53')]>0x0){logger[_0x1607('0x14')](util['format']('[LICENSE]\x20CHANNELS:\x20%s',_0x1f3237[_0x1607('0x53')]));_0x628d5=_0x1f3237[_0x1607('0x53')];}else{logger['info'](_0x1607('0x54'));}}else{logger[_0x1607('0x14')](_0x1607('0x55'));_0x628d5=-0x1;}}})[_0x1607('0x2c')](function(_0x240afa){logger[_0x1607('0xc')](_0x1607('0x56'),_0x240afa[_0x1607('0x13')]);})['finally'](function(){var _0x1e801d=require('./server')(config[_0x1607('0x9')][_0x1607('0xe')],config['agi']['ip'],_0x628d5);_0x1e801d['on'](_0x1607('0xc'),errorHandler);_0x1e801d['on'](_0x1607('0x57'),listeningHandler);_0x1e801d['on'](_0x1607('0x58'),connectionHandler);_0x1e801d['on'](_0x1607('0x32'),closeHandler);});}main();