Built motion from commit (unavailable).|2.5.11
[motion2.git] / server / services / routing / server / index.js
index 38d2c2e..415287f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x22bb=['uuid','../../../config/environment','../../../config/logger','../rpc/openchannelQueueReport','../rpc/mailQueueReport','../rpc/chatQueueReport','../rpc/faxQueueReport','../rpc/whatsappQueueReport','%s.%s.%s','IntervalId','isNil','Intervals','map','interval','rules','message','interaction','applications','isArray','length','existsSync','join','app','.js','toLowerCase','autoreply','split','push','dialogflow','appdata','slice','dialogflowv2','amazonlex','tag','TagId','format','./interval','./applications/','consequence','priority','Push\x20new\x20rule','intervals','\x20|\x20','Please\x20create\x20a\x20new\x20file\x20under','execute','info','Applications\x20executed','stringify','matchPath','emit','error','stack','channel','QueueReport','update','UserId','catch','error\x20update\x20queue\x20report','message\x20is\x20empty','agent','agents','busy','busyQueue','end','hasOwnProperty','capacity','updateRealtime','agent\x20not\x20found','values','chatQueues','loggedIn','name','paused','waiting','mailQueues','available','openchannelQueues','smsQueues','faxQueues','whatsappQueues','chatQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','whatsappQueuesWaitingInteractions','server','listen','127.0.0.1','log','Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!','util','path','jayson/promise','bluebird'];(function(_0x4a9fb1,_0x273043){var _0x348672=function(_0x142b69){while(--_0x142b69){_0x4a9fb1['push'](_0x4a9fb1['shift']());}};_0x348672(++_0x273043);}(_0x22bb,0x170));var _0xb22b=function(_0x4b369d,_0x265eb8){_0x4b369d=_0x4b369d-0x0;var _0x571a98=_0x22bb[_0x4b369d];return _0x571a98;};'use strict';var _=require('lodash');var util=require(_0xb22b('0x0'));var path=require(_0xb22b('0x1'));var fs=require('fs');var jayson=require(_0xb22b('0x2'));var BPromise=require(_0xb22b('0x3'));var uuid=require(_0xb22b('0x4'));var config=require(_0xb22b('0x5'));var logger=require(_0xb22b('0x6'))('routing');var rpc={'openchannelQueueReport':require(_0xb22b('0x7')),'mailQueueReport':require(_0xb22b('0x8')),'chatQueueReport':require(_0xb22b('0x9')),'smsQueueReport':require('../rpc/smsQueueReport'),'faxQueueReport':require(_0xb22b('0xa')),'whatsappQueueReport':require(_0xb22b('0xb'))};var RuleEngine=require('../lib/rule-engine');function getId(_0x8762d7,_0x2557cc,_0x170be6){return util['format'](_0xb22b('0xc'),_0x8762d7,_0x2557cc||0x0,_0x170be6||0x0);}function getIntervals(_0x2ab0f4,_0x4552ff){var _0x3e0c64=[];if(!_['isNil'](_0x4552ff[_0xb22b('0xd')])&&!_[_0xb22b('0xe')](_0x2ab0f4[_0x4552ff[_0xb22b('0xd')]])&&!_[_0xb22b('0xe')](_0x2ab0f4[_0x4552ff[_0xb22b('0xd')]][_0xb22b('0xf')])){_0x3e0c64=_[_0xb22b('0x10')](_0x2ab0f4[_0x4552ff[_0xb22b('0xd')]][_0xb22b('0xf')],_0xb22b('0x11'));}else if(!_[_0xb22b('0xe')](_0x4552ff['interval'])){_0x3e0c64=[_0x4552ff[_0xb22b('0x11')]];}return _0x3e0c64;}exports['listen']=function(_0x3ce122){_0x3ce122[_0xb22b('0x12')]={};return new BPromise(function(_0x4d7092,_0x2a6179){var _0x4946cf={'Start':function(_0x554696){var _0x5f357c=this;return new Promise(function(_0x26e8bb,_0x2c9fa6){if(_0x554696){try{var _0x1295fd=[];var _0x45e65c=getId(_0x554696['channel'],_0x554696[_0xb22b('0x13')]?_0x554696[_0xb22b('0x13')]['id']:0x0,_0x554696[_0xb22b('0x14')]?_0x554696['interaction']['id']:0x0);if(_0x554696[_0xb22b('0x15')]&&_[_0xb22b('0x16')](_0x554696[_0xb22b('0x15')])&&_0x554696[_0xb22b('0x15')]['length']){for(var _0x323133=0x0;_0x323133<_0x554696[_0xb22b('0x15')][_0xb22b('0x17')];_0x323133+=0x1){var _0x4ef81c=_0x554696[_0xb22b('0x15')][_0x323133];if(fs[_0xb22b('0x18')](path[_0xb22b('0x19')](__dirname,'applications',_0x4ef81c[_0xb22b('0x1a')]+_0xb22b('0x1b')))){var _0x5f4183=[];switch(_0x4ef81c[_0xb22b('0x1a')][_0xb22b('0x1c')]()){case _0xb22b('0x1d'):var _0x3a73c3=_0x4ef81c['appdata'][_0xb22b('0x1e')](',');_0x5f4183[_0xb22b('0x1f')](_0x3a73c3[0x0]);_0x5f4183[_0xb22b('0x1f')](_0x3a73c3['slice'](0x1,_0x3a73c3[_0xb22b('0x17')])[_0xb22b('0x19')](','));break;case _0xb22b('0x20'):var _0x4fdc3f=_0x4ef81c[_0xb22b('0x21')]['split'](',');_0x5f4183[_0xb22b('0x1f')](_0x4fdc3f[0x0]);_0x5f4183['push'](_0x4fdc3f[0x1]);_0x5f4183[_0xb22b('0x1f')](_0x4fdc3f[_0xb22b('0x22')](0x2,_0x4fdc3f[_0xb22b('0x17')])[_0xb22b('0x19')](','));break;case _0xb22b('0x23'):var _0x49b481=_0x4ef81c[_0xb22b('0x21')][_0xb22b('0x1e')](',');_0x5f4183[_0xb22b('0x1f')](_0x49b481[0x0]);_0x5f4183[_0xb22b('0x1f')](_0x49b481[0x1]);_0x5f4183['push'](_0x49b481[0x2]);_0x5f4183[_0xb22b('0x1f')](_0x49b481[0x3]);_0x5f4183['push'](_0x49b481[_0xb22b('0x22')](0x4,_0x49b481[_0xb22b('0x17')])[_0xb22b('0x19')](','));break;case _0xb22b('0x24'):var _0x30c0fe=_0x4ef81c[_0xb22b('0x21')][_0xb22b('0x1e')](',');_0x5f4183[_0xb22b('0x1f')](_0x30c0fe[0x0]);_0x5f4183[_0xb22b('0x1f')](_0x30c0fe[0x1]);_0x5f4183[_0xb22b('0x1f')](_0x30c0fe[0x2]);_0x5f4183[_0xb22b('0x1f')](_0x30c0fe[0x3]);_0x5f4183[_0xb22b('0x1f')](_0x30c0fe[_0xb22b('0x22')](0x4,_0x30c0fe[_0xb22b('0x17')])['join'](','));break;case _0xb22b('0x13'):_0x5f4183['push'](_0x4ef81c['appdata']);break;case _0xb22b('0x25'):_0x5f4183[_0xb22b('0x1f')](_0x4ef81c[_0xb22b('0x26')]);_0x5f4183[_0xb22b('0x1f')](_0x4ef81c[_0xb22b('0x21')]);break;default:_0x5f4183=_['isNil'](_0x4ef81c[_0xb22b('0x21')])?[]:_0x4ef81c[_0xb22b('0x21')][_0xb22b('0x1e')](',');}var _0x17b80e={'id':util[_0xb22b('0x27')]('%s:%s:%s',_0x45e65c,_0x4ef81c['id'],_0x4ef81c[_0xb22b('0x1a')]),'condition':require(_0xb22b('0x28'))['condition'](_0x45e65c,getIntervals(_0x3ce122['intervals'],_0x4ef81c),_0x3ce122),'consequence':require(_0xb22b('0x29')+_0x4ef81c[_0xb22b('0x1a')])[_0xb22b('0x2a')](_0x45e65c,_0x5f4183,_0x3ce122,_0x554696),'p':_0x4ef81c[_0xb22b('0x2b')]||0x0};logger['info'](_0xb22b('0x2c'),_0x17b80e['id'],'on\x20interval',getIntervals(_0x3ce122[_0xb22b('0x2d')],_0x4ef81c)[_0xb22b('0x19')](_0xb22b('0x2e')));_0x1295fd[_0xb22b('0x1f')](_0x17b80e);}else{logger['error'](_0xb22b('0x2f'),path[_0xb22b('0x19')](__dirname,_0xb22b('0x15'),_0x4ef81c[_0xb22b('0x1a')]+_0xb22b('0x1b')));}}_0x3ce122[_0xb22b('0x12')][_0x45e65c]=new RuleEngine(_0x1295fd);_0x3ce122[_0xb22b('0x12')][_0x45e65c][_0xb22b('0x30')](_0x554696,function(_0x21df0b){logger[_0xb22b('0x31')](_0xb22b('0x32'),JSON[_0xb22b('0x33')](_0x21df0b[_0xb22b('0x34')]));if(_0x3ce122['rules'][_0x45e65c]){_0x3ce122[_0xb22b('0x12')][_0x45e65c][_0xb22b('0x35')]('complete');}});return _0x26e8bb({'code':0xc8,'message':_0x554696});}else{logger[_0xb22b('0x31')]('No\x20applications\x20to\x20execute');return _0x26e8bb({'code':0xc8,'message':_0x554696});}}catch(_0x311ccd){logger[_0xb22b('0x36')](_0x311ccd[_0xb22b('0x37')]);return _0x2c9fa6(_0x5f357c[_0xb22b('0x36')](0x1f4,_0x311ccd));}}return _0x2c9fa6('routing\x20is\x20empty');});},'AcceptMessage':function(_0x280f7e){var _0x6b31f2=this;return new Promise(function(_0x28dfe6,_0x36934d){if(_0x280f7e['message']&&_0x280f7e[_0xb22b('0x13')]['id']){try{var _0x4573ec=getId(_0x280f7e[_0xb22b('0x38')],_0x280f7e[_0xb22b('0x13')]?_0x280f7e[_0xb22b('0x13')]['id']:0x0,_0x280f7e[_0xb22b('0x14')]?_0x280f7e[_0xb22b('0x14')]['id']:0x0);if(_0x3ce122[_0xb22b('0x12')][_0x4573ec]){_0x3ce122['rules'][_0x4573ec][_0xb22b('0x35')]('end');if(rpc[_0x280f7e[_0xb22b('0x38')]+'QueueReport']){rpc[_0x280f7e[_0xb22b('0x38')]+_0xb22b('0x39')][_0xb22b('0x3a')](_0x4573ec,{'UserId':_0x280f7e[_0xb22b('0x13')][_0xb22b('0x3b')]})[_0xb22b('0x3c')](function(_0x8e4aca){logger['error'](_0xb22b('0x3d'));});}}return _0x28dfe6({'code':0xc8,'message':_0x280f7e});}catch(_0x4e1fc2){logger['error'](_0x4e1fc2[_0xb22b('0x37')]);return _0x36934d(_0x6b31f2[_0xb22b('0x36')](0x1f4,_0x4e1fc2));}}logger[_0xb22b('0x36')](_0xb22b('0x3e'));return _0x36934d(_0x6b31f2[_0xb22b('0x36')](0x1f4,_0xb22b('0x3e')));});},'RejectMessage':function(_0x488220){var _0x3a01e2=this;return new Promise(function(_0x5f1a79,_0xef7bf6){if(_0x488220[_0xb22b('0x3f')]&&_0x488220[_0xb22b('0x3f')]['id']){try{if(_0x3ce122[_0xb22b('0x40')][_0x488220['agent']['id']]){_0x3ce122[_0xb22b('0x40')][_0x488220[_0xb22b('0x3f')]['id']][_0xb22b('0x41')]=![];_0x3ce122[_0xb22b('0x40')][_0x488220[_0xb22b('0x3f')]['id']][_0xb22b('0x42')]=undefined;}return _0x5f1a79({'code':0xc8,'message':_0x488220});}catch(_0x32b3a6){logger[_0xb22b('0x36')](_0x32b3a6['stack']);return _0xef7bf6(_0x3a01e2[_0xb22b('0x36')](0x1f4,_0x32b3a6));}}logger['error']('message\x20is\x20empty');return _0xef7bf6(_0x3a01e2['error'](0x1f4,_0xb22b('0x3e')));});},'AbandonInteraction':function(_0x34f675){var _0x305dcf=this;return new Promise(function(_0x14d840,_0x1ac494){if(_0x34f675[_0xb22b('0x38')]&&_0x34f675[_0xb22b('0x14')]&&_0x34f675[_0xb22b('0x14')]['id']){try{var _0x5c46a8=getId(_0x34f675[_0xb22b('0x38')],_0x34f675['message']?_0x34f675[_0xb22b('0x13')]['id']:0x0,_0x34f675[_0xb22b('0x14')]?_0x34f675[_0xb22b('0x14')]['id']:0x0);if(_0x3ce122['rules'][_0x5c46a8]){_0x3ce122[_0xb22b('0x12')][_0x5c46a8][_0xb22b('0x35')](_0xb22b('0x43'));}return _0x14d840({'code':0xc8,'message':_0x34f675});}catch(_0xb89db1){logger[_0xb22b('0x36')](_0xb89db1[_0xb22b('0x37')]);return _0x1ac494(_0x305dcf[_0xb22b('0x36')](0x1f4,_0xb89db1));}}logger[_0xb22b('0x36')]('message\x20is\x20empty');return _0x1ac494(_0x305dcf['error'](0x1f4,_0xb22b('0x3e')));});},'AgentCapacity':function(_0x73011b){var _0x983936=this;return new Promise(function(_0x4b3d5b,_0x5c9b1f){if(_0x3ce122[_0xb22b('0x40')][_0xb22b('0x44')](_0x73011b['id'])){for(var _0x20e9a6 in _0x73011b[_0xb22b('0x45')]){if(_0x73011b[_0xb22b('0x45')][_0xb22b('0x44')](_0x20e9a6)){if(_0x3ce122[_0xb22b('0x40')][_0x73011b['id']]['hasOwnProperty'](_0x20e9a6+'CurrentCapacity')){_0x3ce122[_0xb22b('0x40')][_0x73011b['id']][_0x20e9a6+'CurrentCapacity']=parseInt(_0x73011b['capacity'][_0x20e9a6],0xa);}}}_0x3ce122[_0xb22b('0x40')][_0x73011b['id']][_0xb22b('0x46')]();return _0x4b3d5b({'code':0xc8,'message':_0x3ce122[_0xb22b('0x40')][_0x73011b['id']]});}else{return _0x5c9b1f(_0x983936[_0xb22b('0x36')](0x1f4,_0xb22b('0x47')));}});},'Agents':function(_0xdc54ca){return new Promise(function(_0x2258db,_0x3fb7af){var _0x2bc6f5=_[_0xb22b('0x48')](_0x3ce122['agents']);_0x2258db({'count':_0x2bc6f5[_0xb22b('0x17')],'rows':_0x2bc6f5});});},'ChatQueues':function(_0x41a10f){return new Promise(function(_0x2f505a,_0x31e756){var _0x54a173=[];for(var _0x168c36 in _0x3ce122['chatQueues']){if(_0x3ce122[_0xb22b('0x49')][_0xb22b('0x44')](_0x168c36)){var _0x214d52=_0x3ce122['chatQueues'][_0x168c36];var _0x387081={'id':_0x214d52['id'],'available':_0x214d52['available'],'loggedIn':_0x214d52[_0xb22b('0x4a')],'name':_0x214d52[_0xb22b('0x4b')],'paused':_0x214d52[_0xb22b('0x4c')],'waiting':_0x214d52[_0xb22b('0x4d')]};_0x54a173[_0xb22b('0x1f')](_0x387081);}}_0x2f505a({'count':_0x54a173[_0xb22b('0x17')],'rows':_0x54a173});});},'MailQueues':function(_0x42c121){return new Promise(function(_0x2642d3,_0x2a301d){var _0x27bfcb=[];for(var _0x3b5596 in _0x3ce122[_0xb22b('0x4e')]){if(_0x3ce122[_0xb22b('0x4e')][_0xb22b('0x44')](_0x3b5596)){var _0xf5b35f=_0x3ce122[_0xb22b('0x4e')][_0x3b5596];var _0xe9cd5={'id':_0xf5b35f['id'],'available':_0xf5b35f[_0xb22b('0x4f')],'loggedIn':_0xf5b35f[_0xb22b('0x4a')],'name':_0xf5b35f[_0xb22b('0x4b')],'paused':_0xf5b35f[_0xb22b('0x4c')],'waiting':_0xf5b35f[_0xb22b('0x4d')]};_0x27bfcb[_0xb22b('0x1f')](_0xe9cd5);}}_0x2642d3({'count':_0x27bfcb[_0xb22b('0x17')],'rows':_0x27bfcb});});},'OpenchannelQueues':function(_0x54b319){return new Promise(function(_0x1adb3c,_0x47d8fc){var _0x36ceb5=[];for(var _0x43275e in _0x3ce122[_0xb22b('0x50')]){if(_0x3ce122[_0xb22b('0x50')][_0xb22b('0x44')](_0x43275e)){var _0x33aaf5=_0x3ce122['openchannelQueues'][_0x43275e];var _0x5b4c41={'id':_0x33aaf5['id'],'available':_0x33aaf5[_0xb22b('0x4f')],'loggedIn':_0x33aaf5[_0xb22b('0x4a')],'name':_0x33aaf5[_0xb22b('0x4b')],'paused':_0x33aaf5['paused'],'waiting':_0x33aaf5[_0xb22b('0x4d')]};_0x36ceb5['push'](_0x5b4c41);}}_0x1adb3c({'count':_0x36ceb5[_0xb22b('0x17')],'rows':_0x36ceb5});});},'SmsQueues':function(_0x20ad3e){return new Promise(function(_0x35f499,_0x4cb363){var _0x4dee0d=[];for(var _0x5e35fb in _0x3ce122[_0xb22b('0x51')]){if(_0x3ce122[_0xb22b('0x51')][_0xb22b('0x44')](_0x5e35fb)){var _0x3762ae=_0x3ce122[_0xb22b('0x51')][_0x5e35fb];var _0x48e371={'id':_0x3762ae['id'],'available':_0x3762ae[_0xb22b('0x4f')],'loggedIn':_0x3762ae['loggedIn'],'name':_0x3762ae[_0xb22b('0x4b')],'paused':_0x3762ae[_0xb22b('0x4c')],'waiting':_0x3762ae[_0xb22b('0x4d')]};_0x4dee0d[_0xb22b('0x1f')](_0x48e371);}}_0x35f499({'count':_0x4dee0d[_0xb22b('0x17')],'rows':_0x4dee0d});});},'FaxQueues':function(_0x3b2ffc){return new Promise(function(_0x137016,_0x1463f6){var _0x1599fc=[];for(var _0x507b71 in _0x3ce122['faxQueues']){if(_0x3ce122[_0xb22b('0x52')][_0xb22b('0x44')](_0x507b71)){var _0x3d023d=_0x3ce122[_0xb22b('0x52')][_0x507b71];var _0x535cdb={'id':_0x3d023d['id'],'available':_0x3d023d[_0xb22b('0x4f')],'loggedIn':_0x3d023d[_0xb22b('0x4a')],'name':_0x3d023d[_0xb22b('0x4b')],'paused':_0x3d023d['paused'],'waiting':_0x3d023d['waiting']};_0x1599fc[_0xb22b('0x1f')](_0x535cdb);}}_0x137016({'count':_0x1599fc[_0xb22b('0x17')],'rows':_0x1599fc});});},'WhatsappQueues':function(_0x39a8bc){return new Promise(function(_0xfc60d8,_0x196a8c){var _0x3db231=[];for(var _0x1f346e in _0x3ce122[_0xb22b('0x53')]){if(_0x3ce122[_0xb22b('0x53')][_0xb22b('0x44')](_0x1f346e)){var _0xe81272=_0x3ce122[_0xb22b('0x53')][_0x1f346e];var _0x1ece34={'id':_0xe81272['id'],'available':_0xe81272[_0xb22b('0x4f')],'loggedIn':_0xe81272[_0xb22b('0x4a')],'name':_0xe81272[_0xb22b('0x4b')],'paused':_0xe81272[_0xb22b('0x4c')],'waiting':_0xe81272[_0xb22b('0x4d')]};_0x3db231[_0xb22b('0x1f')](_0x1ece34);}}_0xfc60d8({'count':_0x3db231[_0xb22b('0x17')],'rows':_0x3db231});});},'ChatQueuesWaitingInteractions':function(_0x4a5ee8){return new Promise(function(_0x53669f,_0x754de6){var _0x2ede34=_[_0xb22b('0x48')](_0x3ce122[_0xb22b('0x54')]);_0x53669f({'count':_0x2ede34[_0xb22b('0x17')],'rows':_0x2ede34});});},'MailQueuesWaitingInteractions':function(_0x35d589){return new Promise(function(_0x4a40ad,_0x2795ca){var _0x3fe33c=_[_0xb22b('0x48')](_0x3ce122['mailQueuesWaitingInteractions']);_0x4a40ad({'count':_0x3fe33c[_0xb22b('0x17')],'rows':_0x3fe33c});});},'OpenchannelQueuesWaitingInteractions':function(_0x56b6a4){return new Promise(function(_0x20707e,_0x5241f2){var _0x12de33=_[_0xb22b('0x48')](_0x3ce122[_0xb22b('0x55')]);_0x20707e({'count':_0x12de33['length'],'rows':_0x12de33});});},'SmsQueuesWaitingInteractions':function(_0x2d23ee){return new Promise(function(_0x568198,_0x49cebf){var _0x485c65=_['values'](_0x3ce122[_0xb22b('0x56')]);_0x568198({'count':_0x485c65[_0xb22b('0x17')],'rows':_0x485c65});});},'FaxQueuesWaitingInteractions':function(_0x503f71){return new Promise(function(_0x92893c,_0x1b637b){var _0x4abb97=_[_0xb22b('0x48')](_0x3ce122['faxQueuesWaitingInteractions']);_0x92893c({'count':_0x4abb97[_0xb22b('0x17')],'rows':_0x4abb97});});},'WhatsappQueuesWaitingInteractions':function(_0x419873){return new Promise(function(_0x33a4cb,_0x5a0047){var _0x1409c5=_[_0xb22b('0x48')](_0x3ce122[_0xb22b('0x57')]);_0x33a4cb({'count':_0x1409c5['length'],'rows':_0x1409c5});});}};var _0x1fa86a=jayson[_0xb22b('0x58')](_0x4946cf)['http']();_0x1fa86a['on'](_0xb22b('0x36'),function(_0x1bd6af){logger[_0xb22b('0x36')](JSON['stringify'](_0x1bd6af));return _0x2a6179(_0x1bd6af);});_0x1fa86a[_0xb22b('0x59')](0x232c,_0xb22b('0x5a'),function(){console[_0xb22b('0x5b')](_0xb22b('0x5c'),0x232c);return _0x4d7092('RPC\x20listening\x20on\x20port:'+0x232c);});});};
\ No newline at end of file
+var _0x9f76=['channel','message','interaction','isArray','applications','length','existsSync','join','app','toLowerCase','autoreply','split','push','slice','dialogflow','appdata','amazonlex','tag','%s:%s:%s','condition','./applications/','consequence','priority','info','on\x20interval','intervals','\x20|\x20','.js','rules','Applications\x20executed','stringify','matchPath','emit','complete','error','stack','routing\x20is\x20empty','end','QueueReport','UserId','catch','error\x20update\x20queue\x20report','message\x20is\x20empty','agent','agents','hasOwnProperty','capacity','CurrentCapacity','agent\x20not\x20found','values','chatQueues','available','loggedIn','name','paused','waiting','mailQueues','openchannelQueues','smsQueues','faxQueues','whatsappQueues','chatQueuesWaitingInteractions','mailQueuesWaitingInteractions','openchannelQueuesWaitingInteractions','smsQueuesWaitingInteractions','faxQueuesWaitingInteractions','server','http','127.0.0.1','log','Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!','RPC\x20listening\x20on\x20port:','lodash','util','path','jayson/promise','bluebird','../../../config/environment','../../../config/logger','../rpc/openchannelQueueReport','../rpc/mailQueueReport','../rpc/chatQueueReport','../rpc/faxQueueReport','../rpc/whatsappQueueReport','../lib/rule-engine','format','%s.%s.%s','isNil','IntervalId','Intervals','map','interval','listen'];(function(_0x17c030,_0x23f9f5){var _0x573b32=function(_0x2f702e){while(--_0x2f702e){_0x17c030['push'](_0x17c030['shift']());}};_0x573b32(++_0x23f9f5);}(_0x9f76,0x1bc));var _0x69f7=function(_0xc4001c,_0x1bf8f0){_0xc4001c=_0xc4001c-0x0;var _0x49f7bc=_0x9f76[_0xc4001c];return _0x49f7bc;};'use strict';var _=require(_0x69f7('0x0'));var util=require(_0x69f7('0x1'));var path=require(_0x69f7('0x2'));var fs=require('fs');var jayson=require(_0x69f7('0x3'));var BPromise=require(_0x69f7('0x4'));var uuid=require('uuid');var config=require(_0x69f7('0x5'));var logger=require(_0x69f7('0x6'))('routing');var rpc={'openchannelQueueReport':require(_0x69f7('0x7')),'mailQueueReport':require(_0x69f7('0x8')),'chatQueueReport':require(_0x69f7('0x9')),'smsQueueReport':require('../rpc/smsQueueReport'),'faxQueueReport':require(_0x69f7('0xa')),'whatsappQueueReport':require(_0x69f7('0xb'))};var RuleEngine=require(_0x69f7('0xc'));function getId(_0x3955bb,_0x1a9d50,_0x15552d){return util[_0x69f7('0xd')](_0x69f7('0xe'),_0x3955bb,_0x1a9d50||0x0,_0x15552d||0x0);}function getIntervals(_0x441383,_0x3f05e0){var _0x569363=[];if(!_['isNil'](_0x3f05e0['IntervalId'])&&!_[_0x69f7('0xf')](_0x441383[_0x3f05e0[_0x69f7('0x10')]])&&!_[_0x69f7('0xf')](_0x441383[_0x3f05e0['IntervalId']][_0x69f7('0x11')])){_0x569363=_[_0x69f7('0x12')](_0x441383[_0x3f05e0[_0x69f7('0x10')]][_0x69f7('0x11')],_0x69f7('0x13'));}else if(!_[_0x69f7('0xf')](_0x3f05e0[_0x69f7('0x13')])){_0x569363=[_0x3f05e0[_0x69f7('0x13')]];}return _0x569363;}exports[_0x69f7('0x14')]=function(_0x3acdbe){_0x3acdbe['rules']={};return new BPromise(function(_0xda6988,_0x47d9fc){var _0x1eea31={'Start':function(_0x499ead){var _0x1b0dfc=this;return new Promise(function(_0x1d060b,_0x589976){if(_0x499ead){try{var _0x1f6f53=[];var _0xddc318=getId(_0x499ead[_0x69f7('0x15')],_0x499ead['message']?_0x499ead[_0x69f7('0x16')]['id']:0x0,_0x499ead[_0x69f7('0x17')]?_0x499ead['interaction']['id']:0x0);if(_0x499ead['applications']&&_[_0x69f7('0x18')](_0x499ead[_0x69f7('0x19')])&&_0x499ead[_0x69f7('0x19')][_0x69f7('0x1a')]){for(var _0x5b7d63=0x0;_0x5b7d63<_0x499ead['applications'][_0x69f7('0x1a')];_0x5b7d63+=0x1){var _0x586693=_0x499ead[_0x69f7('0x19')][_0x5b7d63];if(fs[_0x69f7('0x1b')](path[_0x69f7('0x1c')](__dirname,_0x69f7('0x19'),_0x586693[_0x69f7('0x1d')]+'.js'))){var _0x5c8b45=[];switch(_0x586693['app'][_0x69f7('0x1e')]()){case _0x69f7('0x1f'):var _0x4d27ac=_0x586693['appdata'][_0x69f7('0x20')](',');_0x5c8b45['push'](_0x4d27ac[0x0]);_0x5c8b45[_0x69f7('0x21')](_0x4d27ac[_0x69f7('0x22')](0x1,_0x4d27ac['length'])[_0x69f7('0x1c')](','));break;case _0x69f7('0x23'):var _0x1531b3=_0x586693[_0x69f7('0x24')][_0x69f7('0x20')](',');_0x5c8b45[_0x69f7('0x21')](_0x1531b3[0x0]);_0x5c8b45[_0x69f7('0x21')](_0x1531b3[0x1]);_0x5c8b45[_0x69f7('0x21')](_0x1531b3[_0x69f7('0x22')](0x2,_0x1531b3[_0x69f7('0x1a')])[_0x69f7('0x1c')](','));break;case'dialogflowv2':var _0xb565df=_0x586693[_0x69f7('0x24')][_0x69f7('0x20')](',');_0x5c8b45['push'](_0xb565df[0x0]);_0x5c8b45[_0x69f7('0x21')](_0xb565df[0x1]);_0x5c8b45[_0x69f7('0x21')](_0xb565df[0x2]);_0x5c8b45[_0x69f7('0x21')](_0xb565df[0x3]);_0x5c8b45['push'](_0xb565df[_0x69f7('0x22')](0x4,_0xb565df[_0x69f7('0x1a')])[_0x69f7('0x1c')](','));break;case _0x69f7('0x25'):var _0x579828=_0x586693[_0x69f7('0x24')][_0x69f7('0x20')](',');_0x5c8b45[_0x69f7('0x21')](_0x579828[0x0]);_0x5c8b45[_0x69f7('0x21')](_0x579828[0x1]);_0x5c8b45[_0x69f7('0x21')](_0x579828[0x2]);_0x5c8b45['push'](_0x579828[0x3]);_0x5c8b45[_0x69f7('0x21')](_0x579828[_0x69f7('0x22')](0x4,_0x579828[_0x69f7('0x1a')])[_0x69f7('0x1c')](','));break;case _0x69f7('0x16'):_0x5c8b45[_0x69f7('0x21')](_0x586693[_0x69f7('0x24')]);break;case _0x69f7('0x26'):_0x5c8b45['push'](_0x586693['TagId']);_0x5c8b45[_0x69f7('0x21')](_0x586693[_0x69f7('0x24')]);break;default:_0x5c8b45=_[_0x69f7('0xf')](_0x586693[_0x69f7('0x24')])?[]:_0x586693[_0x69f7('0x24')]['split'](',');}var _0xdf66fa={'id':util[_0x69f7('0xd')](_0x69f7('0x27'),_0xddc318,_0x586693['id'],_0x586693[_0x69f7('0x1d')]),'condition':require('./interval')[_0x69f7('0x28')](_0xddc318,getIntervals(_0x3acdbe['intervals'],_0x586693),_0x3acdbe),'consequence':require(_0x69f7('0x29')+_0x586693[_0x69f7('0x1d')])[_0x69f7('0x2a')](_0xddc318,_0x5c8b45,_0x3acdbe,_0x499ead),'p':_0x586693[_0x69f7('0x2b')]||0x0};logger[_0x69f7('0x2c')]('Push\x20new\x20rule',_0xdf66fa['id'],_0x69f7('0x2d'),getIntervals(_0x3acdbe[_0x69f7('0x2e')],_0x586693)[_0x69f7('0x1c')](_0x69f7('0x2f')));_0x1f6f53[_0x69f7('0x21')](_0xdf66fa);}else{logger['error']('Please\x20create\x20a\x20new\x20file\x20under',path['join'](__dirname,_0x69f7('0x19'),_0x586693[_0x69f7('0x1d')]+_0x69f7('0x30')));}}_0x3acdbe[_0x69f7('0x31')][_0xddc318]=new RuleEngine(_0x1f6f53);_0x3acdbe['rules'][_0xddc318]['execute'](_0x499ead,function(_0x5d9de9){logger['info'](_0x69f7('0x32'),JSON[_0x69f7('0x33')](_0x5d9de9[_0x69f7('0x34')]));if(_0x3acdbe[_0x69f7('0x31')][_0xddc318]){_0x3acdbe[_0x69f7('0x31')][_0xddc318][_0x69f7('0x35')](_0x69f7('0x36'));}});return _0x1d060b({'code':0xc8,'message':_0x499ead});}else{logger[_0x69f7('0x2c')]('No\x20applications\x20to\x20execute');return _0x1d060b({'code':0xc8,'message':_0x499ead});}}catch(_0x574796){logger[_0x69f7('0x37')](_0x574796[_0x69f7('0x38')]);return _0x589976(_0x1b0dfc['error'](0x1f4,_0x574796));}}return _0x589976(_0x69f7('0x39'));});},'AcceptMessage':function(_0x3fcf6b){var _0x3c8dd8=this;return new Promise(function(_0x2f1f2a,_0x112ac9){if(_0x3fcf6b[_0x69f7('0x16')]&&_0x3fcf6b[_0x69f7('0x16')]['id']){try{var _0x590128=getId(_0x3fcf6b[_0x69f7('0x15')],_0x3fcf6b[_0x69f7('0x16')]?_0x3fcf6b[_0x69f7('0x16')]['id']:0x0,_0x3fcf6b[_0x69f7('0x17')]?_0x3fcf6b['interaction']['id']:0x0);if(_0x3acdbe['rules'][_0x590128]){_0x3acdbe[_0x69f7('0x31')][_0x590128][_0x69f7('0x35')](_0x69f7('0x3a'));if(rpc[_0x3fcf6b[_0x69f7('0x15')]+_0x69f7('0x3b')]){rpc[_0x3fcf6b[_0x69f7('0x15')]+'QueueReport']['update'](_0x590128,{'UserId':_0x3fcf6b[_0x69f7('0x16')][_0x69f7('0x3c')]})[_0x69f7('0x3d')](function(_0x2a81fd){logger[_0x69f7('0x37')](_0x69f7('0x3e'));});}}return _0x2f1f2a({'code':0xc8,'message':_0x3fcf6b});}catch(_0x1cc653){logger[_0x69f7('0x37')](_0x1cc653[_0x69f7('0x38')]);return _0x112ac9(_0x3c8dd8[_0x69f7('0x37')](0x1f4,_0x1cc653));}}logger[_0x69f7('0x37')](_0x69f7('0x3f'));return _0x112ac9(_0x3c8dd8[_0x69f7('0x37')](0x1f4,_0x69f7('0x3f')));});},'RejectMessage':function(_0x429ae0){var _0x1e5dec=this;return new Promise(function(_0x29f1ab,_0x39f083){if(_0x429ae0[_0x69f7('0x40')]&&_0x429ae0[_0x69f7('0x40')]['id']){try{if(_0x3acdbe[_0x69f7('0x41')][_0x429ae0['agent']['id']]){_0x3acdbe['agents'][_0x429ae0['agent']['id']]['busy']=![];_0x3acdbe[_0x69f7('0x41')][_0x429ae0[_0x69f7('0x40')]['id']]['busyQueue']=undefined;}return _0x29f1ab({'code':0xc8,'message':_0x429ae0});}catch(_0x31f65d){logger['error'](_0x31f65d[_0x69f7('0x38')]);return _0x39f083(_0x1e5dec[_0x69f7('0x37')](0x1f4,_0x31f65d));}}logger[_0x69f7('0x37')](_0x69f7('0x3f'));return _0x39f083(_0x1e5dec[_0x69f7('0x37')](0x1f4,_0x69f7('0x3f')));});},'AbandonInteraction':function(_0x4c4315){var _0x4d490d=this;return new Promise(function(_0x1ec648,_0x4fc0f4){if(_0x4c4315['channel']&&_0x4c4315[_0x69f7('0x17')]&&_0x4c4315[_0x69f7('0x17')]['id']){try{var _0x477b97=getId(_0x4c4315[_0x69f7('0x15')],_0x4c4315[_0x69f7('0x16')]?_0x4c4315[_0x69f7('0x16')]['id']:0x0,_0x4c4315[_0x69f7('0x17')]?_0x4c4315['interaction']['id']:0x0);if(_0x3acdbe[_0x69f7('0x31')][_0x477b97]){_0x3acdbe['rules'][_0x477b97][_0x69f7('0x35')](_0x69f7('0x3a'));}return _0x1ec648({'code':0xc8,'message':_0x4c4315});}catch(_0x1b8aef){logger['error'](_0x1b8aef[_0x69f7('0x38')]);return _0x4fc0f4(_0x4d490d[_0x69f7('0x37')](0x1f4,_0x1b8aef));}}logger[_0x69f7('0x37')](_0x69f7('0x3f'));return _0x4fc0f4(_0x4d490d[_0x69f7('0x37')](0x1f4,_0x69f7('0x3f')));});},'AgentCapacity':function(_0x562c58){var _0x2635b5=this;return new Promise(function(_0x54b2bd,_0xfac5c2){if(_0x3acdbe['agents'][_0x69f7('0x42')](_0x562c58['id'])){for(var _0x59d8d6 in _0x562c58[_0x69f7('0x43')]){if(_0x562c58[_0x69f7('0x43')][_0x69f7('0x42')](_0x59d8d6)){if(_0x3acdbe[_0x69f7('0x41')][_0x562c58['id']][_0x69f7('0x42')](_0x59d8d6+_0x69f7('0x44'))){_0x3acdbe['agents'][_0x562c58['id']][_0x59d8d6+_0x69f7('0x44')]=parseInt(_0x562c58[_0x69f7('0x43')][_0x59d8d6],0xa);}}}_0x3acdbe['agents'][_0x562c58['id']]['updateRealtime']();return _0x54b2bd({'code':0xc8,'message':_0x3acdbe[_0x69f7('0x41')][_0x562c58['id']]});}else{return _0xfac5c2(_0x2635b5['error'](0x1f4,_0x69f7('0x45')));}});},'Agents':function(_0x40cd40){return new Promise(function(_0x4eed73,_0x3210be){var _0x5e7a73=_[_0x69f7('0x46')](_0x3acdbe[_0x69f7('0x41')]);_0x4eed73({'count':_0x5e7a73[_0x69f7('0x1a')],'rows':_0x5e7a73});});},'ChatQueues':function(_0x3757ca){return new Promise(function(_0x24743b,_0xaf4265){var _0x3e2ee5=[];for(var _0x49760b in _0x3acdbe[_0x69f7('0x47')]){if(_0x3acdbe[_0x69f7('0x47')][_0x69f7('0x42')](_0x49760b)){var _0x3e4421=_0x3acdbe[_0x69f7('0x47')][_0x49760b];var _0x30e2c9={'id':_0x3e4421['id'],'available':_0x3e4421[_0x69f7('0x48')],'loggedIn':_0x3e4421[_0x69f7('0x49')],'name':_0x3e4421[_0x69f7('0x4a')],'paused':_0x3e4421[_0x69f7('0x4b')],'waiting':_0x3e4421[_0x69f7('0x4c')]};_0x3e2ee5[_0x69f7('0x21')](_0x30e2c9);}}_0x24743b({'count':_0x3e2ee5[_0x69f7('0x1a')],'rows':_0x3e2ee5});});},'MailQueues':function(_0x1faac9){return new Promise(function(_0x1400d1,_0x124973){var _0x585c0e=[];for(var _0x2955df in _0x3acdbe[_0x69f7('0x4d')]){if(_0x3acdbe['mailQueues'][_0x69f7('0x42')](_0x2955df)){var _0x17060b=_0x3acdbe[_0x69f7('0x4d')][_0x2955df];var _0x1e83c9={'id':_0x17060b['id'],'available':_0x17060b[_0x69f7('0x48')],'loggedIn':_0x17060b['loggedIn'],'name':_0x17060b[_0x69f7('0x4a')],'paused':_0x17060b[_0x69f7('0x4b')],'waiting':_0x17060b['waiting']};_0x585c0e['push'](_0x1e83c9);}}_0x1400d1({'count':_0x585c0e['length'],'rows':_0x585c0e});});},'OpenchannelQueues':function(_0x578f5b){return new Promise(function(_0x153b60,_0x37f7e4){var _0x40b51b=[];for(var _0x50cf67 in _0x3acdbe[_0x69f7('0x4e')]){if(_0x3acdbe[_0x69f7('0x4e')][_0x69f7('0x42')](_0x50cf67)){var _0x18be70=_0x3acdbe[_0x69f7('0x4e')][_0x50cf67];var _0x4d4a91={'id':_0x18be70['id'],'available':_0x18be70[_0x69f7('0x48')],'loggedIn':_0x18be70[_0x69f7('0x49')],'name':_0x18be70[_0x69f7('0x4a')],'paused':_0x18be70[_0x69f7('0x4b')],'waiting':_0x18be70[_0x69f7('0x4c')]};_0x40b51b[_0x69f7('0x21')](_0x4d4a91);}}_0x153b60({'count':_0x40b51b[_0x69f7('0x1a')],'rows':_0x40b51b});});},'SmsQueues':function(_0x7678fa){return new Promise(function(_0x213969,_0x4cb272){var _0x5df72f=[];for(var _0xfa37a3 in _0x3acdbe[_0x69f7('0x4f')]){if(_0x3acdbe[_0x69f7('0x4f')][_0x69f7('0x42')](_0xfa37a3)){var _0x445093=_0x3acdbe[_0x69f7('0x4f')][_0xfa37a3];var _0x2892bf={'id':_0x445093['id'],'available':_0x445093[_0x69f7('0x48')],'loggedIn':_0x445093['loggedIn'],'name':_0x445093[_0x69f7('0x4a')],'paused':_0x445093['paused'],'waiting':_0x445093[_0x69f7('0x4c')]};_0x5df72f[_0x69f7('0x21')](_0x2892bf);}}_0x213969({'count':_0x5df72f[_0x69f7('0x1a')],'rows':_0x5df72f});});},'FaxQueues':function(_0x4ff5ff){return new Promise(function(_0x1a2b90,_0x3d3a67){var _0x278e43=[];for(var _0x212110 in _0x3acdbe['faxQueues']){if(_0x3acdbe[_0x69f7('0x50')][_0x69f7('0x42')](_0x212110)){var _0x3649ee=_0x3acdbe[_0x69f7('0x50')][_0x212110];var _0x6efbff={'id':_0x3649ee['id'],'available':_0x3649ee[_0x69f7('0x48')],'loggedIn':_0x3649ee['loggedIn'],'name':_0x3649ee[_0x69f7('0x4a')],'paused':_0x3649ee[_0x69f7('0x4b')],'waiting':_0x3649ee[_0x69f7('0x4c')]};_0x278e43[_0x69f7('0x21')](_0x6efbff);}}_0x1a2b90({'count':_0x278e43[_0x69f7('0x1a')],'rows':_0x278e43});});},'WhatsappQueues':function(_0x291c50){return new Promise(function(_0x4e1f61,_0x1ff1e3){var _0x50f530=[];for(var _0x23d2f2 in _0x3acdbe['whatsappQueues']){if(_0x3acdbe[_0x69f7('0x51')]['hasOwnProperty'](_0x23d2f2)){var _0x4a51b7=_0x3acdbe[_0x69f7('0x51')][_0x23d2f2];var _0x4c501d={'id':_0x4a51b7['id'],'available':_0x4a51b7[_0x69f7('0x48')],'loggedIn':_0x4a51b7['loggedIn'],'name':_0x4a51b7[_0x69f7('0x4a')],'paused':_0x4a51b7[_0x69f7('0x4b')],'waiting':_0x4a51b7[_0x69f7('0x4c')]};_0x50f530[_0x69f7('0x21')](_0x4c501d);}}_0x4e1f61({'count':_0x50f530[_0x69f7('0x1a')],'rows':_0x50f530});});},'ChatQueuesWaitingInteractions':function(_0x30a4b4){return new Promise(function(_0x528dc7,_0x3f2c8b){var _0x7e9367=_['values'](_0x3acdbe[_0x69f7('0x52')]);_0x528dc7({'count':_0x7e9367[_0x69f7('0x1a')],'rows':_0x7e9367});});},'MailQueuesWaitingInteractions':function(_0x187c66){return new Promise(function(_0x37c616,_0x405601){var _0x31bf05=_[_0x69f7('0x46')](_0x3acdbe[_0x69f7('0x53')]);_0x37c616({'count':_0x31bf05[_0x69f7('0x1a')],'rows':_0x31bf05});});},'OpenchannelQueuesWaitingInteractions':function(_0x16ee57){return new Promise(function(_0x517a79,_0x42d6b2){var _0x3177c7=_['values'](_0x3acdbe[_0x69f7('0x54')]);_0x517a79({'count':_0x3177c7['length'],'rows':_0x3177c7});});},'SmsQueuesWaitingInteractions':function(_0x2b36ce){return new Promise(function(_0x427317,_0x5cef05){var _0x4b7b65=_[_0x69f7('0x46')](_0x3acdbe[_0x69f7('0x55')]);_0x427317({'count':_0x4b7b65[_0x69f7('0x1a')],'rows':_0x4b7b65});});},'FaxQueuesWaitingInteractions':function(_0x9bdd96){return new Promise(function(_0x189bdc,_0x41e40b){var _0x164881=_['values'](_0x3acdbe[_0x69f7('0x56')]);_0x189bdc({'count':_0x164881[_0x69f7('0x1a')],'rows':_0x164881});});},'WhatsappQueuesWaitingInteractions':function(_0x38a55d){return new Promise(function(_0x3f534c,_0x53411f){var _0x167a50=_['values'](_0x3acdbe['whatsappQueuesWaitingInteractions']);_0x3f534c({'count':_0x167a50[_0x69f7('0x1a')],'rows':_0x167a50});});}};var _0x3377b1=jayson[_0x69f7('0x57')](_0x1eea31)[_0x69f7('0x58')]();_0x3377b1['on']('error',function(_0x8b981c){logger['error'](JSON['stringify'](_0x8b981c));return _0x47d9fc(_0x8b981c);});_0x3377b1[_0x69f7('0x14')](0x232c,_0x69f7('0x59'),function(){console[_0x69f7('0x5a')](_0x69f7('0x5b'),0x232c);return _0xda6988(_0x69f7('0x5c')+0x232c);});});};
\ No newline at end of file