Built motion from commit be44e1e4d16f8b29d243415b03d27262d8601e0e. Version 3.0.0...
[motion-next.git] / server / api / whatsappAccount / whatsappAccount.controller.js
1 const a783_0x37d6=['push','name','ids','getApplications','userProfileId','catch','WhatsappAccount,\x20%s,\x20%s,\x20%s','created','user','twilio','ValidationError','WhatsappMessage','close','List','intersection','entity\x20found','code','fields','UserProfileResource','query','*,*,*,*','params','MessageSid','Messages','autoclose','orderBy','mobile','VIRTUAL','Start','model','then','./whatsappAccount.socket','type','list','From','lodash','notify','WhatsappAccount,\x20%s,\x20%s,\x20%s,\x20%s','difference','attributes','getDispositions','nolimit','limit','mapKey','applications','send','filter','to\x20is\x20mandatory','addAgents','account','Unable\x20to\x20retrieve\x20the\x20current\x20user','http','emit','defaults','includeAll','userWhatsappAccount:remove','rawAttributes','User','update','merge','WhatsappAccount,\x20%s,\x20%s','asc','Pause','get','findOne','pick','removeDispositions','replace','set','WhatsappApplication','findAll','Disposition','filters','whatsapp:','contact','WhatsappAccount','includes','body\x20is\x20mandatory\x20and\x20not\x20empty','autoAssociation','CompanyId','no\x20available\x20attributes','CmContact','../../components/parsers/qs','order','map','isArray','unshift','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','json','end','create','addDisposition','CmList','findAndCountAll','length','out','Contacts','WhatsappInteraction','waitForTheAssignedAgent','ContactId','dataValues','updatedAt','whatsapp','priority','WhatsappAccountId','destroy','include','omit','debug','message','status','../../config/logger','Content-Range','from','info','offset','request\x20sent','CannedAnswer','keys','WhatsappAccounts','ListId','sequelize','sendStatus','startRouting','count','undefined','rows','getAgents','like','removeAnswers','DESC','agent','unmanaged','register','error','options','body','Sequelize','result','removeAgents','mandatoryDispositionPause','../../mysqldb','key','UserId','where','Applications','stringify','interaction','isNil','describe','AttachmentId','addAnswer','createdAt','jayson/promise','bulkCreate','show','sort'];(function(_0x16149e,_0x37d69c){const _0x30add8=function(_0x68a116){while(--_0x68a116){_0x16149e['push'](_0x16149e['shift']());}};_0x30add8(++_0x37d69c);}(a783_0x37d6,0x1a4));const a783_0x30ad=function(_0x16149e,_0x37d69c){_0x16149e=_0x16149e-0x0;let _0x30add8=a783_0x37d6[_0x16149e];return _0x30add8;};const _0x3b39b4=a783_0x30ad;'use strict';const _=require(_0x3b39b4('0x56')),qs=require(_0x3b39b4('0x85')),logger=require(_0x3b39b4('0x5'))('api'),{getSocket}=require('../../rediscache'),socket=getSocket(),db=require(_0x3b39b4('0x23'))['db'],{Op}=require(_0x3b39b4('0xf'));require(_0x3b39b4('0x52'))[_0x3b39b4('0x1b')](socket);const jayson=require(_0x3b39b4('0x2f')),client=jayson['client'][_0x3b39b4('0x66')]({'port':0x232c});function respondWithRpcPromise(_0x68a116,_0x3c20bf,_0x28cba7,_0x2f111d){return new Promise(function(_0x33aded,_0x49a6a5){const _0x2adda7=_0x2f111d||client;return _0x2adda7['request'](_0x68a116,_0x28cba7)['then'](function(_0x2000a0){const _0x5af9c0=a783_0x30ad;logger[_0x5af9c0('0x8')]('WhatsappAccount,\x20%s,\x20%s',_0x3c20bf,_0x5af9c0('0xa')),logger[_0x5af9c0('0x2')](_0x5af9c0('0x39'),_0x3c20bf,_0x5af9c0('0xa'),JSON[_0x5af9c0('0x28')](_0x2000a0));if(_0x2000a0[_0x5af9c0('0x1c')]){if(_0x2000a0[_0x5af9c0('0x1c')][_0x5af9c0('0x43')]===0x1f4)return logger[_0x5af9c0('0x1c')](_0x5af9c0('0x6f'),_0x3c20bf,_0x2000a0['error']['message']),_0x49a6a5(_0x2000a0[_0x5af9c0('0x1c')][_0x5af9c0('0x3')]);return logger[_0x5af9c0('0x1c')](_0x5af9c0('0x6f'),_0x3c20bf,_0x2000a0[_0x5af9c0('0x1c')][_0x5af9c0('0x3')]),_0x33aded(_0x2000a0[_0x5af9c0('0x1c')][_0x5af9c0('0x3')]);}else logger[_0x5af9c0('0x8')](_0x5af9c0('0x6f'),_0x3c20bf,_0x5af9c0('0xa')),_0x33aded(_0x2000a0[_0x5af9c0('0x20')][_0x5af9c0('0x3')]);})['catch'](function(_0x362dd5){const _0x45a62d=a783_0x30ad;logger[_0x45a62d('0x1c')]('WhatsappAccount,\x20%s,\x20%s',_0x3c20bf,_0x362dd5),_0x49a6a5(_0x362dd5);});});}function respondWithStatusCode(_0x22742b,_0x1f413b){return _0x1f413b=_0x1f413b||0xcc,function(_0x3b59d9){const _0x5ca641=a783_0x30ad;if(_0x3b59d9)return _0x22742b[_0x5ca641('0x10')](_0x1f413b);return _0x22742b['status'](_0x1f413b)[_0x5ca641('0x8c')]();};}function respondWithResult(_0x4364e1,_0xdb6039){return _0xdb6039=_0xdb6039||0xc8,function(_0x274f71){const _0x31c54c=a783_0x30ad;if(_0x274f71)return _0x4364e1['status'](_0xdb6039)[_0x31c54c('0x8b')](_0x274f71);};}function respondWithFilteredResult(_0x86688e,_0x1f07b1){return function(_0x1d18a3){const _0x154c95=a783_0x30ad;if(_0x1d18a3){const _0x13efea=_0x1d18a3[_0x154c95('0x12')],_0x554ebd=_0x1f07b1['offset'];let _0x280930=_0x1f07b1['offset']+_0x1f07b1[_0x154c95('0x5d')],_0x37a51c;return _0x280930>=_0x13efea?(_0x280930=_0x13efea,_0x37a51c=0xc8):_0x37a51c=0xce,_0x86688e[_0x154c95('0x4')](_0x37a51c),_0x86688e[_0x154c95('0x77')](_0x154c95('0x6'),_0x554ebd+'-'+_0x280930+'/'+_0x13efea)['json'](_0x1d18a3);}return null;};}function saveUpdates(_0x355f95){return function(_0x5c9a8b){const _0x4d5a4c=a783_0x30ad;if(_0x5c9a8b)return _0x5c9a8b['update'](_0x355f95)[_0x4d5a4c('0x51')](function(_0x193663){return _0x193663;});return null;};}function removeEntity(_0xee6d2d){return function(_0xa17257){const _0x11e6dc=a783_0x30ad;if(_0xa17257)return _0xa17257[_0x11e6dc('0x9c')]()['then'](function(){const _0x5162cd=_0x11e6dc,_0x5b0d8b=_0xa17257[_0x5162cd('0x72')]({'plain':!![]}),_0x37f963='WhatsappAccounts';return db[_0x5162cd('0x45')][_0x5162cd('0x9c')]({'where':{'type':_0x37f963,'resourceId':_0x5b0d8b['id']}})[_0x5162cd('0x51')](function(){return _0xa17257;});})[_0x11e6dc('0x51')](function(){const _0x26350e=_0x11e6dc;_0xee6d2d[_0x26350e('0x4')](0xcc)['end']();});};}function handleEntityNotFound(_0x3f24d9){return function(_0x1668fb){const _0x4f53e2=a783_0x30ad;return!_0x1668fb&&_0x3f24d9[_0x4f53e2('0x10')](0x194),_0x1668fb;};}function handleError(_0xd39c2d,_0x2cde68){return _0x2cde68=_0x2cde68||0x1f4,function(_0xae6d6){const _0x3fc83f=a783_0x30ad;logger[_0x3fc83f('0x1c')](_0xae6d6['stack']),_0xae6d6['name']&&delete _0xae6d6['name'],_0xd39c2d[_0x3fc83f('0x4')](_0x2cde68)[_0x3fc83f('0x60')](_0xae6d6);};}exports['index']=function(_0x4a1b1b,_0x494f19){const _0x178a1e=_0x3b39b4;let _0x202ab7={'include':[{'model':db[_0x178a1e('0x71')],'as':_0x178a1e('0x22')}]};const _0x9dd52c={},_0x1d7f6c={'count':0x0,'rows':[]},_0x1d10b8=_['map'](db['WhatsappAccount'][_0x178a1e('0x6b')],function(_0x231c7a){const _0x1e9c3f=_0x178a1e;return{'name':_0x231c7a['fieldName'],'type':_0x231c7a[_0x1e9c3f('0x53')][_0x1e9c3f('0x24')]};});_0x9dd52c[_0x178a1e('0x50')]=_[_0x178a1e('0x87')](_0x1d10b8,'name'),_0x9dd52c[_0x178a1e('0x46')]=_[_0x178a1e('0xc')](_0x4a1b1b[_0x178a1e('0x46')]),_0x9dd52c[_0x178a1e('0x7b')]=_['intersection'](_0x9dd52c['model'],_0x9dd52c['query']),_0x202ab7[_0x178a1e('0x5a')]=_['intersection'](_0x9dd52c['model'],qs[_0x178a1e('0x44')](_0x4a1b1b[_0x178a1e('0x46')][_0x178a1e('0x44')])),_0x202ab7['attributes']=_0x202ab7[_0x178a1e('0x5a')][_0x178a1e('0x91')]?_0x202ab7['attributes']:_0x9dd52c['model'];typeof _0x4a1b1b['query']['nolimit']===_0x178a1e('0x13')&&(_0x202ab7[_0x178a1e('0x5d')]=qs[_0x178a1e('0x5d')](_0x4a1b1b['query'][_0x178a1e('0x5d')]),_0x202ab7[_0x178a1e('0x9')]=qs['offset'](_0x4a1b1b[_0x178a1e('0x46')][_0x178a1e('0x9')]));_0x202ab7['order']=qs['sort'](_0x4a1b1b[_0x178a1e('0x46')]['sort']),_0x202ab7[_0x178a1e('0x26')]=qs[_0x178a1e('0x7b')](_[_0x178a1e('0x74')](_0x4a1b1b['query'],_0x9dd52c[_0x178a1e('0x7b')]),_0x1d10b8);_0x4a1b1b[_0x178a1e('0x46')][_0x178a1e('0x61')]&&(_0x202ab7[_0x178a1e('0x26')]=_[_0x178a1e('0x6e')](_0x202ab7['where'],{[Op['or']]:_[_0x178a1e('0x87')](_0x1d10b8,function(_0x1230ff){const _0x5e7291=_0x178a1e;if(_0x1230ff['type']!==_0x5e7291('0x4e')){const _0x3628ac={};return _0x3628ac[_0x1230ff[_0x5e7291('0x34')]]={[Op[_0x5e7291('0x16')]]:'%'+_0x4a1b1b[_0x5e7291('0x46')][_0x5e7291('0x61')]+'%'},_0x3628ac;}})}));_0x202ab7=_[_0x178a1e('0x6e')]({},_0x202ab7,_0x4a1b1b[_0x178a1e('0x1d')]);const _0x4f7847={'where':_0x202ab7[_0x178a1e('0x26')]};return db['WhatsappAccount']['count'](_0x4f7847)[_0x178a1e('0x51')](function(_0x322475){const _0x1412a8=_0x178a1e;return _0x1d7f6c['count']=_0x322475,_0x4a1b1b[_0x1412a8('0x46')][_0x1412a8('0x69')]&&(_0x202ab7[_0x1412a8('0x0')]=[{'all':!![]}]),db[_0x1412a8('0x7e')][_0x1412a8('0x79')](_0x202ab7);})[_0x178a1e('0x51')](function(_0x1cb130){const _0x43bdd1=_0x178a1e;return _0x1d7f6c[_0x43bdd1('0x14')]=_0x1cb130,_0x1d7f6c;})[_0x178a1e('0x51')](respondWithFilteredResult(_0x494f19,_0x202ab7))['catch'](handleError(_0x494f19,null));},exports[_0x3b39b4('0x31')]=function(_0x17b91a,_0x55c472){const _0x1a6334=_0x3b39b4;let _0x57aea7={'raw':![],'where':{'id':_0x17b91a[_0x1a6334('0x48')]['id']},'include':[{'model':db[_0x1a6334('0x71')],'as':_0x1a6334('0x22')}]};const _0x259feb={};return _0x259feb[_0x1a6334('0x50')]=_[_0x1a6334('0xc')](db[_0x1a6334('0x7e')]['rawAttributes']),_0x259feb['query']=_['keys'](_0x17b91a['query']),_0x259feb[_0x1a6334('0x7b')]=_[_0x1a6334('0x41')](_0x259feb[_0x1a6334('0x50')],_0x259feb[_0x1a6334('0x46')]),_0x57aea7[_0x1a6334('0x5a')]=_['intersection'](_0x259feb[_0x1a6334('0x50')],qs[_0x1a6334('0x44')](_0x17b91a[_0x1a6334('0x46')]['fields'])),_0x57aea7[_0x1a6334('0x5a')]=_0x57aea7['attributes'][_0x1a6334('0x91')]?_0x57aea7['attributes']:_0x259feb[_0x1a6334('0x50')],_0x17b91a[_0x1a6334('0x46')]['includeAll']&&(_0x57aea7[_0x1a6334('0x0')]=[{'all':!![]}]),_0x57aea7=_[_0x1a6334('0x6e')]({},_0x57aea7,_0x17b91a['options']),db[_0x1a6334('0x7e')][_0x1a6334('0x73')](_0x57aea7)[_0x1a6334('0x51')](handleEntityNotFound(_0x55c472,null))[_0x1a6334('0x51')](respondWithResult(_0x55c472,null))[_0x1a6334('0x38')](handleError(_0x55c472,null));},exports[_0x3b39b4('0x8d')]=function(_0x5b7d2c,_0x245edd){const _0x186471=_0x3b39b4;return db['WhatsappAccount'][_0x186471('0x8d')](_0x5b7d2c[_0x186471('0x1e')],{})[_0x186471('0x51')](function(_0x44e22f){const _0xa53fef=_0x186471,_0x42f060=_0x5b7d2c[_0xa53fef('0x3b')][_0xa53fef('0x72')]({'plain':!![]});if(!_0x42f060)throw new Error(_0xa53fef('0x65'));if(_0x42f060['role']===_0xa53fef('0x3b')){const _0x593021=_0x44e22f[_0xa53fef('0x72')]({'plain':!![]}),_0x306a95=_0xa53fef('0xd');return db['UserProfileSection'][_0xa53fef('0x73')]({'where':{'name':_0x306a95,'userProfileId':_0x42f060[_0xa53fef('0x37')]},'raw':!![]})['then'](function(_0x4e03b8){const _0x25a846=_0xa53fef;return _0x4e03b8&&_0x4e03b8[_0x25a846('0x81')]===0x0?db[_0x25a846('0x45')][_0x25a846('0x8d')]({'name':_0x593021[_0x25a846('0x34')],'resourceId':_0x593021['id'],'type':_0x4e03b8[_0x25a846('0x34')],'sectionId':_0x4e03b8['id']},{})[_0x25a846('0x51')](function(){return _0x44e22f;}):_0x44e22f;})[_0xa53fef('0x38')](function(_0x5ed222){const _0x351924=_0xa53fef;logger[_0x351924('0x1c')](_0x351924('0x8a'),_0x5ed222);throw _0x5ed222;});}return _0x44e22f;})[_0x186471('0x51')](respondWithResult(_0x245edd,0xc9))[_0x186471('0x38')](handleError(_0x245edd,null));},exports[_0x3b39b4('0x6d')]=function(_0x253cb5,_0x587643){const _0x24860f=_0x3b39b4;return _0x253cb5[_0x24860f('0x1e')]['id']&&delete _0x253cb5[_0x24860f('0x1e')]['id'],db['WhatsappAccount'][_0x24860f('0x73')]({'where':{'id':_0x253cb5[_0x24860f('0x48')]['id']},'include':[{'model':db[_0x24860f('0x71')],'as':'mandatoryDispositionPause'}]})[_0x24860f('0x51')](handleEntityNotFound(_0x587643,null))[_0x24860f('0x51')](saveUpdates(_0x253cb5[_0x24860f('0x1e')],null))[_0x24860f('0x51')](respondWithResult(_0x587643,null))[_0x24860f('0x38')](handleError(_0x587643,null));},exports['destroy']=function(_0x114616,_0x39975a){const _0x4db207=_0x3b39b4;return db[_0x4db207('0x7e')][_0x4db207('0x73')]({'where':{'id':_0x114616[_0x4db207('0x48')]['id']}})['then'](handleEntityNotFound(_0x39975a,null))[_0x4db207('0x51')](removeEntity(_0x39975a,null))['catch'](handleError(_0x39975a,null));},exports[_0x3b39b4('0x2b')]=function(_0x8a3d01,_0x4d4fe1){const _0x3772cc=_0x3b39b4;return db[_0x3772cc('0x7e')][_0x3772cc('0x2b')]()[_0x3772cc('0x51')](respondWithResult(_0x4d4fe1,null))[_0x3772cc('0x38')](handleError(_0x4d4fe1,null));},exports[_0x3b39b4('0x8e')]=function(_0x3184e9,_0x5e77aa){const _0x7d1d33=_0x3b39b4;return _0x3184e9['body']['id']&&delete _0x3184e9[_0x7d1d33('0x1e')]['id'],db['WhatsappAccount'][_0x7d1d33('0x73')]({'where':{'id':_0x3184e9[_0x7d1d33('0x48')]['id']}})[_0x7d1d33('0x51')](handleEntityNotFound(_0x5e77aa,null))[_0x7d1d33('0x51')](function(_0x3e963d){const _0x391dd0=_0x7d1d33;if(_0x3e963d)return _0x3184e9[_0x391dd0('0x1e')][_0x391dd0('0x9b')]=_0x3e963d['id'],db['Disposition'][_0x391dd0('0x8d')](_0x3184e9[_0x391dd0('0x1e')]);})['then'](respondWithResult(_0x5e77aa,null))[_0x7d1d33('0x38')](handleError(_0x5e77aa,null));},exports[_0x3b39b4('0x5b')]=function(_0x3970cd,_0x503dc8){const _0xd641d0=_0x3b39b4;let _0x438430={'raw':![],'where':{}};const _0x11c970={},_0xb2cc55={'count':0x0,'rows':[]};return db[_0xd641d0('0x7e')][_0xd641d0('0x73')]({'where':{'id':_0x3970cd[_0xd641d0('0x48')]['id']}})[_0xd641d0('0x51')](handleEntityNotFound(_0x503dc8,null))[_0xd641d0('0x51')](function(_0x2c3a24){const _0x440553=_0xd641d0;if(_0x2c3a24)return _0x11c970[_0x440553('0x50')]=_[_0x440553('0xc')](db[_0x440553('0x7a')][_0x440553('0x6b')]),_0x11c970[_0x440553('0x46')]=_[_0x440553('0xc')](_0x3970cd[_0x440553('0x46')]),_0x11c970[_0x440553('0x7b')]=_['intersection'](_0x11c970['model'],_0x11c970[_0x440553('0x46')]),_0x438430[_0x440553('0x5a')]=_[_0x440553('0x41')](_0x11c970['model'],qs[_0x440553('0x44')](_0x3970cd[_0x440553('0x46')][_0x440553('0x44')])),_0x438430['attributes']=_0x438430[_0x440553('0x5a')][_0x440553('0x91')]?_0x438430['attributes']:_0x11c970['model'],typeof _0x3970cd[_0x440553('0x46')][_0x440553('0x5c')]===_0x440553('0x13')&&(_0x438430[_0x440553('0x5d')]=qs[_0x440553('0x5d')](_0x3970cd[_0x440553('0x46')][_0x440553('0x5d')]),_0x438430[_0x440553('0x9')]=qs[_0x440553('0x9')](_0x3970cd[_0x440553('0x46')][_0x440553('0x9')])),_0x438430[_0x440553('0x86')]=qs[_0x440553('0x32')](_0x3970cd['query'][_0x440553('0x32')]),_0x438430[_0x440553('0x26')]=qs['filters'](_['pick'](_0x3970cd['query'],_0x11c970[_0x440553('0x7b')])),_0x438430['where'][_0x440553('0x9b')]=_0x2c3a24['id'],_0x3970cd[_0x440553('0x46')]['filter']&&(_0x438430[_0x440553('0x26')]=_[_0x440553('0x6e')](_0x438430['where'],{[Op['or']]:_[_0x440553('0x87')](_0x438430['attributes'],function(_0x4f30d3){const _0x3d1bff=_0x440553,_0xe05b30={};return _0xe05b30[_0x4f30d3]={[Op['like']]:'%'+_0x3970cd[_0x3d1bff('0x46')][_0x3d1bff('0x61')]+'%'},_0xe05b30;})})),_0x438430=_[_0x440553('0x6e')]({},_0x438430,_0x3970cd[_0x440553('0x1d')]),db[_0x440553('0x7a')][_0x440553('0x12')]({'where':_0x438430[_0x440553('0x26')]})[_0x440553('0x51')](function(_0x17fea6){const _0x5e4a02=_0x440553;return _0xb2cc55[_0x5e4a02('0x12')]=_0x17fea6,_0x3970cd[_0x5e4a02('0x46')]['includeAll']&&(_0x438430[_0x5e4a02('0x0')]=[{'all':!![]}]),db[_0x5e4a02('0x7a')][_0x5e4a02('0x79')](_0x438430);})[_0x440553('0x51')](function(_0x3fd330){return _0xb2cc55['rows']=_0x3fd330,_0xb2cc55;});})['then'](respondWithFilteredResult(_0x503dc8,_0x438430))[_0xd641d0('0x38')](handleError(_0x503dc8,null));},exports[_0x3b39b4('0x75')]=function(_0x771a52,_0x2a990e){const _0x4bc9ee=_0x3b39b4;return db['WhatsappAccount'][_0x4bc9ee('0x73')]({'where':{'id':_0x771a52[_0x4bc9ee('0x48')]['id']}})[_0x4bc9ee('0x51')](handleEntityNotFound(_0x2a990e,null))[_0x4bc9ee('0x51')](function(_0x5e7e9e){const _0x274a06=_0x4bc9ee;if(_0x5e7e9e)return _0x5e7e9e[_0x274a06('0x75')](_0x771a52[_0x274a06('0x46')][_0x274a06('0x35')]);})[_0x4bc9ee('0x51')](respondWithStatusCode(_0x2a990e,null))['catch'](handleError(_0x2a990e,null));},exports[_0x3b39b4('0x2d')]=function(_0x1ab37a,_0x3a6600){const _0x35c5e9=_0x3b39b4;return _0x1ab37a['body']['id']&&delete _0x1ab37a[_0x35c5e9('0x1e')]['id'],db[_0x35c5e9('0x7e')][_0x35c5e9('0x73')]({'where':{'id':_0x1ab37a[_0x35c5e9('0x48')]['id']}})[_0x35c5e9('0x51')](handleEntityNotFound(_0x3a6600,null))[_0x35c5e9('0x51')](function(_0xd026ff){const _0x106900=_0x35c5e9;if(_0xd026ff)return _0x1ab37a['body'][_0x106900('0x9b')]=_0xd026ff['id'],db[_0x106900('0xb')][_0x106900('0x8d')](_0x1ab37a[_0x106900('0x1e')]);})[_0x35c5e9('0x51')](respondWithResult(_0x3a6600,null))[_0x35c5e9('0x38')](handleError(_0x3a6600,null));},exports['getAnswers']=function(_0x5810a2,_0x32c2c7){const _0x423b5e=_0x3b39b4;let _0xa4bda3={'raw':![],'where':{}};const _0x6d570={},_0x7777b={'count':0x0,'rows':[]};return db[_0x423b5e('0x7e')][_0x423b5e('0x73')]({'where':{'id':_0x5810a2[_0x423b5e('0x48')]['id']}})[_0x423b5e('0x51')](handleEntityNotFound(_0x32c2c7,null))['then'](function(_0x18feed){const _0x47681b=_0x423b5e;if(_0x18feed)return _0x6d570[_0x47681b('0x50')]=_[_0x47681b('0xc')](db[_0x47681b('0xb')][_0x47681b('0x6b')]),_0x6d570['query']=_[_0x47681b('0xc')](_0x5810a2[_0x47681b('0x46')]),_0x6d570[_0x47681b('0x7b')]=_['intersection'](_0x6d570['model'],_0x6d570[_0x47681b('0x46')]),_0xa4bda3[_0x47681b('0x5a')]=_[_0x47681b('0x41')](_0x6d570[_0x47681b('0x50')],qs[_0x47681b('0x44')](_0x5810a2[_0x47681b('0x46')][_0x47681b('0x44')])),_0xa4bda3['attributes']=_0xa4bda3[_0x47681b('0x5a')][_0x47681b('0x91')]?_0xa4bda3['attributes']:_0x6d570[_0x47681b('0x50')],typeof _0x5810a2[_0x47681b('0x46')]['nolimit']==='undefined'&&(_0xa4bda3[_0x47681b('0x5d')]=qs[_0x47681b('0x5d')](_0x5810a2[_0x47681b('0x46')][_0x47681b('0x5d')]),_0xa4bda3[_0x47681b('0x9')]=qs['offset'](_0x5810a2[_0x47681b('0x46')][_0x47681b('0x9')])),_0xa4bda3[_0x47681b('0x86')]=qs['sort'](_0x5810a2[_0x47681b('0x46')]['sort']),_0xa4bda3[_0x47681b('0x26')]=qs[_0x47681b('0x7b')](_['pick'](_0x5810a2['query'],_0x6d570[_0x47681b('0x7b')])),_0xa4bda3[_0x47681b('0x26')][_0x47681b('0x9b')]=_0x18feed['id'],_0x5810a2['query'][_0x47681b('0x61')]&&(_0xa4bda3[_0x47681b('0x26')]=_[_0x47681b('0x6e')](_0xa4bda3[_0x47681b('0x26')],{[Op['or']]:_[_0x47681b('0x87')](_0xa4bda3[_0x47681b('0x5a')],function(_0x596a3a){const _0x18f9f6=_0x47681b,_0x197c77={};return _0x197c77[_0x596a3a]={[Op[_0x18f9f6('0x16')]]:'%'+_0x5810a2[_0x18f9f6('0x46')]['filter']+'%'},_0x197c77;})})),_0xa4bda3=_[_0x47681b('0x6e')]({},_0xa4bda3,_0x5810a2[_0x47681b('0x1d')]),db['CannedAnswer'][_0x47681b('0x12')]({'where':_0xa4bda3[_0x47681b('0x26')]})[_0x47681b('0x51')](function(_0x3de8f5){const _0x1c68c8=_0x47681b;return _0x7777b[_0x1c68c8('0x12')]=_0x3de8f5,_0x5810a2[_0x1c68c8('0x46')]['includeAll']&&(_0xa4bda3['include']=[{'all':!![]}]),db[_0x1c68c8('0xb')]['findAll'](_0xa4bda3);})[_0x47681b('0x51')](function(_0x18d5c4){return _0x7777b['rows']=_0x18d5c4,_0x7777b;});})[_0x423b5e('0x51')](respondWithFilteredResult(_0x32c2c7,_0xa4bda3))['catch'](handleError(_0x32c2c7,null));},exports['removeAnswers']=function(_0x1378ac,_0x4e2391){const _0x3e8d7f=_0x3b39b4;return db['WhatsappAccount'][_0x3e8d7f('0x73')]({'where':{'id':_0x1378ac[_0x3e8d7f('0x48')]['id']}})[_0x3e8d7f('0x51')](handleEntityNotFound(_0x4e2391,null))['then'](function(_0x6e9917){const _0x583903=_0x3e8d7f;if(_0x6e9917)return _0x6e9917[_0x583903('0x17')](_0x1378ac[_0x583903('0x46')]['ids']);})[_0x3e8d7f('0x51')](respondWithStatusCode(_0x4e2391,null))[_0x3e8d7f('0x38')](handleError(_0x4e2391,null));},exports[_0x3b39b4('0x63')]=function(_0x50f255,_0x1eeac9){const _0x313f04=_0x3b39b4;return db['WhatsappAccount'][_0x313f04('0x73')]({'where':{'id':_0x50f255[_0x313f04('0x48')]['id']}})[_0x313f04('0x51')](function(_0x4737e4){const _0x47381d=_0x313f04;if(_0x4737e4)return _0x4737e4['addAgents'](_0x50f255[_0x47381d('0x1e')][_0x47381d('0x35')],{'through':_[_0x47381d('0x1')](_0x50f255[_0x47381d('0x1e')],[_0x47381d('0x35'),'id'])})[_0x47381d('0x51')](function(_0x4e0442){const _0x13a52d=_0x47381d;for(let _0x5bef31=0x0;_0x5bef31<_0x50f255['body']['ids'][_0x13a52d('0x91')];_0x5bef31+=0x1){socket[_0x13a52d('0x67')]('userWhatsappAccount:save',{'UserId':_0x50f255['body'][_0x13a52d('0x35')][_0x5bef31],'WhatsappAccountId':_0x50f255[_0x13a52d('0x48')]['id']});}return _0x4e0442;});})[_0x313f04('0x51')](respondWithResult(_0x1eeac9,null))[_0x313f04('0x38')](handleError(_0x1eeac9,null));},exports[_0x3b39b4('0x21')]=function(_0x24d53d,_0x5a087e){const _0x14c42d=_0x3b39b4;return db[_0x14c42d('0x7e')][_0x14c42d('0x73')]({'where':{'id':_0x24d53d[_0x14c42d('0x48')]['id']}})[_0x14c42d('0x51')](handleEntityNotFound(_0x5a087e,null))[_0x14c42d('0x51')](function(_0x29b4da){const _0x4f3815=_0x14c42d;if(_0x29b4da)return _0x29b4da[_0x4f3815('0x21')](_0x24d53d[_0x4f3815('0x46')][_0x4f3815('0x35')])['then'](function(){const _0x463652=_0x4f3815;if(_[_0x463652('0x88')](_0x24d53d[_0x463652('0x46')][_0x463652('0x35')]))for(let _0x10a849=0x0;_0x10a849<_0x24d53d[_0x463652('0x46')][_0x463652('0x35')][_0x463652('0x91')];_0x10a849+=0x1){socket['emit'](_0x463652('0x6a'),{'UserId':Number(_0x24d53d[_0x463652('0x46')][_0x463652('0x35')][_0x10a849]),'WhatsappAccountId':Number(_0x24d53d['params']['id'])});}else socket['emit'](_0x463652('0x6a'),{'UserId':Number(_0x24d53d[_0x463652('0x46')][_0x463652('0x35')]),'WhatsappAccountId':Number(_0x24d53d['params']['id'])});});})[_0x14c42d('0x51')](respondWithStatusCode(_0x5a087e,null))[_0x14c42d('0x38')](handleError(_0x5a087e,null));},exports['getAgents']=function(_0x196673,_0x464197){const _0x5c3d30=_0x3b39b4;let _0x27ef11={};const _0x341a6a={};let _0xdae17a,_0x45f137;return db[_0x5c3d30('0x7e')][_0x5c3d30('0x73')]({'where':{'id':_0x196673['params']['id']}})['then'](handleEntityNotFound(_0x464197,null))[_0x5c3d30('0x51')](function(_0x4030b4){const _0x410452=_0x5c3d30;if(_0x4030b4)return _0xdae17a=_0x4030b4,_0x341a6a[_0x410452('0x50')]=_[_0x410452('0xc')](db['User'][_0x410452('0x6b')]),_0x341a6a[_0x410452('0x46')]=_[_0x410452('0xc')](_0x196673[_0x410452('0x46')]),_0x341a6a[_0x410452('0x7b')]=_['intersection'](_0x341a6a[_0x410452('0x50')],_0x341a6a['query']),_0x27ef11[_0x410452('0x5a')]=_[_0x410452('0x41')](_0x341a6a['model'],qs[_0x410452('0x44')](_0x196673[_0x410452('0x46')][_0x410452('0x44')])),_0x27ef11['attributes']=_0x27ef11[_0x410452('0x5a')]['length']?_0x27ef11[_0x410452('0x5a')]:_0x341a6a['model'],_0x27ef11[_0x410452('0x86')]=qs[_0x410452('0x32')](_0x196673[_0x410452('0x46')][_0x410452('0x32')]),_0x27ef11[_0x410452('0x26')]=qs[_0x410452('0x7b')](_[_0x410452('0x74')](_0x196673['query'],_0x341a6a[_0x410452('0x7b')])),_0x196673[_0x410452('0x46')][_0x410452('0x61')]&&(_0x27ef11[_0x410452('0x26')]=_['merge'](_0x27ef11['where'],{[Op['or']]:_[_0x410452('0x87')](_0x27ef11[_0x410452('0x5a')],function(_0x37b2d9){const _0x1f57a7=_0x410452,_0x2a1cf6={};return _0x2a1cf6[_0x37b2d9]={[Op[_0x1f57a7('0x16')]]:'%'+_0x196673[_0x1f57a7('0x46')][_0x1f57a7('0x61')]+'%'},_0x2a1cf6;})})),_0x27ef11=_[_0x410452('0x6e')]({},_0x27ef11,_0x196673[_0x410452('0x1d')]),_0xdae17a[_0x410452('0x15')](_0x27ef11);})[_0x5c3d30('0x51')](function(_0x51fe0a){const _0x15669b=_0x5c3d30;if(_0x51fe0a)return _0x45f137=_0x51fe0a['length'],typeof _0x196673[_0x15669b('0x46')][_0x15669b('0x5c')]===_0x15669b('0x13')&&(_0x27ef11[_0x15669b('0x5d')]=qs[_0x15669b('0x5d')](_0x196673[_0x15669b('0x46')]['limit']),_0x27ef11['offset']=qs[_0x15669b('0x9')](_0x196673[_0x15669b('0x46')][_0x15669b('0x9')])),_0xdae17a[_0x15669b('0x15')](_0x27ef11);})[_0x5c3d30('0x51')](function(_0x2cabdc){if(_0x2cabdc)return _0x2cabdc?{'count':_0x45f137,'rows':_0x2cabdc}:null;})[_0x5c3d30('0x51')](respondWithResult(_0x464197,null))['catch'](handleError(_0x464197,null));},exports['addApplications']=function(_0x553729,_0x311389){const _0x26b489=_0x3b39b4;return db[_0x26b489('0x7e')][_0x26b489('0x73')]({'where':{'id':_0x553729[_0x26b489('0x48')]['id']}})[_0x26b489('0x51')](handleEntityNotFound(_0x311389,null))[_0x26b489('0x51')](function(_0x17013b){const _0x15385f=_0x26b489;if(_0x17013b)return db['sequelize']['transaction'](function(_0x25d108){const _0x5f19b0=a783_0x30ad;return db[_0x5f19b0('0x78')]['destroy']({'where':{'WhatsappAccountId':_0x553729[_0x5f19b0('0x48')]['id']},'transaction':_0x25d108})[_0x5f19b0('0x51')](function(){const _0x802960=_0x5f19b0,_0x27912e=_[_0x802960('0x87')](_0x553729['body'],function(_0x3f6a9a){return _0x3f6a9a['WhatsappAccountId']=_0x553729['params']['id'],_0x3f6a9a;});return db['WhatsappApplication'][_0x802960('0x30')](_0x27912e,{'transaction':_0x25d108});});})[_0x15385f('0x51')](function(){const _0xbadb16=_0x15385f;return db[_0xbadb16('0x78')][_0xbadb16('0x90')]({'where':{'WhatsappAccountId':_0x553729[_0xbadb16('0x48')]['id']},'order':_0xbadb16('0x9a')});});})['then'](respondWithResult(_0x311389,null))[_0x26b489('0x38')](handleError(_0x311389,null));},exports[_0x3b39b4('0x36')]=function(_0x3fa0a8,_0x2de688){const _0x506f73=_0x3b39b4;let _0xab4929={};const _0x5163bd={};let _0x3d02e7,_0x5f1235;return db[_0x506f73('0x7e')][_0x506f73('0x73')]({'where':{'id':_0x3fa0a8[_0x506f73('0x48')]['id']}})[_0x506f73('0x51')](handleEntityNotFound(_0x2de688,null))[_0x506f73('0x51')](function(_0x12bd72){const _0x3ffc63=_0x506f73;if(_0x12bd72)return _0x3d02e7=_0x12bd72,_0x5163bd[_0x3ffc63('0x50')]=_['keys'](db[_0x3ffc63('0x78')][_0x3ffc63('0x6b')]),_0x5163bd[_0x3ffc63('0x46')]=_['keys'](_0x3fa0a8[_0x3ffc63('0x46')]),_0x5163bd[_0x3ffc63('0x7b')]=_[_0x3ffc63('0x41')](_0x5163bd['model'],_0x5163bd['query']),_0xab4929['attributes']=_[_0x3ffc63('0x41')](_0x5163bd[_0x3ffc63('0x50')],qs[_0x3ffc63('0x44')](_0x3fa0a8[_0x3ffc63('0x46')][_0x3ffc63('0x44')])),_0xab4929['attributes']=_0xab4929[_0x3ffc63('0x5a')][_0x3ffc63('0x91')]?_0xab4929[_0x3ffc63('0x5a')]:_0x5163bd[_0x3ffc63('0x50')],_0xab4929[_0x3ffc63('0x86')]=qs['sort'](_0x3fa0a8[_0x3ffc63('0x46')]['sort']),_0xab4929[_0x3ffc63('0x26')]=qs['filters'](_[_0x3ffc63('0x74')](_0x3fa0a8['query'],_0x5163bd['filters'])),_0x3fa0a8[_0x3ffc63('0x46')][_0x3ffc63('0x61')]&&(_0xab4929['where']=_[_0x3ffc63('0x6e')](_0xab4929['where'],{[Op['or']]:_[_0x3ffc63('0x87')](_0xab4929[_0x3ffc63('0x5a')],function(_0x196aeb){const _0x4e2b0d=_0x3ffc63,_0x3d6410={};return _0x3d6410[_0x196aeb]={[Op[_0x4e2b0d('0x16')]]:'%'+_0x3fa0a8[_0x4e2b0d('0x46')][_0x4e2b0d('0x61')]+'%'},_0x3d6410;})})),_0xab4929=_[_0x3ffc63('0x6e')]({},_0xab4929,_0x3fa0a8['options']),_0x3d02e7['getApplications'](_0xab4929);})[_0x506f73('0x51')](function(_0x3a59b6){const _0x1cdef4=_0x506f73;if(_0x3a59b6)return _0x5f1235=_0x3a59b6[_0x1cdef4('0x91')],typeof _0x3fa0a8[_0x1cdef4('0x46')]['nolimit']===_0x1cdef4('0x13')&&(_0xab4929['limit']=qs[_0x1cdef4('0x5d')](_0x3fa0a8[_0x1cdef4('0x46')]['limit']),_0xab4929['offset']=qs[_0x1cdef4('0x9')](_0x3fa0a8[_0x1cdef4('0x46')][_0x1cdef4('0x9')])),_0x3d02e7[_0x1cdef4('0x36')](_0xab4929);})[_0x506f73('0x51')](function(_0x361e6d){if(_0x361e6d)return _0x361e6d?{'count':_0x5f1235,'rows':_0x361e6d}:null;})[_0x506f73('0x51')](respondWithResult(_0x2de688,null))[_0x506f73('0x38')](handleError(_0x2de688,null));},exports[_0x3b39b4('0x57')]=function(_0xacac55,_0x2fd7a5){const _0x49b455=_0x3b39b4,_0x56177b={'channel':_0x49b455('0x99')};let _0x4d507d=[],_0x21e642=[];const _0x874388={};return db[_0x49b455('0x7e')]['findOne']({'where':{'id':_0xacac55[_0x49b455('0x48')]['id']},'include':[{'model':db[_0x49b455('0x78')],'as':_0x49b455('0x27')}]})[_0x49b455('0x51')](handleEntityNotFound(_0x2fd7a5,null))[_0x49b455('0x51')](function(_0x378411){const _0x36f8c2=_0x49b455;return _0x56177b['account']=_0x378411,_0x56177b['applications']=_[_0x36f8c2('0x4c')](_0x378411[_0x36f8c2('0x27')],['priority'],[_0x36f8c2('0x70')]),_0x56177b[_0x36f8c2('0x64')][_0x36f8c2('0x27')]&&delete _0x56177b[_0x36f8c2('0x64')][_0x36f8c2('0x27')],db['CmContact'][_0x36f8c2('0x2b')]();})[_0x49b455('0x51')](function(_0x6c041b){const _0x2d42db=_0x49b455;if(!_0x6c041b)throw new db[(_0x2d42db('0x1f'))][(_0x2d42db('0x3d'))](_0x2d42db('0x83'));_0x4d507d=_[_0x2d42db('0x59')](_['keys'](_0x6c041b),[_0x2d42db('0x2e'),_0x2d42db('0x98')]),_0x21e642=_[_0x2d42db('0x59')](_[_0x2d42db('0xc')](_0x6c041b),[_0x2d42db('0x2e'),_0x2d42db('0x98'),_0x2d42db('0x82'),'ListId']),_0x56177b[_0x2d42db('0x1e')]={'mapKey':_0x2d42db('0x4d')};_0x56177b[_0x2d42db('0x64')]['type']&&_0x56177b[_0x2d42db('0x64')][_0x2d42db('0x53')]===_0x2d42db('0x3c')&&(_0x56177b[_0x2d42db('0x1e')][_0x2d42db('0x7')]=_0xacac55['body'][_0x2d42db('0x55')][_0x2d42db('0x76')](_0x2d42db('0x7c'),''),_0x56177b[_0x2d42db('0x1e')]['body']=_0xacac55['body']['Body'],_0x56177b[_0x2d42db('0x1e')]['messageId']=_0xacac55[_0x2d42db('0x1e')][_0x2d42db('0x49')]);_0x56177b[_0x2d42db('0x1e')]['id']&&delete _0x56177b[_0x2d42db('0x1e')]['id'];if(_[_0x2d42db('0x2a')](_0x56177b[_0x2d42db('0x1e')]['from']))throw new db['Sequelize'][(_0x2d42db('0x3d'))]('from\x20is\x20mandatory');if(_['isNil'](_0x56177b[_0x2d42db('0x1e')][_0x2d42db('0x1e')])||_0x56177b[_0x2d42db('0x1e')][_0x2d42db('0x1e')]==='')throw new db[(_0x2d42db('0x1f'))][(_0x2d42db('0x3d'))](_0x2d42db('0x80'));if(_[_0x2d42db('0x2a')](_0x56177b[_0x2d42db('0x1e')][_0x2d42db('0x5e')]))throw new db['Sequelize'][(_0x2d42db('0x3d'))]('mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x21e642);if(!_[_0x2d42db('0x7f')](_0x21e642,_0x56177b['body'][_0x2d42db('0x5e')]))throw new db[(_0x2d42db('0x1f'))][(_0x2d42db('0x3d'))]('mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x21e642);return _0x874388[_0x56177b[_0x2d42db('0x1e')][_0x2d42db('0x5e')]]=_0x56177b[_0x2d42db('0x1e')][_0x2d42db('0x7')],db[_0x2d42db('0x8f')]['findOne']({'where':{'id':_0x56177b[_0x2d42db('0x64')][_0x2d42db('0xe')]},'include':[{'model':db[_0x2d42db('0x84')],'as':_0x2d42db('0x93'),'where':_0x874388,'limit':0x1,'order':[[_0x2d42db('0x98'),_0x2d42db('0x18')]]}]});})['then'](handleEntityNotFound(_0x2fd7a5,null))[_0x49b455('0x51')](function(_0x5b15ff){const _0x3993b7=_0x49b455;if(_0x5b15ff){_0x56177b[_0x3993b7('0x54')]=_['omit'](_0x5b15ff,[_0x3993b7('0x93')]);if(_0x5b15ff[_0x3993b7('0x93')]['length'])return _0x5b15ff[_0x3993b7('0x93')][0x0];const _0x26fcb8=_[_0x3993b7('0x68')](_0x56177b[_0x3993b7('0x1e')],{'firstName':_0x56177b['body']['from'],'ListId':_0x5b15ff['id']});return _0x26fcb8[_0x56177b[_0x3993b7('0x1e')][_0x3993b7('0x5e')]]=_0x56177b[_0x3993b7('0x1e')][_0x3993b7('0x7')],db[_0x3993b7('0x84')][_0x3993b7('0x8d')](_0x26fcb8,{'fields':_0x4d507d,'raw':!![]});}})[_0x49b455('0x51')](handleEntityNotFound(_0x2fd7a5,null))[_0x49b455('0x51')](function(_0x572f14){const _0x47622a=_0x49b455;if(_0x572f14){_0x56177b[_0x47622a('0x7d')]=_0x572f14;const _0x2b2b9f={'ContactId':_0x572f14['id'],'phone':_0x56177b[_0x47622a('0x1e')][_0x47622a('0x7')],'WhatsappAccountId':_0xacac55[_0x47622a('0x48')]['id']},_0x301144={'ContactId':_0x572f14['id'],'WhatsappAccountId':_0xacac55[_0x47622a('0x48')]['id'],'closed':![]};return db[_0x47622a('0x94')][_0x47622a('0x73')]({'where':_0x301144})[_0x47622a('0x51')](function(_0x5955dc){const _0xfbabe1=_0x47622a;if(_0x5955dc)return[_0x5955dc,![]];return db['WhatsappInteraction']['create'](_0x2b2b9f)[_0xfbabe1('0x51')](function(_0x49fcc5){return[_0x49fcc5,!![]];});});}})[_0x49b455('0x51')](function([_0x145af0,_0x11c9e8]){const _0x5e426d=_0x49b455;return _0x56177b['interaction']=_0x145af0[_0x5e426d('0x72')]({'plain':!![]}),_0x56177b['interaction'][_0x5e426d('0x3a')]=![],_0x11c9e8&&(_0x56177b[_0x5e426d('0x64')][_0x5e426d('0x4b')]&&_0x56177b[_0x5e426d('0x5f')][_0x5e426d('0x33')]({'id':0x0,'priority':_0x56177b[_0x5e426d('0x5f')]['length']+0x1,'app':_0x5e426d('0x3f'),'appdata':_0x5e426d('0x1a'),'interval':_0x5e426d('0x47')}),_0x56177b[_0x5e426d('0x29')][_0x5e426d('0x3a')]=!![]),db['WhatsappMessage'][_0x5e426d('0x8d')]({'phone':_0x56177b[_0x5e426d('0x1e')][_0x5e426d('0x7')],'messageId':_0x56177b['body']['messageId'],'body':_0x56177b[_0x5e426d('0x1e')]['body'],'WhatsappAccountId':_0xacac55[_0x5e426d('0x48')]['id'],'WhatsappInteractionId':_0x145af0['id'],'direction':'in','ContactId':_0x145af0[_0x5e426d('0x96')],'AttachmentId':_0x56177b[_0x5e426d('0x1e')][_0x5e426d('0x2c')]});})['then'](function(_0x3e28e7){const _0x38a393=_0x49b455;_0x56177b[_0x38a393('0x3')]=_0x3e28e7;if(_0x56177b[_0x38a393('0x29')]['UserId'])return db[_0x38a393('0x6c')][_0x38a393('0x73')]({'attributes':['id',_0x38a393('0x34')],'where':{'id':_0x56177b[_0x38a393('0x29')][_0x38a393('0x25')]}})[_0x38a393('0x51')](function(_0x41466e){const _0x109555=_0x38a393;return _0x41466e&&_0x56177b[_0x109555('0x5f')][_0x109555('0x89')]({'id':0x0,'priority':0x0,'app':_0x109555('0x19'),'appdata':_0x41466e[_0x109555('0x34')]+','+(_0x56177b[_0x109555('0x64')][_0x109555('0x95')]||0xa),'interval':_0x109555('0x47')}),respondWithRpcPromise('Start',_0x109555('0x11'),_0x56177b);});return respondWithRpcPromise(_0x38a393('0x4f'),_0x38a393('0x11'),_0x56177b);})[_0x49b455('0x51')](function(_0xa2ed9d){const _0x82b2d5=_0x49b455;if(_0xa2ed9d){const _0x393860=0xc8,_0x14abf3='receiveMessage';return logger[_0x82b2d5('0x8')](_0x82b2d5('0x39'),_0x14abf3,_0x393860,'entity\x20found'),logger[_0x82b2d5('0x2')](_0x82b2d5('0x58'),_0x14abf3,_0x393860,_0x82b2d5('0x42'),JSON[_0x82b2d5('0x28')](_0xa2ed9d)),_0x56177b['account'][_0x82b2d5('0x53')]==='twilio'?_0x2fd7a5[_0x82b2d5('0x4')](_0x393860)[_0x82b2d5('0x77')]('Content-Type','text/xml')[_0x82b2d5('0x60')]('<?xml\x20version=\x221.0\x22\x20encoding=\x22UTF-8\x22?>\x0a<Response></Response>'):_0x2fd7a5[_0x82b2d5('0x4')](_0x393860)['json'](_0xa2ed9d);}})[_0x49b455('0x38')](handleError(_0x2fd7a5,null));},exports[_0x3b39b4('0x60')]=function(_0x1d02e5,_0x5938bd){const _0x1fd80e=_0x3b39b4;let _0x2819e6,_0x20e4cd;if(_[_0x1fd80e('0x2a')](_0x1d02e5[_0x1fd80e('0x1e')]['body'])||_0x1d02e5[_0x1fd80e('0x1e')][_0x1fd80e('0x1e')]==='')throw new db[(_0x1fd80e('0x1f'))][(_0x1fd80e('0x3d'))]('body\x20is\x20mandatory\x20and\x20not\x20empty');if(_[_0x1fd80e('0x2a')](_0x1d02e5[_0x1fd80e('0x1e')]['to']))throw new db[(_0x1fd80e('0x1f'))][(_0x1fd80e('0x3d'))](_0x1fd80e('0x62'));const _0x34ec39=_0x1d02e5['body']['to'];return db[_0x1fd80e('0x7e')][_0x1fd80e('0x73')]({'where':{'id':_0x1d02e5[_0x1fd80e('0x48')]['id']},'include':[{'model':db[_0x1fd80e('0x8f')],'as':_0x1fd80e('0x40'),'include':[{'model':db[_0x1fd80e('0x84')],'as':_0x1fd80e('0x93'),'where':{'mobile':_0x34ec39},'limit':0x1,'order':[[_0x1fd80e('0x98'),'DESC']]}]}]})[_0x1fd80e('0x51')](handleEntityNotFound(_0x5938bd,null))[_0x1fd80e('0x51')](function(_0x5cc5bd){const _0x58b5ed=_0x1fd80e;if(_0x5cc5bd&&_0x5cc5bd[_0x58b5ed('0x40')]){_0x2819e6=_0x5cc5bd[_0x58b5ed('0x72')]({'plain':!![]});if(_0x2819e6[_0x58b5ed('0x40')]&&_0x2819e6[_0x58b5ed('0x40')]['Contacts'][_0x58b5ed('0x91')])return _0x2819e6['List'][_0x58b5ed('0x93')][0x0];return db[_0x58b5ed('0x84')]['create'](_[_0x58b5ed('0x68')](_0x1d02e5[_0x58b5ed('0x1e')],{'firstName':_0x34ec39,'mobile':_0x34ec39,'phone':_0x34ec39,'ListId':_0x2819e6[_0x58b5ed('0xe')]}));}})[_0x1fd80e('0x51')](handleEntityNotFound(_0x5938bd,null))[_0x1fd80e('0x51')](function(_0x3c8e05){const _0xac3dfb=_0x1fd80e;if(_0x3c8e05)return _0x20e4cd=_0x3c8e05,db[_0xac3dfb('0x94')][_0xac3dfb('0x73')]({'where':{'ContactId':_0x20e4cd['id'],'closed':![],'WhatsappAccountId':_0x2819e6['id']}})[_0xac3dfb('0x51')](function(_0x5af464){const _0x33ab2b=_0xac3dfb;if(_0x5af464)return[_0x5af464,![]];return db['WhatsappInteraction']['create']({'UserId':_0x1d02e5['user']['id'],'ContactId':_0x20e4cd['id'],'WhatsappAccountId':_0x2819e6['id'],'phone':_0x34ec39,'firstMsgDirection':_0x33ab2b('0x92'),'Messages':[_[_0x33ab2b('0x6e')](_0x1d02e5['body'],{'read':![],'body':_0x1d02e5['body'][_0x33ab2b('0x1e')],'phone':_0x34ec39,'WhatsappAccountId':_0x2819e6['id'],'UserId':_0x1d02e5['user']['id'],'ContactId':_0x20e4cd['id']})]},{'include':[{'model':db[_0x33ab2b('0x3e')],'as':_0x33ab2b('0x4a')}]})['then'](function(_0x107009){return[_0x107009,!![]];});});})[_0x1fd80e('0x51')](function([_0x5aea6c,_0x5e3f79]){const _0xa530fd=_0x1fd80e;if(_0x5e3f79)return _0x5aea6c;return db[_0xa530fd('0x3e')][_0xa530fd('0x8d')](_['merge'](_0x1d02e5['body'],{'read':![],'body':_0x1d02e5[_0xa530fd('0x1e')][_0xa530fd('0x1e')],'phone':_0x34ec39,'WhatsappAccountId':_0x2819e6['id'],'WhatsappInteractionId':_0x5aea6c['id'],'UserId':_0x1d02e5[_0xa530fd('0x3b')]['id'],'ContactId':_0x20e4cd['id']}))[_0xa530fd('0x51')](function(_0x3894a4){const _0x113fca=_0xa530fd;return _0x5aea6c[_0x113fca('0x97')][_0x113fca('0x4a')]=[],_0x5aea6c[_0x113fca('0x97')]['Messages'][_0x113fca('0x33')](_0x3894a4[_0x113fca('0x97')]),_0x5aea6c;});})[_0x1fd80e('0x51')](respondWithResult(_0x5938bd,null))[_0x1fd80e('0x38')](handleError(_0x5938bd,null));};