Built motion from commit b0a9a629.|2.6.33
[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 _0x6c5a=['YYYY-MM-DD\x20HH:mm:ss','omit','info','[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','agicommand','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','code','result','evtHangup','isUndefined','toString','agicommand\x20not\x20found','finally','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','clear','[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','continueAt','Project\x20%s\x20not\x20found','close','Project\x20%s\x20not\x20published','lodash','moment','xml2json','util','agi','./mailRpc','./graph','./vertices','getSquareProjects','catch','error','stack','hasOwnProperty','retry','addVertex','mxCell','length','source','target','value','inspect','start','debug','root','stringify','joinAt','format'];(function(_0x23e202,_0x4762da){var _0xdbeddc=function(_0x388e74){while(--_0x388e74){_0x23e202['push'](_0x23e202['shift']());}};_0xdbeddc(++_0x4762da);}(_0x6c5a,0x93));var _0xa6c5=function(_0x95f4e1,_0x5585bf){_0x95f4e1=_0x95f4e1-0x0;var _0xb2c148=_0x6c5a[_0x95f4e1];return _0xb2c148;};'use strict';var _=require(_0xa6c5('0x0'));var moment=require(_0xa6c5('0x1'));var parser=require(_0xa6c5('0x2'));var util=require(_0xa6c5('0x3'));var logger=require('../../config/logger')(_0xa6c5('0x4'));var rpc=require('./rpc');var mailRpc=require(_0xa6c5('0x5'));var Graph=require(_0xa6c5('0x6'));var Vertices=require(_0xa6c5('0x7'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc[_0xa6c5('0x8')]()[_0xa6c5('0x9')](function(_0x22a475){logger[_0xa6c5('0xa')]('Unable\x20to\x20download\x20CallySquare\x20projects',_0x22a475[_0xa6c5('0xb')]);return[];});}function addVertex(_0x78328a,_0x3677b3,_0x1ccc41){_0x3677b3['agicommand']=_0x1ccc41;if(_0x3677b3[_0xa6c5('0xc')](_0xa6c5('0xd'))){_0x3677b3['maxRetry']=parseInt(_0x3677b3['retry'],0xa);}_0x78328a[_0xa6c5('0xe')](_['omit'](_0x3677b3,_0xa6c5('0xf')));}function initGraph(_0x5ab408,_0x895df1){var _0x10c4aa=new Graph();for(var _0x175d82 in _0x5ab408){if(_0x5ab408[_0xa6c5('0xc')](_0x175d82)){if(_['isArray'](_0x5ab408[_0x175d82])){for(var _0x3ff095=0x0;_0x3ff095<_0x5ab408[_0x175d82][_0xa6c5('0x10')];_0x3ff095+=0x1){addVertex(_0x10c4aa,_0x5ab408[_0x175d82][_0x3ff095],_0x175d82);}}else{addVertex(_0x10c4aa,_0x5ab408[_0x175d82],_0x175d82);}}}for(var _0x57f725=0x0;_0x57f725<_0x895df1[_0xa6c5('0x10')];_0x57f725+=0x1){if(_0x895df1[_0x57f725][_0xa6c5('0x11')]&&_0x895df1[_0x57f725]['target']){_0x10c4aa['addEdge'](_0x895df1[_0x57f725][_0xa6c5('0x11')],_0x895df1[_0x57f725][_0xa6c5('0x12')],_0x895df1[_0x57f725][_0xa6c5('0x13')]);}}return _0x10c4aa;}function getRoot(_0x385774){return parser['toJson'](_0x385774,{'object':!![]})['mxGraphModel']['root'];}function inspect(_0x662390){return util[_0xa6c5('0x14')](_0x662390,{'showHidden':![],'depth':null});}function initialize(_0x43bf96,_0x2f61d7){var _0x3b5a2a=getRoot(_0x43bf96['production']);if(!_0x3b5a2a||!_0x3b5a2a[_0xa6c5('0x15')])return;var _0x5ec786,_0x18dd14,_0x5d4f71;logger[_0xa6c5('0x16')](_0xa6c5('0x17'),JSON[_0xa6c5('0x18')](_0x3b5a2a,null,0x2));_0x2f61d7[_0xa6c5('0x19')]=moment()[_0xa6c5('0x1a')](_0xa6c5('0x1b'));_0x5ec786=initGraph(_[_0xa6c5('0x1c')](_0x3b5a2a,_0xa6c5('0xf')),_0x3b5a2a[_0xa6c5('0xf')]);_0x18dd14=new Vertices(_0x2f61d7,rpc,mailRpc);logger[_0xa6c5('0x1d')](util['format'](_0xa6c5('0x1e'),_0x2f61d7[_0xa6c5('0x1f')],_0x2f61d7[_0xa6c5('0x20')],_0x2f61d7[_0xa6c5('0x21')],_0x2f61d7[_0xa6c5('0x22')],_0x2f61d7[_0xa6c5('0x23')]));_0x5ec786[_0xa6c5('0x24')](_0x3b5a2a[_0xa6c5('0x15')]['id'],function(_0x30c396){try{_0x30c396=_0x18dd14['clear'](_0x30c396);logger['debug']('vertex',JSON[_0xa6c5('0x18')](_0x30c396,null,0x2));if(_0x30c396[_0xa6c5('0x25')]===_0xa6c5('0x26')){logger['info'](_0xa6c5('0x27'));_0x2f61d7[_0xa6c5('0x28')]=_0x30c396['context']||_0x2f61d7['context'];_0x2f61d7[_0xa6c5('0x29')]=_0x30c396['extension'];_0x2f61d7[_0xa6c5('0x2a')]=_0x30c396['priority']?_0x30c396[_0xa6c5('0x2a')]-0x1:0x1;return null;}else if(_0x30c396&&_0x18dd14[_0x30c396[_0xa6c5('0x25')]]){_0x5d4f71=_0x18dd14[_0x30c396['agicommand']](_0x30c396);logger['info'](_0xa6c5('0x2b'),JSON['stringify'](_0x5d4f71,null,0x2));if(_0x5d4f71&&_0x5d4f71[_0xa6c5('0x2c')]===AGI_CODE_SUCCESS&&_0x5d4f71[_0xa6c5('0x2d')]!==AGI_RESULT_ERROR&&!_0x2f61d7[_0xa6c5('0x2e')]){logger[_0xa6c5('0x16')]('response',inspect(_0x5d4f71));return _[_0xa6c5('0x2f')](_0x5d4f71[_0xa6c5('0x2d')])?null:_0x5d4f71[_0xa6c5('0x2d')][_0xa6c5('0x30')]();}else{logger[_0xa6c5('0xa')]('response',inspect(_0x5d4f71));return null;}}else{logger[_0xa6c5('0xa')](_0xa6c5('0x31'));return null;}}catch(_0xf4fa59){logger['error'](_0xf4fa59[_0xa6c5('0xb')]);return null;}});if(_0x3b5a2a[_0xa6c5('0x32')]){logger[_0xa6c5('0x1d')](util['format'](_0xa6c5('0x33'),_0x2f61d7[_0xa6c5('0x1f')],_0x2f61d7['calleridname'],_0x2f61d7[_0xa6c5('0x21')],_0x2f61d7[_0xa6c5('0x22')],_0x2f61d7['uniqueid']));_0x5ec786[_0xa6c5('0x24')](_0x3b5a2a[_0xa6c5('0x32')]['id'],function(_0x24e945){try{_0x24e945=_0x18dd14[_0xa6c5('0x34')](_0x24e945);logger[_0xa6c5('0x16')]('vertex',JSON[_0xa6c5('0x18')](_0x24e945,null,0x2));if(_0x24e945&&_0x18dd14[_0x24e945[_0xa6c5('0x25')]]){_0x5d4f71=_0x18dd14[_0x24e945[_0xa6c5('0x25')]](_0x24e945);if(_0x5d4f71){logger['debug'](_0xa6c5('0x2b'),inspect(_0x5d4f71));return _[_0xa6c5('0x2f')](_0x5d4f71[_0xa6c5('0x2d')])?null:_0x5d4f71[_0xa6c5('0x2d')][_0xa6c5('0x30')]();}else{logger['error']('response',inspect(_0x5d4f71));return null;}}else{logger['error'](_0xa6c5('0x31'));return null;}}catch(_0x57ed56){logger[_0xa6c5('0xa')](_0x57ed56[_0xa6c5('0xb')]);return null;}});}logger[_0xa6c5('0x1d')](util[_0xa6c5('0x1a')](_0xa6c5('0x35'),_0x2f61d7[_0xa6c5('0x1f')],_0x2f61d7[_0xa6c5('0x20')],_0x2f61d7[_0xa6c5('0x21')],_0x2f61d7[_0xa6c5('0x22')],_0x2f61d7[_0xa6c5('0x23')]));logger['info'](util[_0xa6c5('0x1a')]('[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s',_0x2f61d7[_0xa6c5('0x28')],_0x2f61d7['extension'],parseInt(_0x2f61d7['priority'],0xa)+0x1));_0x2f61d7[_0xa6c5('0x36')](_0x2f61d7[_0xa6c5('0x28')],_0x2f61d7[_0xa6c5('0x29')],parseInt(_0x2f61d7['priority'],0xa)+0x1);_0x2f61d7['close']();}function handleNotFound(_0x2845c5){logger[_0xa6c5('0xa')](util['format'](_0xa6c5('0x37'),_0x2845c5[_0xa6c5('0x1f')]));_0x2845c5['continueAt'](_0x2845c5[_0xa6c5('0x28')],_0x2845c5[_0xa6c5('0x29')],parseInt(_0x2845c5[_0xa6c5('0x2a')],0xa)+0x1);_0x2845c5[_0xa6c5('0x38')]();}function handleUnpublished(_0x1ba10d){logger['error'](util[_0xa6c5('0x1a')](_0xa6c5('0x39'),_0x1ba10d[_0xa6c5('0x1f')]));_0x1ba10d[_0xa6c5('0x36')](_0x1ba10d[_0xa6c5('0x28')],_0x1ba10d['extension'],parseInt(_0x1ba10d[_0xa6c5('0x2a')],0xa)+0x1);_0x1ba10d[_0xa6c5('0x38')]();}module['exports']={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};