Built motion from commit efa66e19.|2.6.22
[motion2.git] / server / api / whatsappMessage / whatsappMessage.model.js
index d2009cd..e1d4aeb 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x35cf=['err','WhatsappMessage,\x20%s','lodash','util','../../config/logger','bluebird','request-promise','node-fetch','path','rimraf','../../config/environment','./whatsappMessage.attributes','exports','define','WhatsappMessage','messageId','fti_whatsapp_messages','body','FULLTEXT','models','get','toLowerCase','direction','out','secret','isNil','UserId','WhatsappInteraction','findOne','WhatsappInteractionId','update','createdAt','error','find','WhatsappAccountId','type','twilio','phone','accountSid','authToken','messages','create','whatsapp:','/api/whatsapp/messages/','/status?token=','token','then','sid','catch','WhatsappMessage,\x20%s,\x20%s,\x20%s','inspect','afterCreate','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','sinch','baseUrl','/whatsapp/v1/','/messages/','text','POST','Bearer\x20','application/json','statuses','message_id'];(function(_0x22f2c6,_0x5673bc){var _0x534421=function(_0x44ba17){while(--_0x44ba17){_0x22f2c6['push'](_0x22f2c6['shift']());}};_0x534421(++_0x5673bc);}(_0x35cf,0xbf));var _0xf35c=function(_0x12d5e9,_0x1decd6){_0x12d5e9=_0x12d5e9-0x0;var _0x343939=_0x35cf[_0x12d5e9];return _0x343939;};'use strict';var _=require(_0xf35c('0x0'));var util=require(_0xf35c('0x1'));var logger=require(_0xf35c('0x2'))('api');var moment=require('moment');var BPromise=require(_0xf35c('0x3'));var rp=require(_0xf35c('0x4'));var fetch=require(_0xf35c('0x5'));var fs=require('fs');var path=require(_0xf35c('0x6'));var rimraf=require(_0xf35c('0x7'));var config=require(_0xf35c('0x8'));var attributes=require(_0xf35c('0x9'));module[_0xf35c('0xa')]=function(_0x5795e3,_0x20d12a){return _0x5795e3[_0xf35c('0xb')](_0xf35c('0xc'),attributes,{'tableName':'whatsapp_messages','paranoid':![],'indexes':[{'name':_0xf35c('0xd'),'fields':[_0xf35c('0xd')]},{'name':_0xf35c('0xe'),'fields':[_0xf35c('0xf')],'type':_0xf35c('0x10')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x210126,_0x2f8f3c,_0x5e17ab){var _0x1a6560=_0x5795e3[_0xf35c('0x11')];var _0x17378c=_0x210126[_0xf35c('0x12')]({'plain':!![]});if(_0x17378c['direction'][_0xf35c('0x13')]()==='in'||_0x17378c[_0xf35c('0x14')]['toLowerCase']()===_0xf35c('0x15')&&!_0x17378c[_0xf35c('0x16')]&&!_[_0xf35c('0x17')](_0x17378c[_0xf35c('0x18')])){_0x1a6560[_0xf35c('0x19')][_0xf35c('0x1a')]({'where':{'id':_0x17378c[_0xf35c('0x1b')]}})['then'](function(_0x51ce52){if(_0x51ce52){_0x51ce52[_0xf35c('0x1c')]({'lastMsgAt':_0x17378c[_0xf35c('0x1d')],'lastMsgDirection':_0x17378c['direction']['toLowerCase']()});}})['catch'](function(_0x4f5daf){console[_0xf35c('0x1e')](_0x4f5daf);});}if(_0x17378c['direction']==='out'&&!_0x17378c[_0xf35c('0x16')]){var _0x352de8;_0x1a6560['WhatsappAccount'][_0xf35c('0x1f')]({'where':{'id':_0x17378c[_0xf35c('0x20')]},'raw':!![]})['then'](function(_0x4e35c9){_0x352de8=_0x4e35c9;if(_0x352de8&&_0x352de8['type']){switch(_0x352de8[_0xf35c('0x21')]){case _0xf35c('0x22'):var _0x5534d5=require('twilio');if(_0x352de8['accountSid']&&_0x352de8['authToken']&&_0x352de8[_0xf35c('0x23')]){var _0x53d173=new _0x5534d5(_0x352de8[_0xf35c('0x24')],_0x352de8[_0xf35c('0x25')]);_0x53d173[_0xf35c('0x26')][_0xf35c('0x27')]({'body':_0x17378c['body'],'to':_0xf35c('0x28')+_0x17378c[_0xf35c('0x23')],'from':_0xf35c('0x28')+_0x352de8[_0xf35c('0x23')],'statusCallback':_0x352de8['remote']+_0xf35c('0x29')+_0x17378c['id']+_0xf35c('0x2a')+_0x352de8[_0xf35c('0x2b')]})[_0xf35c('0x2c')](function(_0x31e162){if(_0x31e162[_0xf35c('0x2d')]){return _0x210126[_0xf35c('0x1c')]({'messageId':_0x31e162[_0xf35c('0x2d')]});}})[_0xf35c('0x2e')](function(_0x4b2f81){logger[_0xf35c('0x1e')](_0xf35c('0x2f'),'afterCreate',_0xf35c('0x22'),util[_0xf35c('0x30')](_0x4b2f81,{'showHidden':![],'depth':null}));});}else{logger[_0xf35c('0x1e')](_0xf35c('0x2f'),_0xf35c('0x31'),_0xf35c('0x22'),_0xf35c('0x32'));}break;case _0xf35c('0x33'):var _0x43ab0e=_0x352de8[_0xf35c('0x24')];var _0x2dd6a2=_0x352de8[_0xf35c('0x25')];var _0x465a3c=_0x352de8[_0xf35c('0x34')]+_0xf35c('0x35')+_0x43ab0e+_0xf35c('0x36');var _0x53f4d1={'to':[_0x17378c['phone']],'message':{'type':_0xf35c('0x37'),'text':_0x17378c[_0xf35c('0xf')]}};var _0x5ecaad={'method':_0xf35c('0x38'),'uri':_0x465a3c,'headers':{'Authorization':_0xf35c('0x39')+_0x2dd6a2,'Content-Type':_0xf35c('0x3a')},'body':_0x53f4d1,'json':!![]};rp(_0x5ecaad)[_0xf35c('0x2c')](function(_0x2446ac){if(_0x2446ac[_0xf35c('0x3b')][0x0][_0xf35c('0x3c')]){return _0x210126['update']({'messageId':_0x2446ac['statuses'][0x0]['message_id']});}})[_0xf35c('0x2e')](function(_0x157d35){logger[_0xf35c('0x3d')](_0xf35c('0x3e'),_0x157d35);});break;}}})['finally'](function(){_0x5e17ab();});}else{_0x5e17ab();}}},'charset':'utf8mb4','collate':'utf8mb4_unicode_ci'});};
\ No newline at end of file
+var _0xba0f=['node-fetch','path','rimraf','../../config/environment','exports','define','WhatsappMessage','whatsapp_messages','fti_whatsapp_messages','FULLTEXT','models','get','toLowerCase','direction','secret','isNil','UserId','WhatsappInteraction','findOne','WhatsappInteractionId','then','update','createdAt','catch','error','out','WhatsappAccount','find','type','twilio','authToken','phone','accountSid','messages','create','body','whatsapp:','remote','/api/whatsapp/messages/','/status?token=','sid','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','inspect','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','sinch','/whatsapp/v1/','/messages/','text','POST','Bearer\x20','application/json','statuses','message_id','err','finally','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','bluebird','request-promise'];(function(_0x295f72,_0x5bcfcf){var _0x261db7=function(_0x2f9719){while(--_0x2f9719){_0x295f72['push'](_0x295f72['shift']());}};_0x261db7(++_0x5bcfcf);}(_0xba0f,0x1b3));var _0xfba0=function(_0x2641f9,_0x26715f){_0x2641f9=_0x2641f9-0x0;var _0x585741=_0xba0f[_0x2641f9];return _0x585741;};'use strict';var _=require(_0xfba0('0x0'));var util=require(_0xfba0('0x1'));var logger=require(_0xfba0('0x2'))(_0xfba0('0x3'));var moment=require('moment');var BPromise=require(_0xfba0('0x4'));var rp=require(_0xfba0('0x5'));var fetch=require(_0xfba0('0x6'));var fs=require('fs');var path=require(_0xfba0('0x7'));var rimraf=require(_0xfba0('0x8'));var config=require(_0xfba0('0x9'));var attributes=require('./whatsappMessage.attributes');module[_0xfba0('0xa')]=function(_0x10f1ff,_0x1a665b){return _0x10f1ff[_0xfba0('0xb')](_0xfba0('0xc'),attributes,{'tableName':_0xfba0('0xd'),'paranoid':![],'indexes':[{'name':'messageId','fields':['messageId']},{'name':_0xfba0('0xe'),'fields':['body'],'type':_0xfba0('0xf')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x3587b1,_0x18d00e,_0x56e9e0){var _0x182821=_0x10f1ff[_0xfba0('0x10')];var _0x5b30ae=_0x3587b1[_0xfba0('0x11')]({'plain':!![]});if(_0x5b30ae['direction'][_0xfba0('0x12')]()==='in'||_0x5b30ae[_0xfba0('0x13')][_0xfba0('0x12')]()==='out'&&!_0x5b30ae[_0xfba0('0x14')]&&!_[_0xfba0('0x15')](_0x5b30ae[_0xfba0('0x16')])){_0x182821[_0xfba0('0x17')][_0xfba0('0x18')]({'where':{'id':_0x5b30ae[_0xfba0('0x19')]}})[_0xfba0('0x1a')](function(_0x216354){if(_0x216354){_0x216354[_0xfba0('0x1b')]({'lastMsgAt':_0x5b30ae[_0xfba0('0x1c')],'lastMsgDirection':_0x5b30ae[_0xfba0('0x13')]['toLowerCase']()});}})[_0xfba0('0x1d')](function(_0x39d3c7){console[_0xfba0('0x1e')](_0x39d3c7);});}if(_0x5b30ae[_0xfba0('0x13')]===_0xfba0('0x1f')&&!_0x5b30ae['secret']){var _0x25fa6a;_0x182821[_0xfba0('0x20')][_0xfba0('0x21')]({'where':{'id':_0x5b30ae['WhatsappAccountId']},'raw':!![]})[_0xfba0('0x1a')](function(_0xa52035){_0x25fa6a=_0xa52035;if(_0x25fa6a&&_0x25fa6a[_0xfba0('0x22')]){switch(_0x25fa6a[_0xfba0('0x22')]){case _0xfba0('0x23'):var _0x1c9a29=require(_0xfba0('0x23'));if(_0x25fa6a['accountSid']&&_0x25fa6a[_0xfba0('0x24')]&&_0x25fa6a[_0xfba0('0x25')]){var _0x430f83=new _0x1c9a29(_0x25fa6a[_0xfba0('0x26')],_0x25fa6a[_0xfba0('0x24')]);_0x430f83[_0xfba0('0x27')][_0xfba0('0x28')]({'body':_0x5b30ae[_0xfba0('0x29')],'to':'whatsapp:'+_0x5b30ae[_0xfba0('0x25')],'from':_0xfba0('0x2a')+_0x25fa6a[_0xfba0('0x25')],'statusCallback':_0x25fa6a[_0xfba0('0x2b')]+_0xfba0('0x2c')+_0x5b30ae['id']+_0xfba0('0x2d')+_0x25fa6a['token']})[_0xfba0('0x1a')](function(_0xb26651){if(_0xb26651[_0xfba0('0x2e')]){return _0x3587b1[_0xfba0('0x1b')]({'messageId':_0xb26651[_0xfba0('0x2e')]});}})[_0xfba0('0x1d')](function(_0x35ab50){logger[_0xfba0('0x1e')](_0xfba0('0x2f'),_0xfba0('0x30'),'twilio',util[_0xfba0('0x31')](_0x35ab50,{'showHidden':![],'depth':null}));});}else{logger[_0xfba0('0x1e')](_0xfba0('0x2f'),_0xfba0('0x30'),_0xfba0('0x23'),_0xfba0('0x32'));}break;case _0xfba0('0x33'):var _0x5ab5af=_0x25fa6a[_0xfba0('0x26')];var _0x4bd59c=_0x25fa6a['authToken'];var _0x125e68=_0x25fa6a['baseUrl']+_0xfba0('0x34')+_0x5ab5af+_0xfba0('0x35');var _0x550b62={'to':[_0x5b30ae['phone']],'message':{'type':_0xfba0('0x36'),'text':_0x5b30ae[_0xfba0('0x29')]}};var _0x251726={'method':_0xfba0('0x37'),'uri':_0x125e68,'headers':{'Authorization':_0xfba0('0x38')+_0x4bd59c,'Content-Type':_0xfba0('0x39')},'body':_0x550b62,'json':!![]};rp(_0x251726)['then'](function(_0x39b686){if(_0x39b686[_0xfba0('0x3a')][0x0][_0xfba0('0x3b')]){return _0x3587b1['update']({'messageId':_0x39b686[_0xfba0('0x3a')][0x0]['message_id']});}})[_0xfba0('0x1d')](function(_0x4fc848){logger[_0xfba0('0x3c')]('WhatsappMessage,\x20%s',_0x4fc848);});break;}}})[_0xfba0('0x3d')](function(){_0x56e9e0();});}else{_0x56e9e0();}}},'charset':'utf8mb4','collate':_0xfba0('0x3e')});};
\ No newline at end of file