34beb1cf77c6809b5f64fca146806e61f11af3ce
[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 _0xc24e=['messages','create','whatsapp:','remote','then','sid','catch','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','inspect','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','moment','bluebird','request-promise','path','rimraf','../../config/environment','./whatsappMessage.attributes','exports','define','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','body','FULLTEXT','get','direction','toLowerCase','secret','isNil','WhatsappInteraction','WhatsappInteractionId','update','createdAt','error','out','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid','authToken','phone'];(function(_0x1c223e,_0xc24282){var _0x1db7ad=function(_0x337924){while(--_0x337924){_0x1c223e['push'](_0x1c223e['shift']());}};_0x1db7ad(++_0xc24282);}(_0xc24e,0x1d9));var _0xec24=function(_0x4df0fb,_0x5b1d98){_0x4df0fb=_0x4df0fb-0x0;var _0x2c8a6b=_0xc24e[_0x4df0fb];return _0x2c8a6b;};'use strict';var _=require(_0xec24('0x0'));var util=require(_0xec24('0x1'));var logger=require(_0xec24('0x2'))('api');var moment=require(_0xec24('0x3'));var BPromise=require(_0xec24('0x4'));var rp=require(_0xec24('0x5'));var fs=require('fs');var path=require(_0xec24('0x6'));var rimraf=require(_0xec24('0x7'));var config=require(_0xec24('0x8'));var attributes=require(_0xec24('0x9'));module[_0xec24('0xa')]=function(_0x589e77,_0x5297d0){return _0x589e77[_0xec24('0xb')](_0xec24('0xc'),attributes,{'tableName':_0xec24('0xd'),'paranoid':![],'indexes':[{'name':_0xec24('0xe'),'fields':[_0xec24('0xe')]},{'name':_0xec24('0xf'),'fields':[_0xec24('0x10')],'type':_0xec24('0x11')}],'timestamps':!![],'hooks':{'afterCreate':function(_0xed4ac3,_0x5f4106,_0x5532e4){var _0x238321=_0x589e77['models'];var _0x4832fa=_0xed4ac3[_0xec24('0x12')]({'plain':!![]});if(_0x4832fa[_0xec24('0x13')]['toLowerCase']()==='in'||_0x4832fa['direction'][_0xec24('0x14')]()==='out'&&!_0x4832fa[_0xec24('0x15')]&&!_[_0xec24('0x16')](_0x4832fa['UserId'])){_0x238321[_0xec24('0x17')]['findOne']({'where':{'id':_0x4832fa[_0xec24('0x18')]}})['then'](function(_0x4ed8b9){if(_0x4ed8b9){_0x4ed8b9[_0xec24('0x19')]({'lastMsgAt':_0x4832fa[_0xec24('0x1a')],'lastMsgDirection':_0x4832fa['direction']['toLowerCase']()});}})['catch'](function(_0x3ef9d0){console[_0xec24('0x1b')](_0x3ef9d0);});}if(_0x4832fa[_0xec24('0x13')]===_0xec24('0x1c')&&!_0x4832fa[_0xec24('0x15')]){var _0x5ac1fb;_0x238321[_0xec24('0x1d')][_0xec24('0x1e')]({'where':{'id':_0x4832fa[_0xec24('0x1f')]},'raw':!![]})['then'](function(_0x422205){_0x5ac1fb=_0x422205;if(_0x5ac1fb&&_0x5ac1fb[_0xec24('0x20')]){switch(_0x5ac1fb[_0xec24('0x20')]){case _0xec24('0x21'):var _0x195fc3=require('twilio');if(_0x5ac1fb[_0xec24('0x22')]&&_0x5ac1fb[_0xec24('0x23')]&&_0x5ac1fb[_0xec24('0x24')]){var _0xb7eb20=new _0x195fc3(_0x5ac1fb[_0xec24('0x22')],_0x5ac1fb['authToken']);_0xb7eb20[_0xec24('0x25')][_0xec24('0x26')]({'body':_0x4832fa[_0xec24('0x10')],'to':_0xec24('0x27')+_0x4832fa[_0xec24('0x24')],'from':_0xec24('0x27')+_0x5ac1fb[_0xec24('0x24')],'statusCallback':_0x5ac1fb[_0xec24('0x28')]+'/api/whatsapp/messages/'+_0x4832fa['id']+'/status?token='+_0x5ac1fb['token']})[_0xec24('0x29')](function(_0x397021){if(_0x397021[_0xec24('0x2a')]){return _0xed4ac3[_0xec24('0x19')]({'messageId':_0x397021[_0xec24('0x2a')]});}})[_0xec24('0x2b')](function(_0x451e46){logger[_0xec24('0x1b')](_0xec24('0x2c'),_0xec24('0x2d'),'twilio',util[_0xec24('0x2e')](_0x451e46,{'showHidden':![],'depth':null}));});}else{logger[_0xec24('0x1b')](_0xec24('0x2c'),_0xec24('0x2d'),'twilio',_0xec24('0x2f'));}break;}}})[_0xec24('0x30')](function(){_0x5532e4();});}else{_0x5532e4();}}},'charset':_0xec24('0x31'),'collate':_0xec24('0x32')});};