Built motion from commit f7863d46.|2.5.41
[motion2.git] / server / api / whatsappMessage / whatsappMessage.model.js
index 57bd5cf..9b682f6 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfa11=['/api/whatsapp/messages/','/status?token=','token','sid','catch','error','WhatsappMessage,\x20%s,\x20%s,\x20%s','twilio','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','sinch','baseUrl','/whatsapp/v1/','/messages/','text','body','Bearer\x20','application/json','statuses','message_id','err','utf8mb4','lodash','util','../../config/logger','api','node-fetch','path','../../config/environment','./whatsappMessage.attributes','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','FULLTEXT','models','direction','toLowerCase','out','UserId','WhatsappInteraction','findOne','WhatsappInteractionId','then','update','createdAt','secret','WhatsappAccount','find','type','accountSid','phone','authToken','messages','whatsapp:','remote'];(function(_0x4d1cc6,_0x26bebe){var _0x1a6fee=function(_0x374f30){while(--_0x374f30){_0x4d1cc6['push'](_0x4d1cc6['shift']());}};_0x1a6fee(++_0x26bebe);}(_0xfa11,0xba));var _0x1fa1=function(_0x47cdef,_0x13efcf){_0x47cdef=_0x47cdef-0x0;var _0x83a818=_0xfa11[_0x47cdef];return _0x83a818;};'use strict';var _=require(_0x1fa1('0x0'));var util=require(_0x1fa1('0x1'));var logger=require(_0x1fa1('0x2'))(_0x1fa1('0x3'));var moment=require('moment');var BPromise=require('bluebird');var rp=require('request-promise');var fetch=require(_0x1fa1('0x4'));var fs=require('fs');var path=require(_0x1fa1('0x5'));var rimraf=require('rimraf');var config=require(_0x1fa1('0x6'));var attributes=require(_0x1fa1('0x7'));module['exports']=function(_0x4b47cc,_0x2a2d05){return _0x4b47cc['define'](_0x1fa1('0x8'),attributes,{'tableName':_0x1fa1('0x9'),'paranoid':![],'indexes':[{'name':_0x1fa1('0xa'),'fields':[_0x1fa1('0xa')]},{'name':_0x1fa1('0xb'),'fields':['body'],'type':_0x1fa1('0xc')}],'timestamps':!![],'hooks':{'afterCreate':function(_0xad53fa,_0x453029,_0x40e6e6){var _0x4549d1=_0x4b47cc[_0x1fa1('0xd')];var _0x4ac5d9=_0xad53fa['get']({'plain':!![]});if(_0x4ac5d9[_0x1fa1('0xe')][_0x1fa1('0xf')]()==='in'||_0x4ac5d9[_0x1fa1('0xe')][_0x1fa1('0xf')]()===_0x1fa1('0x10')&&!_0x4ac5d9['secret']&&!_['isNil'](_0x4ac5d9[_0x1fa1('0x11')])){_0x4549d1[_0x1fa1('0x12')][_0x1fa1('0x13')]({'where':{'id':_0x4ac5d9[_0x1fa1('0x14')]}})[_0x1fa1('0x15')](function(_0x158343){if(_0x158343){_0x158343[_0x1fa1('0x16')]({'lastMsgAt':_0x4ac5d9[_0x1fa1('0x17')],'lastMsgDirection':_0x4ac5d9[_0x1fa1('0xe')][_0x1fa1('0xf')]()});}})['catch'](function(_0xc4cda3){console['error'](_0xc4cda3);});}if(_0x4ac5d9[_0x1fa1('0xe')]===_0x1fa1('0x10')&&!_0x4ac5d9[_0x1fa1('0x18')]){var _0x1710d2;_0x4549d1[_0x1fa1('0x19')][_0x1fa1('0x1a')]({'where':{'id':_0x4ac5d9['WhatsappAccountId']},'raw':!![]})[_0x1fa1('0x15')](function(_0x433c77){_0x1710d2=_0x433c77;if(_0x1710d2&&_0x1710d2['type']){switch(_0x1710d2[_0x1fa1('0x1b')]){case'twilio':var _0x4d9164=require('twilio');if(_0x1710d2[_0x1fa1('0x1c')]&&_0x1710d2['authToken']&&_0x1710d2[_0x1fa1('0x1d')]){var _0x562174=new _0x4d9164(_0x1710d2['accountSid'],_0x1710d2[_0x1fa1('0x1e')]);_0x562174[_0x1fa1('0x1f')]['create']({'body':_0x4ac5d9['body'],'to':'whatsapp:'+_0x4ac5d9['phone'],'from':_0x1fa1('0x20')+_0x1710d2[_0x1fa1('0x1d')],'statusCallback':_0x1710d2[_0x1fa1('0x21')]+_0x1fa1('0x22')+_0x4ac5d9['id']+_0x1fa1('0x23')+_0x1710d2[_0x1fa1('0x24')]})[_0x1fa1('0x15')](function(_0x1c92c9){if(_0x1c92c9[_0x1fa1('0x25')]){return _0xad53fa[_0x1fa1('0x16')]({'messageId':_0x1c92c9[_0x1fa1('0x25')]});}})[_0x1fa1('0x26')](function(_0x1dc14d){logger[_0x1fa1('0x27')](_0x1fa1('0x28'),'afterCreate',_0x1fa1('0x29'),util['inspect'](_0x1dc14d,{'showHidden':![],'depth':null}));});}else{logger[_0x1fa1('0x27')]('WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','twilio',_0x1fa1('0x2a'));}break;case _0x1fa1('0x2b'):var _0x47d81e=_0x1710d2[_0x1fa1('0x1c')];var _0xf973a5=_0x1710d2['authToken'];var _0x4b5ecd=_0x1710d2[_0x1fa1('0x2c')]+_0x1fa1('0x2d')+_0x47d81e+_0x1fa1('0x2e');var _0x578216={'to':[_0x4ac5d9[_0x1fa1('0x1d')]],'message':{'type':_0x1fa1('0x2f'),'text':_0x4ac5d9[_0x1fa1('0x30')]}};var _0x58705a={'method':'POST','uri':_0x4b5ecd,'headers':{'Authorization':_0x1fa1('0x31')+_0xf973a5,'Content-Type':_0x1fa1('0x32')},'body':_0x578216,'json':!![]};rp(_0x58705a)[_0x1fa1('0x15')](function(_0x42cdc9){if(_0x42cdc9[_0x1fa1('0x33')][0x0][_0x1fa1('0x34')]){return _0xad53fa[_0x1fa1('0x16')]({'messageId':_0x42cdc9[_0x1fa1('0x33')][0x0][_0x1fa1('0x34')]});}})[_0x1fa1('0x26')](function(_0x57416b){logger[_0x1fa1('0x35')]('WhatsappMessage,\x20%s',_0x57416b);});break;}}})['finally'](function(){_0x40e6e6();});}else{_0x40e6e6();}}},'charset':_0x1fa1('0x36'),'collate':'utf8mb4_unicode_ci'});};
\ No newline at end of file
+var _0xf7c2=['phone','messages','create','whatsapp:','remote','/api/whatsapp/messages/','/status?token=','token','sid','update','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','error','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','baseUrl','/messages/','text','POST','statuses','message_id','err','finally','utf8mb4','lodash','util','../../config/logger','moment','bluebird','request-promise','node-fetch','path','../../config/environment','define','WhatsappMessage','fti_whatsapp_messages','body','FULLTEXT','models','get','toLowerCase','direction','out','UserId','WhatsappInteraction','createdAt','catch','WhatsappAccount','find','WhatsappAccountId','then','type','twilio','accountSid','authToken'];(function(_0x1743e2,_0x5bc363){var _0x39e145=function(_0x226c28){while(--_0x226c28){_0x1743e2['push'](_0x1743e2['shift']());}};_0x39e145(++_0x5bc363);}(_0xf7c2,0x1c7));var _0x2f7c=function(_0x2c63f7,_0x49ec00){_0x2c63f7=_0x2c63f7-0x0;var _0xeeaa93=_0xf7c2[_0x2c63f7];return _0xeeaa93;};'use strict';var _=require(_0x2f7c('0x0'));var util=require(_0x2f7c('0x1'));var logger=require(_0x2f7c('0x2'))('api');var moment=require(_0x2f7c('0x3'));var BPromise=require(_0x2f7c('0x4'));var rp=require(_0x2f7c('0x5'));var fetch=require(_0x2f7c('0x6'));var fs=require('fs');var path=require(_0x2f7c('0x7'));var rimraf=require('rimraf');var config=require(_0x2f7c('0x8'));var attributes=require('./whatsappMessage.attributes');module['exports']=function(_0x31e04a,_0x5d2013){return _0x31e04a[_0x2f7c('0x9')](_0x2f7c('0xa'),attributes,{'tableName':'whatsapp_messages','paranoid':![],'indexes':[{'name':'messageId','fields':['messageId']},{'name':_0x2f7c('0xb'),'fields':[_0x2f7c('0xc')],'type':_0x2f7c('0xd')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x108622,_0x42a116,_0x373ac6){var _0x4a79da=_0x31e04a[_0x2f7c('0xe')];var _0x3414b9=_0x108622[_0x2f7c('0xf')]({'plain':!![]});if(_0x3414b9['direction'][_0x2f7c('0x10')]()==='in'||_0x3414b9[_0x2f7c('0x11')][_0x2f7c('0x10')]()===_0x2f7c('0x12')&&!_0x3414b9['secret']&&!_['isNil'](_0x3414b9[_0x2f7c('0x13')])){_0x4a79da[_0x2f7c('0x14')]['findOne']({'where':{'id':_0x3414b9['WhatsappInteractionId']}})['then'](function(_0x182b42){if(_0x182b42){_0x182b42['update']({'lastMsgAt':_0x3414b9[_0x2f7c('0x15')],'lastMsgDirection':_0x3414b9[_0x2f7c('0x11')][_0x2f7c('0x10')]()});}})[_0x2f7c('0x16')](function(_0x55d4e9){console['error'](_0x55d4e9);});}if(_0x3414b9[_0x2f7c('0x11')]===_0x2f7c('0x12')&&!_0x3414b9['secret']){var _0x561db6;_0x4a79da[_0x2f7c('0x17')][_0x2f7c('0x18')]({'where':{'id':_0x3414b9[_0x2f7c('0x19')]},'raw':!![]})[_0x2f7c('0x1a')](function(_0x32b96b){_0x561db6=_0x32b96b;if(_0x561db6&&_0x561db6['type']){switch(_0x561db6[_0x2f7c('0x1b')]){case _0x2f7c('0x1c'):var _0x2d87eb=require(_0x2f7c('0x1c'));if(_0x561db6[_0x2f7c('0x1d')]&&_0x561db6[_0x2f7c('0x1e')]&&_0x561db6[_0x2f7c('0x1f')]){var _0x3dde00=new _0x2d87eb(_0x561db6[_0x2f7c('0x1d')],_0x561db6[_0x2f7c('0x1e')]);_0x3dde00[_0x2f7c('0x20')][_0x2f7c('0x21')]({'body':_0x3414b9[_0x2f7c('0xc')],'to':_0x2f7c('0x22')+_0x3414b9[_0x2f7c('0x1f')],'from':_0x2f7c('0x22')+_0x561db6['phone'],'statusCallback':_0x561db6[_0x2f7c('0x23')]+_0x2f7c('0x24')+_0x3414b9['id']+_0x2f7c('0x25')+_0x561db6[_0x2f7c('0x26')]})['then'](function(_0x115d35){if(_0x115d35[_0x2f7c('0x27')]){return _0x108622[_0x2f7c('0x28')]({'messageId':_0x115d35[_0x2f7c('0x27')]});}})[_0x2f7c('0x16')](function(_0x49a092){logger['error'](_0x2f7c('0x29'),_0x2f7c('0x2a'),'twilio',util['inspect'](_0x49a092,{'showHidden':![],'depth':null}));});}else{logger[_0x2f7c('0x2b')]('WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate',_0x2f7c('0x1c'),_0x2f7c('0x2c'));}break;case'sinch':var _0x359dc8=_0x561db6[_0x2f7c('0x1d')];var _0x374bfa=_0x561db6[_0x2f7c('0x1e')];var _0x3ac4a4=_0x561db6[_0x2f7c('0x2d')]+'/whatsapp/v1/'+_0x359dc8+_0x2f7c('0x2e');var _0x453c66={'to':[_0x3414b9[_0x2f7c('0x1f')]],'message':{'type':_0x2f7c('0x2f'),'text':_0x3414b9[_0x2f7c('0xc')]}};var _0x5401d4={'method':_0x2f7c('0x30'),'uri':_0x3ac4a4,'headers':{'Authorization':'Bearer\x20'+_0x374bfa,'Content-Type':'application/json'},'body':_0x453c66,'json':!![]};rp(_0x5401d4)['then'](function(_0x2b1d1e){if(_0x2b1d1e[_0x2f7c('0x31')][0x0]['message_id']){return _0x108622[_0x2f7c('0x28')]({'messageId':_0x2b1d1e[_0x2f7c('0x31')][0x0][_0x2f7c('0x32')]});}})[_0x2f7c('0x16')](function(_0x1ded0a){logger[_0x2f7c('0x33')]('WhatsappMessage,\x20%s',_0x1ded0a);});break;}}})[_0x2f7c('0x34')](function(){_0x373ac6();});}else{_0x373ac6();}}},'charset':_0x2f7c('0x35'),'collate':'utf8mb4_unicode_ci'});};
\ No newline at end of file