53b9dc250d87969cea2a2b79685af7da9e5b2b6a
[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 _0x3fff=['agi','./rpc','./vertices','getSquareProjects','catch','error','Unable\x20to\x20download\x20CallySquare\x20projects','hasOwnProperty','maxRetry','retry','addVertex','omit','isArray','length','source','addEdge','target','toJson','mxGraphModel','root','inspect','production','start','debug','stringify','joinAt','format','YYYY-MM-DD\x20HH:mm:ss','mxCell','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','clear','vertex','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','agicommand','response','code','result','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','[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','continueAt','close','Project\x20%s\x20not\x20found','Project\x20%s\x20not\x20published','exports','lodash','moment','xml2json','util','../../config/logger'];(function(_0x4e8836,_0x31c212){var _0x236266=function(_0x2e03ff){while(--_0x2e03ff){_0x4e8836['push'](_0x4e8836['shift']());}};_0x236266(++_0x31c212);}(_0x3fff,0x7b));var _0xf3ff=function(_0x43450f,_0x109af9){_0x43450f=_0x43450f-0x0;var _0x496603=_0x3fff[_0x43450f];return _0x496603;};'use strict';var _=require(_0xf3ff('0x0'));var moment=require(_0xf3ff('0x1'));var parser=require(_0xf3ff('0x2'));var util=require(_0xf3ff('0x3'));var logger=require(_0xf3ff('0x4'))(_0xf3ff('0x5'));var rpc=require(_0xf3ff('0x6'));var mailRpc=require('./mailRpc');var Graph=require('./graph');var Vertices=require(_0xf3ff('0x7'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc[_0xf3ff('0x8')]()[_0xf3ff('0x9')](function(_0x1c6136){logger[_0xf3ff('0xa')](_0xf3ff('0xb'),_0x1c6136['stack']);return[];});}function addVertex(_0x54e9d5,_0x528635,_0x60c8f3){_0x528635['agicommand']=_0x60c8f3;if(_0x528635[_0xf3ff('0xc')]('retry')){_0x528635[_0xf3ff('0xd')]=parseInt(_0x528635[_0xf3ff('0xe')],0xa);}_0x54e9d5[_0xf3ff('0xf')](_[_0xf3ff('0x10')](_0x528635,'mxCell'));}function initGraph(_0x5dfa8a,_0x4b94b2){var _0x179217=new Graph();for(var _0x59960d in _0x5dfa8a){if(_0x5dfa8a[_0xf3ff('0xc')](_0x59960d)){if(_[_0xf3ff('0x11')](_0x5dfa8a[_0x59960d])){for(var _0x449937=0x0;_0x449937<_0x5dfa8a[_0x59960d]['length'];_0x449937+=0x1){addVertex(_0x179217,_0x5dfa8a[_0x59960d][_0x449937],_0x59960d);}}else{addVertex(_0x179217,_0x5dfa8a[_0x59960d],_0x59960d);}}}for(var _0x52d483=0x0;_0x52d483<_0x4b94b2[_0xf3ff('0x12')];_0x52d483+=0x1){if(_0x4b94b2[_0x52d483][_0xf3ff('0x13')]&&_0x4b94b2[_0x52d483]['target']){_0x179217[_0xf3ff('0x14')](_0x4b94b2[_0x52d483]['source'],_0x4b94b2[_0x52d483][_0xf3ff('0x15')],_0x4b94b2[_0x52d483]['value']);}}return _0x179217;}function getRoot(_0x4f1193){return parser[_0xf3ff('0x16')](_0x4f1193,{'object':!![]})[_0xf3ff('0x17')][_0xf3ff('0x18')];}function inspect(_0x3189f1){return util[_0xf3ff('0x19')](_0x3189f1,{'showHidden':![],'depth':null});}function initialize(_0x3dbc49,_0x342882){var _0x55464c=getRoot(_0x3dbc49[_0xf3ff('0x1a')]);if(!_0x55464c||!_0x55464c[_0xf3ff('0x1b')])return;var _0x192af8,_0x1260d4,_0x2e48e9;logger[_0xf3ff('0x1c')](_0xf3ff('0x18'),JSON[_0xf3ff('0x1d')](_0x55464c,null,0x2));_0x342882[_0xf3ff('0x1e')]=moment()[_0xf3ff('0x1f')](_0xf3ff('0x20'));_0x192af8=initGraph(_[_0xf3ff('0x10')](_0x55464c,_0xf3ff('0x21')),_0x55464c[_0xf3ff('0x21')]);_0x1260d4=new Vertices(_0x342882,rpc,mailRpc);logger[_0xf3ff('0x22')](util[_0xf3ff('0x1f')](_0xf3ff('0x23'),_0x342882[_0xf3ff('0x24')],_0x342882[_0xf3ff('0x25')],_0x342882[_0xf3ff('0x26')],_0x342882[_0xf3ff('0x27')],_0x342882[_0xf3ff('0x28')]));_0x192af8[_0xf3ff('0x29')](_0x55464c[_0xf3ff('0x1b')]['id'],function(_0x55a5f0){try{_0x55a5f0=_0x1260d4[_0xf3ff('0x2a')](_0x55a5f0);logger['debug'](_0xf3ff('0x2b'),JSON[_0xf3ff('0x1d')](_0x55a5f0,null,0x2));if(_0x55a5f0['agicommand']===_0xf3ff('0x2c')){logger[_0xf3ff('0x22')](_0xf3ff('0x2d'));_0x342882[_0xf3ff('0x2e')]=_0x55a5f0[_0xf3ff('0x2e')]||_0x342882[_0xf3ff('0x2e')];_0x342882[_0xf3ff('0x2f')]=_0x55a5f0[_0xf3ff('0x2f')];_0x342882[_0xf3ff('0x30')]=_0x55a5f0[_0xf3ff('0x30')]?_0x55a5f0[_0xf3ff('0x30')]-0x1:0x1;return null;}else if(_0x55a5f0&&_0x1260d4[_0x55a5f0[_0xf3ff('0x31')]]){_0x2e48e9=_0x1260d4[_0x55a5f0[_0xf3ff('0x31')]](_0x55a5f0);logger['info'](_0xf3ff('0x32'),JSON[_0xf3ff('0x1d')](_0x2e48e9,null,0x2));if(_0x2e48e9&&_0x2e48e9[_0xf3ff('0x33')]===AGI_CODE_SUCCESS&&_0x2e48e9[_0xf3ff('0x34')]!==AGI_RESULT_ERROR&&!_0x342882['evtHangup']){logger[_0xf3ff('0x1c')](_0xf3ff('0x32'),inspect(_0x2e48e9));return _[_0xf3ff('0x35')](_0x2e48e9[_0xf3ff('0x34')])?null:_0x2e48e9['result'][_0xf3ff('0x36')]();}else{logger['error'](_0xf3ff('0x32'),inspect(_0x2e48e9));return null;}}else{logger[_0xf3ff('0xa')](_0xf3ff('0x37'));return null;}}catch(_0x1ef238){logger[_0xf3ff('0xa')](_0x1ef238['stack']);return null;}});if(_0x55464c[_0xf3ff('0x38')]){logger[_0xf3ff('0x22')](util['format'](_0xf3ff('0x39'),_0x342882['arg_1'],_0x342882[_0xf3ff('0x25')],_0x342882[_0xf3ff('0x26')],_0x342882['dnid'],_0x342882[_0xf3ff('0x28')]));_0x192af8[_0xf3ff('0x29')](_0x55464c[_0xf3ff('0x38')]['id'],function(_0x392596){try{_0x392596=_0x1260d4[_0xf3ff('0x2a')](_0x392596);logger[_0xf3ff('0x1c')](_0xf3ff('0x2b'),JSON[_0xf3ff('0x1d')](_0x392596,null,0x2));if(_0x392596&&_0x1260d4[_0x392596['agicommand']]){_0x2e48e9=_0x1260d4[_0x392596[_0xf3ff('0x31')]](_0x392596);if(_0x2e48e9){logger[_0xf3ff('0x1c')](_0xf3ff('0x32'),inspect(_0x2e48e9));return _[_0xf3ff('0x35')](_0x2e48e9[_0xf3ff('0x34')])?null:_0x2e48e9[_0xf3ff('0x34')][_0xf3ff('0x36')]();}else{logger[_0xf3ff('0xa')](_0xf3ff('0x32'),inspect(_0x2e48e9));return null;}}else{logger['error'](_0xf3ff('0x37'));return null;}}catch(_0x4dba7b){logger[_0xf3ff('0xa')](_0x4dba7b['stack']);return null;}});}logger[_0xf3ff('0x22')](util[_0xf3ff('0x1f')](_0xf3ff('0x3a'),_0x342882[_0xf3ff('0x24')],_0x342882[_0xf3ff('0x25')],_0x342882[_0xf3ff('0x26')],_0x342882[_0xf3ff('0x27')],_0x342882[_0xf3ff('0x28')]));logger[_0xf3ff('0x22')](util[_0xf3ff('0x1f')]('[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s',_0x342882[_0xf3ff('0x2e')],_0x342882['extension'],parseInt(_0x342882[_0xf3ff('0x30')],0xa)+0x1));_0x342882[_0xf3ff('0x3b')](_0x342882['context'],_0x342882[_0xf3ff('0x2f')],parseInt(_0x342882[_0xf3ff('0x30')],0xa)+0x1);_0x342882[_0xf3ff('0x3c')]();}function handleNotFound(_0x34b202){logger[_0xf3ff('0xa')](util[_0xf3ff('0x1f')](_0xf3ff('0x3d'),_0x34b202['arg_1']));_0x34b202[_0xf3ff('0x3b')](_0x34b202[_0xf3ff('0x2e')],_0x34b202[_0xf3ff('0x2f')],parseInt(_0x34b202[_0xf3ff('0x30')],0xa)+0x1);_0x34b202[_0xf3ff('0x3c')]();}function handleUnpublished(_0x2c09e5){logger[_0xf3ff('0xa')](util['format'](_0xf3ff('0x3e'),_0x2c09e5['arg_1']));_0x2c09e5['continueAt'](_0x2c09e5[_0xf3ff('0x2e')],_0x2c09e5[_0xf3ff('0x2f')],parseInt(_0x2c09e5[_0xf3ff('0x30')],0xa)+0x1);_0x2c09e5[_0xf3ff('0x3c')]();}module[_0xf3ff('0x3f')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};