Built motion from commit e493b9a4954b50a8ee6d0034ba3601cd210d989d. Version 3.0.0...
[motion-next.git] / server / config / socketio.js
1 'use strict';const a1055_0x3396=['remoteAddress','UserProfileResource','telephone','telephone:%s','OpenchannelQueue','Campaign','Trunk','map','WhatsappInteractions','SmsInteractions','getFaxQueues','sms','Trunks','findAll','connection','user','resourceId','voice:inbound','CONNECTED','925353rgaIWJ','user:%s','getWhatsappQueues','%s:queue:%s','fax','@mysqldb','getVoiceQueues','WhatsappQueues','push','format','setMaxListeners','voice','default','removeUserSmsInteractions','chat','print','findOne','SmsQueues','OpenchannelInteraction','FaxQueues','connectedAt','getMailQueues','SmsInteraction','FaxQueue','openchannel','WhatsappInteraction','userProfileId','agent','ChatQueue','User','user_has_fax_interactions:remove','type','@utils/console-logger','handshake','leave','IvrCampaigns','VoiceQueues','OpenchannelQueues','user_has_openchannel_interactions:remove','lodash','774544cSXJeL','role','UserProfileSection','removeUserChatInteractions','795209DEwlZr','where','campaign:%s:%s','ivr','then','2AkYPTI','removeUserFaxInteractions','OpenchannelInteractions','453844oVLumf','user_has_whatsapp_interactions:remove','voice:outbound','ChatInteractions','length','undefined','1088228wPLsjG','Agents','664832hASouC','include','VoiceQueue','MailQueue','socketIOConfig','DISCONNECTED','FaxInteraction','disconnect','address','emit','MailQueues','mail','MailInteraction','name','log','ChatQueues','WhatsappQueue','removeUserMailInteractions','autoAssociation','1301751eDKrfU','user_has_mail_interactions:remove','removeUserWhatsappInteractions','request','user_has_chat_interactions:remove','Telephones'];const a1055_0x3631=function(_0x3caa17,_0x2e2b81){_0x3caa17=_0x3caa17-0xad;let _0x33963a=a1055_0x3396[_0x3caa17];return _0x33963a;};const a1055_0x864935=a1055_0x3631;(function(_0x51da71,_0x3f3023){const _0x1ae61a=a1055_0x3631;while(!![]){try{const _0x2f8764=-parseInt(_0x1ae61a(0xed))+-parseInt(_0x1ae61a(0xf1))+parseInt(_0x1ae61a(0x101))+-parseInt(_0x1ae61a(0xf6))*-parseInt(_0x1ae61a(0xf9))+parseInt(_0x1ae61a(0xc5))+-parseInt(_0x1ae61a(0x114))+parseInt(_0x1ae61a(0xff));if(_0x2f8764===_0x3f3023)break;else _0x51da71['push'](_0x51da71['shift']());}catch(_0x275c34){_0x51da71['push'](_0x51da71['shift']());}}}(a1055_0x3396,0xae765));const _=require(a1055_0x864935(0xec)),util=require('util'),{db}=require(a1055_0x864935(0xca)),{consoleLogger}=require(a1055_0x864935(0xe5)),queryQueues={'attributes':['id',a1055_0x864935(0x10e)],'include':[{'as':a1055_0x864935(0x100),'model':db['User'],'attributes':['id','name',a1055_0x864935(0xee)],'raw':!![],'where':{'role':a1055_0x864935(0xe0)},'required':![]}]},queryTelephones={'raw':!![],'attributes':['id',a1055_0x864935(0x10e)],'where':{'role':a1055_0x864935(0xb4)}},queryTrunks={'raw':!![],'attributes':['id',a1055_0x864935(0x10e)]},queryAgents={'raw':!![],'attributes':['id',a1055_0x864935(0x10e)],'where':{'role':a1055_0x864935(0xe0)}},queryCampaigns={'raw':!![],'attributes':['id','name',a1055_0x864935(0xe4)],'where':{'type':a1055_0x864935(0xf4)}};function getAssociatedResources(_0x2febb0,_0x5ed440,_0x1a7f8f){const _0x55cec2=a1055_0x864935;return db[_0x55cec2(0xef)][_0x55cec2(0xd5)]({'where':{'name':_0x2febb0,'userProfileId':_0x5ed440},'raw':!![]})[_0x55cec2(0xf5)](function(_0x43a78a){const _0x2c13bc=_0x55cec2;if(_0x43a78a){if(_0x43a78a[_0x2c13bc(0x113)]){let _0x355a33;switch(_0x2febb0){case _0x2c13bc(0xe9):case _0x2c13bc(0x110):case'FaxQueues':case _0x2c13bc(0xd6):case _0x2c13bc(0x10b):case _0x2c13bc(0xea):case _0x2c13bc(0xcc):_0x355a33=queryQueues;break;case _0x2c13bc(0xb1):_0x355a33=queryTelephones;break;case _0x2c13bc(0xbe):_0x355a33=queryTrunks;break;case _0x2c13bc(0xe8):_0x355a33=queryCampaigns;break;default:break;}return _0x355a33?db[_0x1a7f8f][_0x2c13bc(0xbf)](_0x355a33):_0x355a33;}else return db[_0x2c13bc(0xb3)][_0x2c13bc(0xbf)]({'attributes':[_0x2c13bc(0xc2)],'where':{'sectionId':_0x43a78a['id']},'raw':!![]})[_0x2c13bc(0xf5)](function(_0x1e2029){const _0x32ac55=_0x2c13bc;if(_0x1e2029){const _0x59c2d6={'where':{'id':_[_0x32ac55(0xb9)](_0x1e2029,'resourceId')},'raw':!![]};switch(_0x1a7f8f){case _0x32ac55(0xe2):_0x59c2d6[_0x32ac55(0xf2)][_0x32ac55(0xee)]='telephone';break;case _0x32ac55(0xb7):_0x59c2d6['where']['type']=_0x32ac55(0xf4);break;}return db[_0x1a7f8f][_0x32ac55(0xbf)](_0x59c2d6);}else return[];});}else return[];})[_0x55cec2(0xf5)](function(_0x3d7090){return _0x3d7090;});}function joinOrLeaveQueues(_0x260779,_0x5dcd1c,_0x121674,_0x5dace4){const _0xf07ccb=a1055_0x864935;_0x260779[_0x5dcd1c](util[_0xf07ccb(0xce)](_0xf07ccb(0xc8),_0x121674,_0x5dace4[_0xf07ccb(0x10e)]));if(_0x5dace4[_0xf07ccb(0x100)])for(let _0x20a262=0x0;_0x20a262<_0x5dace4[_0xf07ccb(0x100)][_0xf07ccb(0xfd)];_0x20a262+=0x1){_0x260779[_0x5dcd1c](util[_0xf07ccb(0xce)]('user:%s',_0x5dace4['Agents'][_0x20a262]['name']));}}function joinOrLeave(_0x9bf9fc,_0x34fc75,_0x5fe2e0){const _0xb5abfb=a1055_0x864935;let _0x223d4a;_0x9bf9fc['handshake']['query']['id']&&db[_0xb5abfb(0xe2)][_0xb5abfb(0xd5)]({'attributes':['id',_0xb5abfb(0x10e),'role',_0xb5abfb(0xdf)],'where':{'id':_0x9bf9fc[_0xb5abfb(0xe6)]['query']['id']},'include':[{'model':db['ChatInteraction'],'as':_0xb5abfb(0xfc),'attributes':['id'],'raw':!![]},{'model':db[_0xb5abfb(0x10d)],'as':'MailInteractions','attributes':['id'],'raw':!![]},{'model':db[_0xb5abfb(0x107)],'as':'FaxInteractions','attributes':['id'],'raw':!![]},{'model':db[_0xb5abfb(0xdb)],'as':_0xb5abfb(0xbb),'attributes':['id'],'raw':!![]},{'model':db[_0xb5abfb(0xd7)],'as':'OpenchannelInteractions','attributes':['id'],'raw':!![]},{'model':db[_0xb5abfb(0xde)],'as':_0xb5abfb(0xba),'attributes':['id'],'raw':!![]}]})[_0xb5abfb(0xf5)](function(_0x300eee){const _0x49120e=_0xb5abfb;if(_0x300eee){_0x223d4a=_0x300eee,_0x9bf9fc[_0x34fc75](util[_0x49120e(0xce)](_0x49120e(0xc6),_0x300eee[_0x49120e(0x10e)]));const _0x2336dc=[];switch(_0x300eee['role']){case'admin':_0x9bf9fc[_0x34fc75](_0x49120e(0xc3)),_0x9bf9fc[_0x34fc75](_0x49120e(0xfb));typeof queryQueues[_0x49120e(0x102)]!==_0x49120e(0xfe)&&delete queryQueues[_0x49120e(0x102)];_0x2336dc[_0x49120e(0xcd)](db['VoiceQueue'][_0x49120e(0xbf)](queryQueues)),_0x2336dc[_0x49120e(0xcd)](db[_0x49120e(0xe1)][_0x49120e(0xbf)](queryQueues)),_0x2336dc[_0x49120e(0xcd)](db[_0x49120e(0xdc)]['findAll'](queryQueues)),_0x2336dc[_0x49120e(0xcd)](db['SmsQueue']['findAll'](queryQueues)),_0x2336dc['push'](db[_0x49120e(0x104)][_0x49120e(0xbf)](queryQueues)),_0x2336dc['push'](db['OpenchannelQueue']['findAll'](queryQueues)),_0x2336dc[_0x49120e(0xcd)](db[_0x49120e(0x111)][_0x49120e(0xbf)](queryQueues)),_0x2336dc[_0x49120e(0xcd)](db['User'][_0x49120e(0xbf)](queryTelephones)),_0x2336dc[_0x49120e(0xcd)](db['Trunk'][_0x49120e(0xbf)](queryTrunks)),_0x2336dc[_0x49120e(0xcd)](db['Campaign'][_0x49120e(0xbf)](queryCampaigns)),_0x2336dc[_0x49120e(0xcd)](db[_0x49120e(0xe2)][_0x49120e(0xbf)](queryAgents));break;case _0x49120e(0xc1):_0x9bf9fc[_0x34fc75](_0x49120e(0xc3)),_0x9bf9fc[_0x34fc75]('voice:outbound'),_0x2336dc[_0x49120e(0xcd)](getAssociatedResources(_0x49120e(0xe9),_0x300eee['userProfileId'],_0x49120e(0x103))),_0x2336dc[_0x49120e(0xcd)](getAssociatedResources(_0x49120e(0x110),_0x300eee[_0x49120e(0xdf)],_0x49120e(0xe1))),_0x2336dc[_0x49120e(0xcd)](getAssociatedResources(_0x49120e(0xd8),_0x300eee[_0x49120e(0xdf)],_0x49120e(0xdc))),_0x2336dc[_0x49120e(0xcd)](getAssociatedResources('SmsQueues',_0x300eee[_0x49120e(0xdf)],'SmsQueue')),_0x2336dc[_0x49120e(0xcd)](getAssociatedResources(_0x49120e(0x10b),_0x300eee[_0x49120e(0xdf)],'MailQueue')),_0x2336dc[_0x49120e(0xcd)](getAssociatedResources(_0x49120e(0xea),_0x300eee['userProfileId'],_0x49120e(0xb6))),_0x2336dc[_0x49120e(0xcd)](getAssociatedResources(_0x49120e(0xcc),_0x300eee[_0x49120e(0xdf)],_0x49120e(0x111))),_0x2336dc['push'](getAssociatedResources(_0x49120e(0xb1),_0x300eee['userProfileId'],_0x49120e(0xe2))),_0x2336dc[_0x49120e(0xcd)](getAssociatedResources(_0x49120e(0xbe),_0x300eee[_0x49120e(0xdf)],_0x49120e(0xb8))),_0x2336dc[_0x49120e(0xcd)](getAssociatedResources(_0x49120e(0xe8),_0x300eee[_0x49120e(0xdf)],_0x49120e(0xb7))),_0x2336dc[_0x49120e(0xcd)](db[_0x49120e(0xe2)][_0x49120e(0xbf)](queryAgents));break;case _0x49120e(0xe0):_0x9bf9fc[_0x34fc75]('voice:inbound'),_0x9bf9fc[_0x34fc75](_0x49120e(0xfb)),_0x2336dc['push'](_0x300eee[_0x49120e(0xcb)]({'attributes':['id',_0x49120e(0x10e)]})),_0x2336dc[_0x49120e(0xcd)](_0x300eee['getChatQueues']({'attributes':['id','name']})),_0x2336dc[_0x49120e(0xcd)](_0x300eee[_0x49120e(0xbc)]({'attributes':['id','name']})),_0x2336dc[_0x49120e(0xcd)](_0x300eee['getSmsQueues']({'attributes':['id',_0x49120e(0x10e)]})),_0x2336dc[_0x49120e(0xcd)](_0x300eee[_0x49120e(0xda)]({'attributes':['id',_0x49120e(0x10e)]})),_0x2336dc[_0x49120e(0xcd)](_0x300eee['getOpenchannelQueues']({'attributes':['id',_0x49120e(0x10e)]})),_0x2336dc[_0x49120e(0xcd)](_0x300eee[_0x49120e(0xc7)]({'attributes':['id','name']}));break;}return Promise['all'](_0x2336dc);}})[_0xb5abfb(0xf5)](function(_0x3a5885){const _0x29e727=_0xb5abfb;if(_0x3a5885&&_0x3a5885[_0x29e727(0xfd)])for(let _0x4fc9f5=0x0;_0x4fc9f5<_0x3a5885[_0x29e727(0xfd)];_0x4fc9f5+=0x1){for(let _0x507e68=0x0;_0x507e68<_0x3a5885[_0x4fc9f5][_0x29e727(0xfd)];_0x507e68+=0x1){switch(_0x4fc9f5){case 0x0:joinOrLeaveQueues(_0x9bf9fc,_0x34fc75,_0x29e727(0xd0),_0x3a5885[_0x4fc9f5][_0x507e68]);break;case 0x1:joinOrLeaveQueues(_0x9bf9fc,_0x34fc75,_0x29e727(0xd3),_0x3a5885[_0x4fc9f5][_0x507e68]);break;case 0x2:joinOrLeaveQueues(_0x9bf9fc,_0x34fc75,_0x29e727(0xc9),_0x3a5885[_0x4fc9f5][_0x507e68]);break;case 0x3:joinOrLeaveQueues(_0x9bf9fc,_0x34fc75,_0x29e727(0xbd),_0x3a5885[_0x4fc9f5][_0x507e68]);break;case 0x4:joinOrLeaveQueues(_0x9bf9fc,_0x34fc75,_0x29e727(0x10c),_0x3a5885[_0x4fc9f5][_0x507e68]);break;case 0x5:joinOrLeaveQueues(_0x9bf9fc,_0x34fc75,_0x29e727(0xdd),_0x3a5885[_0x4fc9f5][_0x507e68]);break;case 0x6:joinOrLeaveQueues(_0x9bf9fc,_0x34fc75,'whatsapp',_0x3a5885[_0x4fc9f5][_0x507e68]);break;case 0x7:_0x9bf9fc[_0x34fc75](util[_0x29e727(0xce)](_0x29e727(0xb5),_0x3a5885[_0x4fc9f5][_0x507e68]['name']));break;case 0x8:_0x9bf9fc[_0x34fc75](util[_0x29e727(0xce)]('trunk:%s',_0x3a5885[_0x4fc9f5][_0x507e68][_0x29e727(0x10e)]));break;case 0x9:_0x9bf9fc[_0x34fc75](util[_0x29e727(0xce)](_0x29e727(0xf3),_0x3a5885[_0x4fc9f5][_0x507e68][_0x29e727(0xe4)],_0x3a5885[_0x4fc9f5][_0x507e68][_0x29e727(0x10e)]));break;case 0xa:_0x9bf9fc[_0x34fc75](util[_0x29e727(0xce)](_0x29e727(0xc6),_0x3a5885[_0x4fc9f5][_0x507e68][_0x29e727(0x10e)]));break;}}}})[_0xb5abfb(0xf5)](function(){const _0xf69a33=_0xb5abfb;if(_0x34fc75==='leave'){const _0x1424ee=_['map'](_0x223d4a[_0xf69a33(0xfc)],'id');return _0x223d4a[_0xf69a33(0xf0)](_0x1424ee)['then'](function(){const _0x15efdb=_0xf69a33;for(let _0x2376c7=0x0;_0x2376c7<_0x1424ee[_0x15efdb(0xfd)];_0x2376c7+=0x1){_0x5fe2e0[_0x15efdb(0x10a)](_0x15efdb(0xb0),{'ChatInteractionId':Number(_0x1424ee[_0x2376c7]),'UserId':Number(_0x223d4a['id'])});}});}})[_0xb5abfb(0xf5)](function(){const _0x284789=_0xb5abfb;if(_0x34fc75==='leave'){const _0x42515e=_[_0x284789(0xb9)](_0x223d4a['MailInteractions'],'id');return _0x223d4a[_0x284789(0x112)](_0x42515e)[_0x284789(0xf5)](function(){const _0x537e99=_0x284789;for(let _0xc804e0=0x0;_0xc804e0<_0x42515e[_0x537e99(0xfd)];_0xc804e0+=0x1){_0x5fe2e0[_0x537e99(0x10a)](_0x537e99(0xad),{'MailInteractionId':Number(_0x42515e[_0xc804e0]),'UserId':Number(_0x223d4a['id'])});}});}})[_0xb5abfb(0xf5)](function(){const _0x4314f4=_0xb5abfb;if(_0x34fc75==='leave'){const _0x555331=_[_0x4314f4(0xb9)](_0x223d4a['FaxInteractions'],'id');return _0x223d4a[_0x4314f4(0xf7)](_0x555331)['then'](function(){const _0x969ed7=_0x4314f4;for(let _0x5ec68f=0x0;_0x5ec68f<_0x555331[_0x969ed7(0xfd)];_0x5ec68f+=0x1){_0x5fe2e0[_0x969ed7(0x10a)](_0x969ed7(0xe3),{'FaxInteractionId':Number(_0x555331[_0x5ec68f]),'UserId':Number(_0x223d4a['id'])});}});}})[_0xb5abfb(0xf5)](function(){const _0x410df2=_0xb5abfb;if(_0x34fc75===_0x410df2(0xe7)){const _0x1a36e0=_[_0x410df2(0xb9)](_0x223d4a[_0x410df2(0xbb)],'id');return _0x223d4a[_0x410df2(0xd2)](_0x1a36e0)[_0x410df2(0xf5)](function(){const _0x4f8418=_0x410df2;for(let _0x563f0b=0x0;_0x563f0b<_0x1a36e0[_0x4f8418(0xfd)];_0x563f0b+=0x1){_0x5fe2e0[_0x4f8418(0x10a)]('user_has_sms_interactions:remove',{'SmsInteractionId':Number(_0x1a36e0[_0x563f0b]),'UserId':Number(_0x223d4a['id'])});}});}})[_0xb5abfb(0xf5)](function(){const _0x31fddd=_0xb5abfb;if(_0x34fc75===_0x31fddd(0xe7)){const _0x22469a=_[_0x31fddd(0xb9)](_0x223d4a[_0x31fddd(0xf8)],'id');return _0x223d4a['removeUserOpenchannelInteractions'](_0x22469a)[_0x31fddd(0xf5)](function(){const _0x2caf9a=_0x31fddd;for(let _0x14c71a=0x0;_0x14c71a<_0x22469a[_0x2caf9a(0xfd)];_0x14c71a+=0x1){_0x5fe2e0[_0x2caf9a(0x10a)](_0x2caf9a(0xeb),{'OpenchannelInteractionId':Number(_0x22469a[_0x14c71a]),'UserId':Number(_0x223d4a['id'])});}});}})['then'](function(){const _0x3da035=_0xb5abfb;if(_0x34fc75===_0x3da035(0xe7)){const _0x4ccb72=_[_0x3da035(0xb9)](_0x223d4a[_0x3da035(0xba)],'id');return _0x223d4a[_0x3da035(0xae)](_0x4ccb72)['then'](function(){const _0x4a0090=_0x3da035;for(let _0x55fbd0=0x0;_0x55fbd0<_0x4ccb72[_0x4a0090(0xfd)];_0x55fbd0+=0x1){_0x5fe2e0['emit'](_0x4a0090(0xfa),{'WhatsappInteractionId':Number(_0x4ccb72[_0x55fbd0]),'UserId':Number(_0x223d4a['id'])});}});}})['catch'](function(_0x5b627d){const _0x149b89=_0xb5abfb;_0x9bf9fc[_0x149b89(0x10f)](_0x5b627d);});}function onDisconnect(_0x290bd1,_0x106d66){const _0x8ed083=a1055_0x864935;joinOrLeave(_0x290bd1,_0x8ed083(0xe7),_0x106d66);}function onConnect(_0x3d01b5){joinOrLeave(_0x3d01b5,'join');}function socketIOConfig(_0x1047c1){const _0x28a9d2=a1055_0x864935;_0x1047c1['on'](_0x28a9d2(0xc0),function(_0x474081){const _0x2d1a56=_0x28a9d2;_0x474081[_0x2d1a56(0xcf)](0x0),_0x474081[_0x2d1a56(0x109)]=_0x474081[_0x2d1a56(0xaf)][_0x2d1a56(0xc0)][_0x2d1a56(0xb2)]+':'+_0x474081[_0x2d1a56(0xaf)][_0x2d1a56(0xc0)]['remotePort'],_0x474081[_0x2d1a56(0xd9)]=new Date(),_0x474081[_0x2d1a56(0x10f)]=function(_0x5ddc18){const _0x32a8b0=_0x2d1a56;consoleLogger[_0x32a8b0(0xd4)]('SocketIO\x20'+_0x474081['nsp']['name']+'['+_0x474081[_0x32a8b0(0x109)]+']',_0x5ddc18);},_0x474081['on'](_0x2d1a56(0x108),function(){const _0x20c900=_0x2d1a56;onDisconnect(_0x474081,_0x1047c1),_0x474081[_0x20c900(0x10f)](_0x20c900(0x106));}),onConnect(_0x474081),_0x474081[_0x2d1a56(0x10f)](_0x2d1a56(0xc4));});}exports[a1055_0x864935(0x105)]=socketIOConfig,exports[a1055_0x864935(0xd1)]=socketIOConfig;