Built motion from commit e0fa946e.|2.6.5
[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 _0xc961=['../../config/logger','./graph','getSquareProjects','catch','error','Unable\x20to\x20download\x20CallySquare\x20projects','stack','agicommand','hasOwnProperty','retry','maxRetry','addVertex','omit','mxCell','isArray','length','source','target','addEdge','toJson','mxGraphModel','root','inspect','start','stringify','joinAt','format','YYYY-MM-DD\x20HH:mm:ss','info','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','dnid','uniqueid','vertex','context','extension','priority','code','result','evtHangup','debug','response','isUndefined','toString','agicommand\x20not\x20found','calleridname','callerid','finally','[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','close','Project\x20%s\x20not\x20found','continueAt','exports','lodash','xml2json','util'];(function(_0x4bfc03,_0x3281bb){var _0x266599=function(_0x2c544b){while(--_0x2c544b){_0x4bfc03['push'](_0x4bfc03['shift']());}};_0x266599(++_0x3281bb);}(_0xc961,0x185));var _0x1c96=function(_0x502f0e,_0x3463b3){_0x502f0e=_0x502f0e-0x0;var _0x2522e8=_0xc961[_0x502f0e];return _0x2522e8;};'use strict';var _=require(_0x1c96('0x0'));var moment=require('moment');var parser=require(_0x1c96('0x1'));var util=require(_0x1c96('0x2'));var logger=require(_0x1c96('0x3'))('agi');var rpc=require('./rpc');var mailRpc=require('./mailRpc');var Graph=require(_0x1c96('0x4'));var Vertices=require('./vertices');var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc[_0x1c96('0x5')]()[_0x1c96('0x6')](function(_0x67dc11){logger[_0x1c96('0x7')](_0x1c96('0x8'),_0x67dc11[_0x1c96('0x9')]);return[];});}function addVertex(_0x505489,_0x1a9ef3,_0x3434a2){_0x1a9ef3[_0x1c96('0xa')]=_0x3434a2;if(_0x1a9ef3[_0x1c96('0xb')](_0x1c96('0xc'))){_0x1a9ef3[_0x1c96('0xd')]=parseInt(_0x1a9ef3['retry'],0xa);}_0x505489[_0x1c96('0xe')](_[_0x1c96('0xf')](_0x1a9ef3,_0x1c96('0x10')));}function initGraph(_0x50b2c1,_0x42d306){var _0x2fe473=new Graph();for(var _0x1bdb91 in _0x50b2c1){if(_0x50b2c1['hasOwnProperty'](_0x1bdb91)){if(_[_0x1c96('0x11')](_0x50b2c1[_0x1bdb91])){for(var _0x37fbb1=0x0;_0x37fbb1<_0x50b2c1[_0x1bdb91]['length'];_0x37fbb1+=0x1){addVertex(_0x2fe473,_0x50b2c1[_0x1bdb91][_0x37fbb1],_0x1bdb91);}}else{addVertex(_0x2fe473,_0x50b2c1[_0x1bdb91],_0x1bdb91);}}}for(var _0x1e2c4e=0x0;_0x1e2c4e<_0x42d306[_0x1c96('0x12')];_0x1e2c4e+=0x1){if(_0x42d306[_0x1e2c4e][_0x1c96('0x13')]&&_0x42d306[_0x1e2c4e][_0x1c96('0x14')]){_0x2fe473[_0x1c96('0x15')](_0x42d306[_0x1e2c4e]['source'],_0x42d306[_0x1e2c4e][_0x1c96('0x14')],_0x42d306[_0x1e2c4e]['value']);}}return _0x2fe473;}function getRoot(_0x3bee75){return parser[_0x1c96('0x16')](_0x3bee75,{'object':!![]})[_0x1c96('0x17')][_0x1c96('0x18')];}function inspect(_0x2422db){return util[_0x1c96('0x19')](_0x2422db,{'showHidden':![],'depth':null});}function initialize(_0x105246,_0x48102a){var _0x1d0fbb=getRoot(_0x105246['production']);if(!_0x1d0fbb||!_0x1d0fbb[_0x1c96('0x1a')])return;var _0x5334c8,_0x2216b0,_0x12f2f0;logger['debug']('root',JSON[_0x1c96('0x1b')](_0x1d0fbb,null,0x2));_0x48102a[_0x1c96('0x1c')]=moment()[_0x1c96('0x1d')](_0x1c96('0x1e'));_0x5334c8=initGraph(_[_0x1c96('0xf')](_0x1d0fbb,_0x1c96('0x10')),_0x1d0fbb['mxCell']);_0x2216b0=new Vertices(_0x48102a,rpc,mailRpc);logger[_0x1c96('0x1f')](util[_0x1c96('0x1d')](_0x1c96('0x20'),_0x48102a[_0x1c96('0x21')],_0x48102a['calleridname'],_0x48102a['callerid'],_0x48102a[_0x1c96('0x22')],_0x48102a[_0x1c96('0x23')]));_0x5334c8['traverseBFS'](_0x1d0fbb['start']['id'],function(_0x6feb4c){try{_0x6feb4c=_0x2216b0['clear'](_0x6feb4c);logger['debug'](_0x1c96('0x24'),JSON['stringify'](_0x6feb4c,null,0x2));if(_0x6feb4c[_0x1c96('0xa')]==='gotoc'){logger[_0x1c96('0x1f')]('gotoc\x20block\x20stop\x20traverse\x20BFS');_0x48102a[_0x1c96('0x25')]=_0x6feb4c[_0x1c96('0x25')]||_0x48102a[_0x1c96('0x25')];_0x48102a[_0x1c96('0x26')]=_0x6feb4c[_0x1c96('0x26')];_0x48102a[_0x1c96('0x27')]=_0x6feb4c[_0x1c96('0x27')]?_0x6feb4c[_0x1c96('0x27')]-0x1:0x1;return null;}else if(_0x6feb4c&&_0x2216b0[_0x6feb4c[_0x1c96('0xa')]]){_0x12f2f0=_0x2216b0[_0x6feb4c[_0x1c96('0xa')]](_0x6feb4c);logger[_0x1c96('0x1f')]('response',JSON[_0x1c96('0x1b')](_0x12f2f0,null,0x2));if(_0x12f2f0&&_0x12f2f0[_0x1c96('0x28')]===AGI_CODE_SUCCESS&&_0x12f2f0[_0x1c96('0x29')]!==AGI_RESULT_ERROR&&!_0x48102a[_0x1c96('0x2a')]){logger[_0x1c96('0x2b')](_0x1c96('0x2c'),inspect(_0x12f2f0));return _[_0x1c96('0x2d')](_0x12f2f0[_0x1c96('0x29')])?null:_0x12f2f0['result'][_0x1c96('0x2e')]();}else{logger['error'](_0x1c96('0x2c'),inspect(_0x12f2f0));return null;}}else{logger[_0x1c96('0x7')](_0x1c96('0x2f'));return null;}}catch(_0x3ddd24){logger[_0x1c96('0x7')](_0x3ddd24[_0x1c96('0x9')]);return null;}});if(_0x1d0fbb['finally']){logger[_0x1c96('0x1f')](util['format']('[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x48102a[_0x1c96('0x21')],_0x48102a[_0x1c96('0x30')],_0x48102a[_0x1c96('0x31')],_0x48102a['dnid'],_0x48102a[_0x1c96('0x23')]));_0x5334c8['traverseBFS'](_0x1d0fbb[_0x1c96('0x32')]['id'],function(_0x2bcbc0){try{_0x2bcbc0=_0x2216b0['clear'](_0x2bcbc0);logger[_0x1c96('0x2b')](_0x1c96('0x24'),JSON[_0x1c96('0x1b')](_0x2bcbc0,null,0x2));if(_0x2bcbc0&&_0x2216b0[_0x2bcbc0[_0x1c96('0xa')]]){_0x12f2f0=_0x2216b0[_0x2bcbc0[_0x1c96('0xa')]](_0x2bcbc0);if(_0x12f2f0){logger[_0x1c96('0x2b')](_0x1c96('0x2c'),inspect(_0x12f2f0));return _['isUndefined'](_0x12f2f0[_0x1c96('0x29')])?null:_0x12f2f0['result']['toString']();}else{logger[_0x1c96('0x7')](_0x1c96('0x2c'),inspect(_0x12f2f0));return null;}}else{logger[_0x1c96('0x7')](_0x1c96('0x2f'));return null;}}catch(_0x3bc23f){logger[_0x1c96('0x7')](_0x3bc23f[_0x1c96('0x9')]);return null;}});}logger[_0x1c96('0x1f')](util[_0x1c96('0x1d')](_0x1c96('0x33'),_0x48102a['arg_1'],_0x48102a[_0x1c96('0x30')],_0x48102a[_0x1c96('0x31')],_0x48102a[_0x1c96('0x22')],_0x48102a[_0x1c96('0x23')]));logger[_0x1c96('0x1f')](util[_0x1c96('0x1d')]('[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s',_0x48102a[_0x1c96('0x25')],_0x48102a[_0x1c96('0x26')],parseInt(_0x48102a['priority'],0xa)+0x1));_0x48102a['continueAt'](_0x48102a[_0x1c96('0x25')],_0x48102a['extension'],parseInt(_0x48102a[_0x1c96('0x27')],0xa)+0x1);_0x48102a[_0x1c96('0x34')]();}function handleNotFound(_0x21e5d3){logger[_0x1c96('0x7')](util[_0x1c96('0x1d')](_0x1c96('0x35'),_0x21e5d3[_0x1c96('0x21')]));_0x21e5d3['continueAt'](_0x21e5d3[_0x1c96('0x25')],_0x21e5d3[_0x1c96('0x26')],parseInt(_0x21e5d3['priority'],0xa)+0x1);_0x21e5d3[_0x1c96('0x34')]();}function handleUnpublished(_0x1dfc26){logger[_0x1c96('0x7')](util[_0x1c96('0x1d')]('Project\x20%s\x20not\x20published',_0x1dfc26[_0x1c96('0x21')]));_0x1dfc26[_0x1c96('0x36')](_0x1dfc26[_0x1c96('0x25')],_0x1dfc26['extension'],parseInt(_0x1dfc26[_0x1c96('0x27')],0xa)+0x1);_0x1dfc26[_0x1c96('0x34')]();}module[_0x1c96('0x37')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};