f38c67893a555a1d343fcffe2a2a0ec015586bea
[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 _0x92e9=['authToken','phone','create','whatsapp:','remote','/api/whatsapp/messages/','update','sid','catch','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','bluebird','request-promise','path','rimraf','../../config/environment','./whatsappMessage.attributes','exports','define','WhatsappMessage','messageId','body','FULLTEXT','models','get','toLowerCase','out','secret','isNil','UserId','WhatsappInteraction','then','createdAt','direction','error','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid'];(function(_0x562849,_0x4986dc){var _0x27177b=function(_0x4bce81){while(--_0x4bce81){_0x562849['push'](_0x562849['shift']());}};_0x27177b(++_0x4986dc);}(_0x92e9,0x104));var _0x992e=function(_0x306799,_0x4db284){_0x306799=_0x306799-0x0;var _0x3f2687=_0x92e9[_0x306799];return _0x3f2687;};'use strict';var _=require(_0x992e('0x0'));var util=require(_0x992e('0x1'));var logger=require(_0x992e('0x2'))(_0x992e('0x3'));var moment=require('moment');var BPromise=require(_0x992e('0x4'));var rp=require(_0x992e('0x5'));var fs=require('fs');var path=require(_0x992e('0x6'));var rimraf=require(_0x992e('0x7'));var config=require(_0x992e('0x8'));var attributes=require(_0x992e('0x9'));module[_0x992e('0xa')]=function(_0x284b85,_0x57f1a7){return _0x284b85[_0x992e('0xb')](_0x992e('0xc'),attributes,{'tableName':'whatsapp_messages','paranoid':![],'indexes':[{'name':_0x992e('0xd'),'fields':[_0x992e('0xd')]},{'name':'fti_whatsapp_messages','fields':[_0x992e('0xe')],'type':_0x992e('0xf')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x397175,_0x550764,_0x2afec8){var _0x4669b4=_0x284b85[_0x992e('0x10')];var _0x21d3c5=_0x397175[_0x992e('0x11')]({'plain':!![]});if(_0x21d3c5['direction'][_0x992e('0x12')]()==='in'||_0x21d3c5['direction'][_0x992e('0x12')]()===_0x992e('0x13')&&!_0x21d3c5[_0x992e('0x14')]&&!_[_0x992e('0x15')](_0x21d3c5[_0x992e('0x16')])){_0x4669b4[_0x992e('0x17')]['findOne']({'where':{'id':_0x21d3c5['WhatsappInteractionId']}})[_0x992e('0x18')](function(_0x1e17af){if(_0x1e17af){_0x1e17af['update']({'lastMsgAt':_0x21d3c5[_0x992e('0x19')],'lastMsgDirection':_0x21d3c5[_0x992e('0x1a')][_0x992e('0x12')]()});}})['catch'](function(_0x3ead55){console[_0x992e('0x1b')](_0x3ead55);});}if(_0x21d3c5['direction']===_0x992e('0x13')&&!_0x21d3c5['secret']){var _0x4ce0e4;_0x4669b4[_0x992e('0x1c')][_0x992e('0x1d')]({'where':{'id':_0x21d3c5[_0x992e('0x1e')]},'raw':!![]})[_0x992e('0x18')](function(_0x35ef71){_0x4ce0e4=_0x35ef71;if(_0x4ce0e4&&_0x4ce0e4['type']){switch(_0x4ce0e4[_0x992e('0x1f')]){case _0x992e('0x20'):var _0x39450d=require(_0x992e('0x20'));if(_0x4ce0e4[_0x992e('0x21')]&&_0x4ce0e4[_0x992e('0x22')]&&_0x4ce0e4[_0x992e('0x23')]){var _0x3146d5=new _0x39450d(_0x4ce0e4[_0x992e('0x21')],_0x4ce0e4[_0x992e('0x22')]);_0x3146d5['messages'][_0x992e('0x24')]({'body':_0x21d3c5[_0x992e('0xe')],'to':_0x992e('0x25')+_0x21d3c5[_0x992e('0x23')],'from':_0x992e('0x25')+_0x4ce0e4[_0x992e('0x23')],'statusCallback':_0x4ce0e4[_0x992e('0x26')]+_0x992e('0x27')+_0x21d3c5['id']+'/status?token='+_0x4ce0e4['token']})[_0x992e('0x18')](function(_0x336996){if(_0x336996['sid']){return _0x397175[_0x992e('0x28')]({'messageId':_0x336996[_0x992e('0x29')]});}})[_0x992e('0x2a')](function(_0x5ae7cd){logger[_0x992e('0x1b')](_0x992e('0x2b'),_0x992e('0x2c'),_0x992e('0x20'),util['inspect'](_0x5ae7cd,{'showHidden':![],'depth':null}));});}else{logger[_0x992e('0x1b')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x992e('0x2c'),_0x992e('0x20'),_0x992e('0x2d'));}break;}}})[_0x992e('0x2e')](function(){_0x2afec8();});}else{_0x2afec8();}}},'charset':_0x992e('0x2f'),'collate':_0x992e('0x30')});};