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 _0x6888=['code','result','evtHangup','isUndefined','toString','finally','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','vertex','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','./server','listening','connection','xml2json','syncho','util','moment','../../config/environment','../../config/logger','agi','./mailRpc','./graph','./vertices','defaults','nextTick','error','stack','port','info','format','[LISTENING]\x20Cally\x20Square\x20listening\x20%s:%d','message','[%s]\x20%s','name','[ERROR]\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','toJson','root','agicommand','hasOwnProperty','retry','maxRetry','addVertex','mxCell','isArray','length','source','addEdge','getSquareProject','catch','createSquareReport','then','agi_','substring','inspect','stringify','close','timeout','hangup','production','log','SQUAREROOT','start','debug','joinAt','YYYY-MM-DD\x20HH:mm:ss','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','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','vresponse','response'];(function(_0x2c8d3e,_0x5cc741){var _0x104e8f=function(_0x4bd8e8){while(--_0x4bd8e8){_0x2c8d3e['push'](_0x2c8d3e['shift']());}};_0x104e8f(++_0x5cc741);}(_0x6888,0xd2));var _0x8688=function(_0x565ed7,_0x398228){_0x565ed7=_0x565ed7-0x0;var _0x183ad7=_0x6888[_0x565ed7];return _0x183ad7;};'use strict';var parser=require(_0x8688('0x0'));var _=require('lodash');var syncho=require(_0x8688('0x1'));var util=require(_0x8688('0x2'));var moment=require(_0x8688('0x3'));var config=require(_0x8688('0x4'));var logger=require(_0x8688('0x5'))(_0x8688('0x6'));var utilLicense=require('../../config/license/util');var rpc=require('./rpc');var mailRpc=require(_0x8688('0x7'));var Graph=require(_0x8688('0x8'));var Vertices=require(_0x8688('0x9'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;config[_0x8688('0x6')]=_[_0x8688('0xa')](config[_0x8688('0x6')],{'ip':'127.0.0.1','port':0x11dd});function connectionHandler(_0x457991){process[_0x8688('0xb')](function(){syncho(function(){try{setChannelVariables(_0x457991);agiHandler(_0x457991);}catch(_0x24a82b){logger[_0x8688('0xc')](_0x24a82b[_0x8688('0xd')]);}});});}function listeningHandler(){console['log']('Cally\x20Square\x20server\x20listening\x20on\x20port\x20%d!',config[_0x8688('0x6')][_0x8688('0xe')]);logger[_0x8688('0xf')](util[_0x8688('0x10')](_0x8688('0x11'),config[_0x8688('0x6')]['ip'],config[_0x8688('0x6')][_0x8688('0xe')]));}function errorHandler(_0x3addbe){if(_0x3addbe&&_0x3addbe['name']&&_0x3addbe[_0x8688('0x12')]){logger[_0x8688('0xc')](util[_0x8688('0x10')](_0x8688('0x13'),_0x3addbe[_0x8688('0x14')],_0x3addbe[_0x8688('0x12')]));}else{logger[_0x8688('0xc')](util[_0x8688('0x10')](_0x8688('0x15'),_0x3addbe[_0x8688('0xd')]));}}function closeHandler(){logger[_0x8688('0xf')](util[_0x8688('0x10')]('[CLOSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',this[_0x8688('0x16')],this[_0x8688('0x17')],this[_0x8688('0x18')],this[_0x8688('0x19')],this[_0x8688('0x1a')]));try{createSquareReport(this);}catch(_0x13ee31){logger[_0x8688('0xc')](_0x13ee31['stack']);}}function timeoutHandler(){logger['info'](util[_0x8688('0x10')](_0x8688('0x1b'),this['arg_1'],this['calleridname'],this[_0x8688('0x18')],this[_0x8688('0x19')],this[_0x8688('0x1a')]));}function hangupHandler(){logger[_0x8688('0xf')](util[_0x8688('0x10')](_0x8688('0x1c'),this[_0x8688('0x16')],this[_0x8688('0x17')],this[_0x8688('0x18')],this['dnid'],this[_0x8688('0x1a')]));this['evtHangup']=!![];}function getRoot(_0x32d195){return parser[_0x8688('0x1d')](_0x32d195,{'object':!![]})['mxGraphModel'][_0x8688('0x1e')];}function addVertex(_0x4d80ca,_0x3ca828,_0x3e92cd){_0x3ca828[_0x8688('0x1f')]=_0x3e92cd;if(_0x3ca828[_0x8688('0x20')](_0x8688('0x21'))){_0x3ca828[_0x8688('0x22')]=parseInt(_0x3ca828[_0x8688('0x21')],0xa);}_0x4d80ca[_0x8688('0x23')](_['omit'](_0x3ca828,_0x8688('0x24')));}function initGraph(_0x1447d8,_0x196d50){var _0x2f2707=new Graph();for(var _0x4d4b9c in _0x1447d8){if(_0x1447d8[_0x8688('0x20')](_0x4d4b9c)){if(_[_0x8688('0x25')](_0x1447d8[_0x4d4b9c])){for(var _0xa73617=0x0;_0xa73617<_0x1447d8[_0x4d4b9c]['length'];_0xa73617+=0x1){addVertex(_0x2f2707,_0x1447d8[_0x4d4b9c][_0xa73617],_0x4d4b9c);}}else{addVertex(_0x2f2707,_0x1447d8[_0x4d4b9c],_0x4d4b9c);}}}for(var _0xb05d4a=0x0;_0xb05d4a<_0x196d50[_0x8688('0x26')];_0xb05d4a+=0x1){if(_0x196d50[_0xb05d4a][_0x8688('0x27')]&&_0x196d50[_0xb05d4a]['target']){_0x2f2707[_0x8688('0x28')](_0x196d50[_0xb05d4a]['source'],_0x196d50[_0xb05d4a]['target'],_0x196d50[_0xb05d4a]['value']);}}return _0x2f2707;}function getSquareProject(_0x21ee40,_0xb2d183){rpc[_0x8688('0x29')](_0x21ee40)['then'](function(_0x203814){_0xb2d183(null,_0x203814);})[_0x8688('0x2a')](function(_0xc3c53f){_0xb2d183(null,_0xc3c53f);});}function createSquareReport(_0x2fabfa,_0x1af3d5){rpc[_0x8688('0x2b')](_0x2fabfa)[_0x8688('0x2c')](function(_0x35f4a6){if(_0x1af3d5){_0x1af3d5(null,_0x35f4a6);}})[_0x8688('0x2a')](function(_0x11f071){if(_0x1af3d5){_0x1af3d5(null,_0x11f071);}});}function setChannelVariables(_0x1d6726){for(var _0x574925 in _0x1d6726){if(_0x1d6726[_0x8688('0x20')](_0x574925)){if(_0x574925['indexOf'](_0x8688('0x2d'))===0x0){_0x1d6726[_0x574925[_0x8688('0x2e')](0x4)]=_0x1d6726[_0x574925];delete _0x1d6726[_0x574925];}}}}function getLogFromObject(_0x49afeb){return util[_0x8688('0x2f')](_0x49afeb,{'showHidden':![],'depth':null});}function agiHandler(_0x2854fc){var _0x53b388,_0x52fb83,_0x3336ac,_0x15ceb6,_0x1ed2cf;logger['debug']('variables',JSON[_0x8688('0x30')](_0x2854fc,null,0x2));logger[_0x8688('0xf')](util[_0x8688('0x10')]('[START]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x2854fc['arg_1'],_0x2854fc[_0x8688('0x17')],_0x2854fc[_0x8688('0x18')],_0x2854fc[_0x8688('0x19')],_0x2854fc[_0x8688('0x1a')]));_0x2854fc['on'](_0x8688('0xc'),errorHandler);_0x2854fc['on'](_0x8688('0x31'),closeHandler);_0x2854fc['on'](_0x8688('0x32'),timeoutHandler);_0x2854fc['evtHangup']=![];_0x2854fc['on'](_0x8688('0x33'),hangupHandler);var _0xeb257d=getSquareProject['sync'](null,_0x2854fc[_0x8688('0x16')]);if(_0xeb257d){if(_0xeb257d[_0x8688('0x34')]){_0x53b388=getRoot(_0xeb257d[_0x8688('0x34')]);console[_0x8688('0x35')](_0x8688('0x36'),_0x53b388);if(_0x53b388&&_0x53b388[_0x8688('0x37')]){logger[_0x8688('0x38')](_0x8688('0x1e'),JSON['stringify'](_0x53b388,null,0x2));_0x2854fc[_0x8688('0x39')]=moment()['format'](_0x8688('0x3a'));_0x52fb83=initGraph(_['omit'](_0x53b388,_0x8688('0x24')),_0x53b388[_0x8688('0x24')]);_0x3336ac=new Vertices(_0x2854fc,rpc,mailRpc);console[_0x8688('0x35')](_0x8688('0x3b'),_0x3336ac);logger['info'](util[_0x8688('0x10')](_0x8688('0x3c'),_0x2854fc[_0x8688('0x16')],_0x2854fc['calleridname'],_0x2854fc[_0x8688('0x18')],_0x2854fc[_0x8688('0x19')],_0x2854fc[_0x8688('0x1a')]));console[_0x8688('0x35')](_0x8688('0x3d'));_0x52fb83[_0x8688('0x3e')](_0x53b388[_0x8688('0x37')]['id'],function(_0x3e593a){try{_0x3e593a=_0x3336ac[_0x8688('0x3f')](_0x3e593a);logger[_0x8688('0x38')]('vertex',JSON['stringify'](_0x3e593a,null,0x2));console['log'](_0x8688('0x40'),_0x3e593a);if(_0x3e593a[_0x8688('0x1f')]===_0x8688('0x41')){logger[_0x8688('0xf')](_0x8688('0x42'));_0x2854fc[_0x8688('0x43')]=_0x3e593a[_0x8688('0x43')]||_0x2854fc['context'];_0x2854fc[_0x8688('0x44')]=_0x3e593a[_0x8688('0x44')];_0x2854fc[_0x8688('0x45')]=_0x3e593a['priority']?_0x3e593a[_0x8688('0x45')]-0x1:0x1;return null;}else if(_0x3e593a&&_0x3336ac[_0x3e593a[_0x8688('0x1f')]]){_0x1ed2cf=_0x3336ac[_0x3e593a[_0x8688('0x1f')]](_0x3e593a);console[_0x8688('0x35')](_0x8688('0x46'),_0x1ed2cf);logger[_0x8688('0xf')](_0x8688('0x47'),JSON[_0x8688('0x30')](_0x1ed2cf,null,0x2));if(_0x1ed2cf&&_0x1ed2cf[_0x8688('0x48')]===AGI_CODE_SUCCESS&&_0x1ed2cf[_0x8688('0x49')]!==AGI_RESULT_ERROR&&!_0x2854fc[_0x8688('0x4a')]){logger[_0x8688('0x38')](_0x8688('0x47'),getLogFromObject(_0x1ed2cf));return _[_0x8688('0x4b')](_0x1ed2cf[_0x8688('0x49')])?null:_0x1ed2cf[_0x8688('0x49')][_0x8688('0x4c')]();}else{logger[_0x8688('0xc')]('response',getLogFromObject(_0x1ed2cf));return null;}}else{logger['error']('agicommand\x20not\x20found');return null;}}catch(_0x2ea67c){logger[_0x8688('0xc')](_0x2ea67c['stack']);return null;}});if(_0x53b388[_0x8688('0x4d')]){logger['info'](util[_0x8688('0x10')](_0x8688('0x4e'),_0x2854fc[_0x8688('0x16')],_0x2854fc[_0x8688('0x17')],_0x2854fc[_0x8688('0x18')],_0x2854fc['dnid'],_0x2854fc['uniqueid']));_0x52fb83[_0x8688('0x3e')](_0x53b388[_0x8688('0x4d')]['id'],function(_0x42a41f){try{_0x42a41f=_0x3336ac[_0x8688('0x3f')](_0x42a41f);logger[_0x8688('0x38')](_0x8688('0x4f'),JSON['stringify'](_0x42a41f,null,0x2));if(_0x42a41f&&_0x3336ac[_0x42a41f[_0x8688('0x1f')]]){_0x1ed2cf=_0x3336ac[_0x42a41f['agicommand']](_0x42a41f);if(_0x1ed2cf){logger[_0x8688('0x38')](_0x8688('0x47'),getLogFromObject(_0x1ed2cf));return _['isUndefined'](_0x1ed2cf['result'])?null:_0x1ed2cf[_0x8688('0x49')]['toString']();}else{logger['error'](_0x8688('0x47'),getLogFromObject(_0x1ed2cf));return null;}}else{logger[_0x8688('0xc')](_0x8688('0x50'));return null;}}catch(_0x40b01b){logger[_0x8688('0xc')](_0x40b01b[_0x8688('0xd')]);return null;}});}logger[_0x8688('0xf')](util[_0x8688('0x10')]('[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x2854fc[_0x8688('0x16')],_0x2854fc[_0x8688('0x17')],_0x2854fc[_0x8688('0x18')],_0x2854fc[_0x8688('0x19')],_0x2854fc[_0x8688('0x1a')]));logger[_0x8688('0xf')](util[_0x8688('0x10')](_0x8688('0x51'),_0x2854fc[_0x8688('0x43')],_0x2854fc['extension'],parseInt(_0x2854fc[_0x8688('0x45')],0xa)+0x1));_0x2854fc[_0x8688('0x52')](_0x2854fc[_0x8688('0x43')],_0x2854fc[_0x8688('0x44')],parseInt(_0x2854fc[_0x8688('0x45')],0xa)+0x1);_0x2854fc[_0x8688('0x31')]();}}else{logger[_0x8688('0xc')](util[_0x8688('0x10')](_0x8688('0x53'),_0x2854fc[_0x8688('0x16')]));_0x2854fc[_0x8688('0x52')](_0x2854fc[_0x8688('0x43')],_0x2854fc[_0x8688('0x44')],parseInt(_0x2854fc[_0x8688('0x45')],0xa)+0x1);_0x2854fc[_0x8688('0x31')]();}}else{logger['error'](util[_0x8688('0x10')](_0x8688('0x54'),_0x2854fc[_0x8688('0x16')]));_0x2854fc[_0x8688('0x52')](_0x2854fc[_0x8688('0x43')],_0x2854fc[_0x8688('0x44')],parseInt(_0x2854fc[_0x8688('0x45')],0xa)+0x1);_0x2854fc[_0x8688('0x31')]();}}function main(){var _0xe31fd0;return utilLicense[_0x8688('0x55')]()[_0x8688('0x2c')](function(_0x245a04){if(_0x245a04){if(_0x245a04[_0x8688('0x56')]){if(_0x245a04[_0x8688('0x57')]&&_0x245a04[_0x8688('0x57')]>0x0){logger[_0x8688('0xf')](util['format'](_0x8688('0x58'),_0x245a04[_0x8688('0x57')]));_0xe31fd0=_0x245a04[_0x8688('0x57')];}else{logger['info'](_0x8688('0x59'));}}else{logger[_0x8688('0xf')](_0x8688('0x5a'));_0xe31fd0=-0x1;}}})['catch'](function(_0x46d70e){logger[_0x8688('0xc')]('[LICENSE]',_0x46d70e[_0x8688('0xd')]);})['finally'](function(){var _0x19dd45=require(_0x8688('0x5b'))(config['agi'][_0x8688('0xe')],config['agi']['ip'],_0xe31fd0);_0x19dd45['on']('error',errorHandler);_0x19dd45['on'](_0x8688('0x5c'),listeningHandler);_0x19dd45['on'](_0x8688('0x5d'),connectionHandler);_0x19dd45['on'](_0x8688('0x31'),closeHandler);});}main();