Built motion from commit (unavailable).|2.5.6
[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 _0xed52=['messages','create','remote','/api/whatsapp/messages/','/status?token=','sid','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','utf8mb4_unicode_ci','util','../../config/logger','api','moment','bluebird','path','rimraf','../../config/environment','./whatsappMessage.attributes','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','body','FULLTEXT','models','direction','toLowerCase','out','secret','isNil','UserId','WhatsappInteraction','WhatsappInteractionId','then','update','catch','error','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid','authToken','phone'];(function(_0x6c993a,_0x5ea3ab){var _0x27f547=function(_0x22df20){while(--_0x22df20){_0x6c993a['push'](_0x6c993a['shift']());}};_0x27f547(++_0x5ea3ab);}(_0xed52,0x171));var _0x2ed5=function(_0xbe200f,_0x4b50eb){_0xbe200f=_0xbe200f-0x0;var _0x192597=_0xed52[_0xbe200f];return _0x192597;};'use strict';var _=require('lodash');var util=require(_0x2ed5('0x0'));var logger=require(_0x2ed5('0x1'))(_0x2ed5('0x2'));var moment=require(_0x2ed5('0x3'));var BPromise=require(_0x2ed5('0x4'));var rp=require('request-promise');var fs=require('fs');var path=require(_0x2ed5('0x5'));var rimraf=require(_0x2ed5('0x6'));var config=require(_0x2ed5('0x7'));var attributes=require(_0x2ed5('0x8'));module['exports']=function(_0x460a34,_0x26f10d){return _0x460a34['define'](_0x2ed5('0x9'),attributes,{'tableName':_0x2ed5('0xa'),'paranoid':![],'indexes':[{'name':_0x2ed5('0xb'),'fields':['messageId']},{'name':_0x2ed5('0xc'),'fields':[_0x2ed5('0xd')],'type':_0x2ed5('0xe')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x23f2a6,_0x42a829,_0x1a25fc){var _0x27f73e=_0x460a34[_0x2ed5('0xf')];var _0x4e9365=_0x23f2a6['get']({'plain':!![]});if(_0x4e9365[_0x2ed5('0x10')][_0x2ed5('0x11')]()==='in'||_0x4e9365[_0x2ed5('0x10')][_0x2ed5('0x11')]()===_0x2ed5('0x12')&&!_0x4e9365[_0x2ed5('0x13')]&&!_[_0x2ed5('0x14')](_0x4e9365[_0x2ed5('0x15')])){_0x27f73e[_0x2ed5('0x16')]['findOne']({'where':{'id':_0x4e9365[_0x2ed5('0x17')]}})[_0x2ed5('0x18')](function(_0x14f6e1){if(_0x14f6e1){_0x14f6e1[_0x2ed5('0x19')]({'lastMsgAt':_0x4e9365['createdAt'],'lastMsgDirection':_0x4e9365['direction']['toLowerCase']()});}})[_0x2ed5('0x1a')](function(_0x30558e){console[_0x2ed5('0x1b')](_0x30558e);});}if(_0x4e9365[_0x2ed5('0x10')]==='out'&&!_0x4e9365[_0x2ed5('0x13')]){var _0x2497d7;_0x27f73e[_0x2ed5('0x1c')][_0x2ed5('0x1d')]({'where':{'id':_0x4e9365[_0x2ed5('0x1e')]},'raw':!![]})['then'](function(_0x5eb421){_0x2497d7=_0x5eb421;if(_0x2497d7&&_0x2497d7[_0x2ed5('0x1f')]){switch(_0x2497d7[_0x2ed5('0x1f')]){case _0x2ed5('0x20'):var _0x252bb6=require(_0x2ed5('0x20'));if(_0x2497d7[_0x2ed5('0x21')]&&_0x2497d7[_0x2ed5('0x22')]&&_0x2497d7[_0x2ed5('0x23')]){var _0x35a555=new _0x252bb6(_0x2497d7[_0x2ed5('0x21')],_0x2497d7[_0x2ed5('0x22')]);_0x35a555[_0x2ed5('0x24')][_0x2ed5('0x25')]({'body':_0x4e9365[_0x2ed5('0xd')],'to':'whatsapp:'+_0x4e9365[_0x2ed5('0x23')],'from':'whatsapp:'+_0x2497d7['phone'],'statusCallback':_0x2497d7[_0x2ed5('0x26')]+_0x2ed5('0x27')+_0x4e9365['id']+_0x2ed5('0x28')+_0x2497d7['token']})[_0x2ed5('0x18')](function(_0x639b5a){if(_0x639b5a['sid']){return _0x23f2a6[_0x2ed5('0x19')]({'messageId':_0x639b5a[_0x2ed5('0x29')]});}})[_0x2ed5('0x1a')](function(_0x56362a){logger[_0x2ed5('0x1b')](_0x2ed5('0x2a'),_0x2ed5('0x2b'),'twilio',util['inspect'](_0x56362a,{'showHidden':![],'depth':null}));});}else{logger[_0x2ed5('0x1b')](_0x2ed5('0x2a'),_0x2ed5('0x2b'),_0x2ed5('0x20'),'Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken');}break;}}})['finally'](function(){_0x1a25fc();});}else{_0x1a25fc();}}},'charset':'utf8mb4','collate':_0x2ed5('0x2c')});};