Built motion from commit 53172ac8.|2.6.30
[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 _0xa557=['gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','code','evtHangup','isUndefined','result','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','uniqueid','traverseBFS','finally','[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\x20found','Project\x20%s\x20not\x20published','exports','moment','xml2json','util','../../config/logger','agi','./rpc','./mailRpc','./graph','catch','error','stack','agicommand','hasOwnProperty','retry','maxRetry','addVertex','omit','isArray','length','source','addEdge','target','toJson','mxGraphModel','root','production','start','debug','stringify','YYYY-MM-DD\x20HH:mm:ss','mxCell','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','callerid','clear','vertex'];(function(_0xd93447,_0x34d217){var _0x26c758=function(_0x53559f){while(--_0x53559f){_0xd93447['push'](_0xd93447['shift']());}};_0x26c758(++_0x34d217);}(_0xa557,0x153));var _0x7a55=function(_0x3104e3,_0x55795f){_0x3104e3=_0x3104e3-0x0;var _0x186821=_0xa557[_0x3104e3];return _0x186821;};'use strict';var _=require('lodash');var moment=require(_0x7a55('0x0'));var parser=require(_0x7a55('0x1'));var util=require(_0x7a55('0x2'));var logger=require(_0x7a55('0x3'))(_0x7a55('0x4'));var rpc=require(_0x7a55('0x5'));var mailRpc=require(_0x7a55('0x6'));var Graph=require(_0x7a55('0x7'));var Vertices=require('./vertices');var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc['getSquareProjects']()[_0x7a55('0x8')](function(_0x3107ad){logger[_0x7a55('0x9')]('Unable\x20to\x20download\x20CallySquare\x20projects',_0x3107ad[_0x7a55('0xa')]);return[];});}function addVertex(_0x2f2fe0,_0x21bd4f,_0x362096){_0x21bd4f[_0x7a55('0xb')]=_0x362096;if(_0x21bd4f[_0x7a55('0xc')](_0x7a55('0xd'))){_0x21bd4f[_0x7a55('0xe')]=parseInt(_0x21bd4f[_0x7a55('0xd')],0xa);}_0x2f2fe0[_0x7a55('0xf')](_[_0x7a55('0x10')](_0x21bd4f,'mxCell'));}function initGraph(_0x4e97d0,_0x556f5f){var _0x34b617=new Graph();for(var _0x4665c9 in _0x4e97d0){if(_0x4e97d0[_0x7a55('0xc')](_0x4665c9)){if(_[_0x7a55('0x11')](_0x4e97d0[_0x4665c9])){for(var _0x23944e=0x0;_0x23944e<_0x4e97d0[_0x4665c9][_0x7a55('0x12')];_0x23944e+=0x1){addVertex(_0x34b617,_0x4e97d0[_0x4665c9][_0x23944e],_0x4665c9);}}else{addVertex(_0x34b617,_0x4e97d0[_0x4665c9],_0x4665c9);}}}for(var _0x1c6874=0x0;_0x1c6874<_0x556f5f[_0x7a55('0x12')];_0x1c6874+=0x1){if(_0x556f5f[_0x1c6874][_0x7a55('0x13')]&&_0x556f5f[_0x1c6874]['target']){_0x34b617[_0x7a55('0x14')](_0x556f5f[_0x1c6874][_0x7a55('0x13')],_0x556f5f[_0x1c6874][_0x7a55('0x15')],_0x556f5f[_0x1c6874]['value']);}}return _0x34b617;}function getRoot(_0x11eb88){return parser[_0x7a55('0x16')](_0x11eb88,{'object':!![]})[_0x7a55('0x17')][_0x7a55('0x18')];}function inspect(_0x3a526a){return util['inspect'](_0x3a526a,{'showHidden':![],'depth':null});}function initialize(_0x1caa6c,_0x5dfadf){var _0x590acf=getRoot(_0x1caa6c[_0x7a55('0x19')]);if(!_0x590acf||!_0x590acf[_0x7a55('0x1a')])return;var _0xe8aebd,_0x35276a,_0x46a018;logger[_0x7a55('0x1b')](_0x7a55('0x18'),JSON[_0x7a55('0x1c')](_0x590acf,null,0x2));_0x5dfadf['joinAt']=moment()['format'](_0x7a55('0x1d'));_0xe8aebd=initGraph(_['omit'](_0x590acf,_0x7a55('0x1e')),_0x590acf[_0x7a55('0x1e')]);_0x35276a=new Vertices(_0x5dfadf,rpc,mailRpc);logger[_0x7a55('0x1f')](util[_0x7a55('0x20')](_0x7a55('0x21'),_0x5dfadf[_0x7a55('0x22')],_0x5dfadf[_0x7a55('0x23')],_0x5dfadf[_0x7a55('0x24')],_0x5dfadf['dnid'],_0x5dfadf['uniqueid']));_0xe8aebd['traverseBFS'](_0x590acf['start']['id'],function(_0x598ee9){try{_0x598ee9=_0x35276a[_0x7a55('0x25')](_0x598ee9);logger[_0x7a55('0x1b')](_0x7a55('0x26'),JSON['stringify'](_0x598ee9,null,0x2));if(_0x598ee9[_0x7a55('0xb')]===_0x7a55('0x27')){logger[_0x7a55('0x1f')](_0x7a55('0x28'));_0x5dfadf[_0x7a55('0x29')]=_0x598ee9['context']||_0x5dfadf[_0x7a55('0x29')];_0x5dfadf['extension']=_0x598ee9[_0x7a55('0x2a')];_0x5dfadf[_0x7a55('0x2b')]=_0x598ee9['priority']?_0x598ee9['priority']-0x1:0x1;return null;}else if(_0x598ee9&&_0x35276a[_0x598ee9['agicommand']]){_0x46a018=_0x35276a[_0x598ee9[_0x7a55('0xb')]](_0x598ee9);logger[_0x7a55('0x1f')](_0x7a55('0x2c'),JSON[_0x7a55('0x1c')](_0x46a018,null,0x2));if(_0x46a018&&_0x46a018[_0x7a55('0x2d')]===AGI_CODE_SUCCESS&&_0x46a018['result']!==AGI_RESULT_ERROR&&!_0x5dfadf[_0x7a55('0x2e')]){logger['debug'](_0x7a55('0x2c'),inspect(_0x46a018));return _[_0x7a55('0x2f')](_0x46a018[_0x7a55('0x30')])?null:_0x46a018[_0x7a55('0x30')][_0x7a55('0x31')]();}else{logger['error'](_0x7a55('0x2c'),inspect(_0x46a018));return null;}}else{logger[_0x7a55('0x9')](_0x7a55('0x32'));return null;}}catch(_0x396b61){logger[_0x7a55('0x9')](_0x396b61[_0x7a55('0xa')]);return null;}});if(_0x590acf['finally']){logger[_0x7a55('0x1f')](util[_0x7a55('0x20')](_0x7a55('0x33'),_0x5dfadf[_0x7a55('0x22')],_0x5dfadf[_0x7a55('0x23')],_0x5dfadf['callerid'],_0x5dfadf[_0x7a55('0x34')],_0x5dfadf[_0x7a55('0x35')]));_0xe8aebd[_0x7a55('0x36')](_0x590acf[_0x7a55('0x37')]['id'],function(_0x3a018f){try{_0x3a018f=_0x35276a[_0x7a55('0x25')](_0x3a018f);logger['debug']('vertex',JSON[_0x7a55('0x1c')](_0x3a018f,null,0x2));if(_0x3a018f&&_0x35276a[_0x3a018f[_0x7a55('0xb')]]){_0x46a018=_0x35276a[_0x3a018f[_0x7a55('0xb')]](_0x3a018f);if(_0x46a018){logger[_0x7a55('0x1b')](_0x7a55('0x2c'),inspect(_0x46a018));return _[_0x7a55('0x2f')](_0x46a018[_0x7a55('0x30')])?null:_0x46a018[_0x7a55('0x30')]['toString']();}else{logger[_0x7a55('0x9')](_0x7a55('0x2c'),inspect(_0x46a018));return null;}}else{logger[_0x7a55('0x9')]('agicommand\x20not\x20found');return null;}}catch(_0x11f2e6){logger['error'](_0x11f2e6[_0x7a55('0xa')]);return null;}});}logger[_0x7a55('0x1f')](util[_0x7a55('0x20')](_0x7a55('0x38'),_0x5dfadf[_0x7a55('0x22')],_0x5dfadf[_0x7a55('0x23')],_0x5dfadf[_0x7a55('0x24')],_0x5dfadf[_0x7a55('0x34')],_0x5dfadf['uniqueid']));logger['info'](util[_0x7a55('0x20')](_0x7a55('0x39'),_0x5dfadf[_0x7a55('0x29')],_0x5dfadf[_0x7a55('0x2a')],parseInt(_0x5dfadf['priority'],0xa)+0x1));_0x5dfadf[_0x7a55('0x3a')](_0x5dfadf[_0x7a55('0x29')],_0x5dfadf[_0x7a55('0x2a')],parseInt(_0x5dfadf['priority'],0xa)+0x1);_0x5dfadf[_0x7a55('0x3b')]();}function handleNotFound(_0x1c8a9e){logger[_0x7a55('0x9')](util[_0x7a55('0x20')](_0x7a55('0x3c'),_0x1c8a9e['arg_1']));_0x1c8a9e[_0x7a55('0x3a')](_0x1c8a9e['context'],_0x1c8a9e[_0x7a55('0x2a')],parseInt(_0x1c8a9e[_0x7a55('0x2b')],0xa)+0x1);_0x1c8a9e['close']();}function handleUnpublished(_0x457d3e){logger[_0x7a55('0x9')](util[_0x7a55('0x20')](_0x7a55('0x3d'),_0x457d3e[_0x7a55('0x22')]));_0x457d3e['continueAt'](_0x457d3e['context'],_0x457d3e[_0x7a55('0x2a')],parseInt(_0x457d3e['priority'],0xa)+0x1);_0x457d3e['close']();}module[_0x7a55('0x3e')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};