Built motion from commit f738f9592c388b9f9eb3948f400a5c9d717a3561. Version 3.0.0...
[motion-next.git] / server / api / whatsappAccount / whatsappAccount.controller.js
index b27d4e6..e945e2a 100644 (file)
@@ -1 +1 @@
-const a938_0x4567=['send','from','params','request','list','interaction','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','asc','UserId','applications','agent','update','unmanaged','keys','sendStatus','pick','stack','List','describe','index','entity\x20found','from\x20is\x20mandatory','length','key','WhatsappApplication','WhatsappInteraction','VIRTUAL','push','messageId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','updatedAt','where','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','body','notify','Body','WhatsappAccount,\x20%s,\x20%s,\x20%s','addAnswer','Applications','set','Messages','filter','autoclose','MessageSid','filters','count','removeAgents','nolimit','isArray','stringify','fields','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','From','api','mandatoryDispositionPause','like','bulkCreate','twilio','lodash','ContactId','undefined','body\x20is\x20mandatory\x20and\x20not\x20empty','message','omit','mapKey','model','../../mysqldb','rows','*,*,*,*','WhatsappAccount','AttachmentId','UserProfileResource','CmContact','whatsapp','status','merge','ListId','WhatsappAccount,\x20%s,\x20%s','no\x20available\x20attributes','map','DESC','ids','addAgents','Content-Type','userWhatsappAccount:save','mobile','query','startRouting','waitForTheAssignedAgent','attributes','role','CannedAnswer','options','../../config/logger','name','result','isNil','userWhatsappAccount:remove','Pause','fieldName','defaults','getAgents','dataValues','offset','Contacts','close','emit','created','WhatsappAccounts','limit','destroy','jayson/promise','getDispositions','User','CmList','error','end','get','UserProfileSection','http','includeAll','Disposition','account','create','sort','then','json','show','findOne','catch','Start','../../rediscache','getApplications','includes','debug','rawAttributes','sequelize','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','info','removeDispositions','type','removeAnswers','intersection','include','findAll','out','request\x20sent','user','priority','addDisposition','difference','WhatsappMessage','getAnswers','order','addApplications','receiveMessage','WhatsappAccountId'];(function(_0x3397ca,_0x178cdc){const _0x4567eb=function(_0x124e76){while(--_0x124e76){_0x3397ca['push'](_0x3397ca['shift']());}};_0x4567eb(++_0x178cdc);}(a938_0x4567,0x186));const a938_0x124e=function(_0x3397ca,_0x178cdc){_0x3397ca=_0x3397ca-0xd8;let _0x4567eb=a938_0x4567[_0x3397ca];return _0x4567eb;};const a938_0x4c2b5f=a938_0x124e;'use strict';const _=require(a938_0x4c2b5f(0x163)),qs=require('../../components/parsers/qs'),logger=require(a938_0x4c2b5f(0xe9))(a938_0x4c2b5f(0x15e)),{getSocket}=require(a938_0x4c2b5f(0x10f)),socket=getSocket(),{db}=require(a938_0x4c2b5f(0x16b)),{Op,ValidationError}=require('sequelize');require('./whatsappAccount.socket')['register'](socket);const jayson=require(a938_0x4c2b5f(0xfb)),client=jayson['client'][a938_0x4c2b5f(0x103)]({'port':0x232c});function respondWithRpcPromise(_0x46bf32,_0x1aba18,_0x1c5c40,_0x2f476c){return new Promise(function(_0x26c1c9,_0xad3f88){const _0x167565=a938_0x124e,_0x214116=_0x2f476c||client;return _0x214116[_0x167565(0x12c)](_0x46bf32,_0x1c5c40)[_0x167565(0x109)](function(_0x2f86de){const _0x5a62a0=_0x167565;logger[_0x5a62a0(0x116)](_0x5a62a0(0xd9),_0x1aba18,_0x5a62a0(0x11e)),logger[_0x5a62a0(0x112)](_0x5a62a0(0x14d),_0x1aba18,_0x5a62a0(0x11e),JSON[_0x5a62a0(0x15a)](_0x2f86de));if(_0x2f86de[_0x5a62a0(0xff)]){if(_0x2f86de[_0x5a62a0(0xff)]['code']===0x1f4)return logger['error'](_0x5a62a0(0xd9),_0x1aba18,_0x2f86de['error'][_0x5a62a0(0x167)]),_0xad3f88(_0x2f86de[_0x5a62a0(0xff)][_0x5a62a0(0x167)]);return logger[_0x5a62a0(0xff)](_0x5a62a0(0xd9),_0x1aba18,_0x2f86de[_0x5a62a0(0xff)][_0x5a62a0(0x167)]),_0x26c1c9(_0x2f86de[_0x5a62a0(0xff)][_0x5a62a0(0x167)]);}else logger[_0x5a62a0(0x116)](_0x5a62a0(0xd9),_0x1aba18,_0x5a62a0(0x11e)),_0x26c1c9(_0x2f86de[_0x5a62a0(0xeb)][_0x5a62a0(0x167)]);})[_0x167565(0x10d)](function(_0x1eb4ba){const _0x39993b=_0x167565;logger[_0x39993b(0xff)](_0x39993b(0xd9),_0x1aba18,_0x1eb4ba),_0xad3f88(_0x1eb4ba);});});}function respondWithStatusCode(_0x42b198,_0x143d77){return _0x143d77=_0x143d77||0xcc,function(_0x54b577){const _0x3b11b4=a938_0x124e;if(_0x54b577)return _0x42b198[_0x3b11b4(0x137)](_0x143d77);return _0x42b198[_0x3b11b4(0x173)](_0x143d77)[_0x3b11b4(0x100)]();};}function respondWithResult(_0x5bc405,_0x2ea33c){return _0x2ea33c=_0x2ea33c||0xc8,function(_0x1f8b37){const _0x2d3e00=a938_0x124e;if(_0x1f8b37)return _0x5bc405[_0x2d3e00(0x173)](_0x2ea33c)[_0x2d3e00(0x10a)](_0x1f8b37);};}function respondWithFilteredResult(_0x307c94,_0x41ce12){return function(_0x38fd98){const _0x4fe881=a938_0x124e;if(_0x38fd98){const _0x1fc043=_0x38fd98[_0x4fe881(0x156)],_0x5478f8=_0x41ce12['offset'];let _0x37553f=_0x41ce12['offset']+_0x41ce12[_0x4fe881(0xf9)],_0x31e642;return _0x37553f>=_0x1fc043?(_0x37553f=_0x1fc043,_0x31e642=0xc8):_0x31e642=0xce,_0x307c94[_0x4fe881(0x173)](_0x31e642),_0x307c94['set']('Content-Range',_0x5478f8+'-'+_0x37553f+'/'+_0x1fc043)[_0x4fe881(0x10a)](_0x38fd98);}return null;};}function saveUpdates(_0x5e522a){return function(_0x2d53be){const _0x136e03=a938_0x124e;if(_0x2d53be)return _0x2d53be[_0x136e03(0x134)](_0x5e522a)[_0x136e03(0x109)](function(_0x3a3cb7){return _0x3a3cb7;});return null;};}function removeEntity(_0x46c426){return function(_0x5e17bd){const _0x36721c=a938_0x124e;if(_0x5e17bd)return _0x5e17bd[_0x36721c(0xfa)]()[_0x36721c(0x109)](function(){const _0x56d2d8=_0x36721c,_0x398b49=_0x5e17bd[_0x56d2d8(0x101)]({'plain':!![]}),_0x520c6f='WhatsappAccounts';return db[_0x56d2d8(0x170)]['destroy']({'where':{'type':_0x520c6f,'resourceId':_0x398b49['id']}})[_0x56d2d8(0x109)](function(){return _0x5e17bd;});})['then'](function(){const _0x43673f=_0x36721c;_0x46c426[_0x43673f(0x173)](0xcc)['end']();});};}function handleEntityNotFound(_0x1b57cf){return function(_0x2ec2c3){const _0x9e1bc7=a938_0x124e;return!_0x2ec2c3&&_0x1b57cf[_0x9e1bc7(0x137)](0x194),_0x2ec2c3;};}function handleError(_0x5eeba1,_0x270b55){return _0x270b55=_0x270b55||0x1f4,function(_0x2492be){const _0x39cc6c=a938_0x124e;logger[_0x39cc6c(0xff)](_0x2492be[_0x39cc6c(0x139)]),_0x2492be[_0x39cc6c(0xea)]&&delete _0x2492be[_0x39cc6c(0xea)],_0x5eeba1['status'](_0x270b55)[_0x39cc6c(0x129)](_0x2492be);};}exports[a938_0x4c2b5f(0x13c)]=function(_0x3e697e,_0x3e626a){const _0x1f937b=a938_0x4c2b5f;let _0x57b14a={'include':[{'model':db[_0x1f937b(0xee)],'as':_0x1f937b(0x15f)}]};const _0x3b349a={},_0x589694={'count':0x0,'rows':[]},_0x1d0935=_['map'](db[_0x1f937b(0x16e)][_0x1f937b(0x113)],function(_0xc182d0){const _0x32905e=_0x1f937b;return{'name':_0xc182d0[_0x32905e(0xef)],'type':_0xc182d0[_0x32905e(0x118)][_0x32905e(0x140)]};});_0x3b349a['model']=_[_0x1f937b(0xdb)](_0x1d0935,_0x1f937b(0xea)),_0x3b349a[_0x1f937b(0xe2)]=_[_0x1f937b(0x136)](_0x3e697e[_0x1f937b(0xe2)]),_0x3b349a['filters']=_[_0x1f937b(0x11a)](_0x3b349a[_0x1f937b(0x16a)],_0x3b349a[_0x1f937b(0xe2)]),_0x57b14a[_0x1f937b(0xe5)]=_[_0x1f937b(0x11a)](_0x3b349a[_0x1f937b(0x16a)],qs['fields'](_0x3e697e[_0x1f937b(0xe2)][_0x1f937b(0x15b)])),_0x57b14a[_0x1f937b(0xe5)]=_0x57b14a['attributes'][_0x1f937b(0x13f)]?_0x57b14a[_0x1f937b(0xe5)]:_0x3b349a['model'];typeof _0x3e697e[_0x1f937b(0xe2)][_0x1f937b(0x158)]==='undefined'&&(_0x57b14a[_0x1f937b(0xf9)]=qs[_0x1f937b(0xf9)](_0x3e697e['query'][_0x1f937b(0xf9)]),_0x57b14a[_0x1f937b(0xf3)]=qs['offset'](_0x3e697e['query'][_0x1f937b(0xf3)]));_0x57b14a[_0x1f937b(0x125)]=qs[_0x1f937b(0x108)](_0x3e697e[_0x1f937b(0xe2)][_0x1f937b(0x108)]),_0x57b14a[_0x1f937b(0x148)]=qs[_0x1f937b(0x155)](_[_0x1f937b(0x138)](_0x3e697e[_0x1f937b(0xe2)],_0x3b349a['filters']),_0x1d0935);_0x3e697e[_0x1f937b(0xe2)]['filter']&&(_0x57b14a[_0x1f937b(0x148)]=_[_0x1f937b(0x174)](_0x57b14a[_0x1f937b(0x148)],{[Op['or']]:_[_0x1f937b(0xdb)](_0x1d0935,function(_0x45ecc1){const _0x53fd89=_0x1f937b;if(_0x45ecc1[_0x53fd89(0x118)]!==_0x53fd89(0x143)){const _0x1b6527={};return _0x1b6527[_0x45ecc1[_0x53fd89(0xea)]]={[Op['like']]:'%'+_0x3e697e[_0x53fd89(0xe2)]['filter']+'%'},_0x1b6527;}})}));_0x57b14a=_[_0x1f937b(0x174)]({},_0x57b14a,_0x3e697e[_0x1f937b(0xe8)]);const _0x1bddc8={'where':_0x57b14a[_0x1f937b(0x148)]};return db[_0x1f937b(0x16e)][_0x1f937b(0x156)](_0x1bddc8)['then'](function(_0x2ba344){const _0xf9a0b3=_0x1f937b;return _0x589694['count']=_0x2ba344,_0x3e697e[_0xf9a0b3(0xe2)][_0xf9a0b3(0x104)]&&(_0x57b14a[_0xf9a0b3(0x11b)]=[{'all':!![]}]),db[_0xf9a0b3(0x16e)][_0xf9a0b3(0x11c)](_0x57b14a);})[_0x1f937b(0x109)](function(_0xa3c036){const _0x3e51b8=_0x1f937b;return _0x589694[_0x3e51b8(0x16c)]=_0xa3c036,_0x589694;})[_0x1f937b(0x109)](respondWithFilteredResult(_0x3e626a,_0x57b14a))[_0x1f937b(0x10d)](handleError(_0x3e626a,null));},exports[a938_0x4c2b5f(0x10b)]=function(_0x4927e0,_0x13aed8){const _0x12603e=a938_0x4c2b5f;let _0x9f5f07={'raw':![],'where':{'id':_0x4927e0['params']['id']},'include':[{'model':db[_0x12603e(0xee)],'as':_0x12603e(0x15f)}]};const _0x39ec27={};return _0x39ec27[_0x12603e(0x16a)]=_[_0x12603e(0x136)](db[_0x12603e(0x16e)][_0x12603e(0x113)]),_0x39ec27[_0x12603e(0xe2)]=_[_0x12603e(0x136)](_0x4927e0[_0x12603e(0xe2)]),_0x39ec27[_0x12603e(0x155)]=_[_0x12603e(0x11a)](_0x39ec27[_0x12603e(0x16a)],_0x39ec27['query']),_0x9f5f07[_0x12603e(0xe5)]=_[_0x12603e(0x11a)](_0x39ec27[_0x12603e(0x16a)],qs[_0x12603e(0x15b)](_0x4927e0['query'][_0x12603e(0x15b)])),_0x9f5f07['attributes']=_0x9f5f07['attributes']['length']?_0x9f5f07[_0x12603e(0xe5)]:_0x39ec27['model'],_0x4927e0[_0x12603e(0xe2)][_0x12603e(0x104)]&&(_0x9f5f07['include']=[{'all':!![]}]),_0x9f5f07=_[_0x12603e(0x174)]({},_0x9f5f07,_0x4927e0[_0x12603e(0xe8)]),db[_0x12603e(0x16e)][_0x12603e(0x10c)](_0x9f5f07)[_0x12603e(0x109)](handleEntityNotFound(_0x13aed8,null))[_0x12603e(0x109)](respondWithResult(_0x13aed8,null))['catch'](handleError(_0x13aed8,null));},exports['create']=function(_0x49b110,_0x44f12e){const _0x4a05b3=a938_0x4c2b5f;return db[_0x4a05b3(0x16e)][_0x4a05b3(0x107)](_0x49b110[_0x4a05b3(0x14a)],{})['then'](function(_0x507c64){const _0xa8c78a=_0x4a05b3,_0x572d7f=_0x49b110[_0xa8c78a(0x11f)][_0xa8c78a(0x101)]({'plain':!![]});if(!_0x572d7f)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x572d7f[_0xa8c78a(0xe6)]===_0xa8c78a(0x11f)){const _0x1158e4=_0x507c64['get']({'plain':!![]}),_0x2dadc3=_0xa8c78a(0xf8);return db[_0xa8c78a(0x102)][_0xa8c78a(0x10c)]({'where':{'name':_0x2dadc3,'userProfileId':_0x572d7f['userProfileId']},'raw':!![]})['then'](function(_0x1c0f23){const _0x225a0e=_0xa8c78a;return _0x1c0f23&&_0x1c0f23['autoAssociation']===0x0?db[_0x225a0e(0x170)][_0x225a0e(0x107)]({'name':_0x1158e4[_0x225a0e(0xea)],'resourceId':_0x1158e4['id'],'type':_0x1c0f23['name'],'sectionId':_0x1c0f23['id']},{})['then'](function(){return _0x507c64;}):_0x507c64;})[_0xa8c78a(0x10d)](function(_0x211d2b){const _0x206761=_0xa8c78a;logger[_0x206761(0xff)](_0x206761(0x146),_0x211d2b);throw _0x211d2b;});}return _0x507c64;})[_0x4a05b3(0x109)](respondWithResult(_0x44f12e,0xc9))[_0x4a05b3(0x10d)](handleError(_0x44f12e,null));},exports['update']=function(_0x206425,_0x30c676){const _0x3272a3=a938_0x4c2b5f;return _0x206425[_0x3272a3(0x14a)]['id']&&delete _0x206425[_0x3272a3(0x14a)]['id'],db[_0x3272a3(0x16e)]['findOne']({'where':{'id':_0x206425[_0x3272a3(0x12b)]['id']},'include':[{'model':db[_0x3272a3(0xee)],'as':_0x3272a3(0x15f)}]})[_0x3272a3(0x109)](handleEntityNotFound(_0x30c676,null))[_0x3272a3(0x109)](saveUpdates(_0x206425[_0x3272a3(0x14a)],null))[_0x3272a3(0x109)](respondWithResult(_0x30c676,null))[_0x3272a3(0x10d)](handleError(_0x30c676,null));},exports['destroy']=function(_0x2c3135,_0xea2f17){const _0x217f6c=a938_0x4c2b5f;return db[_0x217f6c(0x16e)][_0x217f6c(0x10c)]({'where':{'id':_0x2c3135[_0x217f6c(0x12b)]['id']}})[_0x217f6c(0x109)](handleEntityNotFound(_0xea2f17,null))[_0x217f6c(0x109)](removeEntity(_0xea2f17,null))[_0x217f6c(0x10d)](handleError(_0xea2f17,null));},exports['describe']=function(_0x4d05e7,_0x16f649){const _0x3fc254=a938_0x4c2b5f;return db['WhatsappAccount'][_0x3fc254(0x13b)]()[_0x3fc254(0x109)](respondWithResult(_0x16f649,null))[_0x3fc254(0x10d)](handleError(_0x16f649,null));},exports[a938_0x4c2b5f(0x121)]=function(_0x46af0d,_0x22ee7c){const _0x1f0e5a=a938_0x4c2b5f;return _0x46af0d[_0x1f0e5a(0x14a)]['id']&&delete _0x46af0d['body']['id'],db['WhatsappAccount'][_0x1f0e5a(0x10c)]({'where':{'id':_0x46af0d[_0x1f0e5a(0x12b)]['id']}})[_0x1f0e5a(0x109)](handleEntityNotFound(_0x22ee7c,null))[_0x1f0e5a(0x109)](function(_0x51bc9b){const _0x3dea61=_0x1f0e5a;if(_0x51bc9b)return _0x46af0d[_0x3dea61(0x14a)][_0x3dea61(0x128)]=_0x51bc9b['id'],db[_0x3dea61(0x105)][_0x3dea61(0x107)](_0x46af0d[_0x3dea61(0x14a)]);})[_0x1f0e5a(0x109)](respondWithResult(_0x22ee7c,null))[_0x1f0e5a(0x10d)](handleError(_0x22ee7c,null));},exports[a938_0x4c2b5f(0xfc)]=function(_0x2adb2e,_0x2d982e){const _0x2fc6f4=a938_0x4c2b5f;let _0x1dfdb8={'raw':![],'where':{}};const _0xcfaee5={},_0x1e3c70={'count':0x0,'rows':[]};return db[_0x2fc6f4(0x16e)][_0x2fc6f4(0x10c)]({'where':{'id':_0x2adb2e[_0x2fc6f4(0x12b)]['id']}})['then'](handleEntityNotFound(_0x2d982e,null))['then'](function(_0x4316db){const _0x26e2b3=_0x2fc6f4;if(_0x4316db)return _0xcfaee5['model']=_['keys'](db[_0x26e2b3(0x105)]['rawAttributes']),_0xcfaee5[_0x26e2b3(0xe2)]=_[_0x26e2b3(0x136)](_0x2adb2e[_0x26e2b3(0xe2)]),_0xcfaee5[_0x26e2b3(0x155)]=_[_0x26e2b3(0x11a)](_0xcfaee5[_0x26e2b3(0x16a)],_0xcfaee5[_0x26e2b3(0xe2)]),_0x1dfdb8[_0x26e2b3(0xe5)]=_[_0x26e2b3(0x11a)](_0xcfaee5[_0x26e2b3(0x16a)],qs[_0x26e2b3(0x15b)](_0x2adb2e[_0x26e2b3(0xe2)][_0x26e2b3(0x15b)])),_0x1dfdb8[_0x26e2b3(0xe5)]=_0x1dfdb8[_0x26e2b3(0xe5)]['length']?_0x1dfdb8['attributes']:_0xcfaee5['model'],typeof _0x2adb2e[_0x26e2b3(0xe2)][_0x26e2b3(0x158)]===_0x26e2b3(0x165)&&(_0x1dfdb8[_0x26e2b3(0xf9)]=qs['limit'](_0x2adb2e[_0x26e2b3(0xe2)]['limit']),_0x1dfdb8['offset']=qs[_0x26e2b3(0xf3)](_0x2adb2e['query']['offset'])),_0x1dfdb8[_0x26e2b3(0x125)]=qs[_0x26e2b3(0x108)](_0x2adb2e['query'][_0x26e2b3(0x108)]),_0x1dfdb8['where']=qs[_0x26e2b3(0x155)](_[_0x26e2b3(0x138)](_0x2adb2e[_0x26e2b3(0xe2)],_0xcfaee5['filters'])),_0x1dfdb8['where'][_0x26e2b3(0x128)]=_0x4316db['id'],_0x2adb2e[_0x26e2b3(0xe2)][_0x26e2b3(0x152)]&&(_0x1dfdb8['where']=_[_0x26e2b3(0x174)](_0x1dfdb8[_0x26e2b3(0x148)],{[Op['or']]:_[_0x26e2b3(0xdb)](_0x1dfdb8['attributes'],function(_0x2f1cd2){const _0x2ae5d1=_0x26e2b3,_0x94480b={};return _0x94480b[_0x2f1cd2]={[Op['like']]:'%'+_0x2adb2e['query'][_0x2ae5d1(0x152)]+'%'},_0x94480b;})})),_0x1dfdb8=_[_0x26e2b3(0x174)]({},_0x1dfdb8,_0x2adb2e[_0x26e2b3(0xe8)]),db['Disposition'][_0x26e2b3(0x156)]({'where':_0x1dfdb8['where']})[_0x26e2b3(0x109)](function(_0x2b7a7c){const _0x53741c=_0x26e2b3;return _0x1e3c70[_0x53741c(0x156)]=_0x2b7a7c,_0x2adb2e[_0x53741c(0xe2)]['includeAll']&&(_0x1dfdb8['include']=[{'all':!![]}]),db[_0x53741c(0x105)][_0x53741c(0x11c)](_0x1dfdb8);})['then'](function(_0x9f0062){const _0x4bee5c=_0x26e2b3;return _0x1e3c70[_0x4bee5c(0x16c)]=_0x9f0062,_0x1e3c70;});})[_0x2fc6f4(0x109)](respondWithFilteredResult(_0x2d982e,_0x1dfdb8))[_0x2fc6f4(0x10d)](handleError(_0x2d982e,null));},exports[a938_0x4c2b5f(0x117)]=function(_0x77da71,_0x37f14c){const _0x3a861a=a938_0x4c2b5f;return db[_0x3a861a(0x16e)]['findOne']({'where':{'id':_0x77da71[_0x3a861a(0x12b)]['id']}})[_0x3a861a(0x109)](handleEntityNotFound(_0x37f14c,null))[_0x3a861a(0x109)](function(_0x136dc1){const _0x1cec0b=_0x3a861a;if(_0x136dc1)return _0x136dc1[_0x1cec0b(0x117)](_0x77da71[_0x1cec0b(0xe2)][_0x1cec0b(0xdd)]);})[_0x3a861a(0x109)](respondWithStatusCode(_0x37f14c,null))[_0x3a861a(0x10d)](handleError(_0x37f14c,null));},exports[a938_0x4c2b5f(0x14e)]=function(_0x637acb,_0x275b6c){const _0x5e03d4=a938_0x4c2b5f;return _0x637acb[_0x5e03d4(0x14a)]['id']&&delete _0x637acb[_0x5e03d4(0x14a)]['id'],db[_0x5e03d4(0x16e)][_0x5e03d4(0x10c)]({'where':{'id':_0x637acb['params']['id']}})[_0x5e03d4(0x109)](handleEntityNotFound(_0x275b6c,null))[_0x5e03d4(0x109)](function(_0xa87745){const _0x167fe3=_0x5e03d4;if(_0xa87745)return _0x637acb[_0x167fe3(0x14a)][_0x167fe3(0x128)]=_0xa87745['id'],db[_0x167fe3(0xe7)][_0x167fe3(0x107)](_0x637acb[_0x167fe3(0x14a)]);})[_0x5e03d4(0x109)](respondWithResult(_0x275b6c,null))[_0x5e03d4(0x10d)](handleError(_0x275b6c,null));},exports[a938_0x4c2b5f(0x124)]=function(_0x26516a,_0x148367){const _0x1ce310=a938_0x4c2b5f;let _0x2fde0d={'raw':![],'where':{}};const _0x197434={},_0x254441={'count':0x0,'rows':[]};return db[_0x1ce310(0x16e)][_0x1ce310(0x10c)]({'where':{'id':_0x26516a[_0x1ce310(0x12b)]['id']}})[_0x1ce310(0x109)](handleEntityNotFound(_0x148367,null))[_0x1ce310(0x109)](function(_0x27f25b){const _0x43ca9e=_0x1ce310;if(_0x27f25b)return _0x197434[_0x43ca9e(0x16a)]=_['keys'](db[_0x43ca9e(0xe7)][_0x43ca9e(0x113)]),_0x197434['query']=_[_0x43ca9e(0x136)](_0x26516a[_0x43ca9e(0xe2)]),_0x197434[_0x43ca9e(0x155)]=_['intersection'](_0x197434['model'],_0x197434[_0x43ca9e(0xe2)]),_0x2fde0d['attributes']=_[_0x43ca9e(0x11a)](_0x197434[_0x43ca9e(0x16a)],qs['fields'](_0x26516a[_0x43ca9e(0xe2)][_0x43ca9e(0x15b)])),_0x2fde0d['attributes']=_0x2fde0d[_0x43ca9e(0xe5)][_0x43ca9e(0x13f)]?_0x2fde0d[_0x43ca9e(0xe5)]:_0x197434[_0x43ca9e(0x16a)],typeof _0x26516a[_0x43ca9e(0xe2)][_0x43ca9e(0x158)]==='undefined'&&(_0x2fde0d[_0x43ca9e(0xf9)]=qs[_0x43ca9e(0xf9)](_0x26516a[_0x43ca9e(0xe2)][_0x43ca9e(0xf9)]),_0x2fde0d[_0x43ca9e(0xf3)]=qs['offset'](_0x26516a['query'][_0x43ca9e(0xf3)])),_0x2fde0d[_0x43ca9e(0x125)]=qs[_0x43ca9e(0x108)](_0x26516a[_0x43ca9e(0xe2)][_0x43ca9e(0x108)]),_0x2fde0d[_0x43ca9e(0x148)]=qs[_0x43ca9e(0x155)](_[_0x43ca9e(0x138)](_0x26516a['query'],_0x197434['filters'])),_0x2fde0d['where'][_0x43ca9e(0x128)]=_0x27f25b['id'],_0x26516a['query'][_0x43ca9e(0x152)]&&(_0x2fde0d[_0x43ca9e(0x148)]=_['merge'](_0x2fde0d[_0x43ca9e(0x148)],{[Op['or']]:_[_0x43ca9e(0xdb)](_0x2fde0d[_0x43ca9e(0xe5)],function(_0x18a5b4){const _0xe8f8a7=_0x43ca9e,_0x2c9f69={};return _0x2c9f69[_0x18a5b4]={[Op[_0xe8f8a7(0x160)]]:'%'+_0x26516a[_0xe8f8a7(0xe2)][_0xe8f8a7(0x152)]+'%'},_0x2c9f69;})})),_0x2fde0d=_[_0x43ca9e(0x174)]({},_0x2fde0d,_0x26516a[_0x43ca9e(0xe8)]),db['CannedAnswer']['count']({'where':_0x2fde0d[_0x43ca9e(0x148)]})[_0x43ca9e(0x109)](function(_0x57edcf){const _0x258fa5=_0x43ca9e;return _0x254441[_0x258fa5(0x156)]=_0x57edcf,_0x26516a['query'][_0x258fa5(0x104)]&&(_0x2fde0d[_0x258fa5(0x11b)]=[{'all':!![]}]),db[_0x258fa5(0xe7)][_0x258fa5(0x11c)](_0x2fde0d);})['then'](function(_0x468b46){const _0xe14e02=_0x43ca9e;return _0x254441[_0xe14e02(0x16c)]=_0x468b46,_0x254441;});})[_0x1ce310(0x109)](respondWithFilteredResult(_0x148367,_0x2fde0d))[_0x1ce310(0x10d)](handleError(_0x148367,null));},exports[a938_0x4c2b5f(0x119)]=function(_0x493222,_0xdef93c){const _0x3a170f=a938_0x4c2b5f;return db[_0x3a170f(0x16e)][_0x3a170f(0x10c)]({'where':{'id':_0x493222[_0x3a170f(0x12b)]['id']}})[_0x3a170f(0x109)](handleEntityNotFound(_0xdef93c,null))['then'](function(_0x274653){const _0x4a9e07=_0x3a170f;if(_0x274653)return _0x274653[_0x4a9e07(0x119)](_0x493222[_0x4a9e07(0xe2)][_0x4a9e07(0xdd)]);})[_0x3a170f(0x109)](respondWithStatusCode(_0xdef93c,null))[_0x3a170f(0x10d)](handleError(_0xdef93c,null));},exports[a938_0x4c2b5f(0xde)]=function(_0x49e862,_0x388f05){const _0x39f003=a938_0x4c2b5f;return db['WhatsappAccount']['findOne']({'where':{'id':_0x49e862['params']['id']}})[_0x39f003(0x109)](function(_0x467463){const _0x108207=_0x39f003;if(_0x467463)return _0x467463['addAgents'](_0x49e862[_0x108207(0x14a)]['ids'],{'through':_[_0x108207(0x168)](_0x49e862[_0x108207(0x14a)],[_0x108207(0xdd),'id'])})['then'](function(_0x390551){const _0x136e90=_0x108207;for(let _0x5c6399=0x0;_0x5c6399<_0x49e862[_0x136e90(0x14a)][_0x136e90(0xdd)][_0x136e90(0x13f)];_0x5c6399+=0x1){socket['emit'](_0x136e90(0xe0),{'UserId':_0x49e862[_0x136e90(0x14a)]['ids'][_0x5c6399],'WhatsappAccountId':_0x49e862[_0x136e90(0x12b)]['id']});}return _0x390551;});})[_0x39f003(0x109)](respondWithResult(_0x388f05,null))[_0x39f003(0x10d)](handleError(_0x388f05,null));},exports['removeAgents']=function(_0x2feeee,_0x14b5b6){const _0x40e6cf=a938_0x4c2b5f;return db[_0x40e6cf(0x16e)][_0x40e6cf(0x10c)]({'where':{'id':_0x2feeee[_0x40e6cf(0x12b)]['id']}})[_0x40e6cf(0x109)](handleEntityNotFound(_0x14b5b6,null))[_0x40e6cf(0x109)](function(_0x4c2644){const _0x142192=_0x40e6cf;if(_0x4c2644)return _0x4c2644[_0x142192(0x157)](_0x2feeee['query'][_0x142192(0xdd)])[_0x142192(0x109)](function(){const _0x3409a4=_0x142192;if(_[_0x3409a4(0x159)](_0x2feeee['query'][_0x3409a4(0xdd)]))for(let _0x2500fe=0x0;_0x2500fe<_0x2feeee[_0x3409a4(0xe2)][_0x3409a4(0xdd)]['length'];_0x2500fe+=0x1){socket[_0x3409a4(0xf6)](_0x3409a4(0xed),{'UserId':Number(_0x2feeee[_0x3409a4(0xe2)]['ids'][_0x2500fe]),'WhatsappAccountId':Number(_0x2feeee[_0x3409a4(0x12b)]['id'])});}else socket[_0x3409a4(0xf6)](_0x3409a4(0xed),{'UserId':Number(_0x2feeee[_0x3409a4(0xe2)][_0x3409a4(0xdd)]),'WhatsappAccountId':Number(_0x2feeee['params']['id'])});});})[_0x40e6cf(0x109)](respondWithStatusCode(_0x14b5b6,null))[_0x40e6cf(0x10d)](handleError(_0x14b5b6,null));},exports[a938_0x4c2b5f(0xf1)]=function(_0x5e7be1,_0x1c0b92){const _0x225923=a938_0x4c2b5f;let _0x5c63d5={};const _0x18f4ed={};let _0x4ff55f,_0x3b4930;return db[_0x225923(0x16e)]['findOne']({'where':{'id':_0x5e7be1[_0x225923(0x12b)]['id']}})[_0x225923(0x109)](handleEntityNotFound(_0x1c0b92,null))[_0x225923(0x109)](function(_0x6df7d1){const _0x4676b4=_0x225923;if(_0x6df7d1)return _0x4ff55f=_0x6df7d1,_0x18f4ed[_0x4676b4(0x16a)]=_[_0x4676b4(0x136)](db[_0x4676b4(0xfd)][_0x4676b4(0x113)]),_0x18f4ed[_0x4676b4(0xe2)]=_[_0x4676b4(0x136)](_0x5e7be1[_0x4676b4(0xe2)]),_0x18f4ed['filters']=_[_0x4676b4(0x11a)](_0x18f4ed['model'],_0x18f4ed[_0x4676b4(0xe2)]),_0x5c63d5[_0x4676b4(0xe5)]=_[_0x4676b4(0x11a)](_0x18f4ed[_0x4676b4(0x16a)],qs[_0x4676b4(0x15b)](_0x5e7be1[_0x4676b4(0xe2)][_0x4676b4(0x15b)])),_0x5c63d5[_0x4676b4(0xe5)]=_0x5c63d5['attributes'][_0x4676b4(0x13f)]?_0x5c63d5[_0x4676b4(0xe5)]:_0x18f4ed[_0x4676b4(0x16a)],_0x5c63d5['order']=qs[_0x4676b4(0x108)](_0x5e7be1[_0x4676b4(0xe2)][_0x4676b4(0x108)]),_0x5c63d5[_0x4676b4(0x148)]=qs[_0x4676b4(0x155)](_[_0x4676b4(0x138)](_0x5e7be1[_0x4676b4(0xe2)],_0x18f4ed[_0x4676b4(0x155)])),_0x5e7be1['query']['filter']&&(_0x5c63d5[_0x4676b4(0x148)]=_[_0x4676b4(0x174)](_0x5c63d5[_0x4676b4(0x148)],{[Op['or']]:_[_0x4676b4(0xdb)](_0x5c63d5['attributes'],function(_0x5a4892){const _0x443d6f=_0x4676b4,_0x3de42a={};return _0x3de42a[_0x5a4892]={[Op[_0x443d6f(0x160)]]:'%'+_0x5e7be1[_0x443d6f(0xe2)]['filter']+'%'},_0x3de42a;})})),_0x5c63d5=_['merge']({},_0x5c63d5,_0x5e7be1[_0x4676b4(0xe8)]),_0x4ff55f[_0x4676b4(0xf1)](_0x5c63d5);})[_0x225923(0x109)](function(_0xcee2b8){const _0x229a6f=_0x225923;if(_0xcee2b8)return _0x3b4930=_0xcee2b8['length'],typeof _0x5e7be1['query'][_0x229a6f(0x158)]===_0x229a6f(0x165)&&(_0x5c63d5[_0x229a6f(0xf9)]=qs[_0x229a6f(0xf9)](_0x5e7be1['query'][_0x229a6f(0xf9)]),_0x5c63d5['offset']=qs[_0x229a6f(0xf3)](_0x5e7be1[_0x229a6f(0xe2)]['offset'])),_0x4ff55f[_0x229a6f(0xf1)](_0x5c63d5);})['then'](function(_0x24f73b){if(_0x24f73b)return _0x24f73b?{'count':_0x3b4930,'rows':_0x24f73b}:null;})[_0x225923(0x109)](respondWithResult(_0x1c0b92,null))[_0x225923(0x10d)](handleError(_0x1c0b92,null));},exports[a938_0x4c2b5f(0x126)]=function(_0x2a03f2,_0x2dfafc){const _0x415bae=a938_0x4c2b5f;return db[_0x415bae(0x16e)][_0x415bae(0x10c)]({'where':{'id':_0x2a03f2[_0x415bae(0x12b)]['id']}})[_0x415bae(0x109)](handleEntityNotFound(_0x2dfafc,null))[_0x415bae(0x109)](function(_0x50cdfd){const _0x4efc1f=_0x415bae;if(_0x50cdfd)return db[_0x4efc1f(0x114)]['transaction'](function(_0x267130){const _0x210347=_0x4efc1f;return db[_0x210347(0x141)][_0x210347(0xfa)]({'where':{'WhatsappAccountId':_0x2a03f2[_0x210347(0x12b)]['id']},'transaction':_0x267130})[_0x210347(0x109)](function(){const _0x1cca9f=_0x210347,_0x3f3baa=_[_0x1cca9f(0xdb)](_0x2a03f2[_0x1cca9f(0x14a)],function(_0x1a940e){const _0x552102=_0x1cca9f;return _0x1a940e[_0x552102(0x128)]=_0x2a03f2[_0x552102(0x12b)]['id'],_0x1a940e;});return db[_0x1cca9f(0x141)][_0x1cca9f(0x161)](_0x3f3baa,{'transaction':_0x267130});});})[_0x4efc1f(0x109)](function(){const _0x260933=_0x4efc1f;return db[_0x260933(0x141)]['findAndCountAll']({'where':{'WhatsappAccountId':_0x2a03f2[_0x260933(0x12b)]['id']},'order':_0x260933(0x120)});});})['then'](respondWithResult(_0x2dfafc,null))[_0x415bae(0x10d)](handleError(_0x2dfafc,null));},exports[a938_0x4c2b5f(0x110)]=function(_0x4bcd99,_0x572721){const _0x45ee4b=a938_0x4c2b5f;let _0x51356b={};const _0x15bc65={};let _0x46cf2c,_0x31a36b;return db[_0x45ee4b(0x16e)]['findOne']({'where':{'id':_0x4bcd99[_0x45ee4b(0x12b)]['id']}})[_0x45ee4b(0x109)](handleEntityNotFound(_0x572721,null))[_0x45ee4b(0x109)](function(_0xcd66e5){const _0x45af6a=_0x45ee4b;if(_0xcd66e5)return _0x46cf2c=_0xcd66e5,_0x15bc65[_0x45af6a(0x16a)]=_[_0x45af6a(0x136)](db[_0x45af6a(0x141)][_0x45af6a(0x113)]),_0x15bc65[_0x45af6a(0xe2)]=_[_0x45af6a(0x136)](_0x4bcd99['query']),_0x15bc65[_0x45af6a(0x155)]=_[_0x45af6a(0x11a)](_0x15bc65[_0x45af6a(0x16a)],_0x15bc65[_0x45af6a(0xe2)]),_0x51356b[_0x45af6a(0xe5)]=_['intersection'](_0x15bc65['model'],qs['fields'](_0x4bcd99[_0x45af6a(0xe2)][_0x45af6a(0x15b)])),_0x51356b['attributes']=_0x51356b[_0x45af6a(0xe5)]['length']?_0x51356b[_0x45af6a(0xe5)]:_0x15bc65[_0x45af6a(0x16a)],_0x51356b[_0x45af6a(0x125)]=qs['sort'](_0x4bcd99[_0x45af6a(0xe2)][_0x45af6a(0x108)]),_0x51356b[_0x45af6a(0x148)]=qs['filters'](_[_0x45af6a(0x138)](_0x4bcd99['query'],_0x15bc65[_0x45af6a(0x155)])),_0x4bcd99[_0x45af6a(0xe2)][_0x45af6a(0x152)]&&(_0x51356b[_0x45af6a(0x148)]=_[_0x45af6a(0x174)](_0x51356b['where'],{[Op['or']]:_[_0x45af6a(0xdb)](_0x51356b[_0x45af6a(0xe5)],function(_0x219fbe){const _0x3fdb5d=_0x45af6a,_0x192176={};return _0x192176[_0x219fbe]={[Op[_0x3fdb5d(0x160)]]:'%'+_0x4bcd99['query'][_0x3fdb5d(0x152)]+'%'},_0x192176;})})),_0x51356b=_[_0x45af6a(0x174)]({},_0x51356b,_0x4bcd99[_0x45af6a(0xe8)]),_0x46cf2c[_0x45af6a(0x110)](_0x51356b);})['then'](function(_0x20ee2a){const _0xc9b91f=_0x45ee4b;if(_0x20ee2a)return _0x31a36b=_0x20ee2a[_0xc9b91f(0x13f)],typeof _0x4bcd99[_0xc9b91f(0xe2)][_0xc9b91f(0x158)]===_0xc9b91f(0x165)&&(_0x51356b[_0xc9b91f(0xf9)]=qs['limit'](_0x4bcd99[_0xc9b91f(0xe2)][_0xc9b91f(0xf9)]),_0x51356b['offset']=qs['offset'](_0x4bcd99[_0xc9b91f(0xe2)][_0xc9b91f(0xf3)])),_0x46cf2c[_0xc9b91f(0x110)](_0x51356b);})[_0x45ee4b(0x109)](function(_0x30bc2d){if(_0x30bc2d)return _0x30bc2d?{'count':_0x31a36b,'rows':_0x30bc2d}:null;})[_0x45ee4b(0x109)](respondWithResult(_0x572721,null))[_0x45ee4b(0x10d)](handleError(_0x572721,null));},exports[a938_0x4c2b5f(0x14b)]=function(_0x6275ab,_0x2b5aae){const _0x44aaeb=a938_0x4c2b5f,_0x76fb28={'channel':_0x44aaeb(0x172)};let _0x3aae23=[],_0x3d5b91=[];const _0xf8ebd3={};return db[_0x44aaeb(0x16e)][_0x44aaeb(0x10c)]({'where':{'id':_0x6275ab[_0x44aaeb(0x12b)]['id']},'include':[{'model':db[_0x44aaeb(0x141)],'as':_0x44aaeb(0x14f)}]})[_0x44aaeb(0x109)](handleEntityNotFound(_0x2b5aae,null))[_0x44aaeb(0x109)](function(_0x4d7d76){const _0x375967=_0x44aaeb;return _0x76fb28['account']=_0x4d7d76,_0x76fb28['applications']=_['orderBy'](_0x4d7d76[_0x375967(0x14f)],[_0x375967(0x120)],[_0x375967(0x130)]),_0x76fb28[_0x375967(0x106)][_0x375967(0x14f)]&&delete _0x76fb28[_0x375967(0x106)]['Applications'],db[_0x375967(0x171)]['describe']();})[_0x44aaeb(0x109)](function(_0x3c7afb){const _0x28b638=_0x44aaeb;if(!_0x3c7afb)throw new ValidationError(_0x28b638(0xda));_0x3aae23=_[_0x28b638(0x122)](_['keys'](_0x3c7afb),['createdAt',_0x28b638(0x147)]),_0x3d5b91=_[_0x28b638(0x122)](_[_0x28b638(0x136)](_0x3c7afb),['createdAt',_0x28b638(0x147),'CompanyId',_0x28b638(0xd8)]),_0x76fb28[_0x28b638(0x14a)]={'mapKey':_0x28b638(0xe1)};_0x76fb28['account'][_0x28b638(0x118)]&&_0x76fb28[_0x28b638(0x106)]['type']==='twilio'&&(_0x76fb28['body'][_0x28b638(0x12a)]=_0x6275ab[_0x28b638(0x14a)][_0x28b638(0x15d)]['replace']('whatsapp:',''),_0x76fb28[_0x28b638(0x14a)][_0x28b638(0x14a)]=_0x6275ab[_0x28b638(0x14a)][_0x28b638(0x14c)],_0x76fb28['body'][_0x28b638(0x145)]=_0x6275ab[_0x28b638(0x14a)][_0x28b638(0x154)]);_0x76fb28[_0x28b638(0x14a)]['id']&&delete _0x76fb28['body']['id'];if(_[_0x28b638(0xec)](_0x76fb28['body'][_0x28b638(0x12a)]))throw new ValidationError(_0x28b638(0x13e));if(_[_0x28b638(0xec)](_0x76fb28[_0x28b638(0x14a)][_0x28b638(0x14a)])||_0x76fb28[_0x28b638(0x14a)]['body']==='')throw new ValidationError(_0x28b638(0x166));if(_[_0x28b638(0xec)](_0x76fb28[_0x28b638(0x14a)][_0x28b638(0x169)]))throw new ValidationError(_0x28b638(0x149)+_0x3d5b91);if(!_[_0x28b638(0x111)](_0x3d5b91,_0x76fb28[_0x28b638(0x14a)]['mapKey']))throw new ValidationError(_0x28b638(0x15c)+_0x3d5b91);return _0xf8ebd3[_0x76fb28[_0x28b638(0x14a)]['mapKey']]=_0x76fb28[_0x28b638(0x14a)][_0x28b638(0x12a)],db[_0x28b638(0xfe)][_0x28b638(0x10c)]({'where':{'id':_0x76fb28['account'][_0x28b638(0xd8)]},'include':[{'model':db['CmContact'],'as':_0x28b638(0xf4),'where':_0xf8ebd3,'limit':0x1,'order':[[_0x28b638(0x147),_0x28b638(0xdc)]]}]});})[_0x44aaeb(0x109)](handleEntityNotFound(_0x2b5aae,null))[_0x44aaeb(0x109)](function(_0xa4175c){const _0x4a2df6=_0x44aaeb;if(_0xa4175c){_0x76fb28[_0x4a2df6(0x12d)]=_[_0x4a2df6(0x168)](_0xa4175c,[_0x4a2df6(0xf4)]);if(_0xa4175c['Contacts'][_0x4a2df6(0x13f)])return _0xa4175c[_0x4a2df6(0xf4)][0x0];const _0x59ccb7=_[_0x4a2df6(0xf0)](_0x76fb28['body'],{'firstName':_0x76fb28['body']['from'],'ListId':_0xa4175c['id']});return _0x59ccb7[_0x76fb28[_0x4a2df6(0x14a)][_0x4a2df6(0x169)]]=_0x76fb28[_0x4a2df6(0x14a)][_0x4a2df6(0x12a)],db['CmContact'][_0x4a2df6(0x107)](_0x59ccb7,{'fields':_0x3aae23,'raw':!![]});}})['then'](handleEntityNotFound(_0x2b5aae,null))[_0x44aaeb(0x109)](function(_0xaf7c35){const _0x50ba2d=_0x44aaeb;if(_0xaf7c35){_0x76fb28['contact']=_0xaf7c35;const _0x13c69e={'ContactId':_0xaf7c35['id'],'phone':_0x76fb28[_0x50ba2d(0x14a)]['from'],'WhatsappAccountId':_0x6275ab[_0x50ba2d(0x12b)]['id']},_0x286541={'ContactId':_0xaf7c35['id'],'WhatsappAccountId':_0x6275ab[_0x50ba2d(0x12b)]['id'],'closed':![]};return db[_0x50ba2d(0x142)][_0x50ba2d(0x10c)]({'where':_0x286541})[_0x50ba2d(0x109)](function(_0xbba979){const _0x4e334c=_0x50ba2d;if(_0xbba979)return[_0xbba979,![]];return db[_0x4e334c(0x142)][_0x4e334c(0x107)](_0x13c69e)[_0x4e334c(0x109)](function(_0x5a1d06){return[_0x5a1d06,!![]];});});}})[_0x44aaeb(0x109)](function([_0x1139a7,_0x2dbea4]){const _0x1c436a=_0x44aaeb;return _0x76fb28[_0x1c436a(0x12e)]=_0x1139a7[_0x1c436a(0x101)]({'plain':!![]}),_0x76fb28[_0x1c436a(0x12e)]['created']=![],_0x2dbea4&&(_0x76fb28[_0x1c436a(0x106)][_0x1c436a(0x153)]&&_0x76fb28[_0x1c436a(0x132)][_0x1c436a(0x144)]({'id':0x0,'priority':_0x76fb28['applications'][_0x1c436a(0x13f)]+0x1,'app':_0x1c436a(0xf5),'appdata':_0x1c436a(0x135),'interval':_0x1c436a(0x16d)}),_0x76fb28[_0x1c436a(0x12e)][_0x1c436a(0xf7)]=!![]),db[_0x1c436a(0x123)][_0x1c436a(0x107)]({'phone':_0x76fb28['body'][_0x1c436a(0x12a)],'messageId':_0x76fb28[_0x1c436a(0x14a)][_0x1c436a(0x145)],'body':_0x76fb28['body'][_0x1c436a(0x14a)],'WhatsappAccountId':_0x6275ab[_0x1c436a(0x12b)]['id'],'WhatsappInteractionId':_0x1139a7['id'],'direction':'in','ContactId':_0x1139a7[_0x1c436a(0x164)],'AttachmentId':_0x76fb28[_0x1c436a(0x14a)][_0x1c436a(0x16f)]});})['then'](function(_0x3f3713){const _0x23c8c3=_0x44aaeb;_0x76fb28[_0x23c8c3(0x167)]=_0x3f3713;if(_0x76fb28['interaction']['UserId'])return db[_0x23c8c3(0xfd)][_0x23c8c3(0x10c)]({'attributes':['id',_0x23c8c3(0xea)],'where':{'id':_0x76fb28[_0x23c8c3(0x12e)][_0x23c8c3(0x131)]}})['then'](function(_0x528d57){const _0x33c9a4=_0x23c8c3;return _0x528d57&&_0x76fb28[_0x33c9a4(0x132)]['unshift']({'id':0x0,'priority':0x0,'app':_0x33c9a4(0x133),'appdata':_0x528d57[_0x33c9a4(0xea)]+','+(_0x76fb28[_0x33c9a4(0x106)][_0x33c9a4(0xe4)]||0xa),'interval':_0x33c9a4(0x16d)}),respondWithRpcPromise(_0x33c9a4(0x10e),_0x33c9a4(0xe3),_0x76fb28);});return respondWithRpcPromise(_0x23c8c3(0x10e),'startRouting',_0x76fb28);})[_0x44aaeb(0x109)](function(_0x50d21f){const _0x2940a6=_0x44aaeb;if(_0x50d21f){const _0x3f5379=0xc8,_0x5be42b=_0x2940a6(0x127);return logger['info']('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x5be42b,_0x3f5379,_0x2940a6(0x13d)),logger[_0x2940a6(0x112)](_0x2940a6(0x12f),_0x5be42b,_0x3f5379,_0x2940a6(0x13d),JSON[_0x2940a6(0x15a)](_0x50d21f)),_0x76fb28[_0x2940a6(0x106)][_0x2940a6(0x118)]===_0x2940a6(0x162)?_0x2b5aae[_0x2940a6(0x173)](_0x3f5379)[_0x2940a6(0x150)](_0x2940a6(0xdf),'text/xml')[_0x2940a6(0x129)](_0x2940a6(0x115)):_0x2b5aae['status'](_0x3f5379)[_0x2940a6(0x10a)](_0x50d21f);}})[_0x44aaeb(0x10d)](handleError(_0x2b5aae,null));},exports[a938_0x4c2b5f(0x129)]=function(_0x5cad55,_0x412dd8){const _0x145cb9=a938_0x4c2b5f;let _0x5432cb,_0x2f9f78;if(_[_0x145cb9(0xec)](_0x5cad55['body'][_0x145cb9(0x14a)])||_0x5cad55[_0x145cb9(0x14a)][_0x145cb9(0x14a)]==='')throw new ValidationError(_0x145cb9(0x166));if(_[_0x145cb9(0xec)](_0x5cad55['body']['to']))throw new ValidationError('to\x20is\x20mandatory');const _0x394aa3=_0x5cad55[_0x145cb9(0x14a)]['to'];return db[_0x145cb9(0x16e)]['findOne']({'where':{'id':_0x5cad55[_0x145cb9(0x12b)]['id']},'include':[{'model':db[_0x145cb9(0xfe)],'as':_0x145cb9(0x13a),'include':[{'model':db[_0x145cb9(0x171)],'as':_0x145cb9(0xf4),'where':{'mobile':_0x394aa3},'limit':0x1,'order':[[_0x145cb9(0x147),'DESC']]}]}]})[_0x145cb9(0x109)](handleEntityNotFound(_0x412dd8,null))[_0x145cb9(0x109)](function(_0x5a7e3b){const _0x452eff=_0x145cb9;if(_0x5a7e3b&&_0x5a7e3b[_0x452eff(0x13a)]){_0x5432cb=_0x5a7e3b['get']({'plain':!![]});if(_0x5432cb[_0x452eff(0x13a)]&&_0x5432cb[_0x452eff(0x13a)][_0x452eff(0xf4)][_0x452eff(0x13f)])return _0x5432cb[_0x452eff(0x13a)][_0x452eff(0xf4)][0x0];return db['CmContact'][_0x452eff(0x107)](_[_0x452eff(0xf0)](_0x5cad55['body'],{'firstName':_0x394aa3,'mobile':_0x394aa3,'phone':_0x394aa3,'ListId':_0x5432cb[_0x452eff(0xd8)]}));}})[_0x145cb9(0x109)](handleEntityNotFound(_0x412dd8,null))['then'](function(_0x4a9612){const _0x10942f=_0x145cb9;if(_0x4a9612)return _0x2f9f78=_0x4a9612,db[_0x10942f(0x142)][_0x10942f(0x10c)]({'where':{'ContactId':_0x2f9f78['id'],'closed':![],'WhatsappAccountId':_0x5432cb['id']}})[_0x10942f(0x109)](function(_0x3500f1){const _0x125e99=_0x10942f;if(_0x3500f1)return[_0x3500f1,![]];return db[_0x125e99(0x142)][_0x125e99(0x107)]({'UserId':_0x5cad55[_0x125e99(0x11f)]['id'],'ContactId':_0x2f9f78['id'],'WhatsappAccountId':_0x5432cb['id'],'phone':_0x394aa3,'firstMsgDirection':_0x125e99(0x11d),'Messages':[_['merge'](_0x5cad55[_0x125e99(0x14a)],{'read':![],'body':_0x5cad55['body'][_0x125e99(0x14a)],'phone':_0x394aa3,'WhatsappAccountId':_0x5432cb['id'],'UserId':_0x5cad55[_0x125e99(0x11f)]['id'],'ContactId':_0x2f9f78['id']})]},{'include':[{'model':db[_0x125e99(0x123)],'as':_0x125e99(0x151)}]})['then'](function(_0x4694ce){return[_0x4694ce,!![]];});});})[_0x145cb9(0x109)](function([_0x44b984,_0x1a2f19]){const _0x5b4ad6=_0x145cb9;if(_0x1a2f19)return _0x44b984;return db[_0x5b4ad6(0x123)]['create'](_[_0x5b4ad6(0x174)](_0x5cad55[_0x5b4ad6(0x14a)],{'read':![],'body':_0x5cad55[_0x5b4ad6(0x14a)][_0x5b4ad6(0x14a)],'phone':_0x394aa3,'WhatsappAccountId':_0x5432cb['id'],'WhatsappInteractionId':_0x44b984['id'],'UserId':_0x5cad55[_0x5b4ad6(0x11f)]['id'],'ContactId':_0x2f9f78['id']}))[_0x5b4ad6(0x109)](function(_0x438369){const _0x37c80a=_0x5b4ad6;return _0x44b984[_0x37c80a(0xf2)][_0x37c80a(0x151)]=[],_0x44b984[_0x37c80a(0xf2)][_0x37c80a(0x151)][_0x37c80a(0x144)](_0x438369[_0x37c80a(0xf2)]),_0x44b984;});})[_0x145cb9(0x109)](respondWithResult(_0x412dd8,null))[_0x145cb9(0x10d)](handleError(_0x412dd8,null));};
\ No newline at end of file
+const a938_0x22d5=['jayson/promise','destroy','includes','userWhatsappAccount:remove','rawAttributes','pick','push','getDispositions','key','error','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','User','rows','isArray','removeAnswers','undefined','sort','sendStatus','send','whatsapp:','UserProfileSection','VIRTUAL','Applications','emit','findOne','message','code','order','register','./whatsappAccount.socket','unmanaged','created','UserId','include','set','mandatoryDispositionPause','mobile','unshift','orderBy','entity\x20found','lodash','list','close','query','getAgents','WhatsappAccountId','client','addDisposition','contact','name','replace','end','request\x20sent','stack','Pause','autoclose','result','DESC','sequelize','Disposition','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','priority','map','model','catch','offset','Start','from\x20is\x20mandatory','dataValues','merge','receiveMessage','describe','text/xml','fields','autoAssociation','filters','defaults','Content-Type','WhatsappAccount,\x20%s,\x20%s,\x20%s','role','mapKey','includeAll','Messages','messageId','then','CmList','show','account','Contacts','Unable\x20to\x20retrieve\x20the\x20current\x20user','findAll','params','nolimit','body\x20is\x20mandatory\x20and\x20not\x20empty','type','../../mysqldb','*,*,*,*','count','options','attributes','Body','body','waitForTheAssignedAgent','createdAt','WhatsappAccount,\x20%s,\x20%s','addAgents','fieldName','transaction','omit','WhatsappAccount','create','removeDispositions','http','where','stringify','info','update','ListId','addAnswer','userProfileId','WhatsappInteraction','debug','get','UserProfileResource','ids','userWhatsappAccount:save','limit','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','agent','filter','notify','like','../../config/logger','updatedAt','<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>','WhatsappMessage','intersection','CannedAnswer','difference','interaction','status','AttachmentId','WhatsappAccounts','keys','from','startRouting','../../rediscache','out','List','applications','CmContact','ContactId','length','json','WhatsappApplication','isNil','user'];(function(_0x18ac63,_0x53768c){const _0x22d57c=function(_0x2835a2){while(--_0x2835a2){_0x18ac63['push'](_0x18ac63['shift']());}};_0x22d57c(++_0x53768c);}(a938_0x22d5,0x179));const a938_0x2835=function(_0x18ac63,_0x53768c){_0x18ac63=_0x18ac63-0x183;let _0x22d57c=a938_0x22d5[_0x18ac63];return _0x22d57c;};const a938_0x4f87d9=a938_0x2835;'use strict';const _=require(a938_0x4f87d9(0x209)),qs=require('../../components/parsers/qs'),logger=require(a938_0x4f87d9(0x1c8))('api'),{getSocket}=require(a938_0x4f87d9(0x1d6)),socket=getSocket(),{db}=require(a938_0x4f87d9(0x1a3)),{Op,ValidationError}=require(a938_0x4f87d9(0x21b));require(a938_0x4f87d9(0x1fe))[a938_0x4f87d9(0x1fd)](socket);const jayson=require(a938_0x4f87d9(0x1e1)),client=jayson[a938_0x4f87d9(0x20f)][a938_0x4f87d9(0x1b4)]({'port':0x232c});function respondWithRpcPromise(_0x36fad2,_0x24e309,_0x23f0b8,_0x234733){return new Promise(function(_0x4c7577,_0x4117e6){const _0x4eccd9=a938_0x2835,_0x726126=_0x234733||client;return _0x726126['request'](_0x36fad2,_0x23f0b8)['then'](function(_0x3947e5){const _0x22bfd4=a938_0x2835;logger[_0x22bfd4(0x1b7)](_0x22bfd4(0x1ac),_0x24e309,_0x22bfd4(0x215)),logger[_0x22bfd4(0x1bd)](_0x22bfd4(0x192),_0x24e309,_0x22bfd4(0x215),JSON[_0x22bfd4(0x1b6)](_0x3947e5));if(_0x3947e5['error']){if(_0x3947e5[_0x22bfd4(0x1ea)][_0x22bfd4(0x1fb)]===0x1f4)return logger['error']('WhatsappAccount,\x20%s,\x20%s',_0x24e309,_0x3947e5['error'][_0x22bfd4(0x1fa)]),_0x4117e6(_0x3947e5[_0x22bfd4(0x1ea)][_0x22bfd4(0x1fa)]);return logger[_0x22bfd4(0x1ea)]('WhatsappAccount,\x20%s,\x20%s',_0x24e309,_0x3947e5['error'][_0x22bfd4(0x1fa)]),_0x4c7577(_0x3947e5[_0x22bfd4(0x1ea)][_0x22bfd4(0x1fa)]);}else logger[_0x22bfd4(0x1b7)](_0x22bfd4(0x1ac),_0x24e309,'request\x20sent'),_0x4c7577(_0x3947e5[_0x22bfd4(0x219)][_0x22bfd4(0x1fa)]);})[_0x4eccd9(0x184)](function(_0x30aeb3){const _0x3ac02e=_0x4eccd9;logger[_0x3ac02e(0x1ea)](_0x3ac02e(0x1ac),_0x24e309,_0x30aeb3),_0x4117e6(_0x30aeb3);});});}function respondWithStatusCode(_0xc6fb56,_0x27ad10){return _0x27ad10=_0x27ad10||0xcc,function(_0xe55989){const _0x9e3046=a938_0x2835;if(_0xe55989)return _0xc6fb56[_0x9e3046(0x1f2)](_0x27ad10);return _0xc6fb56[_0x9e3046(0x1d0)](_0x27ad10)[_0x9e3046(0x214)]();};}function respondWithResult(_0x4035ed,_0x209877){return _0x209877=_0x209877||0xc8,function(_0x4f2aef){const _0x1d9d6f=a938_0x2835;if(_0x4f2aef)return _0x4035ed[_0x1d9d6f(0x1d0)](_0x209877)['json'](_0x4f2aef);};}function respondWithFilteredResult(_0x594d27,_0x36d8a8){return function(_0x2621a0){const _0x4dceda=a938_0x2835;if(_0x2621a0){const _0x740bfd=_0x2621a0['count'],_0x22d6d2=_0x36d8a8[_0x4dceda(0x185)];let _0xecad41=_0x36d8a8['offset']+_0x36d8a8[_0x4dceda(0x1c2)],_0x3d4862;return _0xecad41>=_0x740bfd?(_0xecad41=_0x740bfd,_0x3d4862=0xc8):_0x3d4862=0xce,_0x594d27[_0x4dceda(0x1d0)](_0x3d4862),_0x594d27[_0x4dceda(0x203)]('Content-Range',_0x22d6d2+'-'+_0xecad41+'/'+_0x740bfd)[_0x4dceda(0x1dd)](_0x2621a0);}return null;};}function saveUpdates(_0x9cfdb4){return function(_0x3eade2){const _0x391c0f=a938_0x2835;if(_0x3eade2)return _0x3eade2[_0x391c0f(0x1b8)](_0x9cfdb4)[_0x391c0f(0x198)](function(_0xf153d1){return _0xf153d1;});return null;};}function removeEntity(_0x1c4a7d){return function(_0xa9ed8c){const _0x1ebbb5=a938_0x2835;if(_0xa9ed8c)return _0xa9ed8c['destroy']()[_0x1ebbb5(0x198)](function(){const _0x4aa0fd=_0x1ebbb5,_0x8c29c6=_0xa9ed8c[_0x4aa0fd(0x1be)]({'plain':!![]}),_0x30235b=_0x4aa0fd(0x1d2);return db[_0x4aa0fd(0x1bf)]['destroy']({'where':{'type':_0x30235b,'resourceId':_0x8c29c6['id']}})[_0x4aa0fd(0x198)](function(){return _0xa9ed8c;});})[_0x1ebbb5(0x198)](function(){const _0x166457=_0x1ebbb5;_0x1c4a7d[_0x166457(0x1d0)](0xcc)[_0x166457(0x214)]();});};}function handleEntityNotFound(_0x2a582f){return function(_0x308ea9){const _0x354fdd=a938_0x2835;return!_0x308ea9&&_0x2a582f[_0x354fdd(0x1f2)](0x194),_0x308ea9;};}function handleError(_0x3b263c,_0x35b438){return _0x35b438=_0x35b438||0x1f4,function(_0x15aed2){const _0x5df84b=a938_0x2835;logger[_0x5df84b(0x1ea)](_0x15aed2[_0x5df84b(0x216)]),_0x15aed2[_0x5df84b(0x212)]&&delete _0x15aed2[_0x5df84b(0x212)],_0x3b263c[_0x5df84b(0x1d0)](_0x35b438)[_0x5df84b(0x1f3)](_0x15aed2);};}exports['index']=function(_0xf5d047,_0x1dae28){const _0x1f1fa7=a938_0x4f87d9;let _0x1885dd={'include':[{'model':db[_0x1f1fa7(0x217)],'as':_0x1f1fa7(0x204)}]};const _0x50048e={},_0x2c2267={'count':0x0,'rows':[]},_0x3aee58=_[_0x1f1fa7(0x21f)](db[_0x1f1fa7(0x1b1)]['rawAttributes'],function(_0x37f23b){const _0x4f4a7a=_0x1f1fa7;return{'name':_0x37f23b[_0x4f4a7a(0x1ae)],'type':_0x37f23b[_0x4f4a7a(0x1a2)][_0x4f4a7a(0x1e9)]};});_0x50048e[_0x1f1fa7(0x183)]=_[_0x1f1fa7(0x21f)](_0x3aee58,_0x1f1fa7(0x212)),_0x50048e[_0x1f1fa7(0x20c)]=_[_0x1f1fa7(0x1d3)](_0xf5d047[_0x1f1fa7(0x20c)]),_0x50048e['filters']=_[_0x1f1fa7(0x1cc)](_0x50048e[_0x1f1fa7(0x183)],_0x50048e[_0x1f1fa7(0x20c)]),_0x1885dd['attributes']=_[_0x1f1fa7(0x1cc)](_0x50048e['model'],qs['fields'](_0xf5d047[_0x1f1fa7(0x20c)][_0x1f1fa7(0x18d)])),_0x1885dd['attributes']=_0x1885dd[_0x1f1fa7(0x1a7)][_0x1f1fa7(0x1dc)]?_0x1885dd['attributes']:_0x50048e[_0x1f1fa7(0x183)];typeof _0xf5d047[_0x1f1fa7(0x20c)][_0x1f1fa7(0x1a0)]===_0x1f1fa7(0x1f0)&&(_0x1885dd[_0x1f1fa7(0x1c2)]=qs['limit'](_0xf5d047[_0x1f1fa7(0x20c)][_0x1f1fa7(0x1c2)]),_0x1885dd[_0x1f1fa7(0x185)]=qs[_0x1f1fa7(0x185)](_0xf5d047[_0x1f1fa7(0x20c)][_0x1f1fa7(0x185)]));_0x1885dd[_0x1f1fa7(0x1fc)]=qs[_0x1f1fa7(0x1f1)](_0xf5d047[_0x1f1fa7(0x20c)]['sort']),_0x1885dd[_0x1f1fa7(0x1b5)]=qs['filters'](_[_0x1f1fa7(0x1e6)](_0xf5d047[_0x1f1fa7(0x20c)],_0x50048e[_0x1f1fa7(0x18f)]),_0x3aee58);_0xf5d047[_0x1f1fa7(0x20c)][_0x1f1fa7(0x1c5)]&&(_0x1885dd[_0x1f1fa7(0x1b5)]=_[_0x1f1fa7(0x189)](_0x1885dd[_0x1f1fa7(0x1b5)],{[Op['or']]:_[_0x1f1fa7(0x21f)](_0x3aee58,function(_0x371b71){const _0x3aec43=_0x1f1fa7;if(_0x371b71['type']!==_0x3aec43(0x1f6)){const _0xbd1ff9={};return _0xbd1ff9[_0x371b71[_0x3aec43(0x212)]]={[Op['like']]:'%'+_0xf5d047['query']['filter']+'%'},_0xbd1ff9;}})}));_0x1885dd=_[_0x1f1fa7(0x189)]({},_0x1885dd,_0xf5d047['options']);const _0x589439={'where':_0x1885dd[_0x1f1fa7(0x1b5)]};return db['WhatsappAccount'][_0x1f1fa7(0x1a5)](_0x589439)[_0x1f1fa7(0x198)](function(_0x3179dc){const _0x4cc3c5=_0x1f1fa7;return _0x2c2267['count']=_0x3179dc,_0xf5d047[_0x4cc3c5(0x20c)]['includeAll']&&(_0x1885dd[_0x4cc3c5(0x202)]=[{'all':!![]}]),db[_0x4cc3c5(0x1b1)][_0x4cc3c5(0x19e)](_0x1885dd);})[_0x1f1fa7(0x198)](function(_0xe29eae){const _0x3e59db=_0x1f1fa7;return _0x2c2267[_0x3e59db(0x1ed)]=_0xe29eae,_0x2c2267;})[_0x1f1fa7(0x198)](respondWithFilteredResult(_0x1dae28,_0x1885dd))[_0x1f1fa7(0x184)](handleError(_0x1dae28,null));},exports[a938_0x4f87d9(0x19a)]=function(_0x557f2e,_0x581fb0){const _0x42d2ec=a938_0x4f87d9;let _0x29e6d4={'raw':![],'where':{'id':_0x557f2e[_0x42d2ec(0x19f)]['id']},'include':[{'model':db[_0x42d2ec(0x217)],'as':_0x42d2ec(0x204)}]};const _0x588653={};return _0x588653[_0x42d2ec(0x183)]=_[_0x42d2ec(0x1d3)](db[_0x42d2ec(0x1b1)][_0x42d2ec(0x1e5)]),_0x588653[_0x42d2ec(0x20c)]=_[_0x42d2ec(0x1d3)](_0x557f2e[_0x42d2ec(0x20c)]),_0x588653[_0x42d2ec(0x18f)]=_[_0x42d2ec(0x1cc)](_0x588653[_0x42d2ec(0x183)],_0x588653[_0x42d2ec(0x20c)]),_0x29e6d4[_0x42d2ec(0x1a7)]=_[_0x42d2ec(0x1cc)](_0x588653[_0x42d2ec(0x183)],qs[_0x42d2ec(0x18d)](_0x557f2e['query']['fields'])),_0x29e6d4[_0x42d2ec(0x1a7)]=_0x29e6d4[_0x42d2ec(0x1a7)][_0x42d2ec(0x1dc)]?_0x29e6d4[_0x42d2ec(0x1a7)]:_0x588653['model'],_0x557f2e[_0x42d2ec(0x20c)][_0x42d2ec(0x195)]&&(_0x29e6d4[_0x42d2ec(0x202)]=[{'all':!![]}]),_0x29e6d4=_[_0x42d2ec(0x189)]({},_0x29e6d4,_0x557f2e['options']),db[_0x42d2ec(0x1b1)][_0x42d2ec(0x1f9)](_0x29e6d4)[_0x42d2ec(0x198)](handleEntityNotFound(_0x581fb0,null))[_0x42d2ec(0x198)](respondWithResult(_0x581fb0,null))[_0x42d2ec(0x184)](handleError(_0x581fb0,null));},exports[a938_0x4f87d9(0x1b2)]=function(_0xbf9256,_0x5223cf){const _0x21c357=a938_0x4f87d9;return db[_0x21c357(0x1b1)]['create'](_0xbf9256[_0x21c357(0x1a9)],{})[_0x21c357(0x198)](function(_0x1f9e9a){const _0x27acd3=_0x21c357,_0x49c4d9=_0xbf9256[_0x27acd3(0x1e0)]['get']({'plain':!![]});if(!_0x49c4d9)throw new Error(_0x27acd3(0x19d));if(_0x49c4d9[_0x27acd3(0x193)]===_0x27acd3(0x1e0)){const _0x2cb551=_0x1f9e9a['get']({'plain':!![]}),_0x51c4a7=_0x27acd3(0x1d2);return db[_0x27acd3(0x1f5)][_0x27acd3(0x1f9)]({'where':{'name':_0x51c4a7,'userProfileId':_0x49c4d9[_0x27acd3(0x1bb)]},'raw':!![]})[_0x27acd3(0x198)](function(_0x5a1993){const _0x435de1=_0x27acd3;return _0x5a1993&&_0x5a1993[_0x435de1(0x18e)]===0x0?db[_0x435de1(0x1bf)][_0x435de1(0x1b2)]({'name':_0x2cb551[_0x435de1(0x212)],'resourceId':_0x2cb551['id'],'type':_0x5a1993[_0x435de1(0x212)],'sectionId':_0x5a1993['id']},{})['then'](function(){return _0x1f9e9a;}):_0x1f9e9a;})[_0x27acd3(0x184)](function(_0x36ece2){const _0x20a954=_0x27acd3;logger[_0x20a954(0x1ea)](_0x20a954(0x21d),_0x36ece2);throw _0x36ece2;});}return _0x1f9e9a;})[_0x21c357(0x198)](respondWithResult(_0x5223cf,0xc9))['catch'](handleError(_0x5223cf,null));},exports[a938_0x4f87d9(0x1b8)]=function(_0x465429,_0x5e08fd){const _0x4fc7ce=a938_0x4f87d9;return _0x465429['body']['id']&&delete _0x465429[_0x4fc7ce(0x1a9)]['id'],db[_0x4fc7ce(0x1b1)][_0x4fc7ce(0x1f9)]({'where':{'id':_0x465429['params']['id']},'include':[{'model':db[_0x4fc7ce(0x217)],'as':_0x4fc7ce(0x204)}]})[_0x4fc7ce(0x198)](handleEntityNotFound(_0x5e08fd,null))[_0x4fc7ce(0x198)](saveUpdates(_0x465429['body'],null))[_0x4fc7ce(0x198)](respondWithResult(_0x5e08fd,null))[_0x4fc7ce(0x184)](handleError(_0x5e08fd,null));},exports[a938_0x4f87d9(0x1e2)]=function(_0xf102cf,_0x3c9e97){const _0x27d687=a938_0x4f87d9;return db[_0x27d687(0x1b1)]['findOne']({'where':{'id':_0xf102cf[_0x27d687(0x19f)]['id']}})[_0x27d687(0x198)](handleEntityNotFound(_0x3c9e97,null))[_0x27d687(0x198)](removeEntity(_0x3c9e97,null))[_0x27d687(0x184)](handleError(_0x3c9e97,null));},exports[a938_0x4f87d9(0x18b)]=function(_0x26bbfc,_0x1cf36b){const _0x17ba06=a938_0x4f87d9;return db[_0x17ba06(0x1b1)][_0x17ba06(0x18b)]()[_0x17ba06(0x198)](respondWithResult(_0x1cf36b,null))[_0x17ba06(0x184)](handleError(_0x1cf36b,null));},exports[a938_0x4f87d9(0x210)]=function(_0x425e1c,_0x362dc6){const _0x42fc2f=a938_0x4f87d9;return _0x425e1c[_0x42fc2f(0x1a9)]['id']&&delete _0x425e1c[_0x42fc2f(0x1a9)]['id'],db[_0x42fc2f(0x1b1)][_0x42fc2f(0x1f9)]({'where':{'id':_0x425e1c['params']['id']}})[_0x42fc2f(0x198)](handleEntityNotFound(_0x362dc6,null))[_0x42fc2f(0x198)](function(_0x378432){const _0x4c7780=_0x42fc2f;if(_0x378432)return _0x425e1c[_0x4c7780(0x1a9)][_0x4c7780(0x20e)]=_0x378432['id'],db[_0x4c7780(0x21c)]['create'](_0x425e1c['body']);})['then'](respondWithResult(_0x362dc6,null))[_0x42fc2f(0x184)](handleError(_0x362dc6,null));},exports[a938_0x4f87d9(0x1e8)]=function(_0x33a290,_0x35979b){const _0x282643=a938_0x4f87d9;let _0xd6b0dc={'raw':![],'where':{}};const _0x60ddf5={},_0x475e08={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0x282643(0x1f9)]({'where':{'id':_0x33a290[_0x282643(0x19f)]['id']}})[_0x282643(0x198)](handleEntityNotFound(_0x35979b,null))[_0x282643(0x198)](function(_0x25c0d1){const _0x4e0b92=_0x282643;if(_0x25c0d1)return _0x60ddf5[_0x4e0b92(0x183)]=_[_0x4e0b92(0x1d3)](db['Disposition'][_0x4e0b92(0x1e5)]),_0x60ddf5[_0x4e0b92(0x20c)]=_[_0x4e0b92(0x1d3)](_0x33a290[_0x4e0b92(0x20c)]),_0x60ddf5[_0x4e0b92(0x18f)]=_[_0x4e0b92(0x1cc)](_0x60ddf5['model'],_0x60ddf5['query']),_0xd6b0dc['attributes']=_['intersection'](_0x60ddf5[_0x4e0b92(0x183)],qs[_0x4e0b92(0x18d)](_0x33a290[_0x4e0b92(0x20c)]['fields'])),_0xd6b0dc['attributes']=_0xd6b0dc[_0x4e0b92(0x1a7)]['length']?_0xd6b0dc['attributes']:_0x60ddf5[_0x4e0b92(0x183)],typeof _0x33a290[_0x4e0b92(0x20c)][_0x4e0b92(0x1a0)]==='undefined'&&(_0xd6b0dc[_0x4e0b92(0x1c2)]=qs['limit'](_0x33a290[_0x4e0b92(0x20c)][_0x4e0b92(0x1c2)]),_0xd6b0dc[_0x4e0b92(0x185)]=qs['offset'](_0x33a290['query'][_0x4e0b92(0x185)])),_0xd6b0dc[_0x4e0b92(0x1fc)]=qs[_0x4e0b92(0x1f1)](_0x33a290[_0x4e0b92(0x20c)][_0x4e0b92(0x1f1)]),_0xd6b0dc['where']=qs['filters'](_['pick'](_0x33a290[_0x4e0b92(0x20c)],_0x60ddf5['filters'])),_0xd6b0dc[_0x4e0b92(0x1b5)]['WhatsappAccountId']=_0x25c0d1['id'],_0x33a290[_0x4e0b92(0x20c)][_0x4e0b92(0x1c5)]&&(_0xd6b0dc[_0x4e0b92(0x1b5)]=_[_0x4e0b92(0x189)](_0xd6b0dc[_0x4e0b92(0x1b5)],{[Op['or']]:_[_0x4e0b92(0x21f)](_0xd6b0dc[_0x4e0b92(0x1a7)],function(_0x475e04){const _0x3ed017=_0x4e0b92,_0x546764={};return _0x546764[_0x475e04]={[Op[_0x3ed017(0x1c7)]]:'%'+_0x33a290['query']['filter']+'%'},_0x546764;})})),_0xd6b0dc=_[_0x4e0b92(0x189)]({},_0xd6b0dc,_0x33a290['options']),db[_0x4e0b92(0x21c)][_0x4e0b92(0x1a5)]({'where':_0xd6b0dc[_0x4e0b92(0x1b5)]})['then'](function(_0x45da55){const _0x1e4ab6=_0x4e0b92;return _0x475e08[_0x1e4ab6(0x1a5)]=_0x45da55,_0x33a290[_0x1e4ab6(0x20c)][_0x1e4ab6(0x195)]&&(_0xd6b0dc[_0x1e4ab6(0x202)]=[{'all':!![]}]),db[_0x1e4ab6(0x21c)][_0x1e4ab6(0x19e)](_0xd6b0dc);})[_0x4e0b92(0x198)](function(_0x3170b2){const _0x320828=_0x4e0b92;return _0x475e08[_0x320828(0x1ed)]=_0x3170b2,_0x475e08;});})[_0x282643(0x198)](respondWithFilteredResult(_0x35979b,_0xd6b0dc))['catch'](handleError(_0x35979b,null));},exports[a938_0x4f87d9(0x1b3)]=function(_0x16ed31,_0x2c1289){const _0x5454e4=a938_0x4f87d9;return db['WhatsappAccount'][_0x5454e4(0x1f9)]({'where':{'id':_0x16ed31['params']['id']}})[_0x5454e4(0x198)](handleEntityNotFound(_0x2c1289,null))['then'](function(_0x35b81f){const _0x2026b3=_0x5454e4;if(_0x35b81f)return _0x35b81f['removeDispositions'](_0x16ed31[_0x2026b3(0x20c)][_0x2026b3(0x1c0)]);})['then'](respondWithStatusCode(_0x2c1289,null))['catch'](handleError(_0x2c1289,null));},exports[a938_0x4f87d9(0x1ba)]=function(_0x2d0304,_0x436d06){const _0x2e8ffe=a938_0x4f87d9;return _0x2d0304[_0x2e8ffe(0x1a9)]['id']&&delete _0x2d0304[_0x2e8ffe(0x1a9)]['id'],db['WhatsappAccount'][_0x2e8ffe(0x1f9)]({'where':{'id':_0x2d0304[_0x2e8ffe(0x19f)]['id']}})['then'](handleEntityNotFound(_0x436d06,null))['then'](function(_0x46bae2){const _0x133b16=_0x2e8ffe;if(_0x46bae2)return _0x2d0304['body']['WhatsappAccountId']=_0x46bae2['id'],db['CannedAnswer'][_0x133b16(0x1b2)](_0x2d0304[_0x133b16(0x1a9)]);})[_0x2e8ffe(0x198)](respondWithResult(_0x436d06,null))[_0x2e8ffe(0x184)](handleError(_0x436d06,null));},exports['getAnswers']=function(_0x582539,_0x12dbc0){const _0x532ffd=a938_0x4f87d9;let _0x3d214b={'raw':![],'where':{}};const _0x1d02a6={},_0x455fd4={'count':0x0,'rows':[]};return db['WhatsappAccount'][_0x532ffd(0x1f9)]({'where':{'id':_0x582539['params']['id']}})[_0x532ffd(0x198)](handleEntityNotFound(_0x12dbc0,null))['then'](function(_0x143e6b){const _0x18d900=_0x532ffd;if(_0x143e6b)return _0x1d02a6['model']=_[_0x18d900(0x1d3)](db[_0x18d900(0x1cd)][_0x18d900(0x1e5)]),_0x1d02a6[_0x18d900(0x20c)]=_['keys'](_0x582539[_0x18d900(0x20c)]),_0x1d02a6['filters']=_[_0x18d900(0x1cc)](_0x1d02a6[_0x18d900(0x183)],_0x1d02a6[_0x18d900(0x20c)]),_0x3d214b[_0x18d900(0x1a7)]=_['intersection'](_0x1d02a6['model'],qs[_0x18d900(0x18d)](_0x582539['query'][_0x18d900(0x18d)])),_0x3d214b['attributes']=_0x3d214b[_0x18d900(0x1a7)]['length']?_0x3d214b['attributes']:_0x1d02a6[_0x18d900(0x183)],typeof _0x582539[_0x18d900(0x20c)][_0x18d900(0x1a0)]===_0x18d900(0x1f0)&&(_0x3d214b[_0x18d900(0x1c2)]=qs['limit'](_0x582539[_0x18d900(0x20c)][_0x18d900(0x1c2)]),_0x3d214b[_0x18d900(0x185)]=qs[_0x18d900(0x185)](_0x582539[_0x18d900(0x20c)][_0x18d900(0x185)])),_0x3d214b[_0x18d900(0x1fc)]=qs[_0x18d900(0x1f1)](_0x582539[_0x18d900(0x20c)][_0x18d900(0x1f1)]),_0x3d214b['where']=qs['filters'](_['pick'](_0x582539[_0x18d900(0x20c)],_0x1d02a6['filters'])),_0x3d214b[_0x18d900(0x1b5)][_0x18d900(0x20e)]=_0x143e6b['id'],_0x582539['query'][_0x18d900(0x1c5)]&&(_0x3d214b['where']=_['merge'](_0x3d214b[_0x18d900(0x1b5)],{[Op['or']]:_[_0x18d900(0x21f)](_0x3d214b[_0x18d900(0x1a7)],function(_0x2dd852){const _0x2ec85b=_0x18d900,_0x2dd5bc={};return _0x2dd5bc[_0x2dd852]={[Op[_0x2ec85b(0x1c7)]]:'%'+_0x582539[_0x2ec85b(0x20c)][_0x2ec85b(0x1c5)]+'%'},_0x2dd5bc;})})),_0x3d214b=_[_0x18d900(0x189)]({},_0x3d214b,_0x582539[_0x18d900(0x1a6)]),db[_0x18d900(0x1cd)][_0x18d900(0x1a5)]({'where':_0x3d214b['where']})[_0x18d900(0x198)](function(_0x2779d0){const _0x7878fd=_0x18d900;return _0x455fd4[_0x7878fd(0x1a5)]=_0x2779d0,_0x582539['query'][_0x7878fd(0x195)]&&(_0x3d214b[_0x7878fd(0x202)]=[{'all':!![]}]),db['CannedAnswer']['findAll'](_0x3d214b);})['then'](function(_0x5a09fd){const _0x2f6a3e=_0x18d900;return _0x455fd4[_0x2f6a3e(0x1ed)]=_0x5a09fd,_0x455fd4;});})[_0x532ffd(0x198)](respondWithFilteredResult(_0x12dbc0,_0x3d214b))['catch'](handleError(_0x12dbc0,null));},exports[a938_0x4f87d9(0x1ef)]=function(_0x34d68f,_0xe4338e){const _0x9dd4bf=a938_0x4f87d9;return db[_0x9dd4bf(0x1b1)][_0x9dd4bf(0x1f9)]({'where':{'id':_0x34d68f[_0x9dd4bf(0x19f)]['id']}})['then'](handleEntityNotFound(_0xe4338e,null))['then'](function(_0x253f15){const _0x57b738=_0x9dd4bf;if(_0x253f15)return _0x253f15[_0x57b738(0x1ef)](_0x34d68f[_0x57b738(0x20c)][_0x57b738(0x1c0)]);})[_0x9dd4bf(0x198)](respondWithStatusCode(_0xe4338e,null))['catch'](handleError(_0xe4338e,null));},exports['addAgents']=function(_0x32517f,_0x540866){const _0x28b045=a938_0x4f87d9;return db[_0x28b045(0x1b1)]['findOne']({'where':{'id':_0x32517f['params']['id']}})[_0x28b045(0x198)](function(_0x4b5675){const _0x5a933d=_0x28b045;if(_0x4b5675)return _0x4b5675[_0x5a933d(0x1ad)](_0x32517f[_0x5a933d(0x1a9)][_0x5a933d(0x1c0)],{'through':_[_0x5a933d(0x1b0)](_0x32517f[_0x5a933d(0x1a9)],['ids','id'])})[_0x5a933d(0x198)](function(_0x234af0){const _0x20f85f=_0x5a933d;for(let _0x5c14c5=0x0;_0x5c14c5<_0x32517f['body']['ids'][_0x20f85f(0x1dc)];_0x5c14c5+=0x1){socket[_0x20f85f(0x1f8)](_0x20f85f(0x1c1),{'UserId':_0x32517f['body']['ids'][_0x5c14c5],'WhatsappAccountId':_0x32517f[_0x20f85f(0x19f)]['id']});}return _0x234af0;});})['then'](respondWithResult(_0x540866,null))['catch'](handleError(_0x540866,null));},exports['removeAgents']=function(_0x135196,_0x57f7fc){const _0xd49704=a938_0x4f87d9;return db[_0xd49704(0x1b1)]['findOne']({'where':{'id':_0x135196[_0xd49704(0x19f)]['id']}})[_0xd49704(0x198)](handleEntityNotFound(_0x57f7fc,null))[_0xd49704(0x198)](function(_0x54850b){const _0x411ee2=_0xd49704;if(_0x54850b)return _0x54850b['removeAgents'](_0x135196['query']['ids'])[_0x411ee2(0x198)](function(){const _0x1bf334=_0x411ee2;if(_[_0x1bf334(0x1ee)](_0x135196['query'][_0x1bf334(0x1c0)]))for(let _0x23ac1e=0x0;_0x23ac1e<_0x135196[_0x1bf334(0x20c)][_0x1bf334(0x1c0)][_0x1bf334(0x1dc)];_0x23ac1e+=0x1){socket['emit']('userWhatsappAccount:remove',{'UserId':Number(_0x135196['query'][_0x1bf334(0x1c0)][_0x23ac1e]),'WhatsappAccountId':Number(_0x135196['params']['id'])});}else socket[_0x1bf334(0x1f8)](_0x1bf334(0x1e4),{'UserId':Number(_0x135196[_0x1bf334(0x20c)][_0x1bf334(0x1c0)]),'WhatsappAccountId':Number(_0x135196[_0x1bf334(0x19f)]['id'])});});})[_0xd49704(0x198)](respondWithStatusCode(_0x57f7fc,null))['catch'](handleError(_0x57f7fc,null));},exports[a938_0x4f87d9(0x20d)]=function(_0x3b14a2,_0x26cbd5){const _0x5c84e4=a938_0x4f87d9;let _0x3a1b46={};const _0x192b3e={};let _0x5252c7,_0x23a66f;return db['WhatsappAccount'][_0x5c84e4(0x1f9)]({'where':{'id':_0x3b14a2[_0x5c84e4(0x19f)]['id']}})[_0x5c84e4(0x198)](handleEntityNotFound(_0x26cbd5,null))['then'](function(_0x526ed0){const _0x495396=_0x5c84e4;if(_0x526ed0)return _0x5252c7=_0x526ed0,_0x192b3e[_0x495396(0x183)]=_[_0x495396(0x1d3)](db[_0x495396(0x1ec)]['rawAttributes']),_0x192b3e[_0x495396(0x20c)]=_[_0x495396(0x1d3)](_0x3b14a2[_0x495396(0x20c)]),_0x192b3e['filters']=_[_0x495396(0x1cc)](_0x192b3e[_0x495396(0x183)],_0x192b3e[_0x495396(0x20c)]),_0x3a1b46['attributes']=_[_0x495396(0x1cc)](_0x192b3e[_0x495396(0x183)],qs['fields'](_0x3b14a2[_0x495396(0x20c)][_0x495396(0x18d)])),_0x3a1b46[_0x495396(0x1a7)]=_0x3a1b46[_0x495396(0x1a7)][_0x495396(0x1dc)]?_0x3a1b46[_0x495396(0x1a7)]:_0x192b3e[_0x495396(0x183)],_0x3a1b46['order']=qs[_0x495396(0x1f1)](_0x3b14a2[_0x495396(0x20c)][_0x495396(0x1f1)]),_0x3a1b46['where']=qs[_0x495396(0x18f)](_[_0x495396(0x1e6)](_0x3b14a2[_0x495396(0x20c)],_0x192b3e['filters'])),_0x3b14a2[_0x495396(0x20c)][_0x495396(0x1c5)]&&(_0x3a1b46['where']=_[_0x495396(0x189)](_0x3a1b46[_0x495396(0x1b5)],{[Op['or']]:_[_0x495396(0x21f)](_0x3a1b46[_0x495396(0x1a7)],function(_0x4e2eb1){const _0x1a4692=_0x495396,_0x4b6976={};return _0x4b6976[_0x4e2eb1]={[Op[_0x1a4692(0x1c7)]]:'%'+_0x3b14a2[_0x1a4692(0x20c)][_0x1a4692(0x1c5)]+'%'},_0x4b6976;})})),_0x3a1b46=_[_0x495396(0x189)]({},_0x3a1b46,_0x3b14a2[_0x495396(0x1a6)]),_0x5252c7[_0x495396(0x20d)](_0x3a1b46);})[_0x5c84e4(0x198)](function(_0x323c3b){const _0x1b3fab=_0x5c84e4;if(_0x323c3b)return _0x23a66f=_0x323c3b['length'],typeof _0x3b14a2[_0x1b3fab(0x20c)]['nolimit']===_0x1b3fab(0x1f0)&&(_0x3a1b46['limit']=qs[_0x1b3fab(0x1c2)](_0x3b14a2[_0x1b3fab(0x20c)][_0x1b3fab(0x1c2)]),_0x3a1b46[_0x1b3fab(0x185)]=qs['offset'](_0x3b14a2[_0x1b3fab(0x20c)][_0x1b3fab(0x185)])),_0x5252c7[_0x1b3fab(0x20d)](_0x3a1b46);})[_0x5c84e4(0x198)](function(_0x4706d8){if(_0x4706d8)return _0x4706d8?{'count':_0x23a66f,'rows':_0x4706d8}:null;})[_0x5c84e4(0x198)](respondWithResult(_0x26cbd5,null))['catch'](handleError(_0x26cbd5,null));},exports['addApplications']=function(_0x426ddc,_0x4bfb16){const _0x2c1c1a=a938_0x4f87d9;return db['WhatsappAccount'][_0x2c1c1a(0x1f9)]({'where':{'id':_0x426ddc[_0x2c1c1a(0x19f)]['id']}})['then'](handleEntityNotFound(_0x4bfb16,null))['then'](function(_0x101a0f){const _0x491586=_0x2c1c1a;if(_0x101a0f)return db[_0x491586(0x21b)][_0x491586(0x1af)](function(_0x2eb504){const _0x5f3476=_0x491586;return db[_0x5f3476(0x1de)][_0x5f3476(0x1e2)]({'where':{'WhatsappAccountId':_0x426ddc['params']['id']},'transaction':_0x2eb504})[_0x5f3476(0x198)](function(){const _0x177dbe=_0x5f3476,_0x1e565f=_[_0x177dbe(0x21f)](_0x426ddc[_0x177dbe(0x1a9)],function(_0x4863c0){const _0x5d23f9=_0x177dbe;return _0x4863c0[_0x5d23f9(0x20e)]=_0x426ddc[_0x5d23f9(0x19f)]['id'],_0x4863c0;});return db[_0x177dbe(0x1de)]['bulkCreate'](_0x1e565f,{'transaction':_0x2eb504});});})[_0x491586(0x198)](function(){const _0x24f1b8=_0x491586;return db[_0x24f1b8(0x1de)]['findAndCountAll']({'where':{'WhatsappAccountId':_0x426ddc[_0x24f1b8(0x19f)]['id']},'order':_0x24f1b8(0x21e)});});})[_0x2c1c1a(0x198)](respondWithResult(_0x4bfb16,null))[_0x2c1c1a(0x184)](handleError(_0x4bfb16,null));},exports['getApplications']=function(_0x31a37a,_0x645305){const _0x5e8c53=a938_0x4f87d9;let _0x34d242={};const _0x216549={};let _0x33c390,_0x327c97;return db[_0x5e8c53(0x1b1)][_0x5e8c53(0x1f9)]({'where':{'id':_0x31a37a[_0x5e8c53(0x19f)]['id']}})[_0x5e8c53(0x198)](handleEntityNotFound(_0x645305,null))[_0x5e8c53(0x198)](function(_0x2d36b3){const _0x461125=_0x5e8c53;if(_0x2d36b3)return _0x33c390=_0x2d36b3,_0x216549[_0x461125(0x183)]=_[_0x461125(0x1d3)](db[_0x461125(0x1de)][_0x461125(0x1e5)]),_0x216549[_0x461125(0x20c)]=_[_0x461125(0x1d3)](_0x31a37a[_0x461125(0x20c)]),_0x216549[_0x461125(0x18f)]=_[_0x461125(0x1cc)](_0x216549['model'],_0x216549[_0x461125(0x20c)]),_0x34d242[_0x461125(0x1a7)]=_[_0x461125(0x1cc)](_0x216549['model'],qs[_0x461125(0x18d)](_0x31a37a[_0x461125(0x20c)][_0x461125(0x18d)])),_0x34d242['attributes']=_0x34d242['attributes'][_0x461125(0x1dc)]?_0x34d242[_0x461125(0x1a7)]:_0x216549[_0x461125(0x183)],_0x34d242['order']=qs['sort'](_0x31a37a[_0x461125(0x20c)][_0x461125(0x1f1)]),_0x34d242[_0x461125(0x1b5)]=qs[_0x461125(0x18f)](_['pick'](_0x31a37a[_0x461125(0x20c)],_0x216549[_0x461125(0x18f)])),_0x31a37a[_0x461125(0x20c)]['filter']&&(_0x34d242[_0x461125(0x1b5)]=_[_0x461125(0x189)](_0x34d242[_0x461125(0x1b5)],{[Op['or']]:_[_0x461125(0x21f)](_0x34d242[_0x461125(0x1a7)],function(_0xaf658){const _0x201496=_0x461125,_0x22fe6d={};return _0x22fe6d[_0xaf658]={[Op[_0x201496(0x1c7)]]:'%'+_0x31a37a[_0x201496(0x20c)][_0x201496(0x1c5)]+'%'},_0x22fe6d;})})),_0x34d242=_[_0x461125(0x189)]({},_0x34d242,_0x31a37a[_0x461125(0x1a6)]),_0x33c390['getApplications'](_0x34d242);})[_0x5e8c53(0x198)](function(_0x17883){const _0x302c7b=_0x5e8c53;if(_0x17883)return _0x327c97=_0x17883[_0x302c7b(0x1dc)],typeof _0x31a37a['query'][_0x302c7b(0x1a0)]===_0x302c7b(0x1f0)&&(_0x34d242[_0x302c7b(0x1c2)]=qs['limit'](_0x31a37a['query'][_0x302c7b(0x1c2)]),_0x34d242['offset']=qs['offset'](_0x31a37a[_0x302c7b(0x20c)][_0x302c7b(0x185)])),_0x33c390['getApplications'](_0x34d242);})['then'](function(_0x2da809){if(_0x2da809)return _0x2da809?{'count':_0x327c97,'rows':_0x2da809}:null;})['then'](respondWithResult(_0x645305,null))[_0x5e8c53(0x184)](handleError(_0x645305,null));},exports[a938_0x4f87d9(0x1c6)]=function(_0x384335,_0x4dc021){const _0xed72f0=a938_0x4f87d9,_0x5601a1={'channel':'whatsapp'};let _0x23209d=[],_0x42b41e=[];const _0x20662e={};return db[_0xed72f0(0x1b1)][_0xed72f0(0x1f9)]({'where':{'id':_0x384335['params']['id']},'include':[{'model':db[_0xed72f0(0x1de)],'as':_0xed72f0(0x1f7)}]})[_0xed72f0(0x198)](handleEntityNotFound(_0x4dc021,null))['then'](function(_0x1aa8cb){const _0x19fcb9=_0xed72f0;return _0x5601a1[_0x19fcb9(0x19b)]=_0x1aa8cb,_0x5601a1[_0x19fcb9(0x1d9)]=_[_0x19fcb9(0x207)](_0x1aa8cb[_0x19fcb9(0x1f7)],[_0x19fcb9(0x21e)],['asc']),_0x5601a1['account'][_0x19fcb9(0x1f7)]&&delete _0x5601a1[_0x19fcb9(0x19b)]['Applications'],db[_0x19fcb9(0x1da)][_0x19fcb9(0x18b)]();})['then'](function(_0x2f78e9){const _0x215b92=_0xed72f0;if(!_0x2f78e9)throw new ValidationError('no\x20available\x20attributes');_0x23209d=_[_0x215b92(0x1ce)](_[_0x215b92(0x1d3)](_0x2f78e9),[_0x215b92(0x1ab),_0x215b92(0x1c9)]),_0x42b41e=_[_0x215b92(0x1ce)](_[_0x215b92(0x1d3)](_0x2f78e9),['createdAt',_0x215b92(0x1c9),'CompanyId','ListId']),_0x5601a1[_0x215b92(0x1a9)]={'mapKey':_0x215b92(0x205)};_0x5601a1['account']['type']&&_0x5601a1[_0x215b92(0x19b)][_0x215b92(0x1a2)]==='twilio'&&(_0x5601a1[_0x215b92(0x1a9)][_0x215b92(0x1d4)]=_0x384335[_0x215b92(0x1a9)]['From'][_0x215b92(0x213)](_0x215b92(0x1f4),''),_0x5601a1[_0x215b92(0x1a9)][_0x215b92(0x1a9)]=_0x384335['body'][_0x215b92(0x1a8)],_0x5601a1['body'][_0x215b92(0x197)]=_0x384335[_0x215b92(0x1a9)]['MessageSid']);_0x5601a1[_0x215b92(0x1a9)]['id']&&delete _0x5601a1[_0x215b92(0x1a9)]['id'];if(_[_0x215b92(0x1df)](_0x5601a1[_0x215b92(0x1a9)][_0x215b92(0x1d4)]))throw new ValidationError(_0x215b92(0x187));if(_[_0x215b92(0x1df)](_0x5601a1[_0x215b92(0x1a9)][_0x215b92(0x1a9)])||_0x5601a1[_0x215b92(0x1a9)][_0x215b92(0x1a9)]==='')throw new ValidationError('body\x20is\x20mandatory\x20and\x20not\x20empty');if(_[_0x215b92(0x1df)](_0x5601a1[_0x215b92(0x1a9)][_0x215b92(0x194)]))throw new ValidationError(_0x215b92(0x1eb)+_0x42b41e);if(!_[_0x215b92(0x1e3)](_0x42b41e,_0x5601a1[_0x215b92(0x1a9)]['mapKey']))throw new ValidationError(_0x215b92(0x1c3)+_0x42b41e);return _0x20662e[_0x5601a1[_0x215b92(0x1a9)]['mapKey']]=_0x5601a1[_0x215b92(0x1a9)][_0x215b92(0x1d4)],db[_0x215b92(0x199)]['findOne']({'where':{'id':_0x5601a1[_0x215b92(0x19b)][_0x215b92(0x1b9)]},'include':[{'model':db[_0x215b92(0x1da)],'as':_0x215b92(0x19c),'where':_0x20662e,'limit':0x1,'order':[['updatedAt',_0x215b92(0x21a)]]}]});})[_0xed72f0(0x198)](handleEntityNotFound(_0x4dc021,null))[_0xed72f0(0x198)](function(_0x3b5c1e){const _0xba186=_0xed72f0;if(_0x3b5c1e){_0x5601a1[_0xba186(0x20a)]=_[_0xba186(0x1b0)](_0x3b5c1e,['Contacts']);if(_0x3b5c1e[_0xba186(0x19c)]['length'])return _0x3b5c1e[_0xba186(0x19c)][0x0];const _0x165a39=_[_0xba186(0x190)](_0x5601a1[_0xba186(0x1a9)],{'firstName':_0x5601a1['body'][_0xba186(0x1d4)],'ListId':_0x3b5c1e['id']});return _0x165a39[_0x5601a1['body'][_0xba186(0x194)]]=_0x5601a1['body'][_0xba186(0x1d4)],db[_0xba186(0x1da)]['create'](_0x165a39,{'fields':_0x23209d,'raw':!![]});}})[_0xed72f0(0x198)](handleEntityNotFound(_0x4dc021,null))[_0xed72f0(0x198)](function(_0x558330){const _0x543b35=_0xed72f0;if(_0x558330){_0x5601a1[_0x543b35(0x211)]=_0x558330;const _0xa2c154={'ContactId':_0x558330['id'],'phone':_0x5601a1[_0x543b35(0x1a9)][_0x543b35(0x1d4)],'WhatsappAccountId':_0x384335[_0x543b35(0x19f)]['id']},_0x59057c={'ContactId':_0x558330['id'],'WhatsappAccountId':_0x384335[_0x543b35(0x19f)]['id'],'closed':![]};return db['WhatsappInteraction'][_0x543b35(0x1f9)]({'where':_0x59057c})[_0x543b35(0x198)](function(_0x3a3804){const _0x210c65=_0x543b35;if(_0x3a3804)return[_0x3a3804,![]];return db[_0x210c65(0x1bc)][_0x210c65(0x1b2)](_0xa2c154)[_0x210c65(0x198)](function(_0x478247){return[_0x478247,!![]];});});}})[_0xed72f0(0x198)](function([_0x883e48,_0x4ac6f3]){const _0x2bffc9=_0xed72f0;return _0x5601a1[_0x2bffc9(0x1cf)]=_0x883e48[_0x2bffc9(0x1be)]({'plain':!![]}),_0x5601a1['interaction'][_0x2bffc9(0x200)]=![],_0x4ac6f3&&(_0x5601a1[_0x2bffc9(0x19b)][_0x2bffc9(0x218)]&&_0x5601a1['applications'][_0x2bffc9(0x1e7)]({'id':0x0,'priority':_0x5601a1[_0x2bffc9(0x1d9)][_0x2bffc9(0x1dc)]+0x1,'app':_0x2bffc9(0x20b),'appdata':_0x2bffc9(0x1ff),'interval':_0x2bffc9(0x1a4)}),_0x5601a1[_0x2bffc9(0x1cf)][_0x2bffc9(0x200)]=!![]),db[_0x2bffc9(0x1cb)][_0x2bffc9(0x1b2)]({'phone':_0x5601a1[_0x2bffc9(0x1a9)]['from'],'messageId':_0x5601a1[_0x2bffc9(0x1a9)]['messageId'],'body':_0x5601a1[_0x2bffc9(0x1a9)]['body'],'WhatsappAccountId':_0x384335[_0x2bffc9(0x19f)]['id'],'WhatsappInteractionId':_0x883e48['id'],'direction':'in','ContactId':_0x883e48[_0x2bffc9(0x1db)],'AttachmentId':_0x5601a1[_0x2bffc9(0x1a9)][_0x2bffc9(0x1d1)]});})[_0xed72f0(0x198)](function(_0x50af0b){const _0xd276e6=_0xed72f0;_0x5601a1['message']=_0x50af0b;if(_0x5601a1['interaction'][_0xd276e6(0x201)])return db[_0xd276e6(0x1ec)]['findOne']({'attributes':['id',_0xd276e6(0x212)],'where':{'id':_0x5601a1[_0xd276e6(0x1cf)][_0xd276e6(0x201)]}})[_0xd276e6(0x198)](function(_0x33272f){const _0x2556d5=_0xd276e6;return _0x33272f&&_0x5601a1[_0x2556d5(0x1d9)][_0x2556d5(0x206)]({'id':0x0,'priority':0x0,'app':_0x2556d5(0x1c4),'appdata':_0x33272f[_0x2556d5(0x212)]+','+(_0x5601a1['account'][_0x2556d5(0x1aa)]||0xa),'interval':_0x2556d5(0x1a4)}),respondWithRpcPromise(_0x2556d5(0x186),_0x2556d5(0x1d5),_0x5601a1);});return respondWithRpcPromise(_0xd276e6(0x186),'startRouting',_0x5601a1);})[_0xed72f0(0x198)](function(_0xe71b26){const _0x4c1f66=_0xed72f0;if(_0xe71b26){const _0x2984c3=0xc8,_0x450060=_0x4c1f66(0x18a);return logger[_0x4c1f66(0x1b7)]('WhatsappAccount,\x20%s,\x20%s,\x20%s',_0x450060,_0x2984c3,_0x4c1f66(0x208)),logger['debug']('WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s',_0x450060,_0x2984c3,_0x4c1f66(0x208),JSON[_0x4c1f66(0x1b6)](_0xe71b26)),_0x5601a1[_0x4c1f66(0x19b)][_0x4c1f66(0x1a2)]==='twilio'?_0x4dc021[_0x4c1f66(0x1d0)](_0x2984c3)['set'](_0x4c1f66(0x191),_0x4c1f66(0x18c))[_0x4c1f66(0x1f3)](_0x4c1f66(0x1ca)):_0x4dc021[_0x4c1f66(0x1d0)](_0x2984c3)[_0x4c1f66(0x1dd)](_0xe71b26);}})[_0xed72f0(0x184)](handleError(_0x4dc021,null));},exports[a938_0x4f87d9(0x1f3)]=function(_0x31f9fc,_0x427743){const _0x441560=a938_0x4f87d9;let _0x3263d2,_0x15d7da;if(_[_0x441560(0x1df)](_0x31f9fc[_0x441560(0x1a9)][_0x441560(0x1a9)])||_0x31f9fc['body'][_0x441560(0x1a9)]==='')throw new ValidationError(_0x441560(0x1a1));if(_['isNil'](_0x31f9fc[_0x441560(0x1a9)]['to']))throw new ValidationError('to\x20is\x20mandatory');const _0x12d464=_0x31f9fc[_0x441560(0x1a9)]['to'];return db[_0x441560(0x1b1)]['findOne']({'where':{'id':_0x31f9fc[_0x441560(0x19f)]['id']},'include':[{'model':db['CmList'],'as':_0x441560(0x1d8),'include':[{'model':db[_0x441560(0x1da)],'as':_0x441560(0x19c),'where':{'mobile':_0x12d464},'limit':0x1,'order':[[_0x441560(0x1c9),_0x441560(0x21a)]]}]}]})[_0x441560(0x198)](handleEntityNotFound(_0x427743,null))[_0x441560(0x198)](function(_0x25ff4f){const _0x329542=_0x441560;if(_0x25ff4f&&_0x25ff4f[_0x329542(0x1d8)]){_0x3263d2=_0x25ff4f['get']({'plain':!![]});if(_0x3263d2[_0x329542(0x1d8)]&&_0x3263d2[_0x329542(0x1d8)]['Contacts'][_0x329542(0x1dc)])return _0x3263d2[_0x329542(0x1d8)][_0x329542(0x19c)][0x0];return db[_0x329542(0x1da)][_0x329542(0x1b2)](_[_0x329542(0x190)](_0x31f9fc['body'],{'firstName':_0x12d464,'mobile':_0x12d464,'phone':_0x12d464,'ListId':_0x3263d2['ListId']}));}})['then'](handleEntityNotFound(_0x427743,null))[_0x441560(0x198)](function(_0x2d56ae){const _0x2241b8=_0x441560;if(_0x2d56ae)return _0x15d7da=_0x2d56ae,db[_0x2241b8(0x1bc)][_0x2241b8(0x1f9)]({'where':{'ContactId':_0x15d7da['id'],'closed':![],'WhatsappAccountId':_0x3263d2['id']}})['then'](function(_0xdbf441){const _0x3da914=_0x2241b8;if(_0xdbf441)return[_0xdbf441,![]];return db['WhatsappInteraction'][_0x3da914(0x1b2)]({'UserId':_0x31f9fc[_0x3da914(0x1e0)]['id'],'ContactId':_0x15d7da['id'],'WhatsappAccountId':_0x3263d2['id'],'phone':_0x12d464,'firstMsgDirection':_0x3da914(0x1d7),'Messages':[_['merge'](_0x31f9fc[_0x3da914(0x1a9)],{'read':![],'body':_0x31f9fc[_0x3da914(0x1a9)]['body'],'phone':_0x12d464,'WhatsappAccountId':_0x3263d2['id'],'UserId':_0x31f9fc[_0x3da914(0x1e0)]['id'],'ContactId':_0x15d7da['id']})]},{'include':[{'model':db[_0x3da914(0x1cb)],'as':_0x3da914(0x196)}]})['then'](function(_0x3e2f91){return[_0x3e2f91,!![]];});});})[_0x441560(0x198)](function([_0xe90a1,_0x17d130]){const _0x3f4d8c=_0x441560;if(_0x17d130)return _0xe90a1;return db[_0x3f4d8c(0x1cb)][_0x3f4d8c(0x1b2)](_[_0x3f4d8c(0x189)](_0x31f9fc[_0x3f4d8c(0x1a9)],{'read':![],'body':_0x31f9fc[_0x3f4d8c(0x1a9)][_0x3f4d8c(0x1a9)],'phone':_0x12d464,'WhatsappAccountId':_0x3263d2['id'],'WhatsappInteractionId':_0xe90a1['id'],'UserId':_0x31f9fc[_0x3f4d8c(0x1e0)]['id'],'ContactId':_0x15d7da['id']}))['then'](function(_0xa044fc){const _0x3e01b7=_0x3f4d8c;return _0xe90a1[_0x3e01b7(0x188)][_0x3e01b7(0x196)]=[],_0xe90a1[_0x3e01b7(0x188)][_0x3e01b7(0x196)][_0x3e01b7(0x1e7)](_0xa044fc[_0x3e01b7(0x188)]),_0xe90a1;});})[_0x441560(0x198)](respondWithResult(_0x427743,null))[_0x441560(0x184)](handleError(_0x427743,null));};
\ No newline at end of file