Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / whatsappMessage / whatsappMessage.model.js
index 7eda21a..940758e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x6881=['get','toLowerCase','direction','out','isNil','UserId','WhatsappInteraction','findOne','then','createdAt','catch','error','secret','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid','authToken','phone','messages','create','whatsapp:','remote','/api/whatsapp/messages/','token','sid','update','afterCreate','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','sinch','baseUrl','/whatsapp/v1/','/messages/','text','POST','application/json','statuses','err','finally','utf8mb4_unicode_ci','../../config/logger','api','bluebird','request-promise','node-fetch','rimraf','./whatsappMessage.attributes','define','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','body','FULLTEXT','models'];(function(_0x21a9d9,_0x4d5ac8){var _0x46adce=function(_0xfdd336){while(--_0xfdd336){_0x21a9d9['push'](_0x21a9d9['shift']());}};_0x46adce(++_0x4d5ac8);}(_0x6881,0x10e));var _0x1688=function(_0x1345be,_0x5e6847){_0x1345be=_0x1345be-0x0;var _0x5736af=_0x6881[_0x1345be];return _0x5736af;};'use strict';var _=require('lodash');var util=require('util');var logger=require(_0x1688('0x0'))(_0x1688('0x1'));var moment=require('moment');var BPromise=require(_0x1688('0x2'));var rp=require(_0x1688('0x3'));var fetch=require(_0x1688('0x4'));var fs=require('fs');var path=require('path');var rimraf=require(_0x1688('0x5'));var config=require('../../config/environment');var attributes=require(_0x1688('0x6'));module['exports']=function(_0x323ca9,_0x202ddf){return _0x323ca9[_0x1688('0x7')](_0x1688('0x8'),attributes,{'tableName':_0x1688('0x9'),'paranoid':![],'indexes':[{'name':_0x1688('0xa'),'fields':[_0x1688('0xa')]},{'name':_0x1688('0xb'),'fields':[_0x1688('0xc')],'type':_0x1688('0xd')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x208600,_0x158f19,_0x2550f4){var _0x5539af=_0x323ca9[_0x1688('0xe')];var _0x8020f0=_0x208600[_0x1688('0xf')]({'plain':!![]});if(_0x8020f0['direction'][_0x1688('0x10')]()==='in'||_0x8020f0[_0x1688('0x11')][_0x1688('0x10')]()===_0x1688('0x12')&&!_0x8020f0['secret']&&!_[_0x1688('0x13')](_0x8020f0[_0x1688('0x14')])){_0x5539af[_0x1688('0x15')][_0x1688('0x16')]({'where':{'id':_0x8020f0['WhatsappInteractionId']}})[_0x1688('0x17')](function(_0x1c0f8d){if(_0x1c0f8d){_0x1c0f8d['update']({'lastMsgAt':_0x8020f0[_0x1688('0x18')],'lastMsgDirection':_0x8020f0[_0x1688('0x11')][_0x1688('0x10')]()});}})[_0x1688('0x19')](function(_0x3e63af){console[_0x1688('0x1a')](_0x3e63af);});}if(_0x8020f0[_0x1688('0x11')]===_0x1688('0x12')&&!_0x8020f0[_0x1688('0x1b')]){var _0x318abb;_0x5539af[_0x1688('0x1c')][_0x1688('0x1d')]({'where':{'id':_0x8020f0[_0x1688('0x1e')]},'raw':!![]})[_0x1688('0x17')](function(_0x33f38d){_0x318abb=_0x33f38d;if(_0x318abb&&_0x318abb[_0x1688('0x1f')]){switch(_0x318abb['type']){case _0x1688('0x20'):var _0x29286e=require('twilio');if(_0x318abb[_0x1688('0x21')]&&_0x318abb[_0x1688('0x22')]&&_0x318abb[_0x1688('0x23')]){var _0x580564=new _0x29286e(_0x318abb[_0x1688('0x21')],_0x318abb['authToken']);_0x580564[_0x1688('0x24')][_0x1688('0x25')]({'body':_0x8020f0[_0x1688('0xc')],'to':_0x1688('0x26')+_0x8020f0[_0x1688('0x23')],'from':_0x1688('0x26')+_0x318abb['phone'],'statusCallback':_0x318abb[_0x1688('0x27')]+_0x1688('0x28')+_0x8020f0['id']+'/status?token='+_0x318abb[_0x1688('0x29')]})[_0x1688('0x17')](function(_0x3823ce){if(_0x3823ce[_0x1688('0x2a')]){return _0x208600[_0x1688('0x2b')]({'messageId':_0x3823ce[_0x1688('0x2a')]});}})['catch'](function(_0x45c93a){logger[_0x1688('0x1a')]('WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','twilio',util['inspect'](_0x45c93a,{'showHidden':![],'depth':null}));});}else{logger[_0x1688('0x1a')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x1688('0x2c'),_0x1688('0x20'),_0x1688('0x2d'));}break;case _0x1688('0x2e'):var _0x5171d9=_0x318abb[_0x1688('0x21')];var _0x43bb02=_0x318abb[_0x1688('0x22')];var _0x2731d0=_0x318abb[_0x1688('0x2f')]+_0x1688('0x30')+_0x5171d9+_0x1688('0x31');var _0x3b8075={'to':[_0x8020f0[_0x1688('0x23')]],'message':{'type':_0x1688('0x32'),'text':_0x8020f0[_0x1688('0xc')]}};var _0x12cc75={'method':_0x1688('0x33'),'uri':_0x2731d0,'headers':{'Authorization':'Bearer\x20'+_0x43bb02,'Content-Type':_0x1688('0x34')},'body':_0x3b8075,'json':!![]};rp(_0x12cc75)[_0x1688('0x17')](function(_0x19ee91){if(_0x19ee91[_0x1688('0x35')][0x0]['message_id']){return _0x208600[_0x1688('0x2b')]({'messageId':_0x19ee91['statuses'][0x0]['message_id']});}})[_0x1688('0x19')](function(_0x157ec9){logger[_0x1688('0x36')]('WhatsappMessage,\x20%s',_0x157ec9);});break;}}})[_0x1688('0x37')](function(){_0x2550f4();});}else{_0x2550f4();}}},'charset':'utf8mb4','collate':_0x1688('0x38')});};
\ 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