e37df13b66d6932895a0f709e61cbe424d46f341
[motion-next.git] / server / api / whatsappMessage / whatsappMessage.model.js
1 const a803_0x1c04=['api','createdAt','./whatsappMessage.attributes','/api/whatsapp/messages/','remote','isNil','twilio','phone','findOne','exports','catch','out','finally','afterCreate','WhatsappAccountId','body','WhatsappInteractionId','define','update','error','direction','type','token','secret','sid','toLowerCase','/status?token=','fti_whatsapp_messages','lodash','then','WhatsappMessage,\x20%s,\x20%s,\x20%s','models','util','accountSid','whatsapp:','authToken','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','WhatsappAccount','WhatsappInteraction','FULLTEXT','UserId','create','utf8mb4_unicode_ci','messageId'];(function(_0x1c915f,_0x1c0480){const _0x33d2a1=function(_0x4f8d26){while(--_0x4f8d26){_0x1c915f['push'](_0x1c915f['shift']());}};_0x33d2a1(++_0x1c0480);}(a803_0x1c04,0x8f));const a803_0x33d2=function(_0x1c915f,_0x1c0480){_0x1c915f=_0x1c915f-0x0;let _0x33d2a1=a803_0x1c04[_0x1c915f];return _0x33d2a1;};const _0x2c5560=a803_0x33d2;'use strict';const _=require(_0x2c5560('0x11')),util=require(_0x2c5560('0x15')),logger=require('../../config/logger')(_0x2c5560('0x21')),attributes=require(_0x2c5560('0x23'));module[_0x2c5560('0x2a')]=function(_0x4f8d26){const _0x16d440=_0x2c5560,_0x3f92f4=_0x4f8d26[_0x16d440('0x14')],_0x277bc6=_0x4f8d26[_0x16d440('0x6')]('WhatsappMessage',attributes,{'tableName':'whatsapp_messages','paranoid':![],'indexes':[{'name':_0x16d440('0x20'),'fields':['messageId']},{'name':_0x16d440('0x10'),'fields':[_0x16d440('0x4')],'type':_0x16d440('0x1c')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x5c9a74){const _0x410e48=_0x16d440,_0x4f841e=_0x5c9a74['get']({'plain':!![]});(_0x4f841e[_0x410e48('0x9')][_0x410e48('0xe')]()==='in'||_0x4f841e[_0x410e48('0x9')][_0x410e48('0xe')]()===_0x410e48('0x0')&&!_0x4f841e[_0x410e48('0xc')]&&!_[_0x410e48('0x26')](_0x4f841e[_0x410e48('0x1d')]))&&_0x3f92f4[_0x410e48('0x1b')][_0x410e48('0x29')]({'where':{'id':_0x4f841e[_0x410e48('0x5')]}})[_0x410e48('0x12')](function(_0x285c64){const _0x480bb1=_0x410e48;_0x285c64&&_0x285c64['update']({'lastMsgAt':_0x4f841e[_0x480bb1('0x22')],'lastMsgDirection':_0x4f841e['direction'][_0x480bb1('0xe')]()});})[_0x410e48('0x2b')](function(_0x41110e){const _0x70e02e=_0x410e48;console[_0x70e02e('0x8')](_0x41110e);});if(_0x4f841e[_0x410e48('0x9')]===_0x410e48('0x0')&&!_0x4f841e[_0x410e48('0xc')]){let _0x24b05c;_0x3f92f4[_0x410e48('0x1a')][_0x410e48('0x29')]({'where':{'id':_0x4f841e[_0x410e48('0x3')]},'raw':!![]})['then'](function(_0x12efae){const _0x28755e=_0x410e48;_0x24b05c=_0x12efae;if(_0x24b05c&&_0x24b05c[_0x28755e('0xa')])switch(_0x24b05c[_0x28755e('0xa')]){case _0x28755e('0x27'):{const _0x4a2e9b=require('twilio');if(_0x24b05c[_0x28755e('0x16')]&&_0x24b05c[_0x28755e('0x18')]&&_0x24b05c['phone']){const _0x47b8c4=new _0x4a2e9b(_0x24b05c[_0x28755e('0x16')],_0x24b05c['authToken']);_0x47b8c4['messages'][_0x28755e('0x1e')]({'body':_0x4f841e['body'],'to':'whatsapp:'+_0x4f841e[_0x28755e('0x28')],'from':_0x28755e('0x17')+_0x24b05c[_0x28755e('0x28')],'statusCallback':_0x24b05c[_0x28755e('0x25')]+_0x28755e('0x24')+_0x4f841e['id']+_0x28755e('0xf')+_0x24b05c[_0x28755e('0xb')]})[_0x28755e('0x12')](function(_0x276742){const _0x336a68=_0x28755e;if(_0x276742[_0x336a68('0xd')])return _0x5c9a74[_0x336a68('0x7')]({'messageId':_0x276742[_0x336a68('0xd')]});})[_0x28755e('0x2b')](function(_0x267628){const _0x5929f7=_0x28755e;logger['error']('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x5929f7('0x2'),_0x5929f7('0x27'),util['inspect'](_0x267628,{'showHidden':![],'depth':null}));});}else logger['error'](_0x28755e('0x13'),_0x28755e('0x2'),_0x28755e('0x27'),_0x28755e('0x19'));}break;}})[_0x410e48('0x1')](function(){return null;});}else return null;}},'charset':'utf8mb4','collate':_0x16d440('0x1f')});return _0x277bc6;};