Built motion from commit (unavailable).|2.5.14
[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 _0x4d9e=['nextTick','error','stack','log','port','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','message','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','calleridname','callerid','dnid','arg_1','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','uniqueid','evtHangup','toJson','mxGraphModel','agicommand','retry','maxRetry','addVertex','omit','mxCell','source','target','addEdge','value','getSquareProject','then','catch','createSquareReport','hasOwnProperty','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','root','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','clear','gotoc','context','extension','priority','code','result','isUndefined','toString','response','agicommand\x20not\x20found','finally','traverseBFS','vertex','[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]','listening','connection','xml2json','util','../../config/environment','agi','../../config/license/util','./mailRpc','./graph','./vertices','defaults'];(function(_0x589777,_0x110424){var _0x3b067c=function(_0x59cf29){while(--_0x59cf29){_0x589777['push'](_0x589777['shift']());}};_0x3b067c(++_0x110424);}(_0x4d9e,0x18c));var _0xe4d9=function(_0x32a7f2,_0x43ca7d){_0x32a7f2=_0x32a7f2-0x0;var _0x4c7655=_0x4d9e[_0x32a7f2];return _0x4c7655;};'use strict';var parser=require(_0xe4d9('0x0'));var _=require('lodash');var syncho=require('syncho');var util=require(_0xe4d9('0x1'));var moment=require('moment');var config=require(_0xe4d9('0x2'));var logger=require('../../config/logger')(_0xe4d9('0x3'));var utilLicense=require(_0xe4d9('0x4'));var rpc=require('./rpc');var mailRpc=require(_0xe4d9('0x5'));var Graph=require(_0xe4d9('0x6'));var Vertices=require(_0xe4d9('0x7'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config[_0xe4d9('0x3')]=_[_0xe4d9('0x8')](config[_0xe4d9('0x3')],{'ip':'127.0.0.1','port':0x11dd});function connectionHandler(_0x36316f){process[_0xe4d9('0x9')](function(){syncho(function(){try{setChannelVariables(_0x36316f);agiHandler(_0x36316f);}catch(_0x2a7eee){logger[_0xe4d9('0xa')](_0x2a7eee[_0xe4d9('0xb')]);}});});}function listeningHandler(){console[_0xe4d9('0xc')]('Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!',config[_0xe4d9('0x3')][_0xe4d9('0xd')]);logger[_0xe4d9('0xe')](util[_0xe4d9('0xf')](_0xe4d9('0x10'),config[_0xe4d9('0x3')]['ip'],config[_0xe4d9('0x3')]['port']));}function errorHandler(_0x5ee099){if(_0x5ee099&&_0x5ee099['name']&&_0x5ee099['message']){logger['error'](util['format']('[%s]\x20%s',_0x5ee099['name'],_0x5ee099[_0xe4d9('0x11')]));}else{logger[_0xe4d9('0xa')](util[_0xe4d9('0xf')]('[ERROR]\x20%s',_0x5ee099[_0xe4d9('0xb')]));}}function closeHandler(){logger[_0xe4d9('0xe')](util[_0xe4d9('0xf')](_0xe4d9('0x12'),this['arg_1'],this[_0xe4d9('0x13')],this[_0xe4d9('0x14')],this[_0xe4d9('0x15')],this['uniqueid']));try{createSquareReport(this);}catch(_0x4d2afd){logger[_0xe4d9('0xa')](_0x4d2afd[_0xe4d9('0xb')]);}}function timeoutHandler(){logger['info'](util[_0xe4d9('0xf')]('[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0xe4d9('0x16')],this[_0xe4d9('0x13')],this[_0xe4d9('0x14')],this[_0xe4d9('0x15')],this['uniqueid']));}function hangupHandler(){logger[_0xe4d9('0xe')](util[_0xe4d9('0xf')](_0xe4d9('0x17'),this[_0xe4d9('0x16')],this[_0xe4d9('0x13')],this[_0xe4d9('0x14')],this[_0xe4d9('0x15')],this[_0xe4d9('0x18')]));this[_0xe4d9('0x19')]=!![];}function getRoot(_0x4fed7f){return parser[_0xe4d9('0x1a')](_0x4fed7f,{'object':!![]})[_0xe4d9('0x1b')]['root'];}function addVertex(_0x189dad,_0x50d377,_0x14f3d7){_0x50d377[_0xe4d9('0x1c')]=_0x14f3d7;if(_0x50d377['hasOwnProperty'](_0xe4d9('0x1d'))){_0x50d377[_0xe4d9('0x1e')]=parseInt(_0x50d377['retry'],0xa);}_0x189dad[_0xe4d9('0x1f')](_[_0xe4d9('0x20')](_0x50d377,_0xe4d9('0x21')));}function initGraph(_0x5bb43b,_0x4ee33d){var _0x42e6a0=new Graph();for(var _0x2846e2 in _0x5bb43b){if(_0x5bb43b['hasOwnProperty'](_0x2846e2)){if(_['isArray'](_0x5bb43b[_0x2846e2])){for(var _0x4954b5=0x0;_0x4954b5<_0x5bb43b[_0x2846e2]['length'];_0x4954b5+=0x1){addVertex(_0x42e6a0,_0x5bb43b[_0x2846e2][_0x4954b5],_0x2846e2);}}else{addVertex(_0x42e6a0,_0x5bb43b[_0x2846e2],_0x2846e2);}}}for(var _0x221a61=0x0;_0x221a61<_0x4ee33d['length'];_0x221a61+=0x1){if(_0x4ee33d[_0x221a61][_0xe4d9('0x22')]&&_0x4ee33d[_0x221a61][_0xe4d9('0x23')]){_0x42e6a0[_0xe4d9('0x24')](_0x4ee33d[_0x221a61]['source'],_0x4ee33d[_0x221a61][_0xe4d9('0x23')],_0x4ee33d[_0x221a61][_0xe4d9('0x25')]);}}return _0x42e6a0;}function getSquareProject(_0x250de5,_0x45e8a3){rpc[_0xe4d9('0x26')](_0x250de5)[_0xe4d9('0x27')](function(_0x21b7a9){_0x45e8a3(null,_0x21b7a9);})[_0xe4d9('0x28')](function(_0x1fb637){_0x45e8a3(null,_0x1fb637);});}function createSquareReport(_0x3e6ea7,_0x519c18){rpc[_0xe4d9('0x29')](_0x3e6ea7)['then'](function(_0x22efd2){if(_0x519c18){_0x519c18(null,_0x22efd2);}})[_0xe4d9('0x28')](function(_0x2b716b){if(_0x519c18){_0x519c18(null,_0x2b716b);}});}function setChannelVariables(_0x3721a0){for(var _0xa444d0 in _0x3721a0){if(_0x3721a0[_0xe4d9('0x2a')](_0xa444d0)){if(_0xa444d0['indexOf']('agi_')===0x0){_0x3721a0[_0xa444d0['substring'](0x4)]=_0x3721a0[_0xa444d0];delete _0x3721a0[_0xa444d0];}}}}function getLogFromObject(_0x270cad){return util[_0xe4d9('0x2b')](_0x270cad,{'showHidden':![],'depth':null});}function agiHandler(_0x9f1acf){var _0x4f8abf,_0x5a7422,_0x5ad794,_0x5f230f,_0x2740e0;logger[_0xe4d9('0x2c')]('variables',JSON[_0xe4d9('0x2d')](_0x9f1acf,null,0x2));logger[_0xe4d9('0xe')](util['format'](_0xe4d9('0x2e'),_0x9f1acf[_0xe4d9('0x16')],_0x9f1acf[_0xe4d9('0x13')],_0x9f1acf[_0xe4d9('0x14')],_0x9f1acf[_0xe4d9('0x15')],_0x9f1acf[_0xe4d9('0x18')]));_0x9f1acf['on'](_0xe4d9('0xa'),errorHandler);_0x9f1acf['on'](_0xe4d9('0x2f'),closeHandler);_0x9f1acf['on'](_0xe4d9('0x30'),timeoutHandler);_0x9f1acf[_0xe4d9('0x19')]=![];_0x9f1acf['on'](_0xe4d9('0x31'),hangupHandler);var _0x517f24=getSquareProject[_0xe4d9('0x32')](null,_0x9f1acf[_0xe4d9('0x16')]);if(_0x517f24){if(_0x517f24['production']){_0x4f8abf=getRoot(_0x517f24[_0xe4d9('0x33')]);if(_0x4f8abf&&_0x4f8abf[_0xe4d9('0x34')]){logger[_0xe4d9('0x2c')](_0xe4d9('0x35'),JSON[_0xe4d9('0x2d')](_0x4f8abf,null,0x2));_0x9f1acf[_0xe4d9('0x36')]=moment()[_0xe4d9('0xf')](_0xe4d9('0x37'));_0x5a7422=initGraph(_[_0xe4d9('0x20')](_0x4f8abf,'mxCell'),_0x4f8abf['mxCell']);_0x5ad794=new Vertices(_0x9f1acf,rpc,mailRpc);logger['info'](util[_0xe4d9('0xf')](_0xe4d9('0x38'),_0x9f1acf[_0xe4d9('0x16')],_0x9f1acf[_0xe4d9('0x13')],_0x9f1acf[_0xe4d9('0x14')],_0x9f1acf[_0xe4d9('0x15')],_0x9f1acf[_0xe4d9('0x18')]));_0x5a7422['traverseBFS'](_0x4f8abf['start']['id'],function(_0x51824f){try{_0x51824f=_0x5ad794[_0xe4d9('0x39')](_0x51824f);logger[_0xe4d9('0x2c')]('vertex',JSON[_0xe4d9('0x2d')](_0x51824f,null,0x2));if(_0x51824f[_0xe4d9('0x1c')]===_0xe4d9('0x3a')){logger[_0xe4d9('0xe')]('gotoc\x20block\x20stop\x20traverse\x20BFS');_0x9f1acf[_0xe4d9('0x3b')]=_0x51824f[_0xe4d9('0x3b')]||_0x9f1acf[_0xe4d9('0x3b')];_0x9f1acf[_0xe4d9('0x3c')]=_0x51824f[_0xe4d9('0x3c')];_0x9f1acf[_0xe4d9('0x3d')]=_0x51824f[_0xe4d9('0x3d')]?_0x51824f[_0xe4d9('0x3d')]-0x1:0x1;return null;}else if(_0x51824f&&_0x5ad794[_0x51824f[_0xe4d9('0x1c')]]){_0x2740e0=_0x5ad794[_0x51824f[_0xe4d9('0x1c')]](_0x51824f);logger[_0xe4d9('0xe')]('response',JSON[_0xe4d9('0x2d')](_0x2740e0,null,0x2));if(_0x2740e0&&_0x2740e0[_0xe4d9('0x3e')]===AGI_CODE_SUCCESS&&_0x2740e0[_0xe4d9('0x3f')]!==AGI_RESULT_ERROR&&!_0x9f1acf[_0xe4d9('0x19')]){logger[_0xe4d9('0x2c')]('response',getLogFromObject(_0x2740e0));return _[_0xe4d9('0x40')](_0x2740e0[_0xe4d9('0x3f')])?null:_0x2740e0[_0xe4d9('0x3f')][_0xe4d9('0x41')]();}else{logger[_0xe4d9('0xa')](_0xe4d9('0x42'),getLogFromObject(_0x2740e0));return null;}}else{logger[_0xe4d9('0xa')](_0xe4d9('0x43'));return null;}}catch(_0x42744d){logger[_0xe4d9('0xa')](_0x42744d['stack']);return null;}});if(_0x4f8abf[_0xe4d9('0x44')]){logger[_0xe4d9('0xe')](util[_0xe4d9('0xf')]('[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x9f1acf[_0xe4d9('0x16')],_0x9f1acf[_0xe4d9('0x13')],_0x9f1acf[_0xe4d9('0x14')],_0x9f1acf[_0xe4d9('0x15')],_0x9f1acf[_0xe4d9('0x18')]));_0x5a7422[_0xe4d9('0x45')](_0x4f8abf[_0xe4d9('0x44')]['id'],function(_0x5254b3){try{_0x5254b3=_0x5ad794[_0xe4d9('0x39')](_0x5254b3);logger[_0xe4d9('0x2c')](_0xe4d9('0x46'),JSON[_0xe4d9('0x2d')](_0x5254b3,null,0x2));if(_0x5254b3&&_0x5ad794[_0x5254b3[_0xe4d9('0x1c')]]){_0x2740e0=_0x5ad794[_0x5254b3[_0xe4d9('0x1c')]](_0x5254b3);if(_0x2740e0){logger['debug'](_0xe4d9('0x42'),getLogFromObject(_0x2740e0));return _[_0xe4d9('0x40')](_0x2740e0[_0xe4d9('0x3f')])?null:_0x2740e0[_0xe4d9('0x3f')][_0xe4d9('0x41')]();}else{logger[_0xe4d9('0xa')]('response',getLogFromObject(_0x2740e0));return null;}}else{logger[_0xe4d9('0xa')](_0xe4d9('0x43'));return null;}}catch(_0x53e7c4){logger[_0xe4d9('0xa')](_0x53e7c4['stack']);return null;}});}logger[_0xe4d9('0xe')](util[_0xe4d9('0xf')]('[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x9f1acf[_0xe4d9('0x16')],_0x9f1acf['calleridname'],_0x9f1acf[_0xe4d9('0x14')],_0x9f1acf[_0xe4d9('0x15')],_0x9f1acf[_0xe4d9('0x18')]));logger['info'](util[_0xe4d9('0xf')](_0xe4d9('0x47'),_0x9f1acf['context'],_0x9f1acf[_0xe4d9('0x3c')],parseInt(_0x9f1acf[_0xe4d9('0x3d')],0xa)+0x1));_0x9f1acf[_0xe4d9('0x48')](_0x9f1acf[_0xe4d9('0x3b')],_0x9f1acf['extension'],parseInt(_0x9f1acf['priority'],0xa)+0x1);_0x9f1acf[_0xe4d9('0x2f')]();}}else{logger[_0xe4d9('0xa')](util[_0xe4d9('0xf')](_0xe4d9('0x49'),_0x9f1acf[_0xe4d9('0x16')]));_0x9f1acf[_0xe4d9('0x48')](_0x9f1acf['context'],_0x9f1acf['extension'],parseInt(_0x9f1acf[_0xe4d9('0x3d')],0xa)+0x1);_0x9f1acf[_0xe4d9('0x2f')]();}}else{logger[_0xe4d9('0xa')](util[_0xe4d9('0xf')](_0xe4d9('0x4a'),_0x9f1acf[_0xe4d9('0x16')]));_0x9f1acf['continueAt'](_0x9f1acf[_0xe4d9('0x3b')],_0x9f1acf[_0xe4d9('0x3c')],parseInt(_0x9f1acf[_0xe4d9('0x3d')],0xa)+0x1);_0x9f1acf['close']();}}function main(){var _0x457bfb;return utilLicense[_0xe4d9('0x4b')]()[_0xe4d9('0x27')](function(_0x5ec4bc){if(_0x5ec4bc){if(_0x5ec4bc[_0xe4d9('0x4c')]){if(_0x5ec4bc['callysquare']&&_0x5ec4bc[_0xe4d9('0x4d')]>0x0){logger[_0xe4d9('0xe')](util[_0xe4d9('0xf')]('[LICENSE]\x20CHANNELS:\x20%s',_0x5ec4bc['callysquare']));_0x457bfb=_0x5ec4bc['callysquare'];}else{logger[_0xe4d9('0xe')]('[LICENSE]\x20CHANNELS:\x20UNLIMITED');}}else{logger[_0xe4d9('0xe')]('[LICENSE]\x20VOICE\x20IS\x20DISABLED');_0x457bfb=-0x1;}}})['catch'](function(_0x3c2196){logger[_0xe4d9('0xa')](_0xe4d9('0x4e'),_0x3c2196[_0xe4d9('0xb')]);})[_0xe4d9('0x44')](function(){var _0x580bb4=require('./server')(config['agi']['port'],config[_0xe4d9('0x3')]['ip'],_0x457bfb);_0x580bb4['on'](_0xe4d9('0xa'),errorHandler);_0x580bb4['on'](_0xe4d9('0x4f'),listeningHandler);_0x580bb4['on'](_0xe4d9('0x50'),connectionHandler);_0x580bb4['on'](_0xe4d9('0x2f'),closeHandler);});}main();