Built motion from commit (unavailable).|2.5.26
[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 _0x3527=['body','models','direction','toLowerCase','out','secret','WhatsappInteraction','findOne','then','update','createdAt','catch','error','find','WhatsappAccountId','type','twilio','accountSid','authToken','messages','create','phone','remote','/api/whatsapp/messages/','/status?token=','token','sid','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','finally','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','api','bluebird','request-promise','path','rimraf','../../config/environment','./whatsappMessage.attributes','exports','define','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages'];(function(_0x55f500,_0xd5a849){var _0x5c12f5=function(_0x17a6e7){while(--_0x17a6e7){_0x55f500['push'](_0x55f500['shift']());}};_0x5c12f5(++_0xd5a849);}(_0x3527,0x171));var _0x7352=function(_0x23be51,_0xc02a1b){_0x23be51=_0x23be51-0x0;var _0x47a26d=_0x3527[_0x23be51];return _0x47a26d;};'use strict';var _=require(_0x7352('0x0'));var util=require('util');var logger=require(_0x7352('0x1'))(_0x7352('0x2'));var moment=require('moment');var BPromise=require(_0x7352('0x3'));var rp=require(_0x7352('0x4'));var fs=require('fs');var path=require(_0x7352('0x5'));var rimraf=require(_0x7352('0x6'));var config=require(_0x7352('0x7'));var attributes=require(_0x7352('0x8'));module[_0x7352('0x9')]=function(_0x311bd6,_0x1b95c4){return _0x311bd6[_0x7352('0xa')](_0x7352('0xb'),attributes,{'tableName':_0x7352('0xc'),'paranoid':![],'indexes':[{'name':_0x7352('0xd'),'fields':['messageId']},{'name':_0x7352('0xe'),'fields':[_0x7352('0xf')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x15fb4f,_0x28a03f,_0x17b600){var _0x5b7fa7=_0x311bd6[_0x7352('0x10')];var _0x247455=_0x15fb4f['get']({'plain':!![]});if(_0x247455[_0x7352('0x11')]['toLowerCase']()==='in'||_0x247455[_0x7352('0x11')][_0x7352('0x12')]()===_0x7352('0x13')&&!_0x247455[_0x7352('0x14')]&&!_['isNil'](_0x247455['UserId'])){_0x5b7fa7[_0x7352('0x15')][_0x7352('0x16')]({'where':{'id':_0x247455['WhatsappInteractionId']}})[_0x7352('0x17')](function(_0x31f327){if(_0x31f327){_0x31f327[_0x7352('0x18')]({'lastMsgAt':_0x247455[_0x7352('0x19')],'lastMsgDirection':_0x247455['direction'][_0x7352('0x12')]()});}})[_0x7352('0x1a')](function(_0x3f7a19){console[_0x7352('0x1b')](_0x3f7a19);});}if(_0x247455[_0x7352('0x11')]==='out'&&!_0x247455['secret']){var _0x34a4da;_0x5b7fa7['WhatsappAccount'][_0x7352('0x1c')]({'where':{'id':_0x247455[_0x7352('0x1d')]},'raw':!![]})[_0x7352('0x17')](function(_0xa680b2){_0x34a4da=_0xa680b2;if(_0x34a4da&&_0x34a4da[_0x7352('0x1e')]){switch(_0x34a4da[_0x7352('0x1e')]){case _0x7352('0x1f'):var _0x474c25=require('twilio');if(_0x34a4da[_0x7352('0x20')]&&_0x34a4da['authToken']&&_0x34a4da['phone']){var _0x107bce=new _0x474c25(_0x34a4da['accountSid'],_0x34a4da[_0x7352('0x21')]);_0x107bce[_0x7352('0x22')][_0x7352('0x23')]({'body':_0x247455[_0x7352('0xf')],'to':'whatsapp:'+_0x247455[_0x7352('0x24')],'from':'whatsapp:'+_0x34a4da[_0x7352('0x24')],'statusCallback':_0x34a4da[_0x7352('0x25')]+_0x7352('0x26')+_0x247455['id']+_0x7352('0x27')+_0x34a4da[_0x7352('0x28')]})[_0x7352('0x17')](function(_0x2df120){if(_0x2df120[_0x7352('0x29')]){return _0x15fb4f[_0x7352('0x18')]({'messageId':_0x2df120[_0x7352('0x29')]});}})[_0x7352('0x1a')](function(_0x2033b5){logger[_0x7352('0x1b')](_0x7352('0x2a'),_0x7352('0x2b'),_0x7352('0x1f'),util['inspect'](_0x2033b5,{'showHidden':![],'depth':null}));});}else{logger['error']('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x7352('0x2b'),'twilio',_0x7352('0x2c'));}break;}}})[_0x7352('0x2d')](function(){_0x17b600();});}else{_0x17b600();}}},'charset':_0x7352('0x2e'),'collate':_0x7352('0x2f')});};