7b83ac1f8e8d7a58e61693368b4199883807b319
[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 _0xf80a=['uniqueid','traverseBFS','clear','vertex','agicommand','gotoc','info','context','extension','priority','response','code','result','evtHangup','isUndefined','toString','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','[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s','continueAt','close','Project\x20%s\x20not\x20found','Project\x20%s\x20not\x20published','lodash','xml2json','../../config/logger','./graph','./vertices','catch','error','Unable\x20to\x20download\x20CallySquare\x20projects','stack','retry','maxRetry','mxCell','hasOwnProperty','isArray','length','addEdge','source','value','toJson','mxGraphModel','root','production','start','debug','stringify','joinAt','YYYY-MM-DD\x20HH:mm:ss','omit','format','arg_1','calleridname','callerid','dnid'];(function(_0x365e54,_0x44be74){var _0x13317a=function(_0x2d917f){while(--_0x2d917f){_0x365e54['push'](_0x365e54['shift']());}};_0x13317a(++_0x44be74);}(_0xf80a,0x8a));var _0xaf80=function(_0x592bbf,_0x592f2a){_0x592bbf=_0x592bbf-0x0;var _0x6b3377=_0xf80a[_0x592bbf];return _0x6b3377;};'use strict';var _=require(_0xaf80('0x0'));var moment=require('moment');var parser=require(_0xaf80('0x1'));var util=require('util');var logger=require(_0xaf80('0x2'))('agi');var rpc=require('./rpc');var mailRpc=require('./mailRpc');var Graph=require(_0xaf80('0x3'));var Vertices=require(_0xaf80('0x4'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc['getSquareProjects']()[_0xaf80('0x5')](function(_0x4be301){logger[_0xaf80('0x6')](_0xaf80('0x7'),_0x4be301[_0xaf80('0x8')]);return[];});}function addVertex(_0x27df09,_0x3d2ee8,_0x29f061){_0x3d2ee8['agicommand']=_0x29f061;if(_0x3d2ee8['hasOwnProperty'](_0xaf80('0x9'))){_0x3d2ee8[_0xaf80('0xa')]=parseInt(_0x3d2ee8[_0xaf80('0x9')],0xa);}_0x27df09['addVertex'](_['omit'](_0x3d2ee8,_0xaf80('0xb')));}function initGraph(_0x1b36e0,_0x31ed3e){var _0x29020d=new Graph();for(var _0x15f258 in _0x1b36e0){if(_0x1b36e0[_0xaf80('0xc')](_0x15f258)){if(_[_0xaf80('0xd')](_0x1b36e0[_0x15f258])){for(var _0x2ca8b0=0x0;_0x2ca8b0<_0x1b36e0[_0x15f258][_0xaf80('0xe')];_0x2ca8b0+=0x1){addVertex(_0x29020d,_0x1b36e0[_0x15f258][_0x2ca8b0],_0x15f258);}}else{addVertex(_0x29020d,_0x1b36e0[_0x15f258],_0x15f258);}}}for(var _0x2730f8=0x0;_0x2730f8<_0x31ed3e[_0xaf80('0xe')];_0x2730f8+=0x1){if(_0x31ed3e[_0x2730f8]['source']&&_0x31ed3e[_0x2730f8]['target']){_0x29020d[_0xaf80('0xf')](_0x31ed3e[_0x2730f8][_0xaf80('0x10')],_0x31ed3e[_0x2730f8]['target'],_0x31ed3e[_0x2730f8][_0xaf80('0x11')]);}}return _0x29020d;}function getRoot(_0x5ab053){return parser[_0xaf80('0x12')](_0x5ab053,{'object':!![]})[_0xaf80('0x13')][_0xaf80('0x14')];}function inspect(_0x503a55){return util['inspect'](_0x503a55,{'showHidden':![],'depth':null});}function initialize(_0x28bf71,_0x37f66d){var _0x11536b=getRoot(_0x28bf71[_0xaf80('0x15')]);if(!_0x11536b||!_0x11536b[_0xaf80('0x16')])return;var _0x8ca47,_0x568c37,_0x462b7;logger[_0xaf80('0x17')](_0xaf80('0x14'),JSON[_0xaf80('0x18')](_0x11536b,null,0x2));_0x37f66d[_0xaf80('0x19')]=moment()['format'](_0xaf80('0x1a'));_0x8ca47=initGraph(_[_0xaf80('0x1b')](_0x11536b,_0xaf80('0xb')),_0x11536b['mxCell']);_0x568c37=new Vertices(_0x37f66d,rpc,mailRpc);logger['info'](util[_0xaf80('0x1c')]('[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x37f66d[_0xaf80('0x1d')],_0x37f66d[_0xaf80('0x1e')],_0x37f66d[_0xaf80('0x1f')],_0x37f66d[_0xaf80('0x20')],_0x37f66d[_0xaf80('0x21')]));_0x8ca47[_0xaf80('0x22')](_0x11536b[_0xaf80('0x16')]['id'],function(_0x1b057c){try{_0x1b057c=_0x568c37[_0xaf80('0x23')](_0x1b057c);logger[_0xaf80('0x17')](_0xaf80('0x24'),JSON[_0xaf80('0x18')](_0x1b057c,null,0x2));if(_0x1b057c[_0xaf80('0x25')]===_0xaf80('0x26')){logger[_0xaf80('0x27')]('gotoc\x20block\x20stop\x20traverse\x20BFS');_0x37f66d[_0xaf80('0x28')]=_0x1b057c['context']||_0x37f66d[_0xaf80('0x28')];_0x37f66d[_0xaf80('0x29')]=_0x1b057c[_0xaf80('0x29')];_0x37f66d[_0xaf80('0x2a')]=_0x1b057c[_0xaf80('0x2a')]?_0x1b057c[_0xaf80('0x2a')]-0x1:0x1;return null;}else if(_0x1b057c&&_0x568c37[_0x1b057c[_0xaf80('0x25')]]){_0x462b7=_0x568c37[_0x1b057c[_0xaf80('0x25')]](_0x1b057c);logger[_0xaf80('0x27')](_0xaf80('0x2b'),JSON['stringify'](_0x462b7,null,0x2));if(_0x462b7&&_0x462b7[_0xaf80('0x2c')]===AGI_CODE_SUCCESS&&_0x462b7[_0xaf80('0x2d')]!==AGI_RESULT_ERROR&&!_0x37f66d[_0xaf80('0x2e')]){logger[_0xaf80('0x17')](_0xaf80('0x2b'),inspect(_0x462b7));return _[_0xaf80('0x2f')](_0x462b7[_0xaf80('0x2d')])?null:_0x462b7[_0xaf80('0x2d')][_0xaf80('0x30')]();}else{logger[_0xaf80('0x6')](_0xaf80('0x2b'),inspect(_0x462b7));return null;}}else{logger[_0xaf80('0x6')]('agicommand\x20not\x20found');return null;}}catch(_0x4a86ff){logger[_0xaf80('0x6')](_0x4a86ff[_0xaf80('0x8')]);return null;}});if(_0x11536b[_0xaf80('0x31')]){logger[_0xaf80('0x27')](util['format'](_0xaf80('0x32'),_0x37f66d[_0xaf80('0x1d')],_0x37f66d[_0xaf80('0x1e')],_0x37f66d['callerid'],_0x37f66d['dnid'],_0x37f66d[_0xaf80('0x21')]));_0x8ca47[_0xaf80('0x22')](_0x11536b[_0xaf80('0x31')]['id'],function(_0x4c4d00){try{_0x4c4d00=_0x568c37[_0xaf80('0x23')](_0x4c4d00);logger[_0xaf80('0x17')](_0xaf80('0x24'),JSON[_0xaf80('0x18')](_0x4c4d00,null,0x2));if(_0x4c4d00&&_0x568c37[_0x4c4d00['agicommand']]){_0x462b7=_0x568c37[_0x4c4d00['agicommand']](_0x4c4d00);if(_0x462b7){logger[_0xaf80('0x17')](_0xaf80('0x2b'),inspect(_0x462b7));return _[_0xaf80('0x2f')](_0x462b7[_0xaf80('0x2d')])?null:_0x462b7[_0xaf80('0x2d')][_0xaf80('0x30')]();}else{logger[_0xaf80('0x6')]('response',inspect(_0x462b7));return null;}}else{logger[_0xaf80('0x6')]('agicommand\x20not\x20found');return null;}}catch(_0x3282f1){logger[_0xaf80('0x6')](_0x3282f1[_0xaf80('0x8')]);return null;}});}logger[_0xaf80('0x27')](util['format'](_0xaf80('0x33'),_0x37f66d[_0xaf80('0x1d')],_0x37f66d[_0xaf80('0x1e')],_0x37f66d[_0xaf80('0x1f')],_0x37f66d[_0xaf80('0x20')],_0x37f66d[_0xaf80('0x21')]));logger['info'](util[_0xaf80('0x1c')](_0xaf80('0x34'),_0x37f66d[_0xaf80('0x28')],_0x37f66d[_0xaf80('0x29')],parseInt(_0x37f66d[_0xaf80('0x2a')],0xa)+0x1));_0x37f66d[_0xaf80('0x35')](_0x37f66d[_0xaf80('0x28')],_0x37f66d[_0xaf80('0x29')],parseInt(_0x37f66d[_0xaf80('0x2a')],0xa)+0x1);_0x37f66d[_0xaf80('0x36')]();}function handleNotFound(_0x4016cc){logger[_0xaf80('0x6')](util['format'](_0xaf80('0x37'),_0x4016cc[_0xaf80('0x1d')]));_0x4016cc[_0xaf80('0x35')](_0x4016cc[_0xaf80('0x28')],_0x4016cc['extension'],parseInt(_0x4016cc['priority'],0xa)+0x1);_0x4016cc[_0xaf80('0x36')]();}function handleUnpublished(_0x51077a){logger[_0xaf80('0x6')](util[_0xaf80('0x1c')](_0xaf80('0x38'),_0x51077a[_0xaf80('0x1d')]));_0x51077a[_0xaf80('0x35')](_0x51077a[_0xaf80('0x28')],_0x51077a['extension'],parseInt(_0x51077a[_0xaf80('0x2a')],0xa)+0x1);_0x51077a[_0xaf80('0x36')]();}module['exports']={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};