Built motion from commit (unavailable).|2.5.10
[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 _0xcaed=['WhatsappInteraction','findOne','WhatsappInteractionId','update','catch','secret','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid','authToken','phone','create','body','whatsapp:','remote','/api/whatsapp/messages/','/status?token=','token','then','sid','error','inspect','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','finally','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','request-promise','path','rimraf','../../config/environment','./whatsappMessage.attributes','exports','define','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','FULLTEXT','models','get','direction','toLowerCase','out','UserId'];(function(_0x2e9187,_0x3763f6){var _0x1fc3a8=function(_0xb30d96){while(--_0xb30d96){_0x2e9187['push'](_0x2e9187['shift']());}};_0x1fc3a8(++_0x3763f6);}(_0xcaed,0xed));var _0xdcae=function(_0x5bd370,_0x514e98){_0x5bd370=_0x5bd370-0x0;var _0x41ca12=_0xcaed[_0x5bd370];return _0x41ca12;};'use strict';var _=require(_0xdcae('0x0'));var util=require(_0xdcae('0x1'));var logger=require(_0xdcae('0x2'))(_0xdcae('0x3'));var moment=require(_0xdcae('0x4'));var BPromise=require('bluebird');var rp=require(_0xdcae('0x5'));var fs=require('fs');var path=require(_0xdcae('0x6'));var rimraf=require(_0xdcae('0x7'));var config=require(_0xdcae('0x8'));var attributes=require(_0xdcae('0x9'));module[_0xdcae('0xa')]=function(_0x3dc597,_0x2a1233){return _0x3dc597[_0xdcae('0xb')](_0xdcae('0xc'),attributes,{'tableName':_0xdcae('0xd'),'paranoid':![],'indexes':[{'name':_0xdcae('0xe'),'fields':[_0xdcae('0xe')]},{'name':_0xdcae('0xf'),'fields':['body'],'type':_0xdcae('0x10')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x480839,_0x3910bc,_0x236f90){var _0xa4a1a2=_0x3dc597[_0xdcae('0x11')];var _0x33232f=_0x480839[_0xdcae('0x12')]({'plain':!![]});if(_0x33232f[_0xdcae('0x13')][_0xdcae('0x14')]()==='in'||_0x33232f[_0xdcae('0x13')]['toLowerCase']()===_0xdcae('0x15')&&!_0x33232f['secret']&&!_['isNil'](_0x33232f[_0xdcae('0x16')])){_0xa4a1a2[_0xdcae('0x17')][_0xdcae('0x18')]({'where':{'id':_0x33232f[_0xdcae('0x19')]}})['then'](function(_0x2397b8){if(_0x2397b8){_0x2397b8[_0xdcae('0x1a')]({'lastMsgAt':_0x33232f['createdAt'],'lastMsgDirection':_0x33232f[_0xdcae('0x13')][_0xdcae('0x14')]()});}})[_0xdcae('0x1b')](function(_0x5340a0){console['error'](_0x5340a0);});}if(_0x33232f[_0xdcae('0x13')]==='out'&&!_0x33232f[_0xdcae('0x1c')]){var _0x805aa6;_0xa4a1a2[_0xdcae('0x1d')][_0xdcae('0x1e')]({'where':{'id':_0x33232f[_0xdcae('0x1f')]},'raw':!![]})['then'](function(_0x4f5770){_0x805aa6=_0x4f5770;if(_0x805aa6&&_0x805aa6[_0xdcae('0x20')]){switch(_0x805aa6['type']){case'twilio':var _0x4eeac3=require(_0xdcae('0x21'));if(_0x805aa6[_0xdcae('0x22')]&&_0x805aa6[_0xdcae('0x23')]&&_0x805aa6[_0xdcae('0x24')]){var _0x360978=new _0x4eeac3(_0x805aa6[_0xdcae('0x22')],_0x805aa6[_0xdcae('0x23')]);_0x360978['messages'][_0xdcae('0x25')]({'body':_0x33232f[_0xdcae('0x26')],'to':_0xdcae('0x27')+_0x33232f[_0xdcae('0x24')],'from':_0xdcae('0x27')+_0x805aa6[_0xdcae('0x24')],'statusCallback':_0x805aa6[_0xdcae('0x28')]+_0xdcae('0x29')+_0x33232f['id']+_0xdcae('0x2a')+_0x805aa6[_0xdcae('0x2b')]})[_0xdcae('0x2c')](function(_0x4b9942){if(_0x4b9942[_0xdcae('0x2d')]){return _0x480839[_0xdcae('0x1a')]({'messageId':_0x4b9942[_0xdcae('0x2d')]});}})[_0xdcae('0x1b')](function(_0x5f2b91){logger[_0xdcae('0x2e')]('WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate',_0xdcae('0x21'),util[_0xdcae('0x2f')](_0x5f2b91,{'showHidden':![],'depth':null}));});}else{logger[_0xdcae('0x2e')](_0xdcae('0x30'),_0xdcae('0x31'),_0xdcae('0x21'),'Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken');}break;}}})[_0xdcae('0x32')](function(){_0x236f90();});}else{_0x236f90();}}},'charset':'utf8mb4','collate':_0xdcae('0x33')});};