692c64a063c718066994e5ca049c00b33b7c6dcb
[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 _0xed90=['twilio','accountSid','phone','authToken','messages','create','body','whatsapp:','remote','/api/whatsapp/messages/','token','sid','update','WhatsappMessage,\x20%s,\x20%s,\x20%s','inspect','afterCreate','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','finally','utf8mb4','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','bluebird','path','./whatsappMessage.attributes','exports','define','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','FULLTEXT','models','get','direction','toLowerCase','out','isNil','WhatsappInteraction','findOne','WhatsappInteractionId','then','createdAt','catch','error','secret','type'];(function(_0x5c8adc,_0x1b05c6){var _0x3ab545=function(_0x34fe79){while(--_0x34fe79){_0x5c8adc['push'](_0x5c8adc['shift']());}};_0x3ab545(++_0x1b05c6);}(_0xed90,0x16b));var _0x0ed9=function(_0x329726,_0x5e0f61){_0x329726=_0x329726-0x0;var _0x1f8d62=_0xed90[_0x329726];return _0x1f8d62;};'use strict';var _=require(_0x0ed9('0x0'));var util=require('util');var logger=require(_0x0ed9('0x1'))(_0x0ed9('0x2'));var moment=require(_0x0ed9('0x3'));var BPromise=require(_0x0ed9('0x4'));var rp=require('request-promise');var fs=require('fs');var path=require(_0x0ed9('0x5'));var rimraf=require('rimraf');var config=require('../../config/environment');var attributes=require(_0x0ed9('0x6'));module[_0x0ed9('0x7')]=function(_0x488a40,_0x32957e){return _0x488a40[_0x0ed9('0x8')](_0x0ed9('0x9'),attributes,{'tableName':_0x0ed9('0xa'),'paranoid':![],'indexes':[{'name':_0x0ed9('0xb'),'fields':[_0x0ed9('0xb')]},{'name':_0x0ed9('0xc'),'fields':['body'],'type':_0x0ed9('0xd')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x445c47,_0x3c277f,_0x1abe49){var _0x46916d=_0x488a40[_0x0ed9('0xe')];var _0x8e15d0=_0x445c47[_0x0ed9('0xf')]({'plain':!![]});if(_0x8e15d0[_0x0ed9('0x10')][_0x0ed9('0x11')]()==='in'||_0x8e15d0['direction'][_0x0ed9('0x11')]()===_0x0ed9('0x12')&&!_0x8e15d0['secret']&&!_[_0x0ed9('0x13')](_0x8e15d0['UserId'])){_0x46916d[_0x0ed9('0x14')][_0x0ed9('0x15')]({'where':{'id':_0x8e15d0[_0x0ed9('0x16')]}})[_0x0ed9('0x17')](function(_0x268761){if(_0x268761){_0x268761['update']({'lastMsgAt':_0x8e15d0[_0x0ed9('0x18')],'lastMsgDirection':_0x8e15d0['direction']['toLowerCase']()});}})[_0x0ed9('0x19')](function(_0x49b126){console[_0x0ed9('0x1a')](_0x49b126);});}if(_0x8e15d0[_0x0ed9('0x10')]===_0x0ed9('0x12')&&!_0x8e15d0[_0x0ed9('0x1b')]){var _0x4ce71f;_0x46916d['WhatsappAccount']['find']({'where':{'id':_0x8e15d0['WhatsappAccountId']},'raw':!![]})['then'](function(_0x527414){_0x4ce71f=_0x527414;if(_0x4ce71f&&_0x4ce71f[_0x0ed9('0x1c')]){switch(_0x4ce71f[_0x0ed9('0x1c')]){case _0x0ed9('0x1d'):var _0x54afa9=require(_0x0ed9('0x1d'));if(_0x4ce71f[_0x0ed9('0x1e')]&&_0x4ce71f['authToken']&&_0x4ce71f[_0x0ed9('0x1f')]){var _0x35ba39=new _0x54afa9(_0x4ce71f[_0x0ed9('0x1e')],_0x4ce71f[_0x0ed9('0x20')]);_0x35ba39[_0x0ed9('0x21')][_0x0ed9('0x22')]({'body':_0x8e15d0[_0x0ed9('0x23')],'to':_0x0ed9('0x24')+_0x8e15d0[_0x0ed9('0x1f')],'from':_0x0ed9('0x24')+_0x4ce71f[_0x0ed9('0x1f')],'statusCallback':_0x4ce71f[_0x0ed9('0x25')]+_0x0ed9('0x26')+_0x8e15d0['id']+'/status?token='+_0x4ce71f[_0x0ed9('0x27')]})[_0x0ed9('0x17')](function(_0x523985){if(_0x523985[_0x0ed9('0x28')]){return _0x445c47[_0x0ed9('0x29')]({'messageId':_0x523985[_0x0ed9('0x28')]});}})[_0x0ed9('0x19')](function(_0x24389c){logger[_0x0ed9('0x1a')](_0x0ed9('0x2a'),'afterCreate',_0x0ed9('0x1d'),util[_0x0ed9('0x2b')](_0x24389c,{'showHidden':![],'depth':null}));});}else{logger[_0x0ed9('0x1a')](_0x0ed9('0x2a'),_0x0ed9('0x2c'),_0x0ed9('0x1d'),_0x0ed9('0x2d'));}break;}}})[_0x0ed9('0x2e')](function(){_0x1abe49();});}else{_0x1abe49();}}},'charset':_0x0ed9('0x2f'),'collate':_0x0ed9('0x30')});};