Built motion from commit 10af8726.|2.6.34
[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 _0x3740=['arg_1','traverseBFS','finally','clear','toString','uniqueid','continueAt','close','Project\x20%s\x20not\x20found','Project\x20%s\x20not\x20published','exports','lodash','xml2json','util','../../config/logger','agi','./rpc','./mailRpc','./vertices','getSquareProjects','catch','error','stack','agicommand','hasOwnProperty','retry','maxRetry','addVertex','omit','isArray','length','source','target','addEdge','value','toJson','mxGraphModel','root','inspect','production','start','debug','stringify','joinAt','format','YYYY-MM-DD\x20HH:mm:ss','mxCell','info','calleridname','callerid','dnid','vertex','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','code','result','response','isUndefined','agicommand\x20not\x20found','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s'];(function(_0x5cb1af,_0x4bdc8c){var _0x8d7940=function(_0x3db70a){while(--_0x3db70a){_0x5cb1af['push'](_0x5cb1af['shift']());}};_0x8d7940(++_0x4bdc8c);}(_0x3740,0x1c4));var _0x0374=function(_0x412686,_0x3fde24){_0x412686=_0x412686-0x0;var _0x18619e=_0x3740[_0x412686];return _0x18619e;};'use strict';var _=require(_0x0374('0x0'));var moment=require('moment');var parser=require(_0x0374('0x1'));var util=require(_0x0374('0x2'));var logger=require(_0x0374('0x3'))(_0x0374('0x4'));var rpc=require(_0x0374('0x5'));var mailRpc=require(_0x0374('0x6'));var Graph=require('./graph');var Vertices=require(_0x0374('0x7'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc[_0x0374('0x8')]()[_0x0374('0x9')](function(_0x124b72){logger[_0x0374('0xa')]('Unable\x20to\x20download\x20CallySquare\x20projects',_0x124b72[_0x0374('0xb')]);return[];});}function addVertex(_0x138638,_0xe15340,_0x3159f9){_0xe15340[_0x0374('0xc')]=_0x3159f9;if(_0xe15340[_0x0374('0xd')](_0x0374('0xe'))){_0xe15340[_0x0374('0xf')]=parseInt(_0xe15340[_0x0374('0xe')],0xa);}_0x138638[_0x0374('0x10')](_[_0x0374('0x11')](_0xe15340,'mxCell'));}function initGraph(_0x420c56,_0x576ed2){var _0x472dc2=new Graph();for(var _0x301fcc in _0x420c56){if(_0x420c56[_0x0374('0xd')](_0x301fcc)){if(_[_0x0374('0x12')](_0x420c56[_0x301fcc])){for(var _0x258cca=0x0;_0x258cca<_0x420c56[_0x301fcc][_0x0374('0x13')];_0x258cca+=0x1){addVertex(_0x472dc2,_0x420c56[_0x301fcc][_0x258cca],_0x301fcc);}}else{addVertex(_0x472dc2,_0x420c56[_0x301fcc],_0x301fcc);}}}for(var _0x5afb91=0x0;_0x5afb91<_0x576ed2[_0x0374('0x13')];_0x5afb91+=0x1){if(_0x576ed2[_0x5afb91][_0x0374('0x14')]&&_0x576ed2[_0x5afb91][_0x0374('0x15')]){_0x472dc2[_0x0374('0x16')](_0x576ed2[_0x5afb91][_0x0374('0x14')],_0x576ed2[_0x5afb91][_0x0374('0x15')],_0x576ed2[_0x5afb91][_0x0374('0x17')]);}}return _0x472dc2;}function getRoot(_0x54bfa9){return parser[_0x0374('0x18')](_0x54bfa9,{'object':!![]})[_0x0374('0x19')][_0x0374('0x1a')];}function inspect(_0x3932de){return util[_0x0374('0x1b')](_0x3932de,{'showHidden':![],'depth':null});}function initialize(_0x3b8643,_0x5b9fa1){var _0x3a4950=getRoot(_0x3b8643[_0x0374('0x1c')]);if(!_0x3a4950||!_0x3a4950[_0x0374('0x1d')])return;var _0x44d8ca,_0xd44c7b,_0x3f27b9;logger[_0x0374('0x1e')](_0x0374('0x1a'),JSON[_0x0374('0x1f')](_0x3a4950,null,0x2));_0x5b9fa1[_0x0374('0x20')]=moment()[_0x0374('0x21')](_0x0374('0x22'));_0x44d8ca=initGraph(_['omit'](_0x3a4950,_0x0374('0x23')),_0x3a4950[_0x0374('0x23')]);_0xd44c7b=new Vertices(_0x5b9fa1,rpc,mailRpc);logger[_0x0374('0x24')](util[_0x0374('0x21')]('[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x5b9fa1['arg_1'],_0x5b9fa1[_0x0374('0x25')],_0x5b9fa1[_0x0374('0x26')],_0x5b9fa1[_0x0374('0x27')],_0x5b9fa1['uniqueid']));_0x44d8ca['traverseBFS'](_0x3a4950['start']['id'],function(_0x15e7fe){try{_0x15e7fe=_0xd44c7b['clear'](_0x15e7fe);logger[_0x0374('0x1e')](_0x0374('0x28'),JSON['stringify'](_0x15e7fe,null,0x2));if(_0x15e7fe['agicommand']===_0x0374('0x29')){logger[_0x0374('0x24')](_0x0374('0x2a'));_0x5b9fa1[_0x0374('0x2b')]=_0x15e7fe['context']||_0x5b9fa1['context'];_0x5b9fa1[_0x0374('0x2c')]=_0x15e7fe[_0x0374('0x2c')];_0x5b9fa1[_0x0374('0x2d')]=_0x15e7fe[_0x0374('0x2d')]?_0x15e7fe['priority']-0x1:0x1;return null;}else if(_0x15e7fe&&_0xd44c7b[_0x15e7fe[_0x0374('0xc')]]){_0x3f27b9=_0xd44c7b[_0x15e7fe[_0x0374('0xc')]](_0x15e7fe);logger['info']('response',JSON[_0x0374('0x1f')](_0x3f27b9,null,0x2));if(_0x3f27b9&&_0x3f27b9[_0x0374('0x2e')]===AGI_CODE_SUCCESS&&_0x3f27b9[_0x0374('0x2f')]!==AGI_RESULT_ERROR&&!_0x5b9fa1['evtHangup']){logger[_0x0374('0x1e')](_0x0374('0x30'),inspect(_0x3f27b9));return _[_0x0374('0x31')](_0x3f27b9[_0x0374('0x2f')])?null:_0x3f27b9[_0x0374('0x2f')]['toString']();}else{logger[_0x0374('0xa')](_0x0374('0x30'),inspect(_0x3f27b9));return null;}}else{logger['error'](_0x0374('0x32'));return null;}}catch(_0x5f4660){logger[_0x0374('0xa')](_0x5f4660[_0x0374('0xb')]);return null;}});if(_0x3a4950['finally']){logger[_0x0374('0x24')](util['format'](_0x0374('0x33'),_0x5b9fa1[_0x0374('0x34')],_0x5b9fa1[_0x0374('0x25')],_0x5b9fa1[_0x0374('0x26')],_0x5b9fa1[_0x0374('0x27')],_0x5b9fa1['uniqueid']));_0x44d8ca[_0x0374('0x35')](_0x3a4950[_0x0374('0x36')]['id'],function(_0x29dcef){try{_0x29dcef=_0xd44c7b[_0x0374('0x37')](_0x29dcef);logger[_0x0374('0x1e')](_0x0374('0x28'),JSON[_0x0374('0x1f')](_0x29dcef,null,0x2));if(_0x29dcef&&_0xd44c7b[_0x29dcef['agicommand']]){_0x3f27b9=_0xd44c7b[_0x29dcef[_0x0374('0xc')]](_0x29dcef);if(_0x3f27b9){logger[_0x0374('0x1e')]('response',inspect(_0x3f27b9));return _[_0x0374('0x31')](_0x3f27b9['result'])?null:_0x3f27b9[_0x0374('0x2f')][_0x0374('0x38')]();}else{logger[_0x0374('0xa')](_0x0374('0x30'),inspect(_0x3f27b9));return null;}}else{logger[_0x0374('0xa')](_0x0374('0x32'));return null;}}catch(_0x3a6627){logger[_0x0374('0xa')](_0x3a6627[_0x0374('0xb')]);return null;}});}logger[_0x0374('0x24')](util[_0x0374('0x21')]('[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x5b9fa1[_0x0374('0x34')],_0x5b9fa1[_0x0374('0x25')],_0x5b9fa1[_0x0374('0x26')],_0x5b9fa1[_0x0374('0x27')],_0x5b9fa1[_0x0374('0x39')]));logger['info'](util[_0x0374('0x21')]('[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s',_0x5b9fa1[_0x0374('0x2b')],_0x5b9fa1[_0x0374('0x2c')],parseInt(_0x5b9fa1[_0x0374('0x2d')],0xa)+0x1));_0x5b9fa1[_0x0374('0x3a')](_0x5b9fa1[_0x0374('0x2b')],_0x5b9fa1[_0x0374('0x2c')],parseInt(_0x5b9fa1[_0x0374('0x2d')],0xa)+0x1);_0x5b9fa1[_0x0374('0x3b')]();}function handleNotFound(_0x5ba446){logger[_0x0374('0xa')](util[_0x0374('0x21')](_0x0374('0x3c'),_0x5ba446[_0x0374('0x34')]));_0x5ba446[_0x0374('0x3a')](_0x5ba446[_0x0374('0x2b')],_0x5ba446[_0x0374('0x2c')],parseInt(_0x5ba446[_0x0374('0x2d')],0xa)+0x1);_0x5ba446[_0x0374('0x3b')]();}function handleUnpublished(_0x96d803){logger[_0x0374('0xa')](util[_0x0374('0x21')](_0x0374('0x3d'),_0x96d803[_0x0374('0x34')]));_0x96d803[_0x0374('0x3a')](_0x96d803[_0x0374('0x2b')],_0x96d803[_0x0374('0x2c')],parseInt(_0x96d803['priority'],0xa)+0x1);_0x96d803[_0x0374('0x3b')]();}module[_0x0374('0x3e')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};