Built motion from commit b51cdcb3f2cb46634587ce1d55ea1b8f32dacea6. Version 3.0.0...
[motion-next.git] / server / config / socketio.js
1 const a886_0x3a0c=['type','resourceId','OpenchannelQueue','format','log','getVoiceQueues','Telephones','telephone:%s','autoAssociation','WhatsappQueues','OpenchannelQueues','leave','getChatQueues','user_has_openchannel_interactions:remove','trunk:%s','user','SmsInteractions','util','OpenchannelInteractions','userProfileId','User','connectedAt','include','campaign:%s:%s','FaxQueues','Trunk','disconnect','openchannel','removeFaxInteractions','setMaxListeners','getFaxQueues','ChatQueues','getMailQueues','user:%s','removeWhatsappInteractions','ivr','getOpenchannelQueues','SocketIO\x20','ChatInteraction','Campaign','address','default','MailInteractions','voice:outbound','map','UserProfileSection','OpenchannelInteraction','WhatsappInteraction','MailQueues','../mysqldb','user_has_fax_interactions:remove','MailQueue','SmsQueue','VoiceQueue','catch','ChatInteractions','nsp','WhatsappInteractions','all','join','ChatQueue','DISCONNECTED','WhatsappQueue','UserProfileResource','remoteAddress','role','length','name','Agents','MailInteraction','FaxQueue','request','agent','lodash','where','voice:inbound','undefined','VoiceQueues','connection','mail','removeOpenchannelInteractions','FaxInteraction','user_has_chat_interactions:remove','removeChatInteractions','findAll','then','IvrCampaigns','telephone','getWhatsappQueues','FaxInteractions','user_has_sms_interactions:remove','push','handshake','SmsInteraction','Trunks','findOne','removeSmsInteractions','user_has_whatsapp_interactions:remove','query','SmsQueues','emit','user_has_mail_interactions:remove','fax'];(function(_0x4bded8,_0x3a0c61){const _0x3cfe47=function(_0x2e7f08){while(--_0x2e7f08){_0x4bded8['push'](_0x4bded8['shift']());}};_0x3cfe47(++_0x3a0c61);}(a886_0x3a0c,0x1a4));const a886_0x3cfe=function(_0x4bded8,_0x3a0c61){_0x4bded8=_0x4bded8-0x0;let _0x3cfe47=a886_0x3a0c[_0x4bded8];return _0x3cfe47;};const _0x3d6ca6=a886_0x3cfe;'use strict';const _=require(_0x3d6ca6('0x41')),util=require(_0x3d6ca6('0x9')),db=require(_0x3d6ca6('0x29'))['db'],queryQueues={'attributes':['id',_0x3d6ca6('0x3b')],'include':[{'as':_0x3d6ca6('0x3c'),'model':db['User'],'attributes':['id','name',_0x3d6ca6('0x39')],'raw':!![],'where':{'role':_0x3d6ca6('0x40')},'required':![]}]},queryTelephones={'raw':!![],'attributes':['id',_0x3d6ca6('0x3b')],'where':{'role':_0x3d6ca6('0x4f')}},queryTrunks={'raw':!![],'attributes':['id',_0x3d6ca6('0x3b')]},queryAgents={'raw':!![],'attributes':['id',_0x3d6ca6('0x3b')],'where':{'role':_0x3d6ca6('0x40')}},queryCampaigns={'raw':!![],'attributes':['id',_0x3d6ca6('0x3b'),'type'],'where':{'type':_0x3d6ca6('0x1b')}};function getAssociatedResources(_0x2e7f08,_0x32767b,_0x403565){const _0x4d7643=_0x3d6ca6;return db[_0x4d7643('0x25')][_0x4d7643('0x57')]({'where':{'name':_0x2e7f08,'userProfileId':_0x32767b},'raw':!![]})[_0x4d7643('0x4d')](function(_0x5e5a11){const _0x5b43a0=_0x4d7643;if(_0x5e5a11){if(_0x5e5a11[_0x5b43a0('0x0')]){let _0x2ea5e4;switch(_0x2e7f08){case'VoiceQueues':case _0x5b43a0('0x17'):case _0x5b43a0('0x10'):case _0x5b43a0('0x5b'):case'MailQueues':case _0x5b43a0('0x2'):case _0x5b43a0('0x1'):_0x2ea5e4=queryQueues;break;case _0x5b43a0('0x65'):_0x2ea5e4=queryTelephones;break;case _0x5b43a0('0x56'):_0x2ea5e4=queryTrunks;break;case _0x5b43a0('0x4e'):_0x2ea5e4=queryCampaigns;break;default:break;}return _0x2ea5e4?db[_0x403565][_0x5b43a0('0x4c')](_0x2ea5e4):_0x2ea5e4;}else return db[_0x5b43a0('0x37')][_0x5b43a0('0x4c')]({'attributes':['resourceId'],'where':{'sectionId':_0x5e5a11['id']},'raw':!![]})[_0x5b43a0('0x4d')](function(_0x1ba061){const _0x1ca022=_0x5b43a0;if(_0x1ba061){const _0x259eb6={'where':{'id':_['map'](_0x1ba061,_0x1ca022('0x60'))},'raw':!![]};switch(_0x403565){case _0x1ca022('0xc'):_0x259eb6[_0x1ca022('0x42')][_0x1ca022('0x39')]=_0x1ca022('0x4f');break;case _0x1ca022('0x1f'):_0x259eb6['where'][_0x1ca022('0x5f')]=_0x1ca022('0x1b');break;}return db[_0x403565][_0x1ca022('0x4c')](_0x259eb6);}else return[];});}else return[];})[_0x4d7643('0x4d')](function(_0x39c42e){return _0x39c42e;});}function joinOrLeaveQueues(_0x2c3061,_0x2e80fe,_0x55c91b,_0x4d027e){const _0x513455=_0x3d6ca6;_0x2c3061[_0x2e80fe](util[_0x513455('0x62')]('%s:queue:%s',_0x55c91b,_0x4d027e[_0x513455('0x3b')]));if(_0x4d027e[_0x513455('0x3c')])for(let _0x463ee=0x0;_0x463ee<_0x4d027e[_0x513455('0x3c')][_0x513455('0x3a')];_0x463ee+=0x1){_0x2c3061[_0x2e80fe](util[_0x513455('0x62')]('user:%s',_0x4d027e[_0x513455('0x3c')][_0x463ee][_0x513455('0x3b')]));}}function joinOrLeave(_0x3b337c,_0x444637,_0xc3b5c9){const _0x257d75=_0x3d6ca6;let _0x274060;_0x3b337c[_0x257d75('0x54')][_0x257d75('0x5a')]['id']&&db['User'][_0x257d75('0x57')]({'attributes':['id',_0x257d75('0x3b'),_0x257d75('0x39'),_0x257d75('0xb')],'where':{'id':_0x3b337c['handshake'][_0x257d75('0x5a')]['id']},'include':[{'model':db[_0x257d75('0x1e')],'as':_0x257d75('0x2f'),'attributes':['id'],'raw':!![]},{'model':db[_0x257d75('0x3d')],'as':_0x257d75('0x22'),'attributes':['id'],'raw':!![]},{'model':db[_0x257d75('0x49')],'as':'FaxInteractions','attributes':['id'],'raw':!![]},{'model':db[_0x257d75('0x55')],'as':'SmsInteractions','attributes':['id'],'raw':!![]},{'model':db[_0x257d75('0x26')],'as':'OpenchannelInteractions','attributes':['id'],'raw':!![]},{'model':db[_0x257d75('0x27')],'as':'WhatsappInteractions','attributes':['id'],'raw':!![]}]})[_0x257d75('0x4d')](function(_0x30655f){const _0x2a98a0=_0x257d75;if(_0x30655f){_0x274060=_0x30655f,_0x3b337c[_0x444637](util[_0x2a98a0('0x62')](_0x2a98a0('0x19'),_0x30655f[_0x2a98a0('0x3b')]));const _0x308ecf=[];switch(_0x30655f[_0x2a98a0('0x39')]){case'admin':_0x3b337c[_0x444637](_0x2a98a0('0x43')),_0x3b337c[_0x444637](_0x2a98a0('0x23'));typeof queryQueues[_0x2a98a0('0xe')]!==_0x2a98a0('0x44')&&delete queryQueues[_0x2a98a0('0xe')];_0x308ecf['push'](db[_0x2a98a0('0x2d')][_0x2a98a0('0x4c')](queryQueues)),_0x308ecf[_0x2a98a0('0x53')](db[_0x2a98a0('0x34')][_0x2a98a0('0x4c')](queryQueues)),_0x308ecf[_0x2a98a0('0x53')](db[_0x2a98a0('0x3e')][_0x2a98a0('0x4c')](queryQueues)),_0x308ecf[_0x2a98a0('0x53')](db[_0x2a98a0('0x2c')][_0x2a98a0('0x4c')](queryQueues)),_0x308ecf[_0x2a98a0('0x53')](db['MailQueue']['findAll'](queryQueues)),_0x308ecf[_0x2a98a0('0x53')](db['OpenchannelQueue'][_0x2a98a0('0x4c')](queryQueues)),_0x308ecf[_0x2a98a0('0x53')](db['WhatsappQueue']['findAll'](queryQueues)),_0x308ecf['push'](db[_0x2a98a0('0xc')][_0x2a98a0('0x4c')](queryTelephones)),_0x308ecf[_0x2a98a0('0x53')](db[_0x2a98a0('0x11')][_0x2a98a0('0x4c')](queryTrunks)),_0x308ecf[_0x2a98a0('0x53')](db[_0x2a98a0('0x1f')][_0x2a98a0('0x4c')](queryCampaigns)),_0x308ecf[_0x2a98a0('0x53')](db['User'][_0x2a98a0('0x4c')](queryAgents));break;case _0x2a98a0('0x7'):_0x3b337c[_0x444637](_0x2a98a0('0x43')),_0x3b337c[_0x444637](_0x2a98a0('0x23')),_0x308ecf[_0x2a98a0('0x53')](getAssociatedResources(_0x2a98a0('0x45'),_0x30655f[_0x2a98a0('0xb')],_0x2a98a0('0x2d'))),_0x308ecf['push'](getAssociatedResources(_0x2a98a0('0x17'),_0x30655f[_0x2a98a0('0xb')],_0x2a98a0('0x34'))),_0x308ecf[_0x2a98a0('0x53')](getAssociatedResources(_0x2a98a0('0x10'),_0x30655f[_0x2a98a0('0xb')],_0x2a98a0('0x3e'))),_0x308ecf['push'](getAssociatedResources(_0x2a98a0('0x5b'),_0x30655f[_0x2a98a0('0xb')],_0x2a98a0('0x2c'))),_0x308ecf[_0x2a98a0('0x53')](getAssociatedResources(_0x2a98a0('0x28'),_0x30655f['userProfileId'],_0x2a98a0('0x2b'))),_0x308ecf[_0x2a98a0('0x53')](getAssociatedResources(_0x2a98a0('0x2'),_0x30655f[_0x2a98a0('0xb')],_0x2a98a0('0x61'))),_0x308ecf[_0x2a98a0('0x53')](getAssociatedResources(_0x2a98a0('0x1'),_0x30655f[_0x2a98a0('0xb')],_0x2a98a0('0x36'))),_0x308ecf[_0x2a98a0('0x53')](getAssociatedResources(_0x2a98a0('0x65'),_0x30655f[_0x2a98a0('0xb')],_0x2a98a0('0xc'))),_0x308ecf[_0x2a98a0('0x53')](getAssociatedResources(_0x2a98a0('0x56'),_0x30655f[_0x2a98a0('0xb')],_0x2a98a0('0x11'))),_0x308ecf[_0x2a98a0('0x53')](getAssociatedResources(_0x2a98a0('0x4e'),_0x30655f[_0x2a98a0('0xb')],_0x2a98a0('0x1f'))),_0x308ecf[_0x2a98a0('0x53')](db['User'][_0x2a98a0('0x4c')](queryAgents));break;case _0x2a98a0('0x40'):_0x3b337c[_0x444637](_0x2a98a0('0x43')),_0x3b337c[_0x444637](_0x2a98a0('0x23')),_0x308ecf['push'](_0x30655f[_0x2a98a0('0x64')]({'attributes':['id',_0x2a98a0('0x3b')]})),_0x308ecf[_0x2a98a0('0x53')](_0x30655f[_0x2a98a0('0x4')]({'attributes':['id',_0x2a98a0('0x3b')]})),_0x308ecf[_0x2a98a0('0x53')](_0x30655f[_0x2a98a0('0x16')]({'attributes':['id',_0x2a98a0('0x3b')]})),_0x308ecf[_0x2a98a0('0x53')](_0x30655f['getSmsQueues']({'attributes':['id','name']})),_0x308ecf[_0x2a98a0('0x53')](_0x30655f[_0x2a98a0('0x18')]({'attributes':['id',_0x2a98a0('0x3b')]})),_0x308ecf[_0x2a98a0('0x53')](_0x30655f[_0x2a98a0('0x1c')]({'attributes':['id','name']})),_0x308ecf['push'](_0x30655f[_0x2a98a0('0x50')]({'attributes':['id','name']}));break;}return Promise[_0x2a98a0('0x32')](_0x308ecf);}})['then'](function(_0x106aa6){const _0x2f6a7c=_0x257d75;if(_0x106aa6&&_0x106aa6[_0x2f6a7c('0x3a')])for(let _0xf8912e=0x0;_0xf8912e<_0x106aa6[_0x2f6a7c('0x3a')];_0xf8912e+=0x1){for(let _0x3ca7a5=0x0;_0x3ca7a5<_0x106aa6[_0xf8912e]['length'];_0x3ca7a5+=0x1){switch(_0xf8912e){case 0x0:joinOrLeaveQueues(_0x3b337c,_0x444637,'voice',_0x106aa6[_0xf8912e][_0x3ca7a5]);break;case 0x1:joinOrLeaveQueues(_0x3b337c,_0x444637,'chat',_0x106aa6[_0xf8912e][_0x3ca7a5]);break;case 0x2:joinOrLeaveQueues(_0x3b337c,_0x444637,_0x2f6a7c('0x5e'),_0x106aa6[_0xf8912e][_0x3ca7a5]);break;case 0x3:joinOrLeaveQueues(_0x3b337c,_0x444637,'sms',_0x106aa6[_0xf8912e][_0x3ca7a5]);break;case 0x4:joinOrLeaveQueues(_0x3b337c,_0x444637,_0x2f6a7c('0x47'),_0x106aa6[_0xf8912e][_0x3ca7a5]);break;case 0x5:joinOrLeaveQueues(_0x3b337c,_0x444637,_0x2f6a7c('0x13'),_0x106aa6[_0xf8912e][_0x3ca7a5]);break;case 0x6:joinOrLeaveQueues(_0x3b337c,_0x444637,'whatsapp',_0x106aa6[_0xf8912e][_0x3ca7a5]);break;case 0x7:_0x3b337c[_0x444637](util[_0x2f6a7c('0x62')](_0x2f6a7c('0x66'),_0x106aa6[_0xf8912e][_0x3ca7a5][_0x2f6a7c('0x3b')]));break;case 0x8:_0x3b337c[_0x444637](util[_0x2f6a7c('0x62')](_0x2f6a7c('0x6'),_0x106aa6[_0xf8912e][_0x3ca7a5][_0x2f6a7c('0x3b')]));break;case 0x9:_0x3b337c[_0x444637](util[_0x2f6a7c('0x62')](_0x2f6a7c('0xf'),_0x106aa6[_0xf8912e][_0x3ca7a5][_0x2f6a7c('0x5f')],_0x106aa6[_0xf8912e][_0x3ca7a5]['name']));break;case 0xa:_0x3b337c[_0x444637](util[_0x2f6a7c('0x62')](_0x2f6a7c('0x19'),_0x106aa6[_0xf8912e][_0x3ca7a5]['name']));break;}}}})['then'](function(){const _0x44526b=_0x257d75;if(_0x444637===_0x44526b('0x3')){const _0xd304fd=_['map'](_0x274060['ChatInteractions'],'id');return _0x274060[_0x44526b('0x4b')](_0xd304fd)[_0x44526b('0x4d')](function(){const _0x296a00=_0x44526b;for(let _0x31931d=0x0;_0x31931d<_0xd304fd[_0x296a00('0x3a')];_0x31931d+=0x1){_0xc3b5c9[_0x296a00('0x5c')](_0x296a00('0x4a'),{'ChatInteractionId':Number(_0xd304fd[_0x31931d]),'UserId':Number(_0x274060['id'])});}});}})[_0x257d75('0x4d')](function(){const _0x2823bc=_0x257d75;if(_0x444637===_0x2823bc('0x3')){const _0x7fca80=_[_0x2823bc('0x24')](_0x274060[_0x2823bc('0x22')],'id');return _0x274060['removeMailInteractions'](_0x7fca80)[_0x2823bc('0x4d')](function(){const _0x581320=_0x2823bc;for(let _0x2e0b80=0x0;_0x2e0b80<_0x7fca80[_0x581320('0x3a')];_0x2e0b80+=0x1){_0xc3b5c9[_0x581320('0x5c')](_0x581320('0x5d'),{'MailInteractionId':Number(_0x7fca80[_0x2e0b80]),'UserId':Number(_0x274060['id'])});}});}})['then'](function(){const _0x3227e3=_0x257d75;if(_0x444637===_0x3227e3('0x3')){const _0x434888=_[_0x3227e3('0x24')](_0x274060[_0x3227e3('0x51')],'id');return _0x274060[_0x3227e3('0x14')](_0x434888)[_0x3227e3('0x4d')](function(){const _0x9b4dba=_0x3227e3;for(let _0x3bc54a=0x0;_0x3bc54a<_0x434888[_0x9b4dba('0x3a')];_0x3bc54a+=0x1){_0xc3b5c9[_0x9b4dba('0x5c')](_0x9b4dba('0x2a'),{'FaxInteractionId':Number(_0x434888[_0x3bc54a]),'UserId':Number(_0x274060['id'])});}});}})[_0x257d75('0x4d')](function(){const _0x579f09=_0x257d75;if(_0x444637===_0x579f09('0x3')){const _0x532b2f=_[_0x579f09('0x24')](_0x274060[_0x579f09('0x8')],'id');return _0x274060[_0x579f09('0x58')](_0x532b2f)[_0x579f09('0x4d')](function(){const _0x368323=_0x579f09;for(let _0x301b99=0x0;_0x301b99<_0x532b2f[_0x368323('0x3a')];_0x301b99+=0x1){_0xc3b5c9[_0x368323('0x5c')](_0x368323('0x52'),{'SmsInteractionId':Number(_0x532b2f[_0x301b99]),'UserId':Number(_0x274060['id'])});}});}})[_0x257d75('0x4d')](function(){const _0x220500=_0x257d75;if(_0x444637===_0x220500('0x3')){const _0x367f90=_[_0x220500('0x24')](_0x274060[_0x220500('0xa')],'id');return _0x274060[_0x220500('0x48')](_0x367f90)[_0x220500('0x4d')](function(){const _0x39c273=_0x220500;for(let _0x5a7863=0x0;_0x5a7863<_0x367f90[_0x39c273('0x3a')];_0x5a7863+=0x1){_0xc3b5c9[_0x39c273('0x5c')](_0x39c273('0x5'),{'OpenchannelInteractionId':Number(_0x367f90[_0x5a7863]),'UserId':Number(_0x274060['id'])});}});}})['then'](function(){const _0x3d837a=_0x257d75;if(_0x444637===_0x3d837a('0x3')){const _0x572730=_[_0x3d837a('0x24')](_0x274060[_0x3d837a('0x31')],'id');return _0x274060[_0x3d837a('0x1a')](_0x572730)[_0x3d837a('0x4d')](function(){const _0x35c0c1=_0x3d837a;for(let _0x533af6=0x0;_0x533af6<_0x572730['length'];_0x533af6+=0x1){_0xc3b5c9[_0x35c0c1('0x5c')](_0x35c0c1('0x59'),{'WhatsappInteractionId':Number(_0x572730[_0x533af6]),'UserId':Number(_0x274060['id'])});}});}})[_0x257d75('0x2e')](function(_0xa39a54){const _0x522758=_0x257d75;_0x3b337c[_0x522758('0x63')](_0xa39a54);});}function onDisconnect(_0x5dbf33,_0x1ecc08){const _0x79acf8=_0x3d6ca6;joinOrLeave(_0x5dbf33,_0x79acf8('0x3'),_0x1ecc08);}function onConnect(_0x23949d){const _0x28c2fa=_0x3d6ca6;joinOrLeave(_0x23949d,_0x28c2fa('0x33'));}exports[_0x3d6ca6('0x21')]=function(_0x2a94f6){const _0x323a75=_0x3d6ca6;_0x2a94f6['on'](_0x323a75('0x46'),function(_0x57cedc){const _0x2f9e74=_0x323a75;_0x57cedc[_0x2f9e74('0x15')](0x0),_0x57cedc[_0x2f9e74('0x20')]=_0x57cedc[_0x2f9e74('0x3f')]['connection'][_0x2f9e74('0x38')]+':'+_0x57cedc[_0x2f9e74('0x3f')]['connection']['remotePort'],_0x57cedc[_0x2f9e74('0xd')]=new Date(),_0x57cedc['log']=function(_0x3a52c3){const _0x5979c0=_0x2f9e74;console[_0x5979c0('0x63')](_0x5979c0('0x1d')+_0x57cedc[_0x5979c0('0x30')][_0x5979c0('0x3b')]+'['+_0x57cedc[_0x5979c0('0x20')]+']',_0x3a52c3);},_0x57cedc['on'](_0x2f9e74('0x12'),function(){const _0xd37606=_0x2f9e74;onDisconnect(_0x57cedc,_0x2a94f6),_0x57cedc[_0xd37606('0x63')](_0xd37606('0x35'));}),onConnect(_0x57cedc),_0x57cedc['log']('CONNECTED');});};