d948a37587fe377037a83b5cbde9bf7cf9dde5ee
[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 _0x3d8e=['inspect','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','finally','utf8mb4','lodash','util','../../config/logger','bluebird','request-promise','path','rimraf','./whatsappMessage.attributes','exports','define','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','body','FULLTEXT','models','get','direction','toLowerCase','out','secret','isNil','UserId','WhatsappInteraction','findOne','WhatsappInteractionId','then','update','catch','error','WhatsappAccount','find','type','twilio','authToken','phone','accountSid','messages','create','whatsapp:','/api/whatsapp/messages/','/status?token=','token','sid','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate'];(function(_0x457aef,_0x143e7f){var _0x41f664=function(_0x4862f8){while(--_0x4862f8){_0x457aef['push'](_0x457aef['shift']());}};_0x41f664(++_0x143e7f);}(_0x3d8e,0x169));var _0xe3d8=function(_0x10ff4c,_0x35c7e2){_0x10ff4c=_0x10ff4c-0x0;var _0x28bac8=_0x3d8e[_0x10ff4c];return _0x28bac8;};'use strict';var _=require(_0xe3d8('0x0'));var util=require(_0xe3d8('0x1'));var logger=require(_0xe3d8('0x2'))('api');var moment=require('moment');var BPromise=require(_0xe3d8('0x3'));var rp=require(_0xe3d8('0x4'));var fs=require('fs');var path=require(_0xe3d8('0x5'));var rimraf=require(_0xe3d8('0x6'));var config=require('../../config/environment');var attributes=require(_0xe3d8('0x7'));module[_0xe3d8('0x8')]=function(_0xdb5ba8,_0x4cb106){return _0xdb5ba8[_0xe3d8('0x9')](_0xe3d8('0xa'),attributes,{'tableName':_0xe3d8('0xb'),'paranoid':![],'indexes':[{'name':_0xe3d8('0xc'),'fields':[_0xe3d8('0xc')]},{'name':_0xe3d8('0xd'),'fields':[_0xe3d8('0xe')],'type':_0xe3d8('0xf')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x45c645,_0x3ea335,_0xcccc3e){var _0x2b0f4b=_0xdb5ba8[_0xe3d8('0x10')];var _0x4dcf7e=_0x45c645[_0xe3d8('0x11')]({'plain':!![]});if(_0x4dcf7e[_0xe3d8('0x12')][_0xe3d8('0x13')]()==='in'||_0x4dcf7e['direction'][_0xe3d8('0x13')]()===_0xe3d8('0x14')&&!_0x4dcf7e[_0xe3d8('0x15')]&&!_[_0xe3d8('0x16')](_0x4dcf7e[_0xe3d8('0x17')])){_0x2b0f4b[_0xe3d8('0x18')][_0xe3d8('0x19')]({'where':{'id':_0x4dcf7e[_0xe3d8('0x1a')]}})[_0xe3d8('0x1b')](function(_0x7834c1){if(_0x7834c1){_0x7834c1[_0xe3d8('0x1c')]({'lastMsgAt':_0x4dcf7e['createdAt'],'lastMsgDirection':_0x4dcf7e[_0xe3d8('0x12')][_0xe3d8('0x13')]()});}})[_0xe3d8('0x1d')](function(_0x1a96cf){console[_0xe3d8('0x1e')](_0x1a96cf);});}if(_0x4dcf7e[_0xe3d8('0x12')]===_0xe3d8('0x14')&&!_0x4dcf7e['secret']){var _0x583178;_0x2b0f4b[_0xe3d8('0x1f')][_0xe3d8('0x20')]({'where':{'id':_0x4dcf7e['WhatsappAccountId']},'raw':!![]})[_0xe3d8('0x1b')](function(_0x36e5d7){_0x583178=_0x36e5d7;if(_0x583178&&_0x583178['type']){switch(_0x583178[_0xe3d8('0x21')]){case _0xe3d8('0x22'):var _0x5c5473=require('twilio');if(_0x583178['accountSid']&&_0x583178[_0xe3d8('0x23')]&&_0x583178[_0xe3d8('0x24')]){var _0x568c3b=new _0x5c5473(_0x583178[_0xe3d8('0x25')],_0x583178['authToken']);_0x568c3b[_0xe3d8('0x26')][_0xe3d8('0x27')]({'body':_0x4dcf7e[_0xe3d8('0xe')],'to':_0xe3d8('0x28')+_0x4dcf7e[_0xe3d8('0x24')],'from':_0xe3d8('0x28')+_0x583178[_0xe3d8('0x24')],'statusCallback':_0x583178['remote']+_0xe3d8('0x29')+_0x4dcf7e['id']+_0xe3d8('0x2a')+_0x583178[_0xe3d8('0x2b')]})['then'](function(_0x2659f9){if(_0x2659f9[_0xe3d8('0x2c')]){return _0x45c645[_0xe3d8('0x1c')]({'messageId':_0x2659f9[_0xe3d8('0x2c')]});}})[_0xe3d8('0x1d')](function(_0x2c5d75){logger[_0xe3d8('0x1e')](_0xe3d8('0x2d'),_0xe3d8('0x2e'),'twilio',util[_0xe3d8('0x2f')](_0x2c5d75,{'showHidden':![],'depth':null}));});}else{logger[_0xe3d8('0x1e')](_0xe3d8('0x2d'),_0xe3d8('0x2e'),_0xe3d8('0x22'),_0xe3d8('0x30'));}break;}}})[_0xe3d8('0x31')](function(){_0xcccc3e();});}else{_0xcccc3e();}}},'charset':_0xe3d8('0x32'),'collate':'utf8mb4_unicode_ci'});};