b551dd1de85fd90788ad844240b40604c7515496
[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 _0x7aee=['source','target','addEdge','toJson','root','inspect','production','debug','stringify','YYYY-MM-DD\x20HH:mm:ss','info','[START\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','arg_1','callerid','dnid','uniqueid','traverseBFS','vertex','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','code','result','evtHangup','isUndefined','toString','error','finally','format','[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s','calleridname','clear','agicommand\x20not\x20found','stack','[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','moment','xml2json','util','../../config/logger','agi','./rpc','./mailRpc','./vertices','catch','Unable\x20to\x20download\x20CallySquare\x20projects','agicommand','hasOwnProperty','retry','maxRetry','addVertex','omit','mxCell','length'];(function(_0x1678c8,_0x1c32f4){var _0x387aa9=function(_0x2803bd){while(--_0x2803bd){_0x1678c8['push'](_0x1678c8['shift']());}};_0x387aa9(++_0x1c32f4);}(_0x7aee,0x1d6));var _0xe7ae=function(_0x540e85,_0x598f7){_0x540e85=_0x540e85-0x0;var _0x4940da=_0x7aee[_0x540e85];return _0x4940da;};'use strict';var _=require('lodash');var moment=require(_0xe7ae('0x0'));var parser=require(_0xe7ae('0x1'));var util=require(_0xe7ae('0x2'));var logger=require(_0xe7ae('0x3'))(_0xe7ae('0x4'));var rpc=require(_0xe7ae('0x5'));var mailRpc=require(_0xe7ae('0x6'));var Graph=require('./graph');var Vertices=require(_0xe7ae('0x7'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc['getSquareProjects']()[_0xe7ae('0x8')](function(_0x464342){logger['error'](_0xe7ae('0x9'),_0x464342['stack']);return[];});}function addVertex(_0x5e2c36,_0x2964a9,_0x2389ce){_0x2964a9[_0xe7ae('0xa')]=_0x2389ce;if(_0x2964a9[_0xe7ae('0xb')](_0xe7ae('0xc'))){_0x2964a9[_0xe7ae('0xd')]=parseInt(_0x2964a9[_0xe7ae('0xc')],0xa);}_0x5e2c36[_0xe7ae('0xe')](_[_0xe7ae('0xf')](_0x2964a9,_0xe7ae('0x10')));}function initGraph(_0x470135,_0x3c5127){var _0x4f42cc=new Graph();for(var _0x31456c in _0x470135){if(_0x470135[_0xe7ae('0xb')](_0x31456c)){if(_['isArray'](_0x470135[_0x31456c])){for(var _0x5f0d89=0x0;_0x5f0d89<_0x470135[_0x31456c]['length'];_0x5f0d89+=0x1){addVertex(_0x4f42cc,_0x470135[_0x31456c][_0x5f0d89],_0x31456c);}}else{addVertex(_0x4f42cc,_0x470135[_0x31456c],_0x31456c);}}}for(var _0x36a228=0x0;_0x36a228<_0x3c5127[_0xe7ae('0x11')];_0x36a228+=0x1){if(_0x3c5127[_0x36a228][_0xe7ae('0x12')]&&_0x3c5127[_0x36a228][_0xe7ae('0x13')]){_0x4f42cc[_0xe7ae('0x14')](_0x3c5127[_0x36a228][_0xe7ae('0x12')],_0x3c5127[_0x36a228][_0xe7ae('0x13')],_0x3c5127[_0x36a228]['value']);}}return _0x4f42cc;}function getRoot(_0x5761f5){return parser[_0xe7ae('0x15')](_0x5761f5,{'object':!![]})['mxGraphModel'][_0xe7ae('0x16')];}function inspect(_0x21e584){return util[_0xe7ae('0x17')](_0x21e584,{'showHidden':![],'depth':null});}function initialize(_0x4dda0c,_0x186431){var _0x3bdece=getRoot(_0x4dda0c[_0xe7ae('0x18')]);if(!_0x3bdece||!_0x3bdece['start'])return;var _0x5664a2,_0xce60ad,_0x279cc8;logger[_0xe7ae('0x19')](_0xe7ae('0x16'),JSON[_0xe7ae('0x1a')](_0x3bdece,null,0x2));_0x186431['joinAt']=moment()['format'](_0xe7ae('0x1b'));_0x5664a2=initGraph(_[_0xe7ae('0xf')](_0x3bdece,_0xe7ae('0x10')),_0x3bdece[_0xe7ae('0x10')]);_0xce60ad=new Vertices(_0x186431,rpc,mailRpc);logger[_0xe7ae('0x1c')](util['format'](_0xe7ae('0x1d'),_0x186431[_0xe7ae('0x1e')],_0x186431['calleridname'],_0x186431[_0xe7ae('0x1f')],_0x186431[_0xe7ae('0x20')],_0x186431[_0xe7ae('0x21')]));_0x5664a2[_0xe7ae('0x22')](_0x3bdece['start']['id'],function(_0x3dcc78){try{_0x3dcc78=_0xce60ad['clear'](_0x3dcc78);logger[_0xe7ae('0x19')](_0xe7ae('0x23'),JSON[_0xe7ae('0x1a')](_0x3dcc78,null,0x2));if(_0x3dcc78[_0xe7ae('0xa')]===_0xe7ae('0x24')){logger['info'](_0xe7ae('0x25'));_0x186431['context']=_0x3dcc78[_0xe7ae('0x26')]||_0x186431[_0xe7ae('0x26')];_0x186431[_0xe7ae('0x27')]=_0x3dcc78['extension'];_0x186431[_0xe7ae('0x28')]=_0x3dcc78[_0xe7ae('0x28')]?_0x3dcc78['priority']-0x1:0x1;return null;}else if(_0x3dcc78&&_0xce60ad[_0x3dcc78[_0xe7ae('0xa')]]){_0x279cc8=_0xce60ad[_0x3dcc78[_0xe7ae('0xa')]](_0x3dcc78);logger[_0xe7ae('0x1c')](_0xe7ae('0x29'),JSON[_0xe7ae('0x1a')](_0x279cc8,null,0x2));if(_0x279cc8&&_0x279cc8[_0xe7ae('0x2a')]===AGI_CODE_SUCCESS&&_0x279cc8[_0xe7ae('0x2b')]!==AGI_RESULT_ERROR&&!_0x186431[_0xe7ae('0x2c')]){logger[_0xe7ae('0x19')]('response',inspect(_0x279cc8));return _[_0xe7ae('0x2d')](_0x279cc8[_0xe7ae('0x2b')])?null:_0x279cc8[_0xe7ae('0x2b')][_0xe7ae('0x2e')]();}else{logger[_0xe7ae('0x2f')](_0xe7ae('0x29'),inspect(_0x279cc8));return null;}}else{logger['error']('agicommand\x20not\x20found');return null;}}catch(_0x23f0b5){logger['error'](_0x23f0b5['stack']);return null;}});if(_0x3bdece[_0xe7ae('0x30')]){logger[_0xe7ae('0x1c')](util[_0xe7ae('0x31')](_0xe7ae('0x32'),_0x186431[_0xe7ae('0x1e')],_0x186431[_0xe7ae('0x33')],_0x186431['callerid'],_0x186431[_0xe7ae('0x20')],_0x186431[_0xe7ae('0x21')]));_0x5664a2[_0xe7ae('0x22')](_0x3bdece[_0xe7ae('0x30')]['id'],function(_0x3945ef){try{_0x3945ef=_0xce60ad[_0xe7ae('0x34')](_0x3945ef);logger[_0xe7ae('0x19')](_0xe7ae('0x23'),JSON[_0xe7ae('0x1a')](_0x3945ef,null,0x2));if(_0x3945ef&&_0xce60ad[_0x3945ef[_0xe7ae('0xa')]]){_0x279cc8=_0xce60ad[_0x3945ef['agicommand']](_0x3945ef);if(_0x279cc8){logger[_0xe7ae('0x19')](_0xe7ae('0x29'),inspect(_0x279cc8));return _[_0xe7ae('0x2d')](_0x279cc8[_0xe7ae('0x2b')])?null:_0x279cc8[_0xe7ae('0x2b')][_0xe7ae('0x2e')]();}else{logger['error'](_0xe7ae('0x29'),inspect(_0x279cc8));return null;}}else{logger[_0xe7ae('0x2f')](_0xe7ae('0x35'));return null;}}catch(_0x5122fa){logger[_0xe7ae('0x2f')](_0x5122fa[_0xe7ae('0x36')]);return null;}});}logger[_0xe7ae('0x1c')](util[_0xe7ae('0x31')](_0xe7ae('0x37'),_0x186431['arg_1'],_0x186431[_0xe7ae('0x33')],_0x186431[_0xe7ae('0x1f')],_0x186431[_0xe7ae('0x20')],_0x186431[_0xe7ae('0x21')]));logger[_0xe7ae('0x1c')](util[_0xe7ae('0x31')](_0xe7ae('0x38'),_0x186431[_0xe7ae('0x26')],_0x186431['extension'],parseInt(_0x186431[_0xe7ae('0x28')],0xa)+0x1));_0x186431[_0xe7ae('0x39')](_0x186431[_0xe7ae('0x26')],_0x186431[_0xe7ae('0x27')],parseInt(_0x186431[_0xe7ae('0x28')],0xa)+0x1);_0x186431[_0xe7ae('0x3a')]();}function handleNotFound(_0x4fdca6){logger['error'](util['format'](_0xe7ae('0x3b'),_0x4fdca6[_0xe7ae('0x1e')]));_0x4fdca6[_0xe7ae('0x39')](_0x4fdca6[_0xe7ae('0x26')],_0x4fdca6['extension'],parseInt(_0x4fdca6[_0xe7ae('0x28')],0xa)+0x1);_0x4fdca6[_0xe7ae('0x3a')]();}function handleUnpublished(_0x46db0a){logger[_0xe7ae('0x2f')](util[_0xe7ae('0x31')](_0xe7ae('0x3c'),_0x46db0a[_0xe7ae('0x1e')]));_0x46db0a[_0xe7ae('0x39')](_0x46db0a[_0xe7ae('0x26')],_0x46db0a[_0xe7ae('0x27')],parseInt(_0x46db0a[_0xe7ae('0x28')],0xa)+0x1);_0x46db0a[_0xe7ae('0x3a')]();}module['exports']={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};