534a27703d96950c0e259f1ffaaa48a5b2515ad4
[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 _0x4911=['hasOwnProperty','isArray','length','source','target','addEdge','value','toJson','mxGraphModel','inspect','production','start','root','stringify','joinAt','format','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','arg_1','calleridname','callerid','dnid','uniqueid','traverseBFS','clear','debug','vertex','agicommand','info','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','code','evtHangup','isUndefined','result','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','close','Project\x20%s\x20not\x20found','continueAt','Project\x20%s\x20not\x20published','exports','moment','xml2json','../../config/logger','agi','./mailRpc','./graph','getSquareProjects','catch','error','Unable\x20to\x20download\x20CallySquare\x20projects','stack','retry','omit','mxCell'];(function(_0x1dbb52,_0x17df00){var _0x1a3ab7=function(_0x36e21b){while(--_0x36e21b){_0x1dbb52['push'](_0x1dbb52['shift']());}};_0x1a3ab7(++_0x17df00);}(_0x4911,0x160));var _0x1491=function(_0x184a95,_0x500731){_0x184a95=_0x184a95-0x0;var _0x55eadf=_0x4911[_0x184a95];return _0x55eadf;};'use strict';var _=require('lodash');var moment=require(_0x1491('0x0'));var parser=require(_0x1491('0x1'));var util=require('util');var logger=require(_0x1491('0x2'))(_0x1491('0x3'));var rpc=require('./rpc');var mailRpc=require(_0x1491('0x4'));var Graph=require(_0x1491('0x5'));var Vertices=require('./vertices');var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc[_0x1491('0x6')]()[_0x1491('0x7')](function(_0x3b6250){logger[_0x1491('0x8')](_0x1491('0x9'),_0x3b6250[_0x1491('0xa')]);return[];});}function addVertex(_0x102996,_0x173bdb,_0x412c3b){_0x173bdb['agicommand']=_0x412c3b;if(_0x173bdb['hasOwnProperty'](_0x1491('0xb'))){_0x173bdb['maxRetry']=parseInt(_0x173bdb[_0x1491('0xb')],0xa);}_0x102996['addVertex'](_[_0x1491('0xc')](_0x173bdb,_0x1491('0xd')));}function initGraph(_0xe904e,_0x3233bc){var _0x301062=new Graph();for(var _0x56abbc in _0xe904e){if(_0xe904e[_0x1491('0xe')](_0x56abbc)){if(_[_0x1491('0xf')](_0xe904e[_0x56abbc])){for(var _0x269450=0x0;_0x269450<_0xe904e[_0x56abbc][_0x1491('0x10')];_0x269450+=0x1){addVertex(_0x301062,_0xe904e[_0x56abbc][_0x269450],_0x56abbc);}}else{addVertex(_0x301062,_0xe904e[_0x56abbc],_0x56abbc);}}}for(var _0x5666da=0x0;_0x5666da<_0x3233bc[_0x1491('0x10')];_0x5666da+=0x1){if(_0x3233bc[_0x5666da][_0x1491('0x11')]&&_0x3233bc[_0x5666da][_0x1491('0x12')]){_0x301062[_0x1491('0x13')](_0x3233bc[_0x5666da][_0x1491('0x11')],_0x3233bc[_0x5666da][_0x1491('0x12')],_0x3233bc[_0x5666da][_0x1491('0x14')]);}}return _0x301062;}function getRoot(_0x2577a6){return parser[_0x1491('0x15')](_0x2577a6,{'object':!![]})[_0x1491('0x16')]['root'];}function inspect(_0x22c806){return util[_0x1491('0x17')](_0x22c806,{'showHidden':![],'depth':null});}function initialize(_0x17c672,_0x10531f){var _0x3f27d3=getRoot(_0x17c672[_0x1491('0x18')]);if(!_0x3f27d3||!_0x3f27d3[_0x1491('0x19')])return;var _0x1ef9be,_0xe7659e,_0x30508b;logger['debug'](_0x1491('0x1a'),JSON[_0x1491('0x1b')](_0x3f27d3,null,0x2));_0x10531f[_0x1491('0x1c')]=moment()[_0x1491('0x1d')](_0x1491('0x1e'));_0x1ef9be=initGraph(_[_0x1491('0xc')](_0x3f27d3,_0x1491('0xd')),_0x3f27d3[_0x1491('0xd')]);_0xe7659e=new Vertices(_0x10531f,rpc,mailRpc);logger['info'](util[_0x1491('0x1d')](_0x1491('0x1f'),_0x10531f[_0x1491('0x20')],_0x10531f[_0x1491('0x21')],_0x10531f[_0x1491('0x22')],_0x10531f[_0x1491('0x23')],_0x10531f[_0x1491('0x24')]));_0x1ef9be[_0x1491('0x25')](_0x3f27d3[_0x1491('0x19')]['id'],function(_0x2ea284){try{_0x2ea284=_0xe7659e[_0x1491('0x26')](_0x2ea284);logger[_0x1491('0x27')](_0x1491('0x28'),JSON[_0x1491('0x1b')](_0x2ea284,null,0x2));if(_0x2ea284[_0x1491('0x29')]==='gotoc'){logger[_0x1491('0x2a')](_0x1491('0x2b'));_0x10531f[_0x1491('0x2c')]=_0x2ea284[_0x1491('0x2c')]||_0x10531f[_0x1491('0x2c')];_0x10531f[_0x1491('0x2d')]=_0x2ea284[_0x1491('0x2d')];_0x10531f[_0x1491('0x2e')]=_0x2ea284[_0x1491('0x2e')]?_0x2ea284[_0x1491('0x2e')]-0x1:0x1;return null;}else if(_0x2ea284&&_0xe7659e[_0x2ea284[_0x1491('0x29')]]){_0x30508b=_0xe7659e[_0x2ea284[_0x1491('0x29')]](_0x2ea284);logger[_0x1491('0x2a')](_0x1491('0x2f'),JSON[_0x1491('0x1b')](_0x30508b,null,0x2));if(_0x30508b&&_0x30508b[_0x1491('0x30')]===AGI_CODE_SUCCESS&&_0x30508b['result']!==AGI_RESULT_ERROR&&!_0x10531f[_0x1491('0x31')]){logger['debug'](_0x1491('0x2f'),inspect(_0x30508b));return _[_0x1491('0x32')](_0x30508b[_0x1491('0x33')])?null:_0x30508b[_0x1491('0x33')][_0x1491('0x34')]();}else{logger[_0x1491('0x8')](_0x1491('0x2f'),inspect(_0x30508b));return null;}}else{logger[_0x1491('0x8')](_0x1491('0x35'));return null;}}catch(_0x243754){logger['error'](_0x243754[_0x1491('0xa')]);return null;}});if(_0x3f27d3['finally']){logger[_0x1491('0x2a')](util[_0x1491('0x1d')]('[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x10531f[_0x1491('0x20')],_0x10531f[_0x1491('0x21')],_0x10531f[_0x1491('0x22')],_0x10531f[_0x1491('0x23')],_0x10531f[_0x1491('0x24')]));_0x1ef9be[_0x1491('0x25')](_0x3f27d3['finally']['id'],function(_0x515996){try{_0x515996=_0xe7659e[_0x1491('0x26')](_0x515996);logger[_0x1491('0x27')](_0x1491('0x28'),JSON[_0x1491('0x1b')](_0x515996,null,0x2));if(_0x515996&&_0xe7659e[_0x515996[_0x1491('0x29')]]){_0x30508b=_0xe7659e[_0x515996['agicommand']](_0x515996);if(_0x30508b){logger[_0x1491('0x27')](_0x1491('0x2f'),inspect(_0x30508b));return _[_0x1491('0x32')](_0x30508b['result'])?null:_0x30508b[_0x1491('0x33')]['toString']();}else{logger[_0x1491('0x8')](_0x1491('0x2f'),inspect(_0x30508b));return null;}}else{logger['error']('agicommand\x20not\x20found');return null;}}catch(_0x10dc39){logger[_0x1491('0x8')](_0x10dc39[_0x1491('0xa')]);return null;}});}logger[_0x1491('0x2a')](util[_0x1491('0x1d')](_0x1491('0x36'),_0x10531f['arg_1'],_0x10531f[_0x1491('0x21')],_0x10531f[_0x1491('0x22')],_0x10531f[_0x1491('0x23')],_0x10531f[_0x1491('0x24')]));logger['info'](util[_0x1491('0x1d')](_0x1491('0x37'),_0x10531f[_0x1491('0x2c')],_0x10531f[_0x1491('0x2d')],parseInt(_0x10531f[_0x1491('0x2e')],0xa)+0x1));_0x10531f['continueAt'](_0x10531f[_0x1491('0x2c')],_0x10531f[_0x1491('0x2d')],parseInt(_0x10531f[_0x1491('0x2e')],0xa)+0x1);_0x10531f[_0x1491('0x38')]();}function handleNotFound(_0x4051cb){logger['error'](util[_0x1491('0x1d')](_0x1491('0x39'),_0x4051cb['arg_1']));_0x4051cb[_0x1491('0x3a')](_0x4051cb[_0x1491('0x2c')],_0x4051cb[_0x1491('0x2d')],parseInt(_0x4051cb['priority'],0xa)+0x1);_0x4051cb[_0x1491('0x38')]();}function handleUnpublished(_0x26dc07){logger[_0x1491('0x8')](util[_0x1491('0x1d')](_0x1491('0x3b'),_0x26dc07['arg_1']));_0x26dc07[_0x1491('0x3a')](_0x26dc07[_0x1491('0x2c')],_0x26dc07[_0x1491('0x2d')],parseInt(_0x26dc07[_0x1491('0x2e')],0xa)+0x1);_0x26dc07[_0x1491('0x38')]();}module[_0x1491('0x3c')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};