Built motion from commit (unavailable).|2.5.1
[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 _0x215f=['WhatsappMessage,\x20%s,\x20%s,\x20%s','utf8mb4_unicode_ci','../../config/logger','api','path','../../config/environment','./whatsappMessage.attributes','WhatsappMessage','whatsapp_messages','messageId','fti_whatsapp_messages','body','get','toLowerCase','direction','out','secret','isNil','UserId','findOne','then','update','createdAt','catch','WhatsappAccount','WhatsappAccountId','type','twilio','accountSid','authToken','phone','messages','whatsapp:','remote','/api/whatsapp/messages/','/status?token=','sid','inspect'];(function(_0x815126,_0x378cca){var _0x2d617a=function(_0x191043){while(--_0x191043){_0x815126['push'](_0x815126['shift']());}};_0x2d617a(++_0x378cca);}(_0x215f,0x1f0));var _0xf215=function(_0x38ea85,_0x24dd4b){_0x38ea85=_0x38ea85-0x0;var _0x52c063=_0x215f[_0x38ea85];return _0x52c063;};'use strict';var _=require('lodash');var util=require('util');var logger=require(_0xf215('0x0'))(_0xf215('0x1'));var moment=require('moment');var BPromise=require('bluebird');var rp=require('request-promise');var fs=require('fs');var path=require(_0xf215('0x2'));var rimraf=require('rimraf');var config=require(_0xf215('0x3'));var attributes=require(_0xf215('0x4'));module['exports']=function(_0x5c5228,_0x5b0ee8){return _0x5c5228['define'](_0xf215('0x5'),attributes,{'tableName':_0xf215('0x6'),'paranoid':![],'indexes':[{'name':_0xf215('0x7'),'fields':['messageId']},{'name':_0xf215('0x8'),'fields':[_0xf215('0x9')],'type':'FULLTEXT'}],'timestamps':!![],'hooks':{'afterCreate':function(_0x4e2768,_0x164987,_0x2d1f4c){var _0x2476e2=_0x5c5228['models'];var _0x182e31=_0x4e2768[_0xf215('0xa')]({'plain':!![]});if(_0x182e31['direction'][_0xf215('0xb')]()==='in'||_0x182e31[_0xf215('0xc')][_0xf215('0xb')]()===_0xf215('0xd')&&!_0x182e31[_0xf215('0xe')]&&!_[_0xf215('0xf')](_0x182e31[_0xf215('0x10')])){_0x2476e2['WhatsappInteraction'][_0xf215('0x11')]({'where':{'id':_0x182e31['WhatsappInteractionId']}})[_0xf215('0x12')](function(_0x136644){if(_0x136644){_0x136644[_0xf215('0x13')]({'lastMsgAt':_0x182e31[_0xf215('0x14')],'lastMsgDirection':_0x182e31[_0xf215('0xc')][_0xf215('0xb')]()});}})[_0xf215('0x15')](function(_0x75e14a){console['error'](_0x75e14a);});}if(_0x182e31['direction']===_0xf215('0xd')&&!_0x182e31['secret']){var _0x5294c8;_0x2476e2[_0xf215('0x16')]['find']({'where':{'id':_0x182e31[_0xf215('0x17')]},'raw':!![]})['then'](function(_0x1ce8b3){_0x5294c8=_0x1ce8b3;if(_0x5294c8&&_0x5294c8[_0xf215('0x18')]){switch(_0x5294c8[_0xf215('0x18')]){case _0xf215('0x19'):var _0x53f76c=require(_0xf215('0x19'));if(_0x5294c8[_0xf215('0x1a')]&&_0x5294c8[_0xf215('0x1b')]&&_0x5294c8[_0xf215('0x1c')]){var _0x149ba7=new _0x53f76c(_0x5294c8[_0xf215('0x1a')],_0x5294c8[_0xf215('0x1b')]);_0x149ba7[_0xf215('0x1d')]['create']({'body':_0x182e31[_0xf215('0x9')],'to':'whatsapp:'+_0x182e31[_0xf215('0x1c')],'from':_0xf215('0x1e')+_0x5294c8[_0xf215('0x1c')],'statusCallback':_0x5294c8[_0xf215('0x1f')]+_0xf215('0x20')+_0x182e31['id']+_0xf215('0x21')+_0x5294c8['token']})[_0xf215('0x12')](function(_0x3161e4){if(_0x3161e4[_0xf215('0x22')]){return _0x4e2768[_0xf215('0x13')]({'messageId':_0x3161e4[_0xf215('0x22')]});}})[_0xf215('0x15')](function(_0x5e50a7){logger['error']('WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','twilio',util[_0xf215('0x23')](_0x5e50a7,{'showHidden':![],'depth':null}));});}else{logger['error'](_0xf215('0x24'),'afterCreate','twilio','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken');}break;}}})['finally'](function(){_0x2d1f4c();});}else{_0x2d1f4c();}}},'charset':'utf8mb4','collate':_0xf215('0x25')});};