Built motion from commit (unavailable).|2.5.3
[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 _0xc03e=['port','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','name','message','[%s]\x20%s','[ERROR]\x20%s','stack','[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','calleridname','callerid','uniqueid','dnid','[HANGUP]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','evtHangup','mxGraphModel','root','agicommand','retry','maxRetry','addVertex','omit','mxCell','hasOwnProperty','isArray','length','source','target','value','getSquareProject','then','createSquareReport','catch','agi_','substring','inspect','debug','variables','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','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','traverseBFS','clear','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','result','toString','finally','vertex','isUndefined','agicommand\x20not\x20found','[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','listening','connection','xml2json','util','../../config/environment','agi','../../config/license/util','./rpc','./mailRpc','./graph','./vertices','defaults','nextTick','error','log','Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!'];(function(_0x58e302,_0x1bb64a){var _0x17306b=function(_0x1ccc63){while(--_0x1ccc63){_0x58e302['push'](_0x58e302['shift']());}};_0x17306b(++_0x1bb64a);}(_0xc03e,0x15a));var _0xec03=function(_0x4429e0,_0xee6f1f){_0x4429e0=_0x4429e0-0x0;var _0x51a5b3=_0xc03e[_0x4429e0];return _0x51a5b3;};'use strict';var parser=require(_0xec03('0x0'));var _=require('lodash');var syncho=require('syncho');var util=require(_0xec03('0x1'));var moment=require('moment');var config=require(_0xec03('0x2'));var logger=require('../../config/logger')(_0xec03('0x3'));var utilLicense=require(_0xec03('0x4'));var rpc=require(_0xec03('0x5'));var mailRpc=require(_0xec03('0x6'));var Graph=require(_0xec03('0x7'));var Vertices=require(_0xec03('0x8'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config[_0xec03('0x3')]=_[_0xec03('0x9')](config[_0xec03('0x3')],{'ip':'127.0.0.1','port':0x11dd});function connectionHandler(_0x4205e9){process[_0xec03('0xa')](function(){syncho(function(){try{setChannelVariables(_0x4205e9);agiHandler(_0x4205e9);}catch(_0xde3f78){logger[_0xec03('0xb')](_0xde3f78['stack']);}});});}function listeningHandler(){console[_0xec03('0xc')](_0xec03('0xd'),config[_0xec03('0x3')][_0xec03('0xe')]);logger[_0xec03('0xf')](util[_0xec03('0x10')](_0xec03('0x11'),config[_0xec03('0x3')]['ip'],config['agi'][_0xec03('0xe')]));}function errorHandler(_0x190f46){if(_0x190f46&&_0x190f46[_0xec03('0x12')]&&_0x190f46[_0xec03('0x13')]){logger[_0xec03('0xb')](util[_0xec03('0x10')](_0xec03('0x14'),_0x190f46[_0xec03('0x12')],_0x190f46['message']));}else{logger['error'](util['format'](_0xec03('0x15'),_0x190f46[_0xec03('0x16')]));}}function closeHandler(){logger[_0xec03('0xf')](util[_0xec03('0x10')](_0xec03('0x17'),this[_0xec03('0x18')],this[_0xec03('0x19')],this[_0xec03('0x1a')],this['dnid'],this[_0xec03('0x1b')]));try{createSquareReport(this);}catch(_0x52f6ae){logger[_0xec03('0xb')](_0x52f6ae['stack']);}}function timeoutHandler(){logger[_0xec03('0xf')](util['format']('[TIMEOUT]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0xec03('0x18')],this[_0xec03('0x19')],this[_0xec03('0x1a')],this[_0xec03('0x1c')],this['uniqueid']));}function hangupHandler(){logger[_0xec03('0xf')](util['format'](_0xec03('0x1d'),this[_0xec03('0x18')],this[_0xec03('0x19')],this[_0xec03('0x1a')],this[_0xec03('0x1c')],this[_0xec03('0x1b')]));this[_0xec03('0x1e')]=!![];}function getRoot(_0x3b6ddf){return parser['toJson'](_0x3b6ddf,{'object':!![]})[_0xec03('0x1f')][_0xec03('0x20')];}function addVertex(_0xa16d53,_0x76b813,_0x33de1e){_0x76b813[_0xec03('0x21')]=_0x33de1e;if(_0x76b813['hasOwnProperty'](_0xec03('0x22'))){_0x76b813[_0xec03('0x23')]=parseInt(_0x76b813['retry'],0xa);}_0xa16d53[_0xec03('0x24')](_[_0xec03('0x25')](_0x76b813,_0xec03('0x26')));}function initGraph(_0x445452,_0x1c6870){var _0x581322=new Graph();for(var _0x73cc4f in _0x445452){if(_0x445452[_0xec03('0x27')](_0x73cc4f)){if(_[_0xec03('0x28')](_0x445452[_0x73cc4f])){for(var _0x11a6b6=0x0;_0x11a6b6<_0x445452[_0x73cc4f][_0xec03('0x29')];_0x11a6b6+=0x1){addVertex(_0x581322,_0x445452[_0x73cc4f][_0x11a6b6],_0x73cc4f);}}else{addVertex(_0x581322,_0x445452[_0x73cc4f],_0x73cc4f);}}}for(var _0x58621e=0x0;_0x58621e<_0x1c6870[_0xec03('0x29')];_0x58621e+=0x1){if(_0x1c6870[_0x58621e][_0xec03('0x2a')]&&_0x1c6870[_0x58621e]['target']){_0x581322['addEdge'](_0x1c6870[_0x58621e][_0xec03('0x2a')],_0x1c6870[_0x58621e][_0xec03('0x2b')],_0x1c6870[_0x58621e][_0xec03('0x2c')]);}}return _0x581322;}function getSquareProject(_0x872f98,_0x39f6d8){rpc[_0xec03('0x2d')](_0x872f98)[_0xec03('0x2e')](function(_0x28753c){_0x39f6d8(null,_0x28753c);})['catch'](function(_0x28f60c){_0x39f6d8(null,_0x28f60c);});}function createSquareReport(_0x31c08d,_0x2bd889){rpc[_0xec03('0x2f')](_0x31c08d)[_0xec03('0x2e')](function(_0xa06cb6){if(_0x2bd889){_0x2bd889(null,_0xa06cb6);}})[_0xec03('0x30')](function(_0x30d592){if(_0x2bd889){_0x2bd889(null,_0x30d592);}});}function setChannelVariables(_0x159875){for(var _0x4a4d6a in _0x159875){if(_0x159875['hasOwnProperty'](_0x4a4d6a)){if(_0x4a4d6a['indexOf'](_0xec03('0x31'))===0x0){_0x159875[_0x4a4d6a[_0xec03('0x32')](0x4)]=_0x159875[_0x4a4d6a];delete _0x159875[_0x4a4d6a];}}}}function getLogFromObject(_0xdfd244){return util[_0xec03('0x33')](_0xdfd244,{'showHidden':![],'depth':null});}function agiHandler(_0x5b9549){var _0x576d5e,_0x4c0de1,_0x487b08,_0x356a76,_0x3def6c;logger[_0xec03('0x34')](_0xec03('0x35'),JSON[_0xec03('0x36')](_0x5b9549,null,0x2));logger[_0xec03('0xf')](util[_0xec03('0x10')](_0xec03('0x37'),_0x5b9549[_0xec03('0x18')],_0x5b9549[_0xec03('0x19')],_0x5b9549[_0xec03('0x1a')],_0x5b9549[_0xec03('0x1c')],_0x5b9549['uniqueid']));_0x5b9549['on'](_0xec03('0xb'),errorHandler);_0x5b9549['on'](_0xec03('0x38'),closeHandler);_0x5b9549['on'](_0xec03('0x39'),timeoutHandler);_0x5b9549['evtHangup']=![];_0x5b9549['on'](_0xec03('0x3a'),hangupHandler);var _0x159208=getSquareProject[_0xec03('0x3b')](null,_0x5b9549[_0xec03('0x18')]);if(_0x159208){if(_0x159208[_0xec03('0x3c')]){_0x576d5e=getRoot(_0x159208[_0xec03('0x3c')]);if(_0x576d5e&&_0x576d5e[_0xec03('0x3d')]){logger[_0xec03('0x34')](_0xec03('0x20'),JSON[_0xec03('0x36')](_0x576d5e,null,0x2));_0x5b9549[_0xec03('0x3e')]=moment()['format'](_0xec03('0x3f'));_0x4c0de1=initGraph(_[_0xec03('0x25')](_0x576d5e,_0xec03('0x26')),_0x576d5e[_0xec03('0x26')]);_0x487b08=new Vertices(_0x5b9549,rpc,mailRpc);logger[_0xec03('0xf')](util[_0xec03('0x10')](_0xec03('0x40'),_0x5b9549[_0xec03('0x18')],_0x5b9549['calleridname'],_0x5b9549[_0xec03('0x1a')],_0x5b9549['dnid'],_0x5b9549['uniqueid']));_0x4c0de1[_0xec03('0x41')](_0x576d5e['start']['id'],function(_0x548b81){try{_0x548b81=_0x487b08[_0xec03('0x42')](_0x548b81);logger[_0xec03('0x34')]('vertex',JSON[_0xec03('0x36')](_0x548b81,null,0x2));if(_0x548b81['agicommand']==='gotoc'){logger['info'](_0xec03('0x43'));_0x5b9549[_0xec03('0x44')]=_0x548b81[_0xec03('0x44')]||_0x5b9549[_0xec03('0x44')];_0x5b9549['extension']=_0x548b81[_0xec03('0x45')];_0x5b9549[_0xec03('0x46')]=_0x548b81[_0xec03('0x46')]?_0x548b81[_0xec03('0x46')]-0x1:0x1;return null;}else if(_0x548b81&&_0x487b08[_0x548b81[_0xec03('0x21')]]){_0x3def6c=_0x487b08[_0x548b81[_0xec03('0x21')]](_0x548b81);logger[_0xec03('0xf')](_0xec03('0x47'),JSON[_0xec03('0x36')](_0x3def6c,null,0x2));if(_0x3def6c&&_0x3def6c['code']===AGI_CODE_SUCCESS&&_0x3def6c[_0xec03('0x48')]!==AGI_RESULT_ERROR&&!_0x5b9549[_0xec03('0x1e')]){logger[_0xec03('0x34')](_0xec03('0x47'),getLogFromObject(_0x3def6c));return _['isUndefined'](_0x3def6c[_0xec03('0x48')])?null:_0x3def6c[_0xec03('0x48')][_0xec03('0x49')]();}else{logger[_0xec03('0xb')](_0xec03('0x47'),getLogFromObject(_0x3def6c));return null;}}else{logger[_0xec03('0xb')]('agicommand\x20not\x20found');return null;}}catch(_0x5263fd){logger[_0xec03('0xb')](_0x5263fd[_0xec03('0x16')]);return null;}});if(_0x576d5e[_0xec03('0x4a')]){logger[_0xec03('0xf')](util[_0xec03('0x10')]('[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x5b9549['arg_1'],_0x5b9549[_0xec03('0x19')],_0x5b9549['callerid'],_0x5b9549[_0xec03('0x1c')],_0x5b9549[_0xec03('0x1b')]));_0x4c0de1[_0xec03('0x41')](_0x576d5e[_0xec03('0x4a')]['id'],function(_0x58e200){try{_0x58e200=_0x487b08[_0xec03('0x42')](_0x58e200);logger[_0xec03('0x34')](_0xec03('0x4b'),JSON[_0xec03('0x36')](_0x58e200,null,0x2));if(_0x58e200&&_0x487b08[_0x58e200['agicommand']]){_0x3def6c=_0x487b08[_0x58e200[_0xec03('0x21')]](_0x58e200);if(_0x3def6c){logger['debug'](_0xec03('0x47'),getLogFromObject(_0x3def6c));return _[_0xec03('0x4c')](_0x3def6c[_0xec03('0x48')])?null:_0x3def6c[_0xec03('0x48')][_0xec03('0x49')]();}else{logger[_0xec03('0xb')](_0xec03('0x47'),getLogFromObject(_0x3def6c));return null;}}else{logger['error'](_0xec03('0x4d'));return null;}}catch(_0x177d18){logger[_0xec03('0xb')](_0x177d18[_0xec03('0x16')]);return null;}});}logger['info'](util[_0xec03('0x10')]('[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x5b9549[_0xec03('0x18')],_0x5b9549[_0xec03('0x19')],_0x5b9549[_0xec03('0x1a')],_0x5b9549[_0xec03('0x1c')],_0x5b9549['uniqueid']));logger[_0xec03('0xf')](util[_0xec03('0x10')](_0xec03('0x4e'),_0x5b9549[_0xec03('0x44')],_0x5b9549[_0xec03('0x45')],parseInt(_0x5b9549['priority'],0xa)+0x1));_0x5b9549[_0xec03('0x4f')](_0x5b9549[_0xec03('0x44')],_0x5b9549[_0xec03('0x45')],parseInt(_0x5b9549['priority'],0xa)+0x1);_0x5b9549['close']();}}else{logger[_0xec03('0xb')](util[_0xec03('0x10')](_0xec03('0x50'),_0x5b9549[_0xec03('0x18')]));_0x5b9549['continueAt'](_0x5b9549[_0xec03('0x44')],_0x5b9549[_0xec03('0x45')],parseInt(_0x5b9549[_0xec03('0x46')],0xa)+0x1);_0x5b9549[_0xec03('0x38')]();}}else{logger['error'](util[_0xec03('0x10')](_0xec03('0x51'),_0x5b9549[_0xec03('0x18')]));_0x5b9549[_0xec03('0x4f')](_0x5b9549[_0xec03('0x44')],_0x5b9549[_0xec03('0x45')],parseInt(_0x5b9549[_0xec03('0x46')],0xa)+0x1);_0x5b9549[_0xec03('0x38')]();}}function main(){var _0x5721b6;return utilLicense[_0xec03('0x52')]()[_0xec03('0x2e')](function(_0x2c6ca9){if(_0x2c6ca9){if(_0x2c6ca9[_0xec03('0x53')]){if(_0x2c6ca9['callysquare']&&_0x2c6ca9[_0xec03('0x54')]>0x0){logger[_0xec03('0xf')](util[_0xec03('0x10')](_0xec03('0x55'),_0x2c6ca9['callysquare']));_0x5721b6=_0x2c6ca9[_0xec03('0x54')];}else{logger[_0xec03('0xf')](_0xec03('0x56'));}}else{logger[_0xec03('0xf')](_0xec03('0x57'));_0x5721b6=-0x1;}}})[_0xec03('0x30')](function(_0x1f9272){logger[_0xec03('0xb')]('[LICENSE]',_0x1f9272[_0xec03('0x16')]);})['finally'](function(){var _0x1c395f=require('./server')(config[_0xec03('0x3')][_0xec03('0xe')],config[_0xec03('0x3')]['ip'],_0x5721b6);_0x1c395f['on'](_0xec03('0xb'),errorHandler);_0x1c395f['on'](_0xec03('0x58'),listeningHandler);_0x1c395f['on'](_0xec03('0x59'),connectionHandler);_0x1c395f['on'](_0xec03('0x38'),closeHandler);});}main();