Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / whatsappMessage / whatsappMessage.model.js
index 6230476..940758e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7e1b=['Bearer\x20','application/json','statuses','err','WhatsappMessage,\x20%s','finally','utf8mb4','util','api','moment','bluebird','node-fetch','path','rimraf','../../config/environment','./whatsappMessage.attributes','exports','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','body','models','get','direction','toLowerCase','out','secret','isNil','UserId','findOne','WhatsappInteractionId','then','catch','error','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid','authToken','phone','messages','whatsapp:','/api/whatsapp/messages/','/status?token=','sid','update','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','sinch','baseUrl','/whatsapp/v1/','/messages/','text'];(function(_0x13caa9,_0x525bfd){var _0x48de10=function(_0x254579){while(--_0x254579){_0x13caa9['push'](_0x13caa9['shift']());}};_0x48de10(++_0x525bfd);}(_0x7e1b,0x79));var _0xb7e1=function(_0x1a7846,_0x59723e){_0x1a7846=_0x1a7846-0x0;var _0x48049=_0x7e1b[_0x1a7846];return _0x48049;};'use strict';var _=require('lodash');var util=require(_0xb7e1('0x0'));var logger=require('../../config/logger')(_0xb7e1('0x1'));var moment=require(_0xb7e1('0x2'));var BPromise=require(_0xb7e1('0x3'));var rp=require('request-promise');var fetch=require(_0xb7e1('0x4'));var fs=require('fs');var path=require(_0xb7e1('0x5'));var rimraf=require(_0xb7e1('0x6'));var config=require(_0xb7e1('0x7'));var attributes=require(_0xb7e1('0x8'));module[_0xb7e1('0x9')]=function(_0x23963d,_0x59a588){return _0x23963d['define'](_0xb7e1('0xa'),attributes,{'tableName':_0xb7e1('0xb'),'paranoid':![],'indexes':[{'name':'messageId','fields':[_0xb7e1('0xc')]},{'name':_0xb7e1('0xd'),'fields':[_0xb7e1('0xe')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x18892b,_0x1c9886,_0x32b3f8){var _0x4b2a0a=_0x23963d[_0xb7e1('0xf')];var _0x48819f=_0x18892b[_0xb7e1('0x10')]({'plain':!![]});if(_0x48819f[_0xb7e1('0x11')][_0xb7e1('0x12')]()==='in'||_0x48819f[_0xb7e1('0x11')]['toLowerCase']()===_0xb7e1('0x13')&&!_0x48819f[_0xb7e1('0x14')]&&!_[_0xb7e1('0x15')](_0x48819f[_0xb7e1('0x16')])){_0x4b2a0a['WhatsappInteraction'][_0xb7e1('0x17')]({'where':{'id':_0x48819f[_0xb7e1('0x18')]}})[_0xb7e1('0x19')](function(_0x191e29){if(_0x191e29){_0x191e29['update']({'lastMsgAt':_0x48819f['createdAt'],'lastMsgDirection':_0x48819f[_0xb7e1('0x11')][_0xb7e1('0x12')]()});}})[_0xb7e1('0x1a')](function(_0x509af3){console[_0xb7e1('0x1b')](_0x509af3);});}if(_0x48819f['direction']==='out'&&!_0x48819f[_0xb7e1('0x14')]){var _0x5c1b0e;_0x4b2a0a[_0xb7e1('0x1c')][_0xb7e1('0x1d')]({'where':{'id':_0x48819f[_0xb7e1('0x1e')]},'raw':!![]})[_0xb7e1('0x19')](function(_0x65b2cf){_0x5c1b0e=_0x65b2cf;if(_0x5c1b0e&&_0x5c1b0e[_0xb7e1('0x1f')]){switch(_0x5c1b0e['type']){case _0xb7e1('0x20'):var _0x296ee1=require(_0xb7e1('0x20'));if(_0x5c1b0e[_0xb7e1('0x21')]&&_0x5c1b0e[_0xb7e1('0x22')]&&_0x5c1b0e[_0xb7e1('0x23')]){var _0x342e51=new _0x296ee1(_0x5c1b0e[_0xb7e1('0x21')],_0x5c1b0e[_0xb7e1('0x22')]);_0x342e51[_0xb7e1('0x24')]['create']({'body':_0x48819f[_0xb7e1('0xe')],'to':_0xb7e1('0x25')+_0x48819f[_0xb7e1('0x23')],'from':_0xb7e1('0x25')+_0x5c1b0e[_0xb7e1('0x23')],'statusCallback':_0x5c1b0e['remote']+_0xb7e1('0x26')+_0x48819f['id']+_0xb7e1('0x27')+_0x5c1b0e['token']})[_0xb7e1('0x19')](function(_0x916e92){if(_0x916e92[_0xb7e1('0x28')]){return _0x18892b[_0xb7e1('0x29')]({'messageId':_0x916e92['sid']});}})[_0xb7e1('0x1a')](function(_0x12ed4){logger['error'](_0xb7e1('0x2a'),_0xb7e1('0x2b'),_0xb7e1('0x20'),util['inspect'](_0x12ed4,{'showHidden':![],'depth':null}));});}else{logger[_0xb7e1('0x1b')](_0xb7e1('0x2a'),_0xb7e1('0x2b'),_0xb7e1('0x20'),_0xb7e1('0x2c'));}break;case _0xb7e1('0x2d'):var _0x394ec3=_0x5c1b0e[_0xb7e1('0x21')];var _0xb11ebb=_0x5c1b0e[_0xb7e1('0x22')];var _0x557533=_0x5c1b0e[_0xb7e1('0x2e')]+_0xb7e1('0x2f')+_0x394ec3+_0xb7e1('0x30');var _0x16a407={'to':[_0x48819f[_0xb7e1('0x23')]],'message':{'type':_0xb7e1('0x31'),'text':_0x48819f[_0xb7e1('0xe')]}};var _0x3b5510={'method':'POST','uri':_0x557533,'headers':{'Authorization':_0xb7e1('0x32')+_0xb11ebb,'Content-Type':_0xb7e1('0x33')},'body':_0x16a407,'json':!![]};rp(_0x3b5510)[_0xb7e1('0x19')](function(_0x31ac85){if(_0x31ac85[_0xb7e1('0x34')][0x0]['message_id']){return _0x18892b[_0xb7e1('0x29')]({'messageId':_0x31ac85['statuses'][0x0]['message_id']});}})[_0xb7e1('0x1a')](function(_0x53d26d){logger[_0xb7e1('0x35')](_0xb7e1('0x36'),_0x53d26d);});break;}}})[_0xb7e1('0x37')](function(){_0x32b3f8();});}else{_0x32b3f8();}}},'charset':_0xb7e1('0x38'),'collate':'utf8mb4_unicode_ci'});};
\ No newline at end of file
+var _0xf2cc=['out','secret','isNil','UserId','findOne','WhatsappInteractionId','then','update','createdAt','catch','error','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid','authToken','phone','messages','create','whatsapp:','remote','/api/whatsapp/messages/','sid','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','sinch','baseUrl','/whatsapp/v1/','/messages/','POST','Bearer\x20','message_id','statuses','err','finally','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','request-promise','node-fetch','path','rimraf','./whatsappMessage.attributes','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','body','direction','toLowerCase'];(function(_0x725b8e,_0xc22b48){var _0x43ac45=function(_0x46bb4a){while(--_0x46bb4a){_0x725b8e['push'](_0x725b8e['shift']());}};_0x43ac45(++_0xc22b48);}(_0xf2cc,0x1a8));var _0xcf2c=function(_0x6c993a,_0x5ea3ab){_0x6c993a=_0x6c993a-0x0;var _0x27f547=_0xf2cc[_0x6c993a];return _0x27f547;};'use strict';var _=require(_0xcf2c('0x0'));var util=require('util');var logger=require(_0xcf2c('0x1'))(_0xcf2c('0x2'));var moment=require(_0xcf2c('0x3'));var BPromise=require('bluebird');var rp=require(_0xcf2c('0x4'));var fetch=require(_0xcf2c('0x5'));var fs=require('fs');var path=require(_0xcf2c('0x6'));var rimraf=require(_0xcf2c('0x7'));var config=require('../../config/environment');var attributes=require(_0xcf2c('0x8'));module['exports']=function(_0x9f1849,_0x213bef){return _0x9f1849['define'](_0xcf2c('0x9'),attributes,{'tableName':_0xcf2c('0xa'),'paranoid':![],'indexes':[{'name':_0xcf2c('0xb'),'fields':[_0xcf2c('0xb')]},{'name':_0xcf2c('0xc'),'fields':[_0xcf2c('0xd')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x185ccc,_0xc6aab2,_0x21bc44){var _0x4523b0=_0x9f1849['models'];var _0xad20ff=_0x185ccc['get']({'plain':!![]});if(_0xad20ff[_0xcf2c('0xe')][_0xcf2c('0xf')]()==='in'||_0xad20ff[_0xcf2c('0xe')][_0xcf2c('0xf')]()===_0xcf2c('0x10')&&!_0xad20ff[_0xcf2c('0x11')]&&!_[_0xcf2c('0x12')](_0xad20ff[_0xcf2c('0x13')])){_0x4523b0['WhatsappInteraction'][_0xcf2c('0x14')]({'where':{'id':_0xad20ff[_0xcf2c('0x15')]}})[_0xcf2c('0x16')](function(_0x4e0652){if(_0x4e0652){_0x4e0652[_0xcf2c('0x17')]({'lastMsgAt':_0xad20ff[_0xcf2c('0x18')],'lastMsgDirection':_0xad20ff[_0xcf2c('0xe')]['toLowerCase']()});}})[_0xcf2c('0x19')](function(_0x17944d){console[_0xcf2c('0x1a')](_0x17944d);});}if(_0xad20ff[_0xcf2c('0xe')]===_0xcf2c('0x10')&&!_0xad20ff[_0xcf2c('0x11')]){var _0x22ebb7;_0x4523b0[_0xcf2c('0x1b')][_0xcf2c('0x1c')]({'where':{'id':_0xad20ff[_0xcf2c('0x1d')]},'raw':!![]})[_0xcf2c('0x16')](function(_0x12872a){_0x22ebb7=_0x12872a;if(_0x22ebb7&&_0x22ebb7[_0xcf2c('0x1e')]){switch(_0x22ebb7[_0xcf2c('0x1e')]){case _0xcf2c('0x1f'):var _0x195c71=require(_0xcf2c('0x1f'));if(_0x22ebb7[_0xcf2c('0x20')]&&_0x22ebb7[_0xcf2c('0x21')]&&_0x22ebb7[_0xcf2c('0x22')]){var _0x4738a4=new _0x195c71(_0x22ebb7['accountSid'],_0x22ebb7[_0xcf2c('0x21')]);_0x4738a4[_0xcf2c('0x23')][_0xcf2c('0x24')]({'body':_0xad20ff[_0xcf2c('0xd')],'to':_0xcf2c('0x25')+_0xad20ff[_0xcf2c('0x22')],'from':_0xcf2c('0x25')+_0x22ebb7['phone'],'statusCallback':_0x22ebb7[_0xcf2c('0x26')]+_0xcf2c('0x27')+_0xad20ff['id']+'/status?token='+_0x22ebb7['token']})[_0xcf2c('0x16')](function(_0x10c1fc){if(_0x10c1fc[_0xcf2c('0x28')]){return _0x185ccc['update']({'messageId':_0x10c1fc[_0xcf2c('0x28')]});}})[_0xcf2c('0x19')](function(_0x2ec06d){logger[_0xcf2c('0x1a')](_0xcf2c('0x29'),_0xcf2c('0x2a'),'twilio',util['inspect'](_0x2ec06d,{'showHidden':![],'depth':null}));});}else{logger[_0xcf2c('0x1a')](_0xcf2c('0x29'),_0xcf2c('0x2a'),'twilio','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken');}break;case _0xcf2c('0x2b'):var _0x4f9cb8=_0x22ebb7[_0xcf2c('0x20')];var _0x936704=_0x22ebb7[_0xcf2c('0x21')];var _0x1d4ae8=_0x22ebb7[_0xcf2c('0x2c')]+_0xcf2c('0x2d')+_0x4f9cb8+_0xcf2c('0x2e');var _0x22978f={'to':[_0xad20ff[_0xcf2c('0x22')]],'message':{'type':'text','text':_0xad20ff[_0xcf2c('0xd')]}};var _0x371b8b={'method':_0xcf2c('0x2f'),'uri':_0x1d4ae8,'headers':{'Authorization':_0xcf2c('0x30')+_0x936704,'Content-Type':'application/json'},'body':_0x22978f,'json':!![]};rp(_0x371b8b)['then'](function(_0x113df0){if(_0x113df0['statuses'][0x0][_0xcf2c('0x31')]){return _0x185ccc[_0xcf2c('0x17')]({'messageId':_0x113df0[_0xcf2c('0x32')][0x0][_0xcf2c('0x31')]});}})[_0xcf2c('0x19')](function(_0x158d94){logger[_0xcf2c('0x33')]('WhatsappMessage,\x20%s',_0x158d94);});break;}}})[_0xcf2c('0x34')](function(){_0x21bc44();});}else{_0x21bc44();}}},'charset':_0xcf2c('0x35'),'collate':_0xcf2c('0x36')});};
\ No newline at end of file