2cf023233cb23419009dcc726339e3522a67d878
[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 _0xf1c4=['WhatsappAccountId','type','twilio','accountSid','phone','authToken','create','whatsapp:','remote','/api/whatsapp/messages/','token','sid','catch','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','inspect','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','utf8mb4_unicode_ci','../../config/logger','api','moment','request-promise','rimraf','../../config/environment','./whatsappMessage.attributes','exports','define','WhatsappMessage','whatsapp_messages','fti_whatsapp_messages','body','FULLTEXT','models','get','toLowerCase','out','UserId','WhatsappInteraction','findOne','WhatsappInteractionId','then','update','createdAt','error','direction','secret','find'];(function(_0x11f5ff,_0xa0ef18){var _0x46eefb=function(_0x51872a){while(--_0x51872a){_0x11f5ff['push'](_0x11f5ff['shift']());}};_0x46eefb(++_0xa0ef18);}(_0xf1c4,0x15b));var _0x4f1c=function(_0x21d3d5,_0x2ef038){_0x21d3d5=_0x21d3d5-0x0;var _0x2bf601=_0xf1c4[_0x21d3d5];return _0x2bf601;};'use strict';var _=require('lodash');var util=require('util');var logger=require(_0x4f1c('0x0'))(_0x4f1c('0x1'));var moment=require(_0x4f1c('0x2'));var BPromise=require('bluebird');var rp=require(_0x4f1c('0x3'));var fs=require('fs');var path=require('path');var rimraf=require(_0x4f1c('0x4'));var config=require(_0x4f1c('0x5'));var attributes=require(_0x4f1c('0x6'));module[_0x4f1c('0x7')]=function(_0x5582a1,_0x51582e){return _0x5582a1[_0x4f1c('0x8')](_0x4f1c('0x9'),attributes,{'tableName':_0x4f1c('0xa'),'paranoid':![],'indexes':[{'name':'messageId','fields':['messageId']},{'name':_0x4f1c('0xb'),'fields':[_0x4f1c('0xc')],'type':_0x4f1c('0xd')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x3ee899,_0x1d0906,_0xeb71df){var _0x423a67=_0x5582a1[_0x4f1c('0xe')];var _0xce2314=_0x3ee899[_0x4f1c('0xf')]({'plain':!![]});if(_0xce2314['direction'][_0x4f1c('0x10')]()==='in'||_0xce2314['direction'][_0x4f1c('0x10')]()===_0x4f1c('0x11')&&!_0xce2314['secret']&&!_['isNil'](_0xce2314[_0x4f1c('0x12')])){_0x423a67[_0x4f1c('0x13')][_0x4f1c('0x14')]({'where':{'id':_0xce2314[_0x4f1c('0x15')]}})[_0x4f1c('0x16')](function(_0xdf7ab6){if(_0xdf7ab6){_0xdf7ab6[_0x4f1c('0x17')]({'lastMsgAt':_0xce2314[_0x4f1c('0x18')],'lastMsgDirection':_0xce2314['direction']['toLowerCase']()});}})['catch'](function(_0x4e5ede){console[_0x4f1c('0x19')](_0x4e5ede);});}if(_0xce2314[_0x4f1c('0x1a')]===_0x4f1c('0x11')&&!_0xce2314[_0x4f1c('0x1b')]){var _0xb7287a;_0x423a67['WhatsappAccount'][_0x4f1c('0x1c')]({'where':{'id':_0xce2314[_0x4f1c('0x1d')]},'raw':!![]})[_0x4f1c('0x16')](function(_0x1bf722){_0xb7287a=_0x1bf722;if(_0xb7287a&&_0xb7287a[_0x4f1c('0x1e')]){switch(_0xb7287a[_0x4f1c('0x1e')]){case _0x4f1c('0x1f'):var _0x191ee0=require(_0x4f1c('0x1f'));if(_0xb7287a[_0x4f1c('0x20')]&&_0xb7287a['authToken']&&_0xb7287a[_0x4f1c('0x21')]){var _0x58b714=new _0x191ee0(_0xb7287a[_0x4f1c('0x20')],_0xb7287a[_0x4f1c('0x22')]);_0x58b714['messages'][_0x4f1c('0x23')]({'body':_0xce2314[_0x4f1c('0xc')],'to':'whatsapp:'+_0xce2314['phone'],'from':_0x4f1c('0x24')+_0xb7287a[_0x4f1c('0x21')],'statusCallback':_0xb7287a[_0x4f1c('0x25')]+_0x4f1c('0x26')+_0xce2314['id']+'/status?token='+_0xb7287a[_0x4f1c('0x27')]})[_0x4f1c('0x16')](function(_0x17c4a3){if(_0x17c4a3[_0x4f1c('0x28')]){return _0x3ee899[_0x4f1c('0x17')]({'messageId':_0x17c4a3[_0x4f1c('0x28')]});}})[_0x4f1c('0x29')](function(_0x3165b7){logger[_0x4f1c('0x19')](_0x4f1c('0x2a'),_0x4f1c('0x2b'),_0x4f1c('0x1f'),util[_0x4f1c('0x2c')](_0x3165b7,{'showHidden':![],'depth':null}));});}else{logger[_0x4f1c('0x19')]('WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','twilio',_0x4f1c('0x2d'));}break;}}})['finally'](function(){_0xeb71df();});}else{_0xeb71df();}}},'charset':'utf8mb4','collate':_0x4f1c('0x2e')});};