Built motion from commit 47436d59.|2.6.7
[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 _0x6f6e=['uniqueid','traverseBFS','clear','agicommand','gotoc','info','context','extension','priority','code','result','evtHangup','toString','error','response','agicommand\x20not\x20found','stack','finally','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','callerid','vertex','[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','continueAt','close','Project\x20%s\x20not\x20published','exports','lodash','moment','xml2json','../../config/logger','agi','./rpc','./mailRpc','./vertices','getSquareProjects','catch','Unable\x20to\x20download\x20CallySquare\x20projects','hasOwnProperty','retry','addVertex','omit','mxCell','length','source','addEdge','value','toJson','mxGraphModel','root','inspect','start','debug','stringify','joinAt','format','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','calleridname','dnid'];(function(_0x4565bf,_0x5ad9d6){var _0x5610ba=function(_0x170988){while(--_0x170988){_0x4565bf['push'](_0x4565bf['shift']());}};_0x5610ba(++_0x5ad9d6);}(_0x6f6e,0x93));var _0xe6f6=function(_0xef097b,_0x21195a){_0xef097b=_0xef097b-0x0;var _0x68e197=_0x6f6e[_0xef097b];return _0x68e197;};'use strict';var _=require(_0xe6f6('0x0'));var moment=require(_0xe6f6('0x1'));var parser=require(_0xe6f6('0x2'));var util=require('util');var logger=require(_0xe6f6('0x3'))(_0xe6f6('0x4'));var rpc=require(_0xe6f6('0x5'));var mailRpc=require(_0xe6f6('0x6'));var Graph=require('./graph');var Vertices=require(_0xe6f6('0x7'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc[_0xe6f6('0x8')]()[_0xe6f6('0x9')](function(_0x59202e){logger['error'](_0xe6f6('0xa'),_0x59202e['stack']);return[];});}function addVertex(_0x35a3eb,_0x56158e,_0x58c08a){_0x56158e['agicommand']=_0x58c08a;if(_0x56158e[_0xe6f6('0xb')](_0xe6f6('0xc'))){_0x56158e['maxRetry']=parseInt(_0x56158e['retry'],0xa);}_0x35a3eb[_0xe6f6('0xd')](_[_0xe6f6('0xe')](_0x56158e,_0xe6f6('0xf')));}function initGraph(_0x1b1c92,_0x29a0f0){var _0x5eff45=new Graph();for(var _0x5f1b15 in _0x1b1c92){if(_0x1b1c92[_0xe6f6('0xb')](_0x5f1b15)){if(_['isArray'](_0x1b1c92[_0x5f1b15])){for(var _0x39d6eb=0x0;_0x39d6eb<_0x1b1c92[_0x5f1b15][_0xe6f6('0x10')];_0x39d6eb+=0x1){addVertex(_0x5eff45,_0x1b1c92[_0x5f1b15][_0x39d6eb],_0x5f1b15);}}else{addVertex(_0x5eff45,_0x1b1c92[_0x5f1b15],_0x5f1b15);}}}for(var _0x4fef3b=0x0;_0x4fef3b<_0x29a0f0[_0xe6f6('0x10')];_0x4fef3b+=0x1){if(_0x29a0f0[_0x4fef3b][_0xe6f6('0x11')]&&_0x29a0f0[_0x4fef3b]['target']){_0x5eff45[_0xe6f6('0x12')](_0x29a0f0[_0x4fef3b][_0xe6f6('0x11')],_0x29a0f0[_0x4fef3b]['target'],_0x29a0f0[_0x4fef3b][_0xe6f6('0x13')]);}}return _0x5eff45;}function getRoot(_0x126ecc){return parser[_0xe6f6('0x14')](_0x126ecc,{'object':!![]})[_0xe6f6('0x15')][_0xe6f6('0x16')];}function inspect(_0x4eff35){return util[_0xe6f6('0x17')](_0x4eff35,{'showHidden':![],'depth':null});}function initialize(_0x2289d4,_0x20e909){var _0x5ec16a=getRoot(_0x2289d4['production']);if(!_0x5ec16a||!_0x5ec16a[_0xe6f6('0x18')])return;var _0x3892c7,_0x333875,_0x22ff18;logger[_0xe6f6('0x19')](_0xe6f6('0x16'),JSON[_0xe6f6('0x1a')](_0x5ec16a,null,0x2));_0x20e909[_0xe6f6('0x1b')]=moment()[_0xe6f6('0x1c')]('YYYY-MM-DD\x20HH:mm:ss');_0x3892c7=initGraph(_['omit'](_0x5ec16a,_0xe6f6('0xf')),_0x5ec16a['mxCell']);_0x333875=new Vertices(_0x20e909,rpc,mailRpc);logger['info'](util[_0xe6f6('0x1c')](_0xe6f6('0x1d'),_0x20e909[_0xe6f6('0x1e')],_0x20e909[_0xe6f6('0x1f')],_0x20e909['callerid'],_0x20e909[_0xe6f6('0x20')],_0x20e909[_0xe6f6('0x21')]));_0x3892c7[_0xe6f6('0x22')](_0x5ec16a[_0xe6f6('0x18')]['id'],function(_0x495026){try{_0x495026=_0x333875[_0xe6f6('0x23')](_0x495026);logger[_0xe6f6('0x19')]('vertex',JSON[_0xe6f6('0x1a')](_0x495026,null,0x2));if(_0x495026[_0xe6f6('0x24')]===_0xe6f6('0x25')){logger[_0xe6f6('0x26')]('gotoc\x20block\x20stop\x20traverse\x20BFS');_0x20e909[_0xe6f6('0x27')]=_0x495026[_0xe6f6('0x27')]||_0x20e909['context'];_0x20e909[_0xe6f6('0x28')]=_0x495026[_0xe6f6('0x28')];_0x20e909[_0xe6f6('0x29')]=_0x495026[_0xe6f6('0x29')]?_0x495026['priority']-0x1:0x1;return null;}else if(_0x495026&&_0x333875[_0x495026['agicommand']]){_0x22ff18=_0x333875[_0x495026[_0xe6f6('0x24')]](_0x495026);logger['info']('response',JSON[_0xe6f6('0x1a')](_0x22ff18,null,0x2));if(_0x22ff18&&_0x22ff18[_0xe6f6('0x2a')]===AGI_CODE_SUCCESS&&_0x22ff18[_0xe6f6('0x2b')]!==AGI_RESULT_ERROR&&!_0x20e909[_0xe6f6('0x2c')]){logger[_0xe6f6('0x19')]('response',inspect(_0x22ff18));return _['isUndefined'](_0x22ff18[_0xe6f6('0x2b')])?null:_0x22ff18[_0xe6f6('0x2b')][_0xe6f6('0x2d')]();}else{logger[_0xe6f6('0x2e')](_0xe6f6('0x2f'),inspect(_0x22ff18));return null;}}else{logger['error'](_0xe6f6('0x30'));return null;}}catch(_0x416172){logger[_0xe6f6('0x2e')](_0x416172[_0xe6f6('0x31')]);return null;}});if(_0x5ec16a[_0xe6f6('0x32')]){logger[_0xe6f6('0x26')](util[_0xe6f6('0x1c')](_0xe6f6('0x33'),_0x20e909[_0xe6f6('0x1e')],_0x20e909['calleridname'],_0x20e909[_0xe6f6('0x34')],_0x20e909[_0xe6f6('0x20')],_0x20e909[_0xe6f6('0x21')]));_0x3892c7['traverseBFS'](_0x5ec16a[_0xe6f6('0x32')]['id'],function(_0x58fa84){try{_0x58fa84=_0x333875['clear'](_0x58fa84);logger['debug'](_0xe6f6('0x35'),JSON[_0xe6f6('0x1a')](_0x58fa84,null,0x2));if(_0x58fa84&&_0x333875[_0x58fa84['agicommand']]){_0x22ff18=_0x333875[_0x58fa84[_0xe6f6('0x24')]](_0x58fa84);if(_0x22ff18){logger['debug']('response',inspect(_0x22ff18));return _['isUndefined'](_0x22ff18[_0xe6f6('0x2b')])?null:_0x22ff18[_0xe6f6('0x2b')][_0xe6f6('0x2d')]();}else{logger['error']('response',inspect(_0x22ff18));return null;}}else{logger[_0xe6f6('0x2e')](_0xe6f6('0x30'));return null;}}catch(_0x2f0aef){logger['error'](_0x2f0aef[_0xe6f6('0x31')]);return null;}});}logger['info'](util[_0xe6f6('0x1c')](_0xe6f6('0x36'),_0x20e909['arg_1'],_0x20e909[_0xe6f6('0x1f')],_0x20e909[_0xe6f6('0x34')],_0x20e909[_0xe6f6('0x20')],_0x20e909[_0xe6f6('0x21')]));logger['info'](util[_0xe6f6('0x1c')](_0xe6f6('0x37'),_0x20e909[_0xe6f6('0x27')],_0x20e909['extension'],parseInt(_0x20e909[_0xe6f6('0x29')],0xa)+0x1));_0x20e909[_0xe6f6('0x38')](_0x20e909[_0xe6f6('0x27')],_0x20e909[_0xe6f6('0x28')],parseInt(_0x20e909[_0xe6f6('0x29')],0xa)+0x1);_0x20e909[_0xe6f6('0x39')]();}function handleNotFound(_0x41ea52){logger[_0xe6f6('0x2e')](util[_0xe6f6('0x1c')]('Project\x20%s\x20not\x20found',_0x41ea52[_0xe6f6('0x1e')]));_0x41ea52[_0xe6f6('0x38')](_0x41ea52[_0xe6f6('0x27')],_0x41ea52[_0xe6f6('0x28')],parseInt(_0x41ea52[_0xe6f6('0x29')],0xa)+0x1);_0x41ea52[_0xe6f6('0x39')]();}function handleUnpublished(_0x3c9f14){logger[_0xe6f6('0x2e')](util[_0xe6f6('0x1c')](_0xe6f6('0x3a'),_0x3c9f14[_0xe6f6('0x1e')]));_0x3c9f14[_0xe6f6('0x38')](_0x3c9f14['context'],_0x3c9f14['extension'],parseInt(_0x3c9f14[_0xe6f6('0x29')],0xa)+0x1);_0x3c9f14[_0xe6f6('0x39')]();}module[_0xe6f6('0x3b')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};