Built motion from commit (unavailable).|2.5.4
[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 _0x014f=['WhatsappAccountId','type','twilio','accountSid','authToken','phone','messages','create','body','whatsapp:','remote','/api/whatsapp/messages/','/status?token=','token','sid','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','inspect','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','finally','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','bluebird','request-promise','path','../../config/environment','./whatsappMessage.attributes','exports','define','WhatsappMessage','messageId','FULLTEXT','models','get','direction','toLowerCase','out','isNil','WhatsappInteraction','then','update','createdAt','catch','error','secret','WhatsappAccount','find'];(function(_0xbbf4,_0x3035c5){var _0x54fd3a=function(_0x3e0bcc){while(--_0x3e0bcc){_0xbbf4['push'](_0xbbf4['shift']());}};_0x54fd3a(++_0x3035c5);}(_0x014f,0xab));var _0xf014=function(_0x2b4348,_0x58c328){_0x2b4348=_0x2b4348-0x0;var _0x2f7ab3=_0x014f[_0x2b4348];return _0x2f7ab3;};'use strict';var _=require(_0xf014('0x0'));var util=require(_0xf014('0x1'));var logger=require(_0xf014('0x2'))(_0xf014('0x3'));var moment=require('moment');var BPromise=require(_0xf014('0x4'));var rp=require(_0xf014('0x5'));var fs=require('fs');var path=require(_0xf014('0x6'));var rimraf=require('rimraf');var config=require(_0xf014('0x7'));var attributes=require(_0xf014('0x8'));module[_0xf014('0x9')]=function(_0x30f0bf,_0xd8ed37){return _0x30f0bf[_0xf014('0xa')](_0xf014('0xb'),attributes,{'tableName':'whatsapp_messages','paranoid':![],'indexes':[{'name':_0xf014('0xc'),'fields':['messageId']},{'name':'fti_whatsapp_messages','fields':['body'],'type':_0xf014('0xd')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x5341ab,_0x282d89,_0x5e4fd4){var _0x11b9be=_0x30f0bf[_0xf014('0xe')];var _0x399d2e=_0x5341ab[_0xf014('0xf')]({'plain':!![]});if(_0x399d2e['direction']['toLowerCase']()==='in'||_0x399d2e[_0xf014('0x10')][_0xf014('0x11')]()===_0xf014('0x12')&&!_0x399d2e['secret']&&!_[_0xf014('0x13')](_0x399d2e['UserId'])){_0x11b9be[_0xf014('0x14')]['findOne']({'where':{'id':_0x399d2e['WhatsappInteractionId']}})[_0xf014('0x15')](function(_0x26c4ea){if(_0x26c4ea){_0x26c4ea[_0xf014('0x16')]({'lastMsgAt':_0x399d2e[_0xf014('0x17')],'lastMsgDirection':_0x399d2e['direction'][_0xf014('0x11')]()});}})[_0xf014('0x18')](function(_0x2abf8a){console[_0xf014('0x19')](_0x2abf8a);});}if(_0x399d2e[_0xf014('0x10')]===_0xf014('0x12')&&!_0x399d2e[_0xf014('0x1a')]){var _0x383b80;_0x11b9be[_0xf014('0x1b')][_0xf014('0x1c')]({'where':{'id':_0x399d2e[_0xf014('0x1d')]},'raw':!![]})['then'](function(_0x127e91){_0x383b80=_0x127e91;if(_0x383b80&&_0x383b80[_0xf014('0x1e')]){switch(_0x383b80['type']){case _0xf014('0x1f'):var _0x1a9ac3=require(_0xf014('0x1f'));if(_0x383b80[_0xf014('0x20')]&&_0x383b80[_0xf014('0x21')]&&_0x383b80[_0xf014('0x22')]){var _0x1e6067=new _0x1a9ac3(_0x383b80['accountSid'],_0x383b80['authToken']);_0x1e6067[_0xf014('0x23')][_0xf014('0x24')]({'body':_0x399d2e[_0xf014('0x25')],'to':_0xf014('0x26')+_0x399d2e[_0xf014('0x22')],'from':'whatsapp:'+_0x383b80[_0xf014('0x22')],'statusCallback':_0x383b80[_0xf014('0x27')]+_0xf014('0x28')+_0x399d2e['id']+_0xf014('0x29')+_0x383b80[_0xf014('0x2a')]})['then'](function(_0x50450c){if(_0x50450c[_0xf014('0x2b')]){return _0x5341ab[_0xf014('0x16')]({'messageId':_0x50450c[_0xf014('0x2b')]});}})['catch'](function(_0x55e5f0){logger[_0xf014('0x19')](_0xf014('0x2c'),_0xf014('0x2d'),'twilio',util[_0xf014('0x2e')](_0x55e5f0,{'showHidden':![],'depth':null}));});}else{logger['error']('WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','twilio',_0xf014('0x2f'));}break;}}})[_0xf014('0x30')](function(){_0x5e4fd4();});}else{_0x5e4fd4();}}},'charset':'utf8mb4','collate':_0xf014('0x31')});};