77c783a713b7ea1db0c49303e65f8822edaa1b3e
[motion-next.git] / server / config / socketio.js
1 const a886_0x457c=['VoiceQueue','campaign:%s:%s','MailQueues','lodash','SmsInteraction','user_has_fax_interactions:remove','user_has_sms_interactions:remove','remotePort','type','MailQueue','request','Trunk','name','default','format','getSmsQueues','WhatsappInteractions','User','user:%s','user','where','ivr','SmsQueues','userProfileId','connection','SocketIO\x20','VoiceQueues','%s:queue:%s','removeChatInteractions','user_has_openchannel_interactions:remove','WhatsappQueue','getMailQueues','user_has_mail_interactions:remove','user_has_whatsapp_interactions:remove','agent','../mysqldb','all','CONNECTED','push','FaxInteraction','OpenchannelInteractions','emit','fax','IvrCampaigns','FaxQueue','whatsapp','voice:inbound','setMaxListeners','ChatInteractions','removeWhatsappInteractions','ChatQueues','Campaign','getVoiceQueues','findAll','length','OpenchannelQueues','include','getWhatsappQueues','address','resourceId','SmsQueue','getFaxQueues','findOne','autoAssociation','undefined','user_has_chat_interactions:remove','SmsInteractions','map','leave','removeSmsInteractions','telephone:%s','query','role','trunk:%s','OpenchannelQueue','UserProfileResource','WhatsappQueues','getOpenchannelQueues','getChatQueues','ChatQueue','remoteAddress','connectedAt','nsp','DISCONNECTED','mail','disconnect','FaxQueues','UserProfileSection','sms','Agents','log','then','MailInteraction','telephone','handshake','FaxInteractions','voice:outbound','Telephones','Trunks','openchannel'];(function(_0x303dd5,_0x457cfc){const _0x4c57f1=function(_0x4ffbfa){while(--_0x4ffbfa){_0x303dd5['push'](_0x303dd5['shift']());}};_0x4c57f1(++_0x457cfc);}(a886_0x457c,0x7c));const a886_0x4c57=function(_0x303dd5,_0x457cfc){_0x303dd5=_0x303dd5-0x0;let _0x4c57f1=a886_0x457c[_0x303dd5];return _0x4c57f1;};const _0x489c2f=a886_0x4c57;'use strict';const _=require(_0x489c2f('0x4f')),util=require('util'),db=require(_0x489c2f('0xb'))['db'],queryQueues={'attributes':['id',_0x489c2f('0x58')],'include':[{'as':_0x489c2f('0x41'),'model':db[_0x489c2f('0x5d')],'attributes':['id','name',_0x489c2f('0x30')],'raw':!![],'where':{'role':_0x489c2f('0xa')},'required':![]}]},queryTelephones={'raw':!![],'attributes':['id',_0x489c2f('0x58')],'where':{'role':_0x489c2f('0x45')}},queryTrunks={'raw':!![],'attributes':['id',_0x489c2f('0x58')]},queryAgents={'raw':!![],'attributes':['id',_0x489c2f('0x58')],'where':{'role':_0x489c2f('0xa')}},queryCampaigns={'raw':!![],'attributes':['id',_0x489c2f('0x58'),_0x489c2f('0x54')],'where':{'type':_0x489c2f('0x61')}};function getAssociatedResources(_0x4ffbfa,_0x3a2477,_0x50b721){const _0x28ec9a=_0x489c2f;return db[_0x28ec9a('0x3f')][_0x28ec9a('0x26')]({'where':{'name':_0x4ffbfa,'userProfileId':_0x3a2477},'raw':!![]})[_0x28ec9a('0x43')](function(_0x46e14d){const _0xa7c19b=_0x28ec9a;if(_0x46e14d){if(_0x46e14d[_0xa7c19b('0x27')]){let _0x249e90;switch(_0x4ffbfa){case _0xa7c19b('0x2'):case _0xa7c19b('0x1a'):case'FaxQueues':case _0xa7c19b('0x62'):case _0xa7c19b('0x4e'):case _0xa7c19b('0x1f'):case'WhatsappQueues':_0x249e90=queryQueues;break;case _0xa7c19b('0x49'):_0x249e90=queryTelephones;break;case _0xa7c19b('0x4a'):_0x249e90=queryTrunks;break;case _0xa7c19b('0x13'):_0x249e90=queryCampaigns;break;default:break;}return _0x249e90?db[_0x50b721][_0xa7c19b('0x1d')](_0x249e90):_0x249e90;}else return db[_0xa7c19b('0x33')][_0xa7c19b('0x1d')]({'attributes':[_0xa7c19b('0x23')],'where':{'sectionId':_0x46e14d['id']},'raw':!![]})['then'](function(_0x1de43a){const _0x57024e=_0xa7c19b;if(_0x1de43a){const _0xb70482={'where':{'id':_[_0x57024e('0x2b')](_0x1de43a,_0x57024e('0x23'))},'raw':!![]};switch(_0x50b721){case'User':_0xb70482[_0x57024e('0x60')]['role']=_0x57024e('0x45');break;case _0x57024e('0x1b'):_0xb70482[_0x57024e('0x60')]['type']='ivr';break;}return db[_0x50b721][_0x57024e('0x1d')](_0xb70482);}else return[];});}else return[];})['then'](function(_0x296f75){return _0x296f75;});}function joinOrLeaveQueues(_0x501cd7,_0x4a5c9b,_0x11568f,_0x4d6f31){const _0x294c9d=_0x489c2f;_0x501cd7[_0x4a5c9b](util[_0x294c9d('0x5a')](_0x294c9d('0x3'),_0x11568f,_0x4d6f31[_0x294c9d('0x58')]));if(_0x4d6f31[_0x294c9d('0x41')])for(let _0x55bf3a=0x0;_0x55bf3a<_0x4d6f31[_0x294c9d('0x41')][_0x294c9d('0x1e')];_0x55bf3a+=0x1){_0x501cd7[_0x4a5c9b](util[_0x294c9d('0x5a')]('user:%s',_0x4d6f31[_0x294c9d('0x41')][_0x55bf3a]['name']));}}function joinOrLeave(_0x5eb961,_0x12fe3b,_0xec66ed){const _0x239b73=_0x489c2f;let _0x5adbb9;_0x5eb961[_0x239b73('0x46')][_0x239b73('0x2f')]['id']&&db[_0x239b73('0x5d')][_0x239b73('0x26')]({'attributes':['id','name',_0x239b73('0x30'),_0x239b73('0x63')],'where':{'id':_0x5eb961[_0x239b73('0x46')]['query']['id']},'include':[{'model':db['ChatInteraction'],'as':_0x239b73('0x18'),'attributes':['id'],'raw':!![]},{'model':db[_0x239b73('0x44')],'as':'MailInteractions','attributes':['id'],'raw':!![]},{'model':db[_0x239b73('0xf')],'as':_0x239b73('0x47'),'attributes':['id'],'raw':!![]},{'model':db[_0x239b73('0x50')],'as':'SmsInteractions','attributes':['id'],'raw':!![]},{'model':db['OpenchannelInteraction'],'as':_0x239b73('0x10'),'attributes':['id'],'raw':!![]},{'model':db['WhatsappInteraction'],'as':_0x239b73('0x5c'),'attributes':['id'],'raw':!![]}]})['then'](function(_0x5c0b08){const _0x12234f=_0x239b73;if(_0x5c0b08){_0x5adbb9=_0x5c0b08,_0x5eb961[_0x12fe3b](util['format'](_0x12234f('0x5e'),_0x5c0b08[_0x12234f('0x58')]));const _0x198232=[];switch(_0x5c0b08[_0x12234f('0x30')]){case'admin':_0x5eb961[_0x12fe3b](_0x12234f('0x16')),_0x5eb961[_0x12fe3b](_0x12234f('0x48'));typeof queryQueues[_0x12234f('0x20')]!==_0x12234f('0x28')&&delete queryQueues[_0x12234f('0x20')];_0x198232['push'](db[_0x12234f('0x4c')][_0x12234f('0x1d')](queryQueues)),_0x198232[_0x12234f('0xe')](db['ChatQueue'][_0x12234f('0x1d')](queryQueues)),_0x198232[_0x12234f('0xe')](db[_0x12234f('0x14')][_0x12234f('0x1d')](queryQueues)),_0x198232[_0x12234f('0xe')](db[_0x12234f('0x24')][_0x12234f('0x1d')](queryQueues)),_0x198232[_0x12234f('0xe')](db[_0x12234f('0x55')]['findAll'](queryQueues)),_0x198232[_0x12234f('0xe')](db[_0x12234f('0x32')][_0x12234f('0x1d')](queryQueues)),_0x198232[_0x12234f('0xe')](db[_0x12234f('0x6')][_0x12234f('0x1d')](queryQueues)),_0x198232[_0x12234f('0xe')](db[_0x12234f('0x5d')][_0x12234f('0x1d')](queryTelephones)),_0x198232[_0x12234f('0xe')](db[_0x12234f('0x57')][_0x12234f('0x1d')](queryTrunks)),_0x198232[_0x12234f('0xe')](db[_0x12234f('0x1b')]['findAll'](queryCampaigns)),_0x198232[_0x12234f('0xe')](db['User'][_0x12234f('0x1d')](queryAgents));break;case _0x12234f('0x5f'):_0x5eb961[_0x12fe3b](_0x12234f('0x16')),_0x5eb961[_0x12fe3b](_0x12234f('0x48')),_0x198232[_0x12234f('0xe')](getAssociatedResources(_0x12234f('0x2'),_0x5c0b08[_0x12234f('0x63')],_0x12234f('0x4c'))),_0x198232[_0x12234f('0xe')](getAssociatedResources(_0x12234f('0x1a'),_0x5c0b08['userProfileId'],_0x12234f('0x37'))),_0x198232[_0x12234f('0xe')](getAssociatedResources(_0x12234f('0x3e'),_0x5c0b08[_0x12234f('0x63')],_0x12234f('0x14'))),_0x198232['push'](getAssociatedResources(_0x12234f('0x62'),_0x5c0b08[_0x12234f('0x63')],'SmsQueue')),_0x198232[_0x12234f('0xe')](getAssociatedResources(_0x12234f('0x4e'),_0x5c0b08[_0x12234f('0x63')],_0x12234f('0x55'))),_0x198232[_0x12234f('0xe')](getAssociatedResources(_0x12234f('0x1f'),_0x5c0b08[_0x12234f('0x63')],'OpenchannelQueue')),_0x198232[_0x12234f('0xe')](getAssociatedResources(_0x12234f('0x34'),_0x5c0b08[_0x12234f('0x63')],_0x12234f('0x6'))),_0x198232[_0x12234f('0xe')](getAssociatedResources(_0x12234f('0x49'),_0x5c0b08[_0x12234f('0x63')],_0x12234f('0x5d'))),_0x198232[_0x12234f('0xe')](getAssociatedResources(_0x12234f('0x4a'),_0x5c0b08[_0x12234f('0x63')],_0x12234f('0x57'))),_0x198232[_0x12234f('0xe')](getAssociatedResources(_0x12234f('0x13'),_0x5c0b08[_0x12234f('0x63')],'Campaign')),_0x198232[_0x12234f('0xe')](db[_0x12234f('0x5d')][_0x12234f('0x1d')](queryAgents));break;case _0x12234f('0xa'):_0x5eb961[_0x12fe3b]('voice:inbound'),_0x5eb961[_0x12fe3b]('voice:outbound'),_0x198232[_0x12234f('0xe')](_0x5c0b08[_0x12234f('0x1c')]({'attributes':['id',_0x12234f('0x58')]})),_0x198232[_0x12234f('0xe')](_0x5c0b08[_0x12234f('0x36')]({'attributes':['id',_0x12234f('0x58')]})),_0x198232['push'](_0x5c0b08[_0x12234f('0x25')]({'attributes':['id','name']})),_0x198232[_0x12234f('0xe')](_0x5c0b08[_0x12234f('0x5b')]({'attributes':['id',_0x12234f('0x58')]})),_0x198232[_0x12234f('0xe')](_0x5c0b08[_0x12234f('0x7')]({'attributes':['id','name']})),_0x198232[_0x12234f('0xe')](_0x5c0b08[_0x12234f('0x35')]({'attributes':['id',_0x12234f('0x58')]})),_0x198232[_0x12234f('0xe')](_0x5c0b08[_0x12234f('0x21')]({'attributes':['id',_0x12234f('0x58')]}));break;}return Promise[_0x12234f('0xc')](_0x198232);}})['then'](function(_0x634409){const _0x564827=_0x239b73;if(_0x634409&&_0x634409[_0x564827('0x1e')])for(let _0xe996cd=0x0;_0xe996cd<_0x634409[_0x564827('0x1e')];_0xe996cd+=0x1){for(let _0x2d0a32=0x0;_0x2d0a32<_0x634409[_0xe996cd][_0x564827('0x1e')];_0x2d0a32+=0x1){switch(_0xe996cd){case 0x0:joinOrLeaveQueues(_0x5eb961,_0x12fe3b,'voice',_0x634409[_0xe996cd][_0x2d0a32]);break;case 0x1:joinOrLeaveQueues(_0x5eb961,_0x12fe3b,'chat',_0x634409[_0xe996cd][_0x2d0a32]);break;case 0x2:joinOrLeaveQueues(_0x5eb961,_0x12fe3b,_0x564827('0x12'),_0x634409[_0xe996cd][_0x2d0a32]);break;case 0x3:joinOrLeaveQueues(_0x5eb961,_0x12fe3b,_0x564827('0x40'),_0x634409[_0xe996cd][_0x2d0a32]);break;case 0x4:joinOrLeaveQueues(_0x5eb961,_0x12fe3b,_0x564827('0x3c'),_0x634409[_0xe996cd][_0x2d0a32]);break;case 0x5:joinOrLeaveQueues(_0x5eb961,_0x12fe3b,_0x564827('0x4b'),_0x634409[_0xe996cd][_0x2d0a32]);break;case 0x6:joinOrLeaveQueues(_0x5eb961,_0x12fe3b,_0x564827('0x15'),_0x634409[_0xe996cd][_0x2d0a32]);break;case 0x7:_0x5eb961[_0x12fe3b](util[_0x564827('0x5a')](_0x564827('0x2e'),_0x634409[_0xe996cd][_0x2d0a32][_0x564827('0x58')]));break;case 0x8:_0x5eb961[_0x12fe3b](util[_0x564827('0x5a')](_0x564827('0x31'),_0x634409[_0xe996cd][_0x2d0a32][_0x564827('0x58')]));break;case 0x9:_0x5eb961[_0x12fe3b](util[_0x564827('0x5a')](_0x564827('0x4d'),_0x634409[_0xe996cd][_0x2d0a32][_0x564827('0x54')],_0x634409[_0xe996cd][_0x2d0a32][_0x564827('0x58')]));break;case 0xa:_0x5eb961[_0x12fe3b](util[_0x564827('0x5a')](_0x564827('0x5e'),_0x634409[_0xe996cd][_0x2d0a32][_0x564827('0x58')]));break;}}}})[_0x239b73('0x43')](function(){const _0x197b5c=_0x239b73;if(_0x12fe3b===_0x197b5c('0x2c')){const _0x410c3f=_[_0x197b5c('0x2b')](_0x5adbb9[_0x197b5c('0x18')],'id');return _0x5adbb9[_0x197b5c('0x4')](_0x410c3f)[_0x197b5c('0x43')](function(){const _0x297e68=_0x197b5c;for(let _0x27f28a=0x0;_0x27f28a<_0x410c3f[_0x297e68('0x1e')];_0x27f28a+=0x1){_0xec66ed[_0x297e68('0x11')](_0x297e68('0x29'),{'ChatInteractionId':Number(_0x410c3f[_0x27f28a]),'UserId':Number(_0x5adbb9['id'])});}});}})[_0x239b73('0x43')](function(){const _0x59211b=_0x239b73;if(_0x12fe3b===_0x59211b('0x2c')){const _0x14026f=_[_0x59211b('0x2b')](_0x5adbb9['MailInteractions'],'id');return _0x5adbb9['removeMailInteractions'](_0x14026f)[_0x59211b('0x43')](function(){const _0x12894d=_0x59211b;for(let _0x1c735c=0x0;_0x1c735c<_0x14026f[_0x12894d('0x1e')];_0x1c735c+=0x1){_0xec66ed[_0x12894d('0x11')](_0x12894d('0x8'),{'MailInteractionId':Number(_0x14026f[_0x1c735c]),'UserId':Number(_0x5adbb9['id'])});}});}})[_0x239b73('0x43')](function(){const _0x2a05e2=_0x239b73;if(_0x12fe3b===_0x2a05e2('0x2c')){const _0x5291dc=_[_0x2a05e2('0x2b')](_0x5adbb9[_0x2a05e2('0x47')],'id');return _0x5adbb9['removeFaxInteractions'](_0x5291dc)[_0x2a05e2('0x43')](function(){const _0x8b8f02=_0x2a05e2;for(let _0xeba5d9=0x0;_0xeba5d9<_0x5291dc[_0x8b8f02('0x1e')];_0xeba5d9+=0x1){_0xec66ed[_0x8b8f02('0x11')](_0x8b8f02('0x51'),{'FaxInteractionId':Number(_0x5291dc[_0xeba5d9]),'UserId':Number(_0x5adbb9['id'])});}});}})['then'](function(){const _0x4d0b26=_0x239b73;if(_0x12fe3b===_0x4d0b26('0x2c')){const _0x2eec21=_[_0x4d0b26('0x2b')](_0x5adbb9[_0x4d0b26('0x2a')],'id');return _0x5adbb9[_0x4d0b26('0x2d')](_0x2eec21)['then'](function(){const _0x1b8c05=_0x4d0b26;for(let _0x4e0382=0x0;_0x4e0382<_0x2eec21['length'];_0x4e0382+=0x1){_0xec66ed[_0x1b8c05('0x11')](_0x1b8c05('0x52'),{'SmsInteractionId':Number(_0x2eec21[_0x4e0382]),'UserId':Number(_0x5adbb9['id'])});}});}})[_0x239b73('0x43')](function(){const _0x17a937=_0x239b73;if(_0x12fe3b===_0x17a937('0x2c')){const _0x405ca1=_[_0x17a937('0x2b')](_0x5adbb9[_0x17a937('0x10')],'id');return _0x5adbb9['removeOpenchannelInteractions'](_0x405ca1)['then'](function(){const _0x5044d7=_0x17a937;for(let _0x3e4068=0x0;_0x3e4068<_0x405ca1[_0x5044d7('0x1e')];_0x3e4068+=0x1){_0xec66ed[_0x5044d7('0x11')](_0x5044d7('0x5'),{'OpenchannelInteractionId':Number(_0x405ca1[_0x3e4068]),'UserId':Number(_0x5adbb9['id'])});}});}})[_0x239b73('0x43')](function(){const _0x442f28=_0x239b73;if(_0x12fe3b===_0x442f28('0x2c')){const _0x32b00f=_[_0x442f28('0x2b')](_0x5adbb9[_0x442f28('0x5c')],'id');return _0x5adbb9[_0x442f28('0x19')](_0x32b00f)['then'](function(){const _0x4b3ee0=_0x442f28;for(let _0xf26d3c=0x0;_0xf26d3c<_0x32b00f['length'];_0xf26d3c+=0x1){_0xec66ed[_0x4b3ee0('0x11')](_0x4b3ee0('0x9'),{'WhatsappInteractionId':Number(_0x32b00f[_0xf26d3c]),'UserId':Number(_0x5adbb9['id'])});}});}})['catch'](function(_0x20428b){const _0x1ec501=_0x239b73;_0x5eb961[_0x1ec501('0x42')](_0x20428b);});}function onDisconnect(_0xc8238d,_0x552e44){const _0x49a2d9=_0x489c2f;joinOrLeave(_0xc8238d,_0x49a2d9('0x2c'),_0x552e44);}function onConnect(_0xf7c979){joinOrLeave(_0xf7c979,'join');}exports[_0x489c2f('0x59')]=function(_0x5e0a17){const _0x2ecf84=_0x489c2f;_0x5e0a17['on'](_0x2ecf84('0x0'),function(_0x3a7ccb){const _0x213696=_0x2ecf84;_0x3a7ccb[_0x213696('0x17')](0x0),_0x3a7ccb[_0x213696('0x22')]=_0x3a7ccb[_0x213696('0x56')][_0x213696('0x0')][_0x213696('0x38')]+':'+_0x3a7ccb[_0x213696('0x56')][_0x213696('0x0')][_0x213696('0x53')],_0x3a7ccb[_0x213696('0x39')]=new Date(),_0x3a7ccb[_0x213696('0x42')]=function(_0x2c5dc2){const _0x264ef2=_0x213696;console[_0x264ef2('0x42')](_0x264ef2('0x1')+_0x3a7ccb[_0x264ef2('0x3a')]['name']+'['+_0x3a7ccb['address']+']',_0x2c5dc2);},_0x3a7ccb['on'](_0x213696('0x3d'),function(){const _0x28610c=_0x213696;onDisconnect(_0x3a7ccb,_0x5e0a17),_0x3a7ccb['log'](_0x28610c('0x3b'));}),onConnect(_0x3a7ccb),_0x3a7ccb[_0x213696('0x42')](_0x213696('0xd'));});};