2caf09ba3c4938bb3e4e3c94abbcd17c92296ce4
[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 _0x1f5b=['finally','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','uniqueid','[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','calleridname','continueAt','close','Project\x20%s\x20not\x20found','Project\x20%s\x20not\x20published','exports','../../config/logger','agi','./rpc','./mailRpc','./graph','./vertices','getSquareProjects','catch','error','Unable\x20to\x20download\x20CallySquare\x20projects','stack','hasOwnProperty','retry','maxRetry','addVertex','omit','mxCell','isArray','length','source','target','addEdge','value','toJson','mxGraphModel','inspect','production','start','debug','root','stringify','joinAt','format','YYYY-MM-DD\x20HH:mm:ss','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','callerid','dnid','clear','vertex','agicommand','gotoc','info','context','extension','priority','response','result','evtHangup','isUndefined','toString'];(function(_0x5011da,_0x698ce0){var _0xd0cd45=function(_0x523d55){while(--_0x523d55){_0x5011da['push'](_0x5011da['shift']());}};_0xd0cd45(++_0x698ce0);}(_0x1f5b,0xc1));var _0xb1f5=function(_0x446a5f,_0x490261){_0x446a5f=_0x446a5f-0x0;var _0x3922f7=_0x1f5b[_0x446a5f];return _0x3922f7;};'use strict';var _=require('lodash');var moment=require('moment');var parser=require('xml2json');var util=require('util');var logger=require(_0xb1f5('0x0'))(_0xb1f5('0x1'));var rpc=require(_0xb1f5('0x2'));var mailRpc=require(_0xb1f5('0x3'));var Graph=require(_0xb1f5('0x4'));var Vertices=require(_0xb1f5('0x5'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc[_0xb1f5('0x6')]()[_0xb1f5('0x7')](function(_0x33493f){logger[_0xb1f5('0x8')](_0xb1f5('0x9'),_0x33493f[_0xb1f5('0xa')]);return[];});}function addVertex(_0x7e98bc,_0x296c91,_0x4190fd){_0x296c91['agicommand']=_0x4190fd;if(_0x296c91[_0xb1f5('0xb')](_0xb1f5('0xc'))){_0x296c91[_0xb1f5('0xd')]=parseInt(_0x296c91[_0xb1f5('0xc')],0xa);}_0x7e98bc[_0xb1f5('0xe')](_[_0xb1f5('0xf')](_0x296c91,_0xb1f5('0x10')));}function initGraph(_0x4e5166,_0x373a33){var _0xc12fc9=new Graph();for(var _0x68f334 in _0x4e5166){if(_0x4e5166['hasOwnProperty'](_0x68f334)){if(_[_0xb1f5('0x11')](_0x4e5166[_0x68f334])){for(var _0x29bd58=0x0;_0x29bd58<_0x4e5166[_0x68f334]['length'];_0x29bd58+=0x1){addVertex(_0xc12fc9,_0x4e5166[_0x68f334][_0x29bd58],_0x68f334);}}else{addVertex(_0xc12fc9,_0x4e5166[_0x68f334],_0x68f334);}}}for(var _0x13908c=0x0;_0x13908c<_0x373a33[_0xb1f5('0x12')];_0x13908c+=0x1){if(_0x373a33[_0x13908c][_0xb1f5('0x13')]&&_0x373a33[_0x13908c][_0xb1f5('0x14')]){_0xc12fc9[_0xb1f5('0x15')](_0x373a33[_0x13908c][_0xb1f5('0x13')],_0x373a33[_0x13908c][_0xb1f5('0x14')],_0x373a33[_0x13908c][_0xb1f5('0x16')]);}}return _0xc12fc9;}function getRoot(_0x34c6f2){return parser[_0xb1f5('0x17')](_0x34c6f2,{'object':!![]})[_0xb1f5('0x18')]['root'];}function inspect(_0x432563){return util[_0xb1f5('0x19')](_0x432563,{'showHidden':![],'depth':null});}function initialize(_0x5c677c,_0x5cff05){var _0x3afb1a=getRoot(_0x5c677c[_0xb1f5('0x1a')]);if(!_0x3afb1a||!_0x3afb1a[_0xb1f5('0x1b')])return;var _0x4ea179,_0xd99879,_0x43e3eb;logger[_0xb1f5('0x1c')](_0xb1f5('0x1d'),JSON[_0xb1f5('0x1e')](_0x3afb1a,null,0x2));_0x5cff05[_0xb1f5('0x1f')]=moment()[_0xb1f5('0x20')](_0xb1f5('0x21'));_0x4ea179=initGraph(_[_0xb1f5('0xf')](_0x3afb1a,'mxCell'),_0x3afb1a[_0xb1f5('0x10')]);_0xd99879=new Vertices(_0x5cff05,rpc,mailRpc);logger['info'](util[_0xb1f5('0x20')](_0xb1f5('0x22'),_0x5cff05[_0xb1f5('0x23')],_0x5cff05['calleridname'],_0x5cff05[_0xb1f5('0x24')],_0x5cff05[_0xb1f5('0x25')],_0x5cff05['uniqueid']));_0x4ea179['traverseBFS'](_0x3afb1a['start']['id'],function(_0x1f12f6){try{_0x1f12f6=_0xd99879[_0xb1f5('0x26')](_0x1f12f6);logger[_0xb1f5('0x1c')](_0xb1f5('0x27'),JSON[_0xb1f5('0x1e')](_0x1f12f6,null,0x2));if(_0x1f12f6[_0xb1f5('0x28')]===_0xb1f5('0x29')){logger[_0xb1f5('0x2a')]('gotoc\x20block\x20stop\x20traverse\x20BFS');_0x5cff05['context']=_0x1f12f6[_0xb1f5('0x2b')]||_0x5cff05[_0xb1f5('0x2b')];_0x5cff05[_0xb1f5('0x2c')]=_0x1f12f6[_0xb1f5('0x2c')];_0x5cff05[_0xb1f5('0x2d')]=_0x1f12f6[_0xb1f5('0x2d')]?_0x1f12f6[_0xb1f5('0x2d')]-0x1:0x1;return null;}else if(_0x1f12f6&&_0xd99879[_0x1f12f6[_0xb1f5('0x28')]]){_0x43e3eb=_0xd99879[_0x1f12f6[_0xb1f5('0x28')]](_0x1f12f6);logger['info'](_0xb1f5('0x2e'),JSON[_0xb1f5('0x1e')](_0x43e3eb,null,0x2));if(_0x43e3eb&&_0x43e3eb['code']===AGI_CODE_SUCCESS&&_0x43e3eb[_0xb1f5('0x2f')]!==AGI_RESULT_ERROR&&!_0x5cff05[_0xb1f5('0x30')]){logger[_0xb1f5('0x1c')](_0xb1f5('0x2e'),inspect(_0x43e3eb));return _[_0xb1f5('0x31')](_0x43e3eb[_0xb1f5('0x2f')])?null:_0x43e3eb[_0xb1f5('0x2f')][_0xb1f5('0x32')]();}else{logger[_0xb1f5('0x8')](_0xb1f5('0x2e'),inspect(_0x43e3eb));return null;}}else{logger['error']('agicommand\x20not\x20found');return null;}}catch(_0x274789){logger['error'](_0x274789[_0xb1f5('0xa')]);return null;}});if(_0x3afb1a[_0xb1f5('0x33')]){logger[_0xb1f5('0x2a')](util[_0xb1f5('0x20')](_0xb1f5('0x34'),_0x5cff05[_0xb1f5('0x23')],_0x5cff05['calleridname'],_0x5cff05[_0xb1f5('0x24')],_0x5cff05[_0xb1f5('0x25')],_0x5cff05[_0xb1f5('0x35')]));_0x4ea179['traverseBFS'](_0x3afb1a[_0xb1f5('0x33')]['id'],function(_0x260553){try{_0x260553=_0xd99879[_0xb1f5('0x26')](_0x260553);logger['debug']('vertex',JSON[_0xb1f5('0x1e')](_0x260553,null,0x2));if(_0x260553&&_0xd99879[_0x260553[_0xb1f5('0x28')]]){_0x43e3eb=_0xd99879[_0x260553[_0xb1f5('0x28')]](_0x260553);if(_0x43e3eb){logger[_0xb1f5('0x1c')](_0xb1f5('0x2e'),inspect(_0x43e3eb));return _[_0xb1f5('0x31')](_0x43e3eb[_0xb1f5('0x2f')])?null:_0x43e3eb[_0xb1f5('0x2f')][_0xb1f5('0x32')]();}else{logger[_0xb1f5('0x8')]('response',inspect(_0x43e3eb));return null;}}else{logger[_0xb1f5('0x8')]('agicommand\x20not\x20found');return null;}}catch(_0x33043e){logger[_0xb1f5('0x8')](_0x33043e[_0xb1f5('0xa')]);return null;}});}logger[_0xb1f5('0x2a')](util[_0xb1f5('0x20')](_0xb1f5('0x36'),_0x5cff05[_0xb1f5('0x23')],_0x5cff05[_0xb1f5('0x37')],_0x5cff05[_0xb1f5('0x24')],_0x5cff05[_0xb1f5('0x25')],_0x5cff05[_0xb1f5('0x35')]));logger[_0xb1f5('0x2a')](util['format']('[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s',_0x5cff05['context'],_0x5cff05[_0xb1f5('0x2c')],parseInt(_0x5cff05[_0xb1f5('0x2d')],0xa)+0x1));_0x5cff05[_0xb1f5('0x38')](_0x5cff05[_0xb1f5('0x2b')],_0x5cff05['extension'],parseInt(_0x5cff05[_0xb1f5('0x2d')],0xa)+0x1);_0x5cff05[_0xb1f5('0x39')]();}function handleNotFound(_0xe2103f){logger[_0xb1f5('0x8')](util[_0xb1f5('0x20')](_0xb1f5('0x3a'),_0xe2103f[_0xb1f5('0x23')]));_0xe2103f[_0xb1f5('0x38')](_0xe2103f[_0xb1f5('0x2b')],_0xe2103f[_0xb1f5('0x2c')],parseInt(_0xe2103f[_0xb1f5('0x2d')],0xa)+0x1);_0xe2103f[_0xb1f5('0x39')]();}function handleUnpublished(_0xfb95f3){logger['error'](util['format'](_0xb1f5('0x3b'),_0xfb95f3[_0xb1f5('0x23')]));_0xfb95f3[_0xb1f5('0x38')](_0xfb95f3[_0xb1f5('0x2b')],_0xfb95f3[_0xb1f5('0x2c')],parseInt(_0xfb95f3['priority'],0xa)+0x1);_0xfb95f3['close']();}module[_0xb1f5('0x3c')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};