49706f87c6569384da5066859a203a118bc2ed3d
[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 _0x463a=['addVertex','omit','mxCell','isArray','length','source','target','addEdge','value','mxGraphModel','root','inspect','production','stringify','joinAt','format','info','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','calleridname','callerid','dnid','uniqueid','traverseBFS','start','clear','debug','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','evtHangup','isUndefined','result','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','arg_1','vertex','[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','exports','lodash','moment','util','./rpc','./mailRpc','./graph','./vertices','error','stack','agicommand','hasOwnProperty','retry','maxRetry'];(function(_0x457b64,_0x49a219){var _0x437111=function(_0x3dad3d){while(--_0x3dad3d){_0x457b64['push'](_0x457b64['shift']());}};_0x437111(++_0x49a219);}(_0x463a,0x1cb));var _0xa463=function(_0x31cb5f,_0x2df766){_0x31cb5f=_0x31cb5f-0x0;var _0x586042=_0x463a[_0x31cb5f];return _0x586042;};'use strict';var _=require(_0xa463('0x0'));var moment=require(_0xa463('0x1'));var parser=require('xml2json');var util=require(_0xa463('0x2'));var logger=require('../../config/logger')('agi');var rpc=require(_0xa463('0x3'));var mailRpc=require(_0xa463('0x4'));var Graph=require(_0xa463('0x5'));var Vertices=require(_0xa463('0x6'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc['getSquareProjects']()['catch'](function(_0x40d9a1){logger[_0xa463('0x7')]('Unable\x20to\x20download\x20CallySquare\x20projects',_0x40d9a1[_0xa463('0x8')]);return[];});}function addVertex(_0xcaf14d,_0x2be30c,_0x1fbdec){_0x2be30c[_0xa463('0x9')]=_0x1fbdec;if(_0x2be30c[_0xa463('0xa')](_0xa463('0xb'))){_0x2be30c[_0xa463('0xc')]=parseInt(_0x2be30c[_0xa463('0xb')],0xa);}_0xcaf14d[_0xa463('0xd')](_[_0xa463('0xe')](_0x2be30c,_0xa463('0xf')));}function initGraph(_0x3eebc6,_0x4bd451){var _0x4ee196=new Graph();for(var _0x28e219 in _0x3eebc6){if(_0x3eebc6[_0xa463('0xa')](_0x28e219)){if(_[_0xa463('0x10')](_0x3eebc6[_0x28e219])){for(var _0x5cd692=0x0;_0x5cd692<_0x3eebc6[_0x28e219][_0xa463('0x11')];_0x5cd692+=0x1){addVertex(_0x4ee196,_0x3eebc6[_0x28e219][_0x5cd692],_0x28e219);}}else{addVertex(_0x4ee196,_0x3eebc6[_0x28e219],_0x28e219);}}}for(var _0x75948e=0x0;_0x75948e<_0x4bd451[_0xa463('0x11')];_0x75948e+=0x1){if(_0x4bd451[_0x75948e][_0xa463('0x12')]&&_0x4bd451[_0x75948e][_0xa463('0x13')]){_0x4ee196[_0xa463('0x14')](_0x4bd451[_0x75948e]['source'],_0x4bd451[_0x75948e][_0xa463('0x13')],_0x4bd451[_0x75948e][_0xa463('0x15')]);}}return _0x4ee196;}function getRoot(_0x29bb73){return parser['toJson'](_0x29bb73,{'object':!![]})[_0xa463('0x16')][_0xa463('0x17')];}function inspect(_0xbd422b){return util[_0xa463('0x18')](_0xbd422b,{'showHidden':![],'depth':null});}function initialize(_0x24253f,_0x45d405){var _0x20e257=getRoot(_0x24253f[_0xa463('0x19')]);if(!_0x20e257||!_0x20e257['start'])return;var _0x1e3f30,_0x1911f6,_0x3325b0;logger['debug'](_0xa463('0x17'),JSON[_0xa463('0x1a')](_0x20e257,null,0x2));_0x45d405[_0xa463('0x1b')]=moment()[_0xa463('0x1c')]('YYYY-MM-DD\x20HH:mm:ss');_0x1e3f30=initGraph(_[_0xa463('0xe')](_0x20e257,_0xa463('0xf')),_0x20e257[_0xa463('0xf')]);_0x1911f6=new Vertices(_0x45d405,rpc,mailRpc);logger[_0xa463('0x1d')](util[_0xa463('0x1c')](_0xa463('0x1e'),_0x45d405['arg_1'],_0x45d405[_0xa463('0x1f')],_0x45d405[_0xa463('0x20')],_0x45d405[_0xa463('0x21')],_0x45d405[_0xa463('0x22')]));_0x1e3f30[_0xa463('0x23')](_0x20e257[_0xa463('0x24')]['id'],function(_0xaf7a70){try{_0xaf7a70=_0x1911f6[_0xa463('0x25')](_0xaf7a70);logger[_0xa463('0x26')]('vertex',JSON['stringify'](_0xaf7a70,null,0x2));if(_0xaf7a70[_0xa463('0x9')]==='gotoc'){logger[_0xa463('0x1d')](_0xa463('0x27'));_0x45d405[_0xa463('0x28')]=_0xaf7a70[_0xa463('0x28')]||_0x45d405['context'];_0x45d405[_0xa463('0x29')]=_0xaf7a70[_0xa463('0x29')];_0x45d405[_0xa463('0x2a')]=_0xaf7a70[_0xa463('0x2a')]?_0xaf7a70['priority']-0x1:0x1;return null;}else if(_0xaf7a70&&_0x1911f6[_0xaf7a70[_0xa463('0x9')]]){_0x3325b0=_0x1911f6[_0xaf7a70['agicommand']](_0xaf7a70);logger[_0xa463('0x1d')](_0xa463('0x2b'),JSON['stringify'](_0x3325b0,null,0x2));if(_0x3325b0&&_0x3325b0['code']===AGI_CODE_SUCCESS&&_0x3325b0['result']!==AGI_RESULT_ERROR&&!_0x45d405[_0xa463('0x2c')]){logger[_0xa463('0x26')](_0xa463('0x2b'),inspect(_0x3325b0));return _[_0xa463('0x2d')](_0x3325b0[_0xa463('0x2e')])?null:_0x3325b0[_0xa463('0x2e')][_0xa463('0x2f')]();}else{logger[_0xa463('0x7')]('response',inspect(_0x3325b0));return null;}}else{logger['error'](_0xa463('0x30'));return null;}}catch(_0x9f7001){logger[_0xa463('0x7')](_0x9f7001[_0xa463('0x8')]);return null;}});if(_0x20e257[_0xa463('0x31')]){logger['info'](util[_0xa463('0x1c')](_0xa463('0x32'),_0x45d405[_0xa463('0x33')],_0x45d405[_0xa463('0x1f')],_0x45d405['callerid'],_0x45d405[_0xa463('0x21')],_0x45d405['uniqueid']));_0x1e3f30[_0xa463('0x23')](_0x20e257[_0xa463('0x31')]['id'],function(_0x505028){try{_0x505028=_0x1911f6[_0xa463('0x25')](_0x505028);logger[_0xa463('0x26')](_0xa463('0x34'),JSON[_0xa463('0x1a')](_0x505028,null,0x2));if(_0x505028&&_0x1911f6[_0x505028[_0xa463('0x9')]]){_0x3325b0=_0x1911f6[_0x505028['agicommand']](_0x505028);if(_0x3325b0){logger[_0xa463('0x26')](_0xa463('0x2b'),inspect(_0x3325b0));return _['isUndefined'](_0x3325b0[_0xa463('0x2e')])?null:_0x3325b0[_0xa463('0x2e')]['toString']();}else{logger[_0xa463('0x7')](_0xa463('0x2b'),inspect(_0x3325b0));return null;}}else{logger[_0xa463('0x7')](_0xa463('0x30'));return null;}}catch(_0x29307f){logger[_0xa463('0x7')](_0x29307f[_0xa463('0x8')]);return null;}});}logger[_0xa463('0x1d')](util[_0xa463('0x1c')](_0xa463('0x35'),_0x45d405['arg_1'],_0x45d405['calleridname'],_0x45d405[_0xa463('0x20')],_0x45d405[_0xa463('0x21')],_0x45d405[_0xa463('0x22')]));logger[_0xa463('0x1d')](util[_0xa463('0x1c')](_0xa463('0x36'),_0x45d405[_0xa463('0x28')],_0x45d405[_0xa463('0x29')],parseInt(_0x45d405[_0xa463('0x2a')],0xa)+0x1));_0x45d405[_0xa463('0x37')](_0x45d405['context'],_0x45d405[_0xa463('0x29')],parseInt(_0x45d405[_0xa463('0x2a')],0xa)+0x1);_0x45d405[_0xa463('0x38')]();}function handleNotFound(_0x40d4ca){logger[_0xa463('0x7')](util[_0xa463('0x1c')](_0xa463('0x39'),_0x40d4ca['arg_1']));_0x40d4ca['continueAt'](_0x40d4ca['context'],_0x40d4ca[_0xa463('0x29')],parseInt(_0x40d4ca[_0xa463('0x2a')],0xa)+0x1);_0x40d4ca[_0xa463('0x38')]();}function handleUnpublished(_0x1f2426){logger[_0xa463('0x7')](util['format']('Project\x20%s\x20not\x20published',_0x1f2426[_0xa463('0x33')]));_0x1f2426['continueAt'](_0x1f2426[_0xa463('0x28')],_0x1f2426[_0xa463('0x29')],parseInt(_0x1f2426['priority'],0xa)+0x1);_0x1f2426['close']();}module[_0xa463('0x3a')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};