Built motion from commit b51cdcb3f2cb46634587ce1d55ea1b8f32dacea6. Version 3.0.0...
[motion-next.git] / server / services / routing / server / index.js
1 const a1217_0x409d=['message','waiting','routing','matchPath','mailQueues','chatQueuesWaitingInteractions','isArray','./interval','intervals','chatQueues','./applications/','openchannelQueues','../rpc/openchannelQueueReport','dialogflow','mailQueuesWaitingInteractions','app','%s:%s:%s','busy','split','whatsappQueues','map','amazonlex','path','priority','openchannelQueuesWaitingInteractions','catch','info','channel','UserId','available','end','undefined','emit','listen','update','paused','capacity','complete','condition','127.0.0.1','isNil','join','error\x20update\x20queue\x20report','lodash','execute','toLowerCase','RPC\x20listening\x20on\x20port:','busyQueue','http','IntervalId','../rpc/smsQueueReport','agent\x20not\x20found','util','agent','log','faxQueues','.js','tag','server','%s.%s.%s','message\x20is\x20empty','name','loggedIn','values','updateRealtime','Push\x20new\x20rule','error','No\x20applications\x20to\x20execute','push','rules','agents','stack','../rpc/faxQueueReport','QueueReport','Routing\x20RPC\x20server\x20listening\x20on\x20127.0.0.1:%d!','length','smsQueuesWaitingInteractions','on\x20interval','faxQueuesWaitingInteractions','interval','format','../../../config/logger','appdata','Please\x20create\x20a\x20new\x20file\x20under','TagId','smsQueues','Intervals','stringify','../lib/rule-engine','whatsappQueuesWaitingInteractions','applications','interaction','slice','autoreply'];(function(_0x39a449,_0x409de3){const _0x2c83fa=function(_0x1a8186){while(--_0x1a8186){_0x39a449['push'](_0x39a449['shift']());}};_0x2c83fa(++_0x409de3);}(a1217_0x409d,0x6c));const a1217_0x2c83=function(_0x39a449,_0x409de3){_0x39a449=_0x39a449-0x0;let _0x2c83fa=a1217_0x409d[_0x39a449];return _0x2c83fa;};const _0x5aa3d5=a1217_0x2c83;'use strict';const _=require(_0x5aa3d5('0x1d')),util=require(_0x5aa3d5('0x26')),path=require(_0x5aa3d5('0x8')),fs=require('fs'),jayson=require('jayson/promise'),logger=require(_0x5aa3d5('0x43'))(_0x5aa3d5('0x52')),rpc={'openchannelQueueReport':require(_0x5aa3d5('0x5c')),'mailQueueReport':require('../rpc/mailQueueReport'),'chatQueueReport':require('../rpc/chatQueueReport'),'smsQueueReport':require(_0x5aa3d5('0x24')),'faxQueueReport':require(_0x5aa3d5('0x3a')),'whatsappQueueReport':require('../rpc/whatsappQueueReport')},RuleEngine=require(_0x5aa3d5('0x4a'));function getId(_0x1a8186,_0x158597,_0x42c7bf){const _0x254b84=_0x5aa3d5;return util[_0x254b84('0x42')](_0x254b84('0x2d'),_0x1a8186,_0x158597||0x0,_0x42c7bf||0x0);}function getIntervals(_0x3a5d00,_0x5c704f){const _0x403694=_0x5aa3d5;let _0x386771=[];if(!_[_0x403694('0x1a')](_0x5c704f[_0x403694('0x23')])&&!_[_0x403694('0x1a')](_0x3a5d00[_0x5c704f[_0x403694('0x23')]])&&!_[_0x403694('0x1a')](_0x3a5d00[_0x5c704f[_0x403694('0x23')]][_0x403694('0x48')]))_0x386771=_[_0x403694('0x6')](_0x3a5d00[_0x5c704f['IntervalId']]['Intervals'],_0x403694('0x41'));else!_[_0x403694('0x1a')](_0x5c704f[_0x403694('0x41')])&&(_0x386771=[_0x5c704f[_0x403694('0x41')]]);return _0x386771;}exports[_0x5aa3d5('0x13')]=function(_0x4d8c98){const _0x28891c=_0x5aa3d5;return _0x4d8c98[_0x28891c('0x37')]={},new Promise(function(_0x31d179,_0x1f6639){const _0x3499bb=_0x28891c,_0x3ffeca={'Start':function(_0x3c85a8){const _0x1f17b8=this;return new Promise(function(_0x5497fb,_0x1049cb){const _0xbd03c4=a1217_0x2c83;if(_0x3c85a8)try{const _0x4244c5=[],_0x377588=getId(_0x3c85a8[_0xbd03c4('0xd')],_0x3c85a8[_0xbd03c4('0x50')]?_0x3c85a8[_0xbd03c4('0x50')]['id']:0x0,_0x3c85a8[_0xbd03c4('0x4d')]?_0x3c85a8[_0xbd03c4('0x4d')]['id']:0x0);if(_0x3c85a8['applications']&&_[_0xbd03c4('0x56')](_0x3c85a8[_0xbd03c4('0x4c')])&&_0x3c85a8[_0xbd03c4('0x4c')][_0xbd03c4('0x3d')]){for(let _0x185c91=0x0;_0x185c91<_0x3c85a8[_0xbd03c4('0x4c')]['length'];_0x185c91+=0x1){const _0x2c451d=_0x3c85a8['applications'][_0x185c91];if(fs['existsSync'](path[_0xbd03c4('0x1b')](__dirname,'applications',_0x2c451d['app']+_0xbd03c4('0x2a')))){let _0x1febba=[];switch(_0x2c451d[_0xbd03c4('0x1')][_0xbd03c4('0x1f')]()){case _0xbd03c4('0x4f'):{const _0x3deb9f=_0x2c451d[_0xbd03c4('0x44')][_0xbd03c4('0x4')](',');_0x1febba['push'](_0x3deb9f[0x0]),_0x1febba[_0xbd03c4('0x36')](_0x3deb9f[_0xbd03c4('0x4e')](0x1,_0x3deb9f[_0xbd03c4('0x3d')])[_0xbd03c4('0x1b')](','));}break;case _0xbd03c4('0x5d'):{const _0xa04499=_0x2c451d[_0xbd03c4('0x44')]['split'](',');_0x1febba[_0xbd03c4('0x36')](_0xa04499[0x0]),_0x1febba[_0xbd03c4('0x36')](_0xa04499[0x1]),_0x1febba[_0xbd03c4('0x36')](_0xa04499[_0xbd03c4('0x4e')](0x2,_0xa04499[_0xbd03c4('0x3d')])[_0xbd03c4('0x1b')](','));}break;case _0xbd03c4('0x7'):{const _0x590f59=_0x2c451d[_0xbd03c4('0x44')]['split'](',');_0x1febba['push'](_0x590f59[0x0]),_0x1febba[_0xbd03c4('0x36')](_0x590f59[0x1]),_0x1febba['push'](_0x590f59[0x2]),_0x1febba['push'](_0x590f59[0x3]),_0x1febba['push'](_0x590f59[_0xbd03c4('0x4e')](0x4,_0x590f59[_0xbd03c4('0x3d')])[_0xbd03c4('0x1b')](','));}break;case _0xbd03c4('0x50'):_0x1febba[_0xbd03c4('0x36')](_0x2c451d[_0xbd03c4('0x44')]);break;case _0xbd03c4('0x2b'):_0x1febba['push'](_0x2c451d[_0xbd03c4('0x46')]),_0x1febba[_0xbd03c4('0x36')](_0x2c451d[_0xbd03c4('0x44')]);break;default:_0x1febba=_['isNil'](_0x2c451d[_0xbd03c4('0x44')])?[]:_0x2c451d['appdata']['split'](',');}const _0x4568a9={'id':util[_0xbd03c4('0x42')](_0xbd03c4('0x2'),_0x377588,_0x2c451d['id'],_0x2c451d[_0xbd03c4('0x1')]),'condition':require(_0xbd03c4('0x57'))[_0xbd03c4('0x18')](_0x377588,getIntervals(_0x4d8c98[_0xbd03c4('0x58')],_0x2c451d),_0x4d8c98),'consequence':require(_0xbd03c4('0x5a')+_0x2c451d[_0xbd03c4('0x1')])['consequence'](_0x377588,_0x1febba,_0x4d8c98,_0x3c85a8),'p':_0x2c451d[_0xbd03c4('0x9')]||0x0};logger[_0xbd03c4('0xc')](_0xbd03c4('0x33'),_0x4568a9['id'],_0xbd03c4('0x3f'),getIntervals(_0x4d8c98[_0xbd03c4('0x58')],_0x2c451d)[_0xbd03c4('0x1b')]('\x20|\x20')),_0x4244c5['push'](_0x4568a9);}else logger[_0xbd03c4('0x34')](_0xbd03c4('0x45'),path['join'](__dirname,'applications',_0x2c451d[_0xbd03c4('0x1')]+_0xbd03c4('0x2a')));}return _0x4d8c98[_0xbd03c4('0x37')][_0x377588]=new RuleEngine(_0x4244c5),_0x4d8c98[_0xbd03c4('0x37')][_0x377588][_0xbd03c4('0x1e')](_0x3c85a8,function(_0x2e1f59){const _0x51ed59=_0xbd03c4;logger['info']('Applications\x20executed',JSON[_0x51ed59('0x49')](_0x2e1f59[_0x51ed59('0x53')])),_0x4d8c98[_0x51ed59('0x37')][_0x377588]&&_0x4d8c98[_0x51ed59('0x37')][_0x377588][_0x51ed59('0x12')](_0x51ed59('0x17'));}),_0x5497fb({'code':0xc8,'message':_0x3c85a8});}else return logger[_0xbd03c4('0xc')](_0xbd03c4('0x35')),_0x5497fb({'code':0xc8,'message':_0x3c85a8});}catch(_0x53c6cc){return logger['error'](_0x53c6cc['stack']),_0x1049cb(_0x1f17b8[_0xbd03c4('0x34')](0x1f4,_0x53c6cc));}return _0x1049cb('routing\x20is\x20empty');});},'AcceptMessage':function(_0x10c94f){const _0x1335a7=this;return new Promise(function(_0xc6c7b,_0x540056){const _0x10d328=a1217_0x2c83;if(_0x10c94f[_0x10d328('0x50')]&&_0x10c94f['message']['id'])try{const _0x522092=getId(_0x10c94f[_0x10d328('0xd')],_0x10c94f['message']?_0x10c94f[_0x10d328('0x50')]['id']:0x0,_0x10c94f['interaction']?_0x10c94f[_0x10d328('0x4d')]['id']:0x0);return _0x4d8c98[_0x10d328('0x37')][_0x522092]&&(_0x4d8c98[_0x10d328('0x37')][_0x522092][_0x10d328('0x12')](_0x10d328('0x10')),rpc[_0x10c94f[_0x10d328('0xd')]+'QueueReport']&&rpc[_0x10c94f[_0x10d328('0xd')]+_0x10d328('0x3b')][_0x10d328('0x14')](_0x522092,{'UserId':_0x10c94f[_0x10d328('0x50')][_0x10d328('0xe')]})[_0x10d328('0xb')](function(){const _0x5e342d=_0x10d328;logger['error'](_0x5e342d('0x1c'));})),_0xc6c7b({'code':0xc8,'message':_0x10c94f});}catch(_0x33f04c){return logger[_0x10d328('0x34')](_0x33f04c[_0x10d328('0x39')]),_0x540056(_0x1335a7[_0x10d328('0x34')](0x1f4,_0x33f04c));}return logger['error'](_0x10d328('0x2e')),_0x540056(_0x1335a7[_0x10d328('0x34')](0x1f4,'message\x20is\x20empty'));});},'RejectMessage':function(_0x2a8a2d){const _0x5633d6=this;return new Promise(function(_0xdf5379,_0x8a5ac6){const _0x51d045=a1217_0x2c83;if(_0x2a8a2d[_0x51d045('0x27')]&&_0x2a8a2d[_0x51d045('0x27')]['id'])try{return _0x4d8c98[_0x51d045('0x38')][_0x2a8a2d['agent']['id']]&&(_0x4d8c98[_0x51d045('0x38')][_0x2a8a2d['agent']['id']][_0x51d045('0x3')]=![],_0x4d8c98[_0x51d045('0x38')][_0x2a8a2d[_0x51d045('0x27')]['id']][_0x51d045('0x21')]=undefined),_0xdf5379({'code':0xc8,'message':_0x2a8a2d});}catch(_0x20010b){return logger[_0x51d045('0x34')](_0x20010b[_0x51d045('0x39')]),_0x8a5ac6(_0x5633d6[_0x51d045('0x34')](0x1f4,_0x20010b));}return logger[_0x51d045('0x34')]('message\x20is\x20empty'),_0x8a5ac6(_0x5633d6[_0x51d045('0x34')](0x1f4,_0x51d045('0x2e')));});},'AbandonInteraction':function(_0x4f7817){const _0x446a5c=this;return new Promise(function(_0xd779c8,_0x117cfb){const _0x54a390=a1217_0x2c83;if(_0x4f7817[_0x54a390('0xd')]&&_0x4f7817[_0x54a390('0x4d')]&&_0x4f7817[_0x54a390('0x4d')]['id'])try{const _0x9e608d=getId(_0x4f7817[_0x54a390('0xd')],_0x4f7817[_0x54a390('0x50')]?_0x4f7817[_0x54a390('0x50')]['id']:0x0,_0x4f7817[_0x54a390('0x4d')]?_0x4f7817['interaction']['id']:0x0);return _0x4d8c98[_0x54a390('0x37')][_0x9e608d]&&_0x4d8c98[_0x54a390('0x37')][_0x9e608d][_0x54a390('0x12')](_0x54a390('0x10')),_0xd779c8({'code':0xc8,'message':_0x4f7817});}catch(_0x52f9eb){return logger['error'](_0x52f9eb[_0x54a390('0x39')]),_0x117cfb(_0x446a5c[_0x54a390('0x34')](0x1f4,_0x52f9eb));}return logger[_0x54a390('0x34')](_0x54a390('0x2e')),_0x117cfb(_0x446a5c[_0x54a390('0x34')](0x1f4,'message\x20is\x20empty'));});},'AgentCapacity':function(_0x4072f0){const _0x25e99d=this;return new Promise(function(_0x909d94,_0x1982d2){const _0x25c5e2=a1217_0x2c83;if(typeof _0x4d8c98[_0x25c5e2('0x38')][_0x4072f0['id']]!==_0x25c5e2('0x11')){for(const _0x55ee46 in _0x4072f0[_0x25c5e2('0x16')]){typeof _0x4072f0[_0x25c5e2('0x16')][_0x55ee46]!==_0x25c5e2('0x11')&&(typeof _0x4d8c98[_0x25c5e2('0x38')][_0x4072f0['id']][_0x55ee46+'CurrentCapacity']!==_0x25c5e2('0x11')&&(_0x4d8c98[_0x25c5e2('0x38')][_0x4072f0['id']][_0x55ee46+'CurrentCapacity']=parseInt(_0x4072f0['capacity'][_0x55ee46],0xa)));}return _0x4d8c98['agents'][_0x4072f0['id']][_0x25c5e2('0x32')](),_0x909d94({'code':0xc8,'message':_0x4d8c98[_0x25c5e2('0x38')][_0x4072f0['id']]});}else return _0x1982d2(_0x25e99d[_0x25c5e2('0x34')](0x1f4,_0x25c5e2('0x25')));});},'Agents':function(){return new Promise(function(_0x195b2c){const _0xecbf5a=a1217_0x2c83,_0x418582=_[_0xecbf5a('0x31')](_0x4d8c98[_0xecbf5a('0x38')]);_0x195b2c({'count':_0x418582['length'],'rows':_0x418582});});},'ChatQueues':function(){return new Promise(function(_0x5e332e){const _0x3389ad=a1217_0x2c83,_0x4e2ea7=[];for(const _0x22a788 in _0x4d8c98[_0x3389ad('0x59')]){if(typeof _0x4d8c98['chatQueues'][_0x22a788]!==_0x3389ad('0x11')){const _0x22c6ab=_0x4d8c98['chatQueues'][_0x22a788],_0x1bfb95={'id':_0x22c6ab['id'],'available':_0x22c6ab[_0x3389ad('0xf')],'loggedIn':_0x22c6ab[_0x3389ad('0x30')],'name':_0x22c6ab[_0x3389ad('0x2f')],'paused':_0x22c6ab[_0x3389ad('0x15')],'waiting':_0x22c6ab['waiting']};_0x4e2ea7[_0x3389ad('0x36')](_0x1bfb95);}}_0x5e332e({'count':_0x4e2ea7[_0x3389ad('0x3d')],'rows':_0x4e2ea7});});},'MailQueues':function(){return new Promise(function(_0x382f23){const _0x2c448c=a1217_0x2c83,_0x1c3bfe=[];for(const _0x47fa87 in _0x4d8c98[_0x2c448c('0x54')]){if(typeof _0x4d8c98[_0x2c448c('0x54')][_0x47fa87]!==_0x2c448c('0x11')){const _0x5d1a98=_0x4d8c98[_0x2c448c('0x54')][_0x47fa87],_0x3b12c8={'id':_0x5d1a98['id'],'available':_0x5d1a98[_0x2c448c('0xf')],'loggedIn':_0x5d1a98[_0x2c448c('0x30')],'name':_0x5d1a98[_0x2c448c('0x2f')],'paused':_0x5d1a98['paused'],'waiting':_0x5d1a98[_0x2c448c('0x51')]};_0x1c3bfe[_0x2c448c('0x36')](_0x3b12c8);}}_0x382f23({'count':_0x1c3bfe[_0x2c448c('0x3d')],'rows':_0x1c3bfe});});},'OpenchannelQueues':function(){return new Promise(function(_0x2b662d){const _0xa2ad8d=a1217_0x2c83,_0x22717e=[];for(const _0x11bd1c in _0x4d8c98[_0xa2ad8d('0x5b')]){if(typeof _0x4d8c98[_0xa2ad8d('0x5b')][_0x11bd1c]!==_0xa2ad8d('0x11')){const _0x10aa9c=_0x4d8c98[_0xa2ad8d('0x5b')][_0x11bd1c],_0x403932={'id':_0x10aa9c['id'],'available':_0x10aa9c['available'],'loggedIn':_0x10aa9c['loggedIn'],'name':_0x10aa9c[_0xa2ad8d('0x2f')],'paused':_0x10aa9c[_0xa2ad8d('0x15')],'waiting':_0x10aa9c[_0xa2ad8d('0x51')]};_0x22717e[_0xa2ad8d('0x36')](_0x403932);}}_0x2b662d({'count':_0x22717e[_0xa2ad8d('0x3d')],'rows':_0x22717e});});},'SmsQueues':function(){return new Promise(function(_0x3c09cc){const _0x30bb8e=a1217_0x2c83,_0x21ce7e=[];for(const _0xeb547c in _0x4d8c98['smsQueues']){if(typeof _0x4d8c98[_0x30bb8e('0x47')][_0xeb547c]!==_0x30bb8e('0x11')){const _0x479a64=_0x4d8c98[_0x30bb8e('0x47')][_0xeb547c],_0x11627d={'id':_0x479a64['id'],'available':_0x479a64['available'],'loggedIn':_0x479a64[_0x30bb8e('0x30')],'name':_0x479a64[_0x30bb8e('0x2f')],'paused':_0x479a64['paused'],'waiting':_0x479a64['waiting']};_0x21ce7e[_0x30bb8e('0x36')](_0x11627d);}}_0x3c09cc({'count':_0x21ce7e[_0x30bb8e('0x3d')],'rows':_0x21ce7e});});},'FaxQueues':function(){return new Promise(function(_0x5f2430){const _0x58d9f3=a1217_0x2c83,_0x341065=[];for(const _0x3cd092 in _0x4d8c98['faxQueues']){if(typeof _0x4d8c98[_0x58d9f3('0x29')][_0x3cd092]!==_0x58d9f3('0x11')){const _0x306d6f=_0x4d8c98['faxQueues'][_0x3cd092],_0x3e72b1={'id':_0x306d6f['id'],'available':_0x306d6f[_0x58d9f3('0xf')],'loggedIn':_0x306d6f[_0x58d9f3('0x30')],'name':_0x306d6f[_0x58d9f3('0x2f')],'paused':_0x306d6f[_0x58d9f3('0x15')],'waiting':_0x306d6f[_0x58d9f3('0x51')]};_0x341065[_0x58d9f3('0x36')](_0x3e72b1);}}_0x5f2430({'count':_0x341065[_0x58d9f3('0x3d')],'rows':_0x341065});});},'WhatsappQueues':function(){return new Promise(function(_0xf1498e){const _0x55922b=a1217_0x2c83,_0x55606a=[];for(const _0x390f75 in _0x4d8c98['whatsappQueues']){if(typeof _0x4d8c98['whatsappQueues'][_0x390f75]!==_0x55922b('0x11')){const _0x462364=_0x4d8c98[_0x55922b('0x5')][_0x390f75],_0x4692ca={'id':_0x462364['id'],'available':_0x462364[_0x55922b('0xf')],'loggedIn':_0x462364[_0x55922b('0x30')],'name':_0x462364[_0x55922b('0x2f')],'paused':_0x462364[_0x55922b('0x15')],'waiting':_0x462364[_0x55922b('0x51')]};_0x55606a['push'](_0x4692ca);}}_0xf1498e({'count':_0x55606a[_0x55922b('0x3d')],'rows':_0x55606a});});},'ChatQueuesWaitingInteractions':function(){return new Promise(function(_0x2f0f67){const _0x3f8efd=a1217_0x2c83,_0x16f806=_[_0x3f8efd('0x31')](_0x4d8c98[_0x3f8efd('0x55')]);_0x2f0f67({'count':_0x16f806['length'],'rows':_0x16f806});});},'MailQueuesWaitingInteractions':function(){return new Promise(function(_0x16030d){const _0x2c7ff9=a1217_0x2c83,_0x5b0429=_[_0x2c7ff9('0x31')](_0x4d8c98[_0x2c7ff9('0x0')]);_0x16030d({'count':_0x5b0429[_0x2c7ff9('0x3d')],'rows':_0x5b0429});});},'OpenchannelQueuesWaitingInteractions':function(){return new Promise(function(_0x58f05e){const _0x2b82a5=a1217_0x2c83,_0x4ff3f9=_[_0x2b82a5('0x31')](_0x4d8c98[_0x2b82a5('0xa')]);_0x58f05e({'count':_0x4ff3f9[_0x2b82a5('0x3d')],'rows':_0x4ff3f9});});},'SmsQueuesWaitingInteractions':function(){return new Promise(function(_0x5a9304){const _0x3fd216=a1217_0x2c83,_0x370395=_[_0x3fd216('0x31')](_0x4d8c98[_0x3fd216('0x3e')]);_0x5a9304({'count':_0x370395[_0x3fd216('0x3d')],'rows':_0x370395});});},'FaxQueuesWaitingInteractions':function(){return new Promise(function(_0x38d13c){const _0x5e92b5=a1217_0x2c83,_0x374a71=_['values'](_0x4d8c98[_0x5e92b5('0x40')]);_0x38d13c({'count':_0x374a71[_0x5e92b5('0x3d')],'rows':_0x374a71});});},'WhatsappQueuesWaitingInteractions':function(){return new Promise(function(_0x4010fd){const _0x4a3afe=a1217_0x2c83,_0x598bf0=_[_0x4a3afe('0x31')](_0x4d8c98[_0x4a3afe('0x4b')]);_0x4010fd({'count':_0x598bf0['length'],'rows':_0x598bf0});});}},_0x265173=jayson[_0x3499bb('0x2c')](_0x3ffeca)[_0x3499bb('0x22')]();_0x265173['on']('error',function(_0x1ac500){const _0x2a3761=_0x3499bb;return logger[_0x2a3761('0x34')](JSON[_0x2a3761('0x49')](_0x1ac500)),_0x1f6639(_0x1ac500);}),_0x265173['listen'](0x232c,_0x3499bb('0x19'),function(){const _0x24a83e=_0x3499bb;return console[_0x24a83e('0x28')](_0x24a83e('0x3c'),0x232c),_0x31d179(_0x24a83e('0x20')+0x232c);});});};