79258e9678cac62b2dc5b03679f0ed9ff41a7621
[motion2.git] / server / services / agi / project.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 _0x50a4=['dnid','continueAt','Project\x20%s\x20not\x20found','close','Project\x20%s\x20not\x20published','exports','lodash','moment','xml2json','util','../../config/logger','agi','./mailRpc','./vertices','getSquareProjects','error','Unable\x20to\x20download\x20CallySquare\x20projects','stack','hasOwnProperty','retry','addVertex','omit','mxCell','source','target','addEdge','value','mxGraphModel','inspect','production','debug','root','joinAt','YYYY-MM-DD\x20HH:mm:ss','info','format','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','calleridname','callerid','start','clear','vertex','agicommand','gotoc','context','extension','priority','stringify','result','evtHangup','response','toString','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','uniqueid','finally','isUndefined','agicommand\x20not\x20found'];(function(_0x2514e2,_0x7490ad){var _0x28b546=function(_0x250a47){while(--_0x250a47){_0x2514e2['push'](_0x2514e2['shift']());}};_0x28b546(++_0x7490ad);}(_0x50a4,0xb4));var _0x450a=function(_0x5e0406,_0x21dfea){_0x5e0406=_0x5e0406-0x0;var _0x81d10=_0x50a4[_0x5e0406];return _0x81d10;};'use strict';var _=require(_0x450a('0x0'));var moment=require(_0x450a('0x1'));var parser=require(_0x450a('0x2'));var util=require(_0x450a('0x3'));var logger=require(_0x450a('0x4'))(_0x450a('0x5'));var rpc=require('./rpc');var mailRpc=require(_0x450a('0x6'));var Graph=require('./graph');var Vertices=require(_0x450a('0x7'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc[_0x450a('0x8')]()['catch'](function(_0x396b75){logger[_0x450a('0x9')](_0x450a('0xa'),_0x396b75[_0x450a('0xb')]);return[];});}function addVertex(_0x30f5f2,_0x3e675b,_0x8d59ee){_0x3e675b['agicommand']=_0x8d59ee;if(_0x3e675b[_0x450a('0xc')](_0x450a('0xd'))){_0x3e675b['maxRetry']=parseInt(_0x3e675b[_0x450a('0xd')],0xa);}_0x30f5f2[_0x450a('0xe')](_[_0x450a('0xf')](_0x3e675b,_0x450a('0x10')));}function initGraph(_0x13253f,_0x5ed007){var _0x48e4be=new Graph();for(var _0x35d2f8 in _0x13253f){if(_0x13253f[_0x450a('0xc')](_0x35d2f8)){if(_['isArray'](_0x13253f[_0x35d2f8])){for(var _0x12a6b7=0x0;_0x12a6b7<_0x13253f[_0x35d2f8]['length'];_0x12a6b7+=0x1){addVertex(_0x48e4be,_0x13253f[_0x35d2f8][_0x12a6b7],_0x35d2f8);}}else{addVertex(_0x48e4be,_0x13253f[_0x35d2f8],_0x35d2f8);}}}for(var _0x215284=0x0;_0x215284<_0x5ed007['length'];_0x215284+=0x1){if(_0x5ed007[_0x215284][_0x450a('0x11')]&&_0x5ed007[_0x215284][_0x450a('0x12')]){_0x48e4be[_0x450a('0x13')](_0x5ed007[_0x215284][_0x450a('0x11')],_0x5ed007[_0x215284][_0x450a('0x12')],_0x5ed007[_0x215284][_0x450a('0x14')]);}}return _0x48e4be;}function getRoot(_0x1ed445){return parser['toJson'](_0x1ed445,{'object':!![]})[_0x450a('0x15')]['root'];}function inspect(_0x17a011){return util[_0x450a('0x16')](_0x17a011,{'showHidden':![],'depth':null});}function initialize(_0x51dac4,_0x451e22){var _0x60aead=getRoot(_0x51dac4[_0x450a('0x17')]);if(!_0x60aead||!_0x60aead['start'])return;var _0x209eb1,_0x2cb073,_0x2dc1ea;logger[_0x450a('0x18')](_0x450a('0x19'),JSON['stringify'](_0x60aead,null,0x2));_0x451e22[_0x450a('0x1a')]=moment()['format'](_0x450a('0x1b'));_0x209eb1=initGraph(_[_0x450a('0xf')](_0x60aead,_0x450a('0x10')),_0x60aead[_0x450a('0x10')]);_0x2cb073=new Vertices(_0x451e22,rpc,mailRpc);logger[_0x450a('0x1c')](util[_0x450a('0x1d')](_0x450a('0x1e'),_0x451e22[_0x450a('0x1f')],_0x451e22[_0x450a('0x20')],_0x451e22[_0x450a('0x21')],_0x451e22['dnid'],_0x451e22['uniqueid']));_0x209eb1['traverseBFS'](_0x60aead[_0x450a('0x22')]['id'],function(_0x1a0299){try{_0x1a0299=_0x2cb073[_0x450a('0x23')](_0x1a0299);logger[_0x450a('0x18')](_0x450a('0x24'),JSON['stringify'](_0x1a0299,null,0x2));if(_0x1a0299[_0x450a('0x25')]===_0x450a('0x26')){logger[_0x450a('0x1c')]('gotoc\x20block\x20stop\x20traverse\x20BFS');_0x451e22['context']=_0x1a0299[_0x450a('0x27')]||_0x451e22['context'];_0x451e22[_0x450a('0x28')]=_0x1a0299[_0x450a('0x28')];_0x451e22['priority']=_0x1a0299['priority']?_0x1a0299[_0x450a('0x29')]-0x1:0x1;return null;}else if(_0x1a0299&&_0x2cb073[_0x1a0299[_0x450a('0x25')]]){_0x2dc1ea=_0x2cb073[_0x1a0299[_0x450a('0x25')]](_0x1a0299);logger[_0x450a('0x1c')]('response',JSON[_0x450a('0x2a')](_0x2dc1ea,null,0x2));if(_0x2dc1ea&&_0x2dc1ea['code']===AGI_CODE_SUCCESS&&_0x2dc1ea[_0x450a('0x2b')]!==AGI_RESULT_ERROR&&!_0x451e22[_0x450a('0x2c')]){logger[_0x450a('0x18')](_0x450a('0x2d'),inspect(_0x2dc1ea));return _['isUndefined'](_0x2dc1ea[_0x450a('0x2b')])?null:_0x2dc1ea[_0x450a('0x2b')][_0x450a('0x2e')]();}else{logger['error'](_0x450a('0x2d'),inspect(_0x2dc1ea));return null;}}else{logger[_0x450a('0x9')]('agicommand\x20not\x20found');return null;}}catch(_0x1d2a9a){logger['error'](_0x1d2a9a['stack']);return null;}});if(_0x60aead['finally']){logger['info'](util[_0x450a('0x1d')](_0x450a('0x2f'),_0x451e22[_0x450a('0x1f')],_0x451e22['calleridname'],_0x451e22[_0x450a('0x21')],_0x451e22['dnid'],_0x451e22[_0x450a('0x30')]));_0x209eb1['traverseBFS'](_0x60aead[_0x450a('0x31')]['id'],function(_0x305a84){try{_0x305a84=_0x2cb073[_0x450a('0x23')](_0x305a84);logger[_0x450a('0x18')](_0x450a('0x24'),JSON[_0x450a('0x2a')](_0x305a84,null,0x2));if(_0x305a84&&_0x2cb073[_0x305a84['agicommand']]){_0x2dc1ea=_0x2cb073[_0x305a84[_0x450a('0x25')]](_0x305a84);if(_0x2dc1ea){logger[_0x450a('0x18')](_0x450a('0x2d'),inspect(_0x2dc1ea));return _[_0x450a('0x32')](_0x2dc1ea[_0x450a('0x2b')])?null:_0x2dc1ea[_0x450a('0x2b')]['toString']();}else{logger[_0x450a('0x9')]('response',inspect(_0x2dc1ea));return null;}}else{logger['error'](_0x450a('0x33'));return null;}}catch(_0x2e9480){logger[_0x450a('0x9')](_0x2e9480[_0x450a('0xb')]);return null;}});}logger['info'](util['format']('[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x451e22[_0x450a('0x1f')],_0x451e22['calleridname'],_0x451e22['callerid'],_0x451e22[_0x450a('0x34')],_0x451e22[_0x450a('0x30')]));logger[_0x450a('0x1c')](util[_0x450a('0x1d')]('[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s',_0x451e22[_0x450a('0x27')],_0x451e22['extension'],parseInt(_0x451e22[_0x450a('0x29')],0xa)+0x1));_0x451e22[_0x450a('0x35')](_0x451e22[_0x450a('0x27')],_0x451e22['extension'],parseInt(_0x451e22['priority'],0xa)+0x1);_0x451e22['close']();}function handleNotFound(_0x49ec66){logger[_0x450a('0x9')](util[_0x450a('0x1d')](_0x450a('0x36'),_0x49ec66['arg_1']));_0x49ec66[_0x450a('0x35')](_0x49ec66[_0x450a('0x27')],_0x49ec66['extension'],parseInt(_0x49ec66[_0x450a('0x29')],0xa)+0x1);_0x49ec66[_0x450a('0x37')]();}function handleUnpublished(_0x39d535){logger['error'](util[_0x450a('0x1d')](_0x450a('0x38'),_0x39d535['arg_1']));_0x39d535[_0x450a('0x35')](_0x39d535[_0x450a('0x27')],_0x39d535['extension'],parseInt(_0x39d535['priority'],0xa)+0x1);_0x39d535[_0x450a('0x37')]();}module[_0x450a('0x39')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};