Built motion from commit ffdca78c.|2.6.24
[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 _0x7dc5=['mxGraphModel','root','inspect','start','debug','stringify','joinAt','format','YYYY-MM-DD\x20HH:mm:ss','info','arg_1','calleridname','dnid','uniqueid','traverseBFS','clear','vertex','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','code','result','evtHangup','response','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','callerid','[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','Project\x20%s\x20not\x20found','close','Project\x20%s\x20not\x20published','exports','moment','util','agi','./rpc','./mailRpc','./graph','./vertices','getSquareProjects','error','Unable\x20to\x20download\x20CallySquare\x20projects','stack','agicommand','hasOwnProperty','retry','maxRetry','addVertex','omit','mxCell','isArray','length','source','addEdge','target','value','toJson'];(function(_0xf5d71c,_0x2613a6){var _0x5af672=function(_0x191f52){while(--_0x191f52){_0xf5d71c['push'](_0xf5d71c['shift']());}};_0x5af672(++_0x2613a6);}(_0x7dc5,0x167));var _0x57dc=function(_0xf9431c,_0x4754b5){_0xf9431c=_0xf9431c-0x0;var _0x53fc33=_0x7dc5[_0xf9431c];return _0x53fc33;};'use strict';var _=require('lodash');var moment=require(_0x57dc('0x0'));var parser=require('xml2json');var util=require(_0x57dc('0x1'));var logger=require('../../config/logger')(_0x57dc('0x2'));var rpc=require(_0x57dc('0x3'));var mailRpc=require(_0x57dc('0x4'));var Graph=require(_0x57dc('0x5'));var Vertices=require(_0x57dc('0x6'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc[_0x57dc('0x7')]()['catch'](function(_0x2e4e54){logger[_0x57dc('0x8')](_0x57dc('0x9'),_0x2e4e54[_0x57dc('0xa')]);return[];});}function addVertex(_0x591792,_0x28308a,_0x199323){_0x28308a[_0x57dc('0xb')]=_0x199323;if(_0x28308a[_0x57dc('0xc')](_0x57dc('0xd'))){_0x28308a[_0x57dc('0xe')]=parseInt(_0x28308a[_0x57dc('0xd')],0xa);}_0x591792[_0x57dc('0xf')](_[_0x57dc('0x10')](_0x28308a,_0x57dc('0x11')));}function initGraph(_0x52b3d0,_0x3f45f5){var _0x2f41cc=new Graph();for(var _0xbc7493 in _0x52b3d0){if(_0x52b3d0[_0x57dc('0xc')](_0xbc7493)){if(_[_0x57dc('0x12')](_0x52b3d0[_0xbc7493])){for(var _0x4c1fcc=0x0;_0x4c1fcc<_0x52b3d0[_0xbc7493]['length'];_0x4c1fcc+=0x1){addVertex(_0x2f41cc,_0x52b3d0[_0xbc7493][_0x4c1fcc],_0xbc7493);}}else{addVertex(_0x2f41cc,_0x52b3d0[_0xbc7493],_0xbc7493);}}}for(var _0x269c1b=0x0;_0x269c1b<_0x3f45f5[_0x57dc('0x13')];_0x269c1b+=0x1){if(_0x3f45f5[_0x269c1b][_0x57dc('0x14')]&&_0x3f45f5[_0x269c1b]['target']){_0x2f41cc[_0x57dc('0x15')](_0x3f45f5[_0x269c1b]['source'],_0x3f45f5[_0x269c1b][_0x57dc('0x16')],_0x3f45f5[_0x269c1b][_0x57dc('0x17')]);}}return _0x2f41cc;}function getRoot(_0x4af601){return parser[_0x57dc('0x18')](_0x4af601,{'object':!![]})[_0x57dc('0x19')][_0x57dc('0x1a')];}function inspect(_0x28f21b){return util[_0x57dc('0x1b')](_0x28f21b,{'showHidden':![],'depth':null});}function initialize(_0x3ed0b2,_0x4f0821){var _0x238e1a=getRoot(_0x3ed0b2['production']);if(!_0x238e1a||!_0x238e1a[_0x57dc('0x1c')])return;var _0x1deeab,_0xdc47dc,_0x4e47f2;logger[_0x57dc('0x1d')](_0x57dc('0x1a'),JSON[_0x57dc('0x1e')](_0x238e1a,null,0x2));_0x4f0821[_0x57dc('0x1f')]=moment()[_0x57dc('0x20')](_0x57dc('0x21'));_0x1deeab=initGraph(_[_0x57dc('0x10')](_0x238e1a,'mxCell'),_0x238e1a['mxCell']);_0xdc47dc=new Vertices(_0x4f0821,rpc,mailRpc);logger[_0x57dc('0x22')](util[_0x57dc('0x20')]('[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x4f0821[_0x57dc('0x23')],_0x4f0821[_0x57dc('0x24')],_0x4f0821['callerid'],_0x4f0821[_0x57dc('0x25')],_0x4f0821[_0x57dc('0x26')]));_0x1deeab[_0x57dc('0x27')](_0x238e1a[_0x57dc('0x1c')]['id'],function(_0x23f46d){try{_0x23f46d=_0xdc47dc[_0x57dc('0x28')](_0x23f46d);logger[_0x57dc('0x1d')](_0x57dc('0x29'),JSON[_0x57dc('0x1e')](_0x23f46d,null,0x2));if(_0x23f46d[_0x57dc('0xb')]===_0x57dc('0x2a')){logger['info'](_0x57dc('0x2b'));_0x4f0821[_0x57dc('0x2c')]=_0x23f46d[_0x57dc('0x2c')]||_0x4f0821['context'];_0x4f0821[_0x57dc('0x2d')]=_0x23f46d[_0x57dc('0x2d')];_0x4f0821['priority']=_0x23f46d[_0x57dc('0x2e')]?_0x23f46d['priority']-0x1:0x1;return null;}else if(_0x23f46d&&_0xdc47dc[_0x23f46d[_0x57dc('0xb')]]){_0x4e47f2=_0xdc47dc[_0x23f46d['agicommand']](_0x23f46d);logger['info']('response',JSON[_0x57dc('0x1e')](_0x4e47f2,null,0x2));if(_0x4e47f2&&_0x4e47f2[_0x57dc('0x2f')]===AGI_CODE_SUCCESS&&_0x4e47f2[_0x57dc('0x30')]!==AGI_RESULT_ERROR&&!_0x4f0821[_0x57dc('0x31')]){logger['debug'](_0x57dc('0x32'),inspect(_0x4e47f2));return _[_0x57dc('0x33')](_0x4e47f2[_0x57dc('0x30')])?null:_0x4e47f2[_0x57dc('0x30')][_0x57dc('0x34')]();}else{logger[_0x57dc('0x8')]('response',inspect(_0x4e47f2));return null;}}else{logger[_0x57dc('0x8')](_0x57dc('0x35'));return null;}}catch(_0x1d7b53){logger[_0x57dc('0x8')](_0x1d7b53[_0x57dc('0xa')]);return null;}});if(_0x238e1a[_0x57dc('0x36')]){logger[_0x57dc('0x22')](util[_0x57dc('0x20')](_0x57dc('0x37'),_0x4f0821['arg_1'],_0x4f0821['calleridname'],_0x4f0821[_0x57dc('0x38')],_0x4f0821[_0x57dc('0x25')],_0x4f0821['uniqueid']));_0x1deeab[_0x57dc('0x27')](_0x238e1a[_0x57dc('0x36')]['id'],function(_0x33fc32){try{_0x33fc32=_0xdc47dc[_0x57dc('0x28')](_0x33fc32);logger[_0x57dc('0x1d')](_0x57dc('0x29'),JSON['stringify'](_0x33fc32,null,0x2));if(_0x33fc32&&_0xdc47dc[_0x33fc32[_0x57dc('0xb')]]){_0x4e47f2=_0xdc47dc[_0x33fc32[_0x57dc('0xb')]](_0x33fc32);if(_0x4e47f2){logger['debug']('response',inspect(_0x4e47f2));return _[_0x57dc('0x33')](_0x4e47f2[_0x57dc('0x30')])?null:_0x4e47f2[_0x57dc('0x30')]['toString']();}else{logger[_0x57dc('0x8')](_0x57dc('0x32'),inspect(_0x4e47f2));return null;}}else{logger[_0x57dc('0x8')](_0x57dc('0x35'));return null;}}catch(_0x48619c){logger[_0x57dc('0x8')](_0x48619c[_0x57dc('0xa')]);return null;}});}logger[_0x57dc('0x22')](util[_0x57dc('0x20')](_0x57dc('0x39'),_0x4f0821[_0x57dc('0x23')],_0x4f0821['calleridname'],_0x4f0821['callerid'],_0x4f0821[_0x57dc('0x25')],_0x4f0821[_0x57dc('0x26')]));logger[_0x57dc('0x22')](util[_0x57dc('0x20')](_0x57dc('0x3a'),_0x4f0821[_0x57dc('0x2c')],_0x4f0821[_0x57dc('0x2d')],parseInt(_0x4f0821['priority'],0xa)+0x1));_0x4f0821[_0x57dc('0x3b')](_0x4f0821[_0x57dc('0x2c')],_0x4f0821[_0x57dc('0x2d')],parseInt(_0x4f0821[_0x57dc('0x2e')],0xa)+0x1);_0x4f0821['close']();}function handleNotFound(_0x10b346){logger['error'](util[_0x57dc('0x20')](_0x57dc('0x3c'),_0x10b346[_0x57dc('0x23')]));_0x10b346[_0x57dc('0x3b')](_0x10b346[_0x57dc('0x2c')],_0x10b346['extension'],parseInt(_0x10b346[_0x57dc('0x2e')],0xa)+0x1);_0x10b346[_0x57dc('0x3d')]();}function handleUnpublished(_0x221388){logger[_0x57dc('0x8')](util['format'](_0x57dc('0x3e'),_0x221388[_0x57dc('0x23')]));_0x221388[_0x57dc('0x3b')](_0x221388['context'],_0x221388['extension'],parseInt(_0x221388[_0x57dc('0x2e')],0xa)+0x1);_0x221388[_0x57dc('0x3d')]();}module[_0x57dc('0x3f')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};