Built motion from commit f623a78c.|2.6.31
[motion2.git] / server / api / whatsappMessage / whatsappMessage.model.js
index 9e11683..53dce75 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x6f93=['statuses','message_id','catch','err','WhatsappMessage,\x20%s','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','request-promise','rimraf','../../config/environment','./whatsappMessage.attributes','exports','define','whatsapp_messages','messageId','FULLTEXT','direction','toLowerCase','out','secret','isNil','UserId','WhatsappInteraction','findOne','WhatsappInteractionId','then','update','createdAt','error','WhatsappAccount','find','type','twilio','accountSid','authToken','phone','messages','create','body','whatsapp:','remote','/api/whatsapp/messages/','/status?token=','sid','afterCreate','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','sinch','baseUrl','/messages/','text','POST','application/json'];(function(_0x28f00a,_0x2f8daa){var _0xf27eb7=function(_0x755918){while(--_0x755918){_0x28f00a['push'](_0x28f00a['shift']());}};_0xf27eb7(++_0x2f8daa);}(_0x6f93,0xb3));var _0x36f9=function(_0x4656fb,_0x3e5507){_0x4656fb=_0x4656fb-0x0;var _0x16b9ac=_0x6f93[_0x4656fb];return _0x16b9ac;};'use strict';var _=require(_0x36f9('0x0'));var util=require(_0x36f9('0x1'));var logger=require(_0x36f9('0x2'))(_0x36f9('0x3'));var moment=require('moment');var BPromise=require('bluebird');var rp=require(_0x36f9('0x4'));var fetch=require('node-fetch');var fs=require('fs');var path=require('path');var rimraf=require(_0x36f9('0x5'));var config=require(_0x36f9('0x6'));var attributes=require(_0x36f9('0x7'));module[_0x36f9('0x8')]=function(_0x5f218c,_0x59ffc0){return _0x5f218c[_0x36f9('0x9')]('WhatsappMessage',attributes,{'tableName':_0x36f9('0xa'),'paranoid':![],'indexes':[{'name':_0x36f9('0xb'),'fields':[_0x36f9('0xb')]},{'name':'fti_whatsapp_messages','fields':['body'],'type':_0x36f9('0xc')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x466f5d,_0x6a1fcf,_0x42437a){var _0x3580ed=_0x5f218c['models'];var _0x5cc29a=_0x466f5d['get']({'plain':!![]});if(_0x5cc29a[_0x36f9('0xd')][_0x36f9('0xe')]()==='in'||_0x5cc29a['direction'][_0x36f9('0xe')]()===_0x36f9('0xf')&&!_0x5cc29a[_0x36f9('0x10')]&&!_[_0x36f9('0x11')](_0x5cc29a[_0x36f9('0x12')])){_0x3580ed[_0x36f9('0x13')][_0x36f9('0x14')]({'where':{'id':_0x5cc29a[_0x36f9('0x15')]}})[_0x36f9('0x16')](function(_0x428569){if(_0x428569){_0x428569[_0x36f9('0x17')]({'lastMsgAt':_0x5cc29a[_0x36f9('0x18')],'lastMsgDirection':_0x5cc29a['direction'][_0x36f9('0xe')]()});}})['catch'](function(_0x1cb856){console[_0x36f9('0x19')](_0x1cb856);});}if(_0x5cc29a[_0x36f9('0xd')]===_0x36f9('0xf')&&!_0x5cc29a['secret']){var _0x2b36b9;_0x3580ed[_0x36f9('0x1a')][_0x36f9('0x1b')]({'where':{'id':_0x5cc29a['WhatsappAccountId']},'raw':!![]})[_0x36f9('0x16')](function(_0x4d79fa){_0x2b36b9=_0x4d79fa;if(_0x2b36b9&&_0x2b36b9[_0x36f9('0x1c')]){switch(_0x2b36b9['type']){case _0x36f9('0x1d'):var _0x2021e8=require('twilio');if(_0x2b36b9[_0x36f9('0x1e')]&&_0x2b36b9[_0x36f9('0x1f')]&&_0x2b36b9[_0x36f9('0x20')]){var _0x4c3fbf=new _0x2021e8(_0x2b36b9[_0x36f9('0x1e')],_0x2b36b9['authToken']);_0x4c3fbf[_0x36f9('0x21')][_0x36f9('0x22')]({'body':_0x5cc29a[_0x36f9('0x23')],'to':_0x36f9('0x24')+_0x5cc29a[_0x36f9('0x20')],'from':_0x36f9('0x24')+_0x2b36b9[_0x36f9('0x20')],'statusCallback':_0x2b36b9[_0x36f9('0x25')]+_0x36f9('0x26')+_0x5cc29a['id']+_0x36f9('0x27')+_0x2b36b9['token']})[_0x36f9('0x16')](function(_0x2cdb7e){if(_0x2cdb7e[_0x36f9('0x28')]){return _0x466f5d[_0x36f9('0x17')]({'messageId':_0x2cdb7e[_0x36f9('0x28')]});}})['catch'](function(_0x598573){logger['error']('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x36f9('0x29'),_0x36f9('0x1d'),util['inspect'](_0x598573,{'showHidden':![],'depth':null}));});}else{logger[_0x36f9('0x19')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x36f9('0x29'),'twilio',_0x36f9('0x2a'));}break;case _0x36f9('0x2b'):var _0x8052ec=_0x2b36b9[_0x36f9('0x1e')];var _0x3c7a80=_0x2b36b9[_0x36f9('0x1f')];var _0x5bb989=_0x2b36b9[_0x36f9('0x2c')]+'/whatsapp/v1/'+_0x8052ec+_0x36f9('0x2d');var _0x134fa3={'to':[_0x5cc29a[_0x36f9('0x20')]],'message':{'type':_0x36f9('0x2e'),'text':_0x5cc29a[_0x36f9('0x23')]}};var _0x4e3b22={'method':_0x36f9('0x2f'),'uri':_0x5bb989,'headers':{'Authorization':'Bearer\x20'+_0x3c7a80,'Content-Type':_0x36f9('0x30')},'body':_0x134fa3,'json':!![]};rp(_0x4e3b22)[_0x36f9('0x16')](function(_0x53432d){if(_0x53432d[_0x36f9('0x31')][0x0][_0x36f9('0x32')]){return _0x466f5d[_0x36f9('0x17')]({'messageId':_0x53432d[_0x36f9('0x31')][0x0][_0x36f9('0x32')]});}})[_0x36f9('0x33')](function(_0x3e1990){logger[_0x36f9('0x34')](_0x36f9('0x35'),_0x3e1990);});break;}}})[_0x36f9('0x36')](function(){_0x42437a();});}else{_0x42437a();}}},'charset':_0x36f9('0x37'),'collate':_0x36f9('0x38')});};
\ No newline at end of file
+var _0x4022=['WhatsappAccountId','type','twilio','accountSid','authToken','phone','messages','whatsapp:','/api/whatsapp/messages/','token','sid','update','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','inspect','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','sinch','/messages/','text','statuses','message_id','WhatsappMessage,\x20%s','finally','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','bluebird','request-promise','node-fetch','path','../../config/environment','./whatsappMessage.attributes','exports','define','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','body','FULLTEXT','models','get','direction','toLowerCase','out','secret','UserId','WhatsappInteraction','findOne','WhatsappInteractionId','then','createdAt','catch','error','WhatsappAccount'];(function(_0x340a8d,_0xf5522d){var _0x1ed015=function(_0x5d46c7){while(--_0x5d46c7){_0x340a8d['push'](_0x340a8d['shift']());}};_0x1ed015(++_0xf5522d);}(_0x4022,0x101));var _0x2402=function(_0x50fe03,_0x106ccb){_0x50fe03=_0x50fe03-0x0;var _0x93afa8=_0x4022[_0x50fe03];return _0x93afa8;};'use strict';var _=require(_0x2402('0x0'));var util=require('util');var logger=require(_0x2402('0x1'))(_0x2402('0x2'));var moment=require(_0x2402('0x3'));var BPromise=require(_0x2402('0x4'));var rp=require(_0x2402('0x5'));var fetch=require(_0x2402('0x6'));var fs=require('fs');var path=require(_0x2402('0x7'));var rimraf=require('rimraf');var config=require(_0x2402('0x8'));var attributes=require(_0x2402('0x9'));module[_0x2402('0xa')]=function(_0x450e4f,_0x2df402){return _0x450e4f[_0x2402('0xb')](_0x2402('0xc'),attributes,{'tableName':_0x2402('0xd'),'paranoid':![],'indexes':[{'name':_0x2402('0xe'),'fields':[_0x2402('0xe')]},{'name':_0x2402('0xf'),'fields':[_0x2402('0x10')],'type':_0x2402('0x11')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x39db5a,_0x385a62,_0x9dbd9a){var _0x1bf5f1=_0x450e4f[_0x2402('0x12')];var _0x5a8156=_0x39db5a[_0x2402('0x13')]({'plain':!![]});if(_0x5a8156[_0x2402('0x14')][_0x2402('0x15')]()==='in'||_0x5a8156[_0x2402('0x14')]['toLowerCase']()===_0x2402('0x16')&&!_0x5a8156[_0x2402('0x17')]&&!_['isNil'](_0x5a8156[_0x2402('0x18')])){_0x1bf5f1[_0x2402('0x19')][_0x2402('0x1a')]({'where':{'id':_0x5a8156[_0x2402('0x1b')]}})[_0x2402('0x1c')](function(_0x312b5a){if(_0x312b5a){_0x312b5a['update']({'lastMsgAt':_0x5a8156[_0x2402('0x1d')],'lastMsgDirection':_0x5a8156[_0x2402('0x14')][_0x2402('0x15')]()});}})[_0x2402('0x1e')](function(_0x170096){console[_0x2402('0x1f')](_0x170096);});}if(_0x5a8156[_0x2402('0x14')]==='out'&&!_0x5a8156['secret']){var _0x461feb;_0x1bf5f1[_0x2402('0x20')]['find']({'where':{'id':_0x5a8156[_0x2402('0x21')]},'raw':!![]})[_0x2402('0x1c')](function(_0x5112fc){_0x461feb=_0x5112fc;if(_0x461feb&&_0x461feb[_0x2402('0x22')]){switch(_0x461feb['type']){case _0x2402('0x23'):var _0x55bca5=require(_0x2402('0x23'));if(_0x461feb[_0x2402('0x24')]&&_0x461feb[_0x2402('0x25')]&&_0x461feb[_0x2402('0x26')]){var _0x347859=new _0x55bca5(_0x461feb[_0x2402('0x24')],_0x461feb[_0x2402('0x25')]);_0x347859[_0x2402('0x27')]['create']({'body':_0x5a8156[_0x2402('0x10')],'to':_0x2402('0x28')+_0x5a8156[_0x2402('0x26')],'from':_0x2402('0x28')+_0x461feb[_0x2402('0x26')],'statusCallback':_0x461feb['remote']+_0x2402('0x29')+_0x5a8156['id']+'/status?token='+_0x461feb[_0x2402('0x2a')]})['then'](function(_0x2af203){if(_0x2af203[_0x2402('0x2b')]){return _0x39db5a[_0x2402('0x2c')]({'messageId':_0x2af203[_0x2402('0x2b')]});}})[_0x2402('0x1e')](function(_0x3ed961){logger[_0x2402('0x1f')](_0x2402('0x2d'),_0x2402('0x2e'),'twilio',util[_0x2402('0x2f')](_0x3ed961,{'showHidden':![],'depth':null}));});}else{logger[_0x2402('0x1f')](_0x2402('0x2d'),_0x2402('0x2e'),_0x2402('0x23'),_0x2402('0x30'));}break;case _0x2402('0x31'):var _0x4484b6=_0x461feb[_0x2402('0x24')];var _0x1e5859=_0x461feb['authToken'];var _0x30778b=_0x461feb['baseUrl']+'/whatsapp/v1/'+_0x4484b6+_0x2402('0x32');var _0x15cf15={'to':[_0x5a8156[_0x2402('0x26')]],'message':{'type':_0x2402('0x33'),'text':_0x5a8156['body']}};var _0x56d784={'method':'POST','uri':_0x30778b,'headers':{'Authorization':'Bearer\x20'+_0x1e5859,'Content-Type':'application/json'},'body':_0x15cf15,'json':!![]};rp(_0x56d784)[_0x2402('0x1c')](function(_0x37a82a){if(_0x37a82a[_0x2402('0x34')][0x0][_0x2402('0x35')]){return _0x39db5a[_0x2402('0x2c')]({'messageId':_0x37a82a[_0x2402('0x34')][0x0]['message_id']});}})[_0x2402('0x1e')](function(_0x1371be){logger['err'](_0x2402('0x36'),_0x1371be);});break;}}})[_0x2402('0x37')](function(){_0x9dbd9a();});}else{_0x9dbd9a();}}},'charset':_0x2402('0x38'),'collate':_0x2402('0x39')});};
\ No newline at end of file