Built motion from commit (unavailable).|2.6.0
[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 _0x3f81=['rimraf','./whatsappMessage.attributes','exports','define','WhatsappMessage','whatsapp_messages','messageId','body','models','get','direction','toLowerCase','out','secret','isNil','UserId','WhatsappInteraction','WhatsappInteractionId','then','createdAt','catch','error','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid','messages','whatsapp:','phone','remote','/status?token=','token','sid','update','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','finally','utf8mb4','utf8mb4_unicode_ci','lodash','util','../../config/logger','api','moment','request-promise','path'];(function(_0x5ed740,_0xb983b8){var _0x2d22ad=function(_0x88877e){while(--_0x88877e){_0x5ed740['push'](_0x5ed740['shift']());}};_0x2d22ad(++_0xb983b8);}(_0x3f81,0x11f));var _0x13f8=function(_0x529a3a,_0x5b3217){_0x529a3a=_0x529a3a-0x0;var _0x10d93f=_0x3f81[_0x529a3a];return _0x10d93f;};'use strict';var _=require(_0x13f8('0x0'));var util=require(_0x13f8('0x1'));var logger=require(_0x13f8('0x2'))(_0x13f8('0x3'));var moment=require(_0x13f8('0x4'));var BPromise=require('bluebird');var rp=require(_0x13f8('0x5'));var fs=require('fs');var path=require(_0x13f8('0x6'));var rimraf=require(_0x13f8('0x7'));var config=require('../../config/environment');var attributes=require(_0x13f8('0x8'));module[_0x13f8('0x9')]=function(_0x46fd9a,_0x1e329f){return _0x46fd9a[_0x13f8('0xa')](_0x13f8('0xb'),attributes,{'tableName':_0x13f8('0xc'),'paranoid':![],'indexes':[{'name':_0x13f8('0xd'),'fields':[_0x13f8('0xd')]},{'name':'fti_whatsapp_messages','fields':[_0x13f8('0xe')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x435ba,_0x33b742,_0x48d6ce){var _0x338943=_0x46fd9a[_0x13f8('0xf')];var _0x180eb8=_0x435ba[_0x13f8('0x10')]({'plain':!![]});if(_0x180eb8[_0x13f8('0x11')][_0x13f8('0x12')]()==='in'||_0x180eb8[_0x13f8('0x11')][_0x13f8('0x12')]()===_0x13f8('0x13')&&!_0x180eb8[_0x13f8('0x14')]&&!_[_0x13f8('0x15')](_0x180eb8[_0x13f8('0x16')])){_0x338943[_0x13f8('0x17')]['findOne']({'where':{'id':_0x180eb8[_0x13f8('0x18')]}})[_0x13f8('0x19')](function(_0x221052){if(_0x221052){_0x221052['update']({'lastMsgAt':_0x180eb8[_0x13f8('0x1a')],'lastMsgDirection':_0x180eb8[_0x13f8('0x11')][_0x13f8('0x12')]()});}})[_0x13f8('0x1b')](function(_0x1c1db7){console[_0x13f8('0x1c')](_0x1c1db7);});}if(_0x180eb8['direction']==='out'&&!_0x180eb8['secret']){var _0x39ba92;_0x338943[_0x13f8('0x1d')][_0x13f8('0x1e')]({'where':{'id':_0x180eb8[_0x13f8('0x1f')]},'raw':!![]})['then'](function(_0x361d5f){_0x39ba92=_0x361d5f;if(_0x39ba92&&_0x39ba92[_0x13f8('0x20')]){switch(_0x39ba92[_0x13f8('0x20')]){case _0x13f8('0x21'):var _0x9b65c9=require(_0x13f8('0x21'));if(_0x39ba92[_0x13f8('0x22')]&&_0x39ba92['authToken']&&_0x39ba92['phone']){var _0x29e935=new _0x9b65c9(_0x39ba92[_0x13f8('0x22')],_0x39ba92['authToken']);_0x29e935[_0x13f8('0x23')]['create']({'body':_0x180eb8[_0x13f8('0xe')],'to':_0x13f8('0x24')+_0x180eb8[_0x13f8('0x25')],'from':'whatsapp:'+_0x39ba92[_0x13f8('0x25')],'statusCallback':_0x39ba92[_0x13f8('0x26')]+'/api/whatsapp/messages/'+_0x180eb8['id']+_0x13f8('0x27')+_0x39ba92[_0x13f8('0x28')]})['then'](function(_0x4e66a3){if(_0x4e66a3[_0x13f8('0x29')]){return _0x435ba[_0x13f8('0x2a')]({'messageId':_0x4e66a3['sid']});}})[_0x13f8('0x1b')](function(_0x1a57bd){logger[_0x13f8('0x1c')](_0x13f8('0x2b'),_0x13f8('0x2c'),_0x13f8('0x21'),util['inspect'](_0x1a57bd,{'showHidden':![],'depth':null}));});}else{logger['error'](_0x13f8('0x2b'),_0x13f8('0x2c'),_0x13f8('0x21'),_0x13f8('0x2d'));}break;}}})[_0x13f8('0x2e')](function(){_0x48d6ce();});}else{_0x48d6ce();}}},'charset':_0x13f8('0x2f'),'collate':_0x13f8('0x30')});};