Built motion from commit d1eab355.|2.6.28
[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 _0x3d2f=['retry','mxCell','isArray','length','source','value','toJson','mxGraphModel','root','inspect','start','debug','stringify','joinAt','omit','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','uniqueid','traverseBFS','clear','vertex','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','result','evtHangup','response','isUndefined','toString','agicommand\x20not\x20found','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','dnid','finally','[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s','continueAt','close','Project\x20%s\x20not\x20found','exports','lodash','moment','xml2json','util','agi','./rpc','./mailRpc','./graph','./vertices','catch','error','stack','agicommand','maxRetry'];(function(_0x8c53a4,_0x5442fe){var _0x14ef6a=function(_0x45e8d3){while(--_0x45e8d3){_0x8c53a4['push'](_0x8c53a4['shift']());}};_0x14ef6a(++_0x5442fe);}(_0x3d2f,0xd6));var _0xf3d2=function(_0x4bb321,_0x50015b){_0x4bb321=_0x4bb321-0x0;var _0x270955=_0x3d2f[_0x4bb321];return _0x270955;};'use strict';var _=require(_0xf3d2('0x0'));var moment=require(_0xf3d2('0x1'));var parser=require(_0xf3d2('0x2'));var util=require(_0xf3d2('0x3'));var logger=require('../../config/logger')(_0xf3d2('0x4'));var rpc=require(_0xf3d2('0x5'));var mailRpc=require(_0xf3d2('0x6'));var Graph=require(_0xf3d2('0x7'));var Vertices=require(_0xf3d2('0x8'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc['getSquareProjects']()[_0xf3d2('0x9')](function(_0x2d944d){logger[_0xf3d2('0xa')]('Unable\x20to\x20download\x20CallySquare\x20projects',_0x2d944d[_0xf3d2('0xb')]);return[];});}function addVertex(_0x18f01f,_0x5a8962,_0x454dc2){_0x5a8962[_0xf3d2('0xc')]=_0x454dc2;if(_0x5a8962['hasOwnProperty']('retry')){_0x5a8962[_0xf3d2('0xd')]=parseInt(_0x5a8962[_0xf3d2('0xe')],0xa);}_0x18f01f['addVertex'](_['omit'](_0x5a8962,_0xf3d2('0xf')));}function initGraph(_0xe168ea,_0x49e973){var _0x21c866=new Graph();for(var _0x36929d in _0xe168ea){if(_0xe168ea['hasOwnProperty'](_0x36929d)){if(_[_0xf3d2('0x10')](_0xe168ea[_0x36929d])){for(var _0x374ee5=0x0;_0x374ee5<_0xe168ea[_0x36929d][_0xf3d2('0x11')];_0x374ee5+=0x1){addVertex(_0x21c866,_0xe168ea[_0x36929d][_0x374ee5],_0x36929d);}}else{addVertex(_0x21c866,_0xe168ea[_0x36929d],_0x36929d);}}}for(var _0x3fda64=0x0;_0x3fda64<_0x49e973['length'];_0x3fda64+=0x1){if(_0x49e973[_0x3fda64][_0xf3d2('0x12')]&&_0x49e973[_0x3fda64]['target']){_0x21c866['addEdge'](_0x49e973[_0x3fda64][_0xf3d2('0x12')],_0x49e973[_0x3fda64]['target'],_0x49e973[_0x3fda64][_0xf3d2('0x13')]);}}return _0x21c866;}function getRoot(_0xcf05ee){return parser[_0xf3d2('0x14')](_0xcf05ee,{'object':!![]})[_0xf3d2('0x15')][_0xf3d2('0x16')];}function inspect(_0x3f7a4a){return util[_0xf3d2('0x17')](_0x3f7a4a,{'showHidden':![],'depth':null});}function initialize(_0x3b2900,_0x2c2a2e){var _0x106d6d=getRoot(_0x3b2900['production']);if(!_0x106d6d||!_0x106d6d[_0xf3d2('0x18')])return;var _0x3d57aa,_0x42359a,_0x9bc1b9;logger[_0xf3d2('0x19')]('root',JSON[_0xf3d2('0x1a')](_0x106d6d,null,0x2));_0x2c2a2e[_0xf3d2('0x1b')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x3d57aa=initGraph(_[_0xf3d2('0x1c')](_0x106d6d,_0xf3d2('0xf')),_0x106d6d[_0xf3d2('0xf')]);_0x42359a=new Vertices(_0x2c2a2e,rpc,mailRpc);logger[_0xf3d2('0x1d')](util[_0xf3d2('0x1e')](_0xf3d2('0x1f'),_0x2c2a2e[_0xf3d2('0x20')],_0x2c2a2e[_0xf3d2('0x21')],_0x2c2a2e['callerid'],_0x2c2a2e['dnid'],_0x2c2a2e[_0xf3d2('0x22')]));_0x3d57aa[_0xf3d2('0x23')](_0x106d6d[_0xf3d2('0x18')]['id'],function(_0x326528){try{_0x326528=_0x42359a[_0xf3d2('0x24')](_0x326528);logger['debug'](_0xf3d2('0x25'),JSON['stringify'](_0x326528,null,0x2));if(_0x326528[_0xf3d2('0xc')]===_0xf3d2('0x26')){logger[_0xf3d2('0x1d')](_0xf3d2('0x27'));_0x2c2a2e[_0xf3d2('0x28')]=_0x326528[_0xf3d2('0x28')]||_0x2c2a2e['context'];_0x2c2a2e[_0xf3d2('0x29')]=_0x326528[_0xf3d2('0x29')];_0x2c2a2e['priority']=_0x326528[_0xf3d2('0x2a')]?_0x326528['priority']-0x1:0x1;return null;}else if(_0x326528&&_0x42359a[_0x326528['agicommand']]){_0x9bc1b9=_0x42359a[_0x326528['agicommand']](_0x326528);logger[_0xf3d2('0x1d')]('response',JSON[_0xf3d2('0x1a')](_0x9bc1b9,null,0x2));if(_0x9bc1b9&&_0x9bc1b9['code']===AGI_CODE_SUCCESS&&_0x9bc1b9[_0xf3d2('0x2b')]!==AGI_RESULT_ERROR&&!_0x2c2a2e[_0xf3d2('0x2c')]){logger[_0xf3d2('0x19')](_0xf3d2('0x2d'),inspect(_0x9bc1b9));return _[_0xf3d2('0x2e')](_0x9bc1b9[_0xf3d2('0x2b')])?null:_0x9bc1b9[_0xf3d2('0x2b')][_0xf3d2('0x2f')]();}else{logger[_0xf3d2('0xa')](_0xf3d2('0x2d'),inspect(_0x9bc1b9));return null;}}else{logger['error'](_0xf3d2('0x30'));return null;}}catch(_0x52639d){logger[_0xf3d2('0xa')](_0x52639d[_0xf3d2('0xb')]);return null;}});if(_0x106d6d['finally']){logger['info'](util[_0xf3d2('0x1e')](_0xf3d2('0x31'),_0x2c2a2e[_0xf3d2('0x20')],_0x2c2a2e[_0xf3d2('0x21')],_0x2c2a2e['callerid'],_0x2c2a2e[_0xf3d2('0x32')],_0x2c2a2e[_0xf3d2('0x22')]));_0x3d57aa['traverseBFS'](_0x106d6d[_0xf3d2('0x33')]['id'],function(_0x28df37){try{_0x28df37=_0x42359a[_0xf3d2('0x24')](_0x28df37);logger[_0xf3d2('0x19')](_0xf3d2('0x25'),JSON[_0xf3d2('0x1a')](_0x28df37,null,0x2));if(_0x28df37&&_0x42359a[_0x28df37[_0xf3d2('0xc')]]){_0x9bc1b9=_0x42359a[_0x28df37[_0xf3d2('0xc')]](_0x28df37);if(_0x9bc1b9){logger[_0xf3d2('0x19')](_0xf3d2('0x2d'),inspect(_0x9bc1b9));return _[_0xf3d2('0x2e')](_0x9bc1b9['result'])?null:_0x9bc1b9['result'][_0xf3d2('0x2f')]();}else{logger[_0xf3d2('0xa')](_0xf3d2('0x2d'),inspect(_0x9bc1b9));return null;}}else{logger['error']('agicommand\x20not\x20found');return null;}}catch(_0x20aa1c){logger['error'](_0x20aa1c[_0xf3d2('0xb')]);return null;}});}logger['info'](util[_0xf3d2('0x1e')]('[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x2c2a2e[_0xf3d2('0x20')],_0x2c2a2e['calleridname'],_0x2c2a2e['callerid'],_0x2c2a2e[_0xf3d2('0x32')],_0x2c2a2e[_0xf3d2('0x22')]));logger['info'](util[_0xf3d2('0x1e')](_0xf3d2('0x34'),_0x2c2a2e['context'],_0x2c2a2e[_0xf3d2('0x29')],parseInt(_0x2c2a2e['priority'],0xa)+0x1));_0x2c2a2e[_0xf3d2('0x35')](_0x2c2a2e[_0xf3d2('0x28')],_0x2c2a2e[_0xf3d2('0x29')],parseInt(_0x2c2a2e[_0xf3d2('0x2a')],0xa)+0x1);_0x2c2a2e[_0xf3d2('0x36')]();}function handleNotFound(_0x47c3d2){logger[_0xf3d2('0xa')](util[_0xf3d2('0x1e')](_0xf3d2('0x37'),_0x47c3d2['arg_1']));_0x47c3d2['continueAt'](_0x47c3d2['context'],_0x47c3d2[_0xf3d2('0x29')],parseInt(_0x47c3d2[_0xf3d2('0x2a')],0xa)+0x1);_0x47c3d2[_0xf3d2('0x36')]();}function handleUnpublished(_0x196419){logger[_0xf3d2('0xa')](util[_0xf3d2('0x1e')]('Project\x20%s\x20not\x20published',_0x196419[_0xf3d2('0x20')]));_0x196419[_0xf3d2('0x35')](_0x196419[_0xf3d2('0x28')],_0x196419[_0xf3d2('0x29')],parseInt(_0x196419[_0xf3d2('0x2a')],0xa)+0x1);_0x196419[_0xf3d2('0x36')]();}module[_0xf3d2('0x38')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};