cc5a59972a51f99a1b78de7617c93b1993c635c4
[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 _0xeb3f=['calleridname','[GOTO]\x20context:\x20%s\x20extension:\x20%s\x20priority:\x20%s','continueAt','close','Project\x20%s\x20not\x20found','Project\x20%s\x20not\x20published','exports','lodash','xml2json','util','../../config/logger','agi','./rpc','./graph','./vertices','catch','stack','agicommand','retry','maxRetry','hasOwnProperty','isArray','length','source','target','value','mxGraphModel','root','inspect','start','stringify','joinAt','omit','mxCell','info','format','[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','debug','gotoc','gotoc\x20block\x20stop\x20traverse\x20BFS','context','extension','priority','response','result','evtHangup','isUndefined','toString','error','agicommand\x20not\x20found','finally','traverseBFS','clear','vertex','[END]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s'];(function(_0xd0b415,_0x149675){var _0x2bdf2c=function(_0x59fbfa){while(--_0x59fbfa){_0xd0b415['push'](_0xd0b415['shift']());}};_0x2bdf2c(++_0x149675);}(_0xeb3f,0x7d));var _0xfeb3=function(_0x2c91e9,_0x2fb965){_0x2c91e9=_0x2c91e9-0x0;var _0x13f0ff=_0xeb3f[_0x2c91e9];return _0x13f0ff;};'use strict';var _=require(_0xfeb3('0x0'));var moment=require('moment');var parser=require(_0xfeb3('0x1'));var util=require(_0xfeb3('0x2'));var logger=require(_0xfeb3('0x3'))(_0xfeb3('0x4'));var rpc=require(_0xfeb3('0x5'));var mailRpc=require('./mailRpc');var Graph=require(_0xfeb3('0x6'));var Vertices=require(_0xfeb3('0x7'));var AGI_CODE_SUCCESS=0xc8;var AGI_RESULT_ERROR=-0x1;function getAll(){return rpc['getSquareProjects']()[_0xfeb3('0x8')](function(_0xc74c3c){logger['error']('Unable\x20to\x20download\x20CallySquare\x20projects',_0xc74c3c[_0xfeb3('0x9')]);return[];});}function addVertex(_0x3147b2,_0x3fa351,_0x9ee518){_0x3fa351[_0xfeb3('0xa')]=_0x9ee518;if(_0x3fa351['hasOwnProperty'](_0xfeb3('0xb'))){_0x3fa351[_0xfeb3('0xc')]=parseInt(_0x3fa351[_0xfeb3('0xb')],0xa);}_0x3147b2['addVertex'](_['omit'](_0x3fa351,'mxCell'));}function initGraph(_0x4b8dde,_0x1d2dd3){var _0x2b6684=new Graph();for(var _0x448bb4 in _0x4b8dde){if(_0x4b8dde[_0xfeb3('0xd')](_0x448bb4)){if(_[_0xfeb3('0xe')](_0x4b8dde[_0x448bb4])){for(var _0x3bc973=0x0;_0x3bc973<_0x4b8dde[_0x448bb4]['length'];_0x3bc973+=0x1){addVertex(_0x2b6684,_0x4b8dde[_0x448bb4][_0x3bc973],_0x448bb4);}}else{addVertex(_0x2b6684,_0x4b8dde[_0x448bb4],_0x448bb4);}}}for(var _0x4bbfcd=0x0;_0x4bbfcd<_0x1d2dd3[_0xfeb3('0xf')];_0x4bbfcd+=0x1){if(_0x1d2dd3[_0x4bbfcd][_0xfeb3('0x10')]&&_0x1d2dd3[_0x4bbfcd][_0xfeb3('0x11')]){_0x2b6684['addEdge'](_0x1d2dd3[_0x4bbfcd]['source'],_0x1d2dd3[_0x4bbfcd][_0xfeb3('0x11')],_0x1d2dd3[_0x4bbfcd][_0xfeb3('0x12')]);}}return _0x2b6684;}function getRoot(_0x5ec804){return parser['toJson'](_0x5ec804,{'object':!![]})[_0xfeb3('0x13')][_0xfeb3('0x14')];}function inspect(_0x5315f6){return util[_0xfeb3('0x15')](_0x5315f6,{'showHidden':![],'depth':null});}function initialize(_0x2340e5,_0x8dd88b){var _0xd46923=getRoot(_0x2340e5['production']);if(!_0xd46923||!_0xd46923[_0xfeb3('0x16')])return;var _0x1ce3d2,_0x53a97e,_0x27c4fe;logger['debug'](_0xfeb3('0x14'),JSON[_0xfeb3('0x17')](_0xd46923,null,0x2));_0x8dd88b[_0xfeb3('0x18')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x1ce3d2=initGraph(_[_0xfeb3('0x19')](_0xd46923,_0xfeb3('0x1a')),_0xd46923[_0xfeb3('0x1a')]);_0x53a97e=new Vertices(_0x8dd88b,rpc,mailRpc);logger[_0xfeb3('0x1b')](util[_0xfeb3('0x1c')](_0xfeb3('0x1d'),_0x8dd88b[_0xfeb3('0x1e')],_0x8dd88b['calleridname'],_0x8dd88b[_0xfeb3('0x1f')],_0x8dd88b[_0xfeb3('0x20')],_0x8dd88b[_0xfeb3('0x21')]));_0x1ce3d2['traverseBFS'](_0xd46923[_0xfeb3('0x16')]['id'],function(_0x3f32a0){try{_0x3f32a0=_0x53a97e['clear'](_0x3f32a0);logger[_0xfeb3('0x22')]('vertex',JSON[_0xfeb3('0x17')](_0x3f32a0,null,0x2));if(_0x3f32a0['agicommand']===_0xfeb3('0x23')){logger['info'](_0xfeb3('0x24'));_0x8dd88b[_0xfeb3('0x25')]=_0x3f32a0[_0xfeb3('0x25')]||_0x8dd88b[_0xfeb3('0x25')];_0x8dd88b['extension']=_0x3f32a0[_0xfeb3('0x26')];_0x8dd88b[_0xfeb3('0x27')]=_0x3f32a0['priority']?_0x3f32a0['priority']-0x1:0x1;return null;}else if(_0x3f32a0&&_0x53a97e[_0x3f32a0['agicommand']]){_0x27c4fe=_0x53a97e[_0x3f32a0[_0xfeb3('0xa')]](_0x3f32a0);logger[_0xfeb3('0x1b')](_0xfeb3('0x28'),JSON['stringify'](_0x27c4fe,null,0x2));if(_0x27c4fe&&_0x27c4fe['code']===AGI_CODE_SUCCESS&&_0x27c4fe[_0xfeb3('0x29')]!==AGI_RESULT_ERROR&&!_0x8dd88b[_0xfeb3('0x2a')]){logger[_0xfeb3('0x22')](_0xfeb3('0x28'),inspect(_0x27c4fe));return _[_0xfeb3('0x2b')](_0x27c4fe['result'])?null:_0x27c4fe[_0xfeb3('0x29')][_0xfeb3('0x2c')]();}else{logger[_0xfeb3('0x2d')]('response',inspect(_0x27c4fe));return null;}}else{logger[_0xfeb3('0x2d')](_0xfeb3('0x2e'));return null;}}catch(_0x5109f4){logger[_0xfeb3('0x2d')](_0x5109f4[_0xfeb3('0x9')]);return null;}});if(_0xd46923[_0xfeb3('0x2f')]){logger[_0xfeb3('0x1b')](util[_0xfeb3('0x1c')]('[FINALLY\x20TRAVERSE]\x20%s\x20project:\x20from\x20\x22%s\x22\x20<%s>\x20to\x20extension\x20%s\x20with\x20uniqueid\x20%s',_0x8dd88b['arg_1'],_0x8dd88b['calleridname'],_0x8dd88b['callerid'],_0x8dd88b[_0xfeb3('0x20')],_0x8dd88b[_0xfeb3('0x21')]));_0x1ce3d2[_0xfeb3('0x30')](_0xd46923[_0xfeb3('0x2f')]['id'],function(_0x3df254){try{_0x3df254=_0x53a97e[_0xfeb3('0x31')](_0x3df254);logger['debug'](_0xfeb3('0x32'),JSON[_0xfeb3('0x17')](_0x3df254,null,0x2));if(_0x3df254&&_0x53a97e[_0x3df254[_0xfeb3('0xa')]]){_0x27c4fe=_0x53a97e[_0x3df254[_0xfeb3('0xa')]](_0x3df254);if(_0x27c4fe){logger[_0xfeb3('0x22')]('response',inspect(_0x27c4fe));return _['isUndefined'](_0x27c4fe[_0xfeb3('0x29')])?null:_0x27c4fe[_0xfeb3('0x29')]['toString']();}else{logger['error'](_0xfeb3('0x28'),inspect(_0x27c4fe));return null;}}else{logger['error'](_0xfeb3('0x2e'));return null;}}catch(_0x227894){logger[_0xfeb3('0x2d')](_0x227894[_0xfeb3('0x9')]);return null;}});}logger['info'](util[_0xfeb3('0x1c')](_0xfeb3('0x33'),_0x8dd88b[_0xfeb3('0x1e')],_0x8dd88b[_0xfeb3('0x34')],_0x8dd88b['callerid'],_0x8dd88b['dnid'],_0x8dd88b[_0xfeb3('0x21')]));logger[_0xfeb3('0x1b')](util[_0xfeb3('0x1c')](_0xfeb3('0x35'),_0x8dd88b[_0xfeb3('0x25')],_0x8dd88b[_0xfeb3('0x26')],parseInt(_0x8dd88b[_0xfeb3('0x27')],0xa)+0x1));_0x8dd88b[_0xfeb3('0x36')](_0x8dd88b['context'],_0x8dd88b[_0xfeb3('0x26')],parseInt(_0x8dd88b['priority'],0xa)+0x1);_0x8dd88b[_0xfeb3('0x37')]();}function handleNotFound(_0x13eeab){logger[_0xfeb3('0x2d')](util[_0xfeb3('0x1c')](_0xfeb3('0x38'),_0x13eeab['arg_1']));_0x13eeab['continueAt'](_0x13eeab[_0xfeb3('0x25')],_0x13eeab['extension'],parseInt(_0x13eeab[_0xfeb3('0x27')],0xa)+0x1);_0x13eeab[_0xfeb3('0x37')]();}function handleUnpublished(_0x2f1347){logger[_0xfeb3('0x2d')](util[_0xfeb3('0x1c')](_0xfeb3('0x39'),_0x2f1347[_0xfeb3('0x1e')]));_0x2f1347[_0xfeb3('0x36')](_0x2f1347['context'],_0x2f1347['extension'],parseInt(_0x2f1347['priority'],0xa)+0x1);_0x2f1347[_0xfeb3('0x37')]();}module[_0xfeb3('0x3a')]={'getAll':getAll,'handleNotFound':handleNotFound,'handleUnpublished':handleUnpublished,'initialize':initialize};