Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / whatsappMessage / whatsappMessage.model.js
index 207e1c0..940758e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x77bf=['direction','out','secret','UserId','WhatsappInteraction','findOne','WhatsappInteractionId','then','update','createdAt','catch','error','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid','phone','authToken','messages','create','body','whatsapp:','remote','token','sid','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','baseUrl','/whatsapp/v1/','text','POST','application/json','statuses','message_id','err','finally','utf8mb4','lodash','api','moment','bluebird','request-promise','rimraf','./whatsappMessage.attributes','exports','define','whatsapp_messages','FULLTEXT','get','toLowerCase'];(function(_0x4a5452,_0xa31da4){var _0x209900=function(_0x15b396){while(--_0x15b396){_0x4a5452['push'](_0x4a5452['shift']());}};_0x209900(++_0xa31da4);}(_0x77bf,0x166));var _0xf77b=function(_0x3a97e5,_0x466a95){_0x3a97e5=_0x3a97e5-0x0;var _0x13f3f4=_0x77bf[_0x3a97e5];return _0x13f3f4;};'use strict';var _=require(_0xf77b('0x0'));var util=require('util');var logger=require('../../config/logger')(_0xf77b('0x1'));var moment=require(_0xf77b('0x2'));var BPromise=require(_0xf77b('0x3'));var rp=require(_0xf77b('0x4'));var fetch=require('node-fetch');var fs=require('fs');var path=require('path');var rimraf=require(_0xf77b('0x5'));var config=require('../../config/environment');var attributes=require(_0xf77b('0x6'));module[_0xf77b('0x7')]=function(_0x10e5b7,_0x4da016){return _0x10e5b7[_0xf77b('0x8')]('WhatsappMessage',attributes,{'tableName':_0xf77b('0x9'),'paranoid':![],'indexes':[{'name':'messageId','fields':['messageId']},{'name':'fti_whatsapp_messages','fields':['body'],'type':_0xf77b('0xa')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x19ec51,_0x3af70b,_0x48c2a9){var _0x2d4910=_0x10e5b7['models'];var _0x460383=_0x19ec51[_0xf77b('0xb')]({'plain':!![]});if(_0x460383['direction'][_0xf77b('0xc')]()==='in'||_0x460383[_0xf77b('0xd')][_0xf77b('0xc')]()===_0xf77b('0xe')&&!_0x460383[_0xf77b('0xf')]&&!_['isNil'](_0x460383[_0xf77b('0x10')])){_0x2d4910[_0xf77b('0x11')][_0xf77b('0x12')]({'where':{'id':_0x460383[_0xf77b('0x13')]}})[_0xf77b('0x14')](function(_0x2a551c){if(_0x2a551c){_0x2a551c[_0xf77b('0x15')]({'lastMsgAt':_0x460383[_0xf77b('0x16')],'lastMsgDirection':_0x460383['direction']['toLowerCase']()});}})[_0xf77b('0x17')](function(_0x318854){console[_0xf77b('0x18')](_0x318854);});}if(_0x460383['direction']===_0xf77b('0xe')&&!_0x460383['secret']){var _0xa1e350;_0x2d4910[_0xf77b('0x19')][_0xf77b('0x1a')]({'where':{'id':_0x460383[_0xf77b('0x1b')]},'raw':!![]})['then'](function(_0x22197b){_0xa1e350=_0x22197b;if(_0xa1e350&&_0xa1e350[_0xf77b('0x1c')]){switch(_0xa1e350[_0xf77b('0x1c')]){case _0xf77b('0x1d'):var _0xaab3ef=require('twilio');if(_0xa1e350[_0xf77b('0x1e')]&&_0xa1e350['authToken']&&_0xa1e350[_0xf77b('0x1f')]){var _0x2d977b=new _0xaab3ef(_0xa1e350['accountSid'],_0xa1e350[_0xf77b('0x20')]);_0x2d977b[_0xf77b('0x21')][_0xf77b('0x22')]({'body':_0x460383[_0xf77b('0x23')],'to':_0xf77b('0x24')+_0x460383['phone'],'from':_0xf77b('0x24')+_0xa1e350[_0xf77b('0x1f')],'statusCallback':_0xa1e350[_0xf77b('0x25')]+'/api/whatsapp/messages/'+_0x460383['id']+'/status?token='+_0xa1e350[_0xf77b('0x26')]})[_0xf77b('0x14')](function(_0x2b1bf3){if(_0x2b1bf3[_0xf77b('0x27')]){return _0x19ec51[_0xf77b('0x15')]({'messageId':_0x2b1bf3[_0xf77b('0x27')]});}})[_0xf77b('0x17')](function(_0x388da1){logger[_0xf77b('0x18')](_0xf77b('0x28'),_0xf77b('0x29'),_0xf77b('0x1d'),util['inspect'](_0x388da1,{'showHidden':![],'depth':null}));});}else{logger['error'](_0xf77b('0x28'),_0xf77b('0x29'),_0xf77b('0x1d'),_0xf77b('0x2a'));}break;case'sinch':var _0x4fcca6=_0xa1e350[_0xf77b('0x1e')];var _0x241536=_0xa1e350['authToken'];var _0x5c62ef=_0xa1e350[_0xf77b('0x2b')]+_0xf77b('0x2c')+_0x4fcca6+'/messages/';var _0x388df9={'to':[_0x460383['phone']],'message':{'type':_0xf77b('0x2d'),'text':_0x460383['body']}};var _0x579c1c={'method':_0xf77b('0x2e'),'uri':_0x5c62ef,'headers':{'Authorization':'Bearer\x20'+_0x241536,'Content-Type':_0xf77b('0x2f')},'body':_0x388df9,'json':!![]};rp(_0x579c1c)[_0xf77b('0x14')](function(_0x2e6b79){if(_0x2e6b79[_0xf77b('0x30')][0x0][_0xf77b('0x31')]){return _0x19ec51['update']({'messageId':_0x2e6b79[_0xf77b('0x30')][0x0][_0xf77b('0x31')]});}})[_0xf77b('0x17')](function(_0x5313bb){logger[_0xf77b('0x32')]('WhatsappMessage,\x20%s',_0x5313bb);});break;}}})[_0xf77b('0x33')](function(){_0x48c2a9();});}else{_0x48c2a9();}}},'charset':_0xf77b('0x34'),'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