Built motion from commit (unavailable).|2.5.9
[motion2.git] / server / api / whatsappMessage / whatsappMessage.model.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x510c=['rimraf','../../config/environment','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','body','FULLTEXT','models','direction','toLowerCase','secret','isNil','UserId','WhatsappInteraction','findOne','WhatsappInteractionId','createdAt','error','out','WhatsappAccount','find','type','twilio','accountSid','phone','messages','create','whatsapp:','/api/whatsapp/messages/','token','then','sid','update','catch','afterCreate','WhatsappMessage,\x20%s,\x20%s,\x20%s','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','finally','utf8mb4','lodash','util','../../config/logger','api','moment','bluebird','request-promise','path'];(function(_0x2a7ae1,_0x2fcbad){var _0x15427f=function(_0x27b9c4){while(--_0x27b9c4){_0x2a7ae1['push'](_0x2a7ae1['shift']());}};_0x15427f(++_0x2fcbad);}(_0x510c,0xe8));var _0xc510=function(_0x4ff0f2,_0x2c5e60){_0x4ff0f2=_0x4ff0f2-0x0;var _0x1ec08b=_0x510c[_0x4ff0f2];return _0x1ec08b;};'use strict';var _=require(_0xc510('0x0'));var util=require(_0xc510('0x1'));var logger=require(_0xc510('0x2'))(_0xc510('0x3'));var moment=require(_0xc510('0x4'));var BPromise=require(_0xc510('0x5'));var rp=require(_0xc510('0x6'));var fs=require('fs');var path=require(_0xc510('0x7'));var rimraf=require(_0xc510('0x8'));var config=require(_0xc510('0x9'));var attributes=require('./whatsappMessage.attributes');module['exports']=function(_0x4c7ee2,_0x43d64c){return _0x4c7ee2['define'](_0xc510('0xa'),attributes,{'tableName':_0xc510('0xb'),'paranoid':![],'indexes':[{'name':_0xc510('0xc'),'fields':[_0xc510('0xc')]},{'name':_0xc510('0xd'),'fields':[_0xc510('0xe')],'type':_0xc510('0xf')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x21f57d,_0x618bd9,_0x2ceb8b){var _0x19c161=_0x4c7ee2[_0xc510('0x10')];var _0xf85b4=_0x21f57d['get']({'plain':!![]});if(_0xf85b4[_0xc510('0x11')][_0xc510('0x12')]()==='in'||_0xf85b4[_0xc510('0x11')][_0xc510('0x12')]()==='out'&&!_0xf85b4[_0xc510('0x13')]&&!_[_0xc510('0x14')](_0xf85b4[_0xc510('0x15')])){_0x19c161[_0xc510('0x16')][_0xc510('0x17')]({'where':{'id':_0xf85b4[_0xc510('0x18')]}})['then'](function(_0x460f0e){if(_0x460f0e){_0x460f0e['update']({'lastMsgAt':_0xf85b4[_0xc510('0x19')],'lastMsgDirection':_0xf85b4['direction'][_0xc510('0x12')]()});}})['catch'](function(_0x59c66a){console[_0xc510('0x1a')](_0x59c66a);});}if(_0xf85b4['direction']===_0xc510('0x1b')&&!_0xf85b4['secret']){var _0x194d2d;_0x19c161[_0xc510('0x1c')][_0xc510('0x1d')]({'where':{'id':_0xf85b4['WhatsappAccountId']},'raw':!![]})['then'](function(_0x5e6698){_0x194d2d=_0x5e6698;if(_0x194d2d&&_0x194d2d[_0xc510('0x1e')]){switch(_0x194d2d[_0xc510('0x1e')]){case _0xc510('0x1f'):var _0xf8677b=require('twilio');if(_0x194d2d[_0xc510('0x20')]&&_0x194d2d['authToken']&&_0x194d2d[_0xc510('0x21')]){var _0x24d78e=new _0xf8677b(_0x194d2d[_0xc510('0x20')],_0x194d2d['authToken']);_0x24d78e[_0xc510('0x22')][_0xc510('0x23')]({'body':_0xf85b4[_0xc510('0xe')],'to':_0xc510('0x24')+_0xf85b4[_0xc510('0x21')],'from':_0xc510('0x24')+_0x194d2d['phone'],'statusCallback':_0x194d2d['remote']+_0xc510('0x25')+_0xf85b4['id']+'/status?token='+_0x194d2d[_0xc510('0x26')]})[_0xc510('0x27')](function(_0x2fdf81){if(_0x2fdf81[_0xc510('0x28')]){return _0x21f57d[_0xc510('0x29')]({'messageId':_0x2fdf81[_0xc510('0x28')]});}})[_0xc510('0x2a')](function(_0x51f932){logger[_0xc510('0x1a')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0xc510('0x2b'),_0xc510('0x1f'),util['inspect'](_0x51f932,{'showHidden':![],'depth':null}));});}else{logger[_0xc510('0x1a')](_0xc510('0x2c'),'afterCreate','twilio',_0xc510('0x2d'));}break;}}})[_0xc510('0x2e')](function(){_0x2ceb8b();});}else{_0x2ceb8b();}}},'charset':_0xc510('0x2f'),'collate':'utf8mb4_unicode_ci'});};