Built motion from commit (unavailable).|2.5.22
[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 _0x4bc0=['sid','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','finally','utf8mb4_unicode_ci','lodash','../../config/logger','api','moment','bluebird','request-promise','path','rimraf','../../config/environment','./whatsappMessage.attributes','define','whatsapp_messages','messageId','body','FULLTEXT','models','get','direction','toLowerCase','out','secret','isNil','UserId','WhatsappInteraction','WhatsappInteractionId','then','createdAt','catch','error','WhatsappAccount','find','WhatsappAccountId','type','twilio','accountSid','authToken','phone','messages','create','whatsapp:','remote','/status?token=','update'];(function(_0x2cfe0c,_0x32fe20){var _0x21d694=function(_0x8fabf0){while(--_0x8fabf0){_0x2cfe0c['push'](_0x2cfe0c['shift']());}};_0x21d694(++_0x32fe20);}(_0x4bc0,0xf5));var _0x04bc=function(_0x240c8a,_0x48a74b){_0x240c8a=_0x240c8a-0x0;var _0x20ae1d=_0x4bc0[_0x240c8a];return _0x20ae1d;};'use strict';var _=require(_0x04bc('0x0'));var util=require('util');var logger=require(_0x04bc('0x1'))(_0x04bc('0x2'));var moment=require(_0x04bc('0x3'));var BPromise=require(_0x04bc('0x4'));var rp=require(_0x04bc('0x5'));var fs=require('fs');var path=require(_0x04bc('0x6'));var rimraf=require(_0x04bc('0x7'));var config=require(_0x04bc('0x8'));var attributes=require(_0x04bc('0x9'));module['exports']=function(_0x3e3517,_0x9eda6){return _0x3e3517[_0x04bc('0xa')]('WhatsappMessage',attributes,{'tableName':_0x04bc('0xb'),'paranoid':![],'indexes':[{'name':_0x04bc('0xc'),'fields':['messageId']},{'name':'fti_whatsapp_messages','fields':[_0x04bc('0xd')],'type':_0x04bc('0xe')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x12aa7e,_0x1b9a16,_0x965198){var _0x5e3214=_0x3e3517[_0x04bc('0xf')];var _0x566bb1=_0x12aa7e[_0x04bc('0x10')]({'plain':!![]});if(_0x566bb1[_0x04bc('0x11')][_0x04bc('0x12')]()==='in'||_0x566bb1[_0x04bc('0x11')][_0x04bc('0x12')]()===_0x04bc('0x13')&&!_0x566bb1[_0x04bc('0x14')]&&!_[_0x04bc('0x15')](_0x566bb1[_0x04bc('0x16')])){_0x5e3214[_0x04bc('0x17')]['findOne']({'where':{'id':_0x566bb1[_0x04bc('0x18')]}})[_0x04bc('0x19')](function(_0x1ca55d){if(_0x1ca55d){_0x1ca55d['update']({'lastMsgAt':_0x566bb1[_0x04bc('0x1a')],'lastMsgDirection':_0x566bb1['direction'][_0x04bc('0x12')]()});}})[_0x04bc('0x1b')](function(_0x3eba3e){console[_0x04bc('0x1c')](_0x3eba3e);});}if(_0x566bb1[_0x04bc('0x11')]==='out'&&!_0x566bb1[_0x04bc('0x14')]){var _0x360d68;_0x5e3214[_0x04bc('0x1d')][_0x04bc('0x1e')]({'where':{'id':_0x566bb1[_0x04bc('0x1f')]},'raw':!![]})[_0x04bc('0x19')](function(_0x24f123){_0x360d68=_0x24f123;if(_0x360d68&&_0x360d68[_0x04bc('0x20')]){switch(_0x360d68[_0x04bc('0x20')]){case _0x04bc('0x21'):var _0x5f4256=require('twilio');if(_0x360d68[_0x04bc('0x22')]&&_0x360d68[_0x04bc('0x23')]&&_0x360d68[_0x04bc('0x24')]){var _0x3733be=new _0x5f4256(_0x360d68[_0x04bc('0x22')],_0x360d68[_0x04bc('0x23')]);_0x3733be[_0x04bc('0x25')][_0x04bc('0x26')]({'body':_0x566bb1[_0x04bc('0xd')],'to':_0x04bc('0x27')+_0x566bb1[_0x04bc('0x24')],'from':_0x04bc('0x27')+_0x360d68[_0x04bc('0x24')],'statusCallback':_0x360d68[_0x04bc('0x28')]+'/api/whatsapp/messages/'+_0x566bb1['id']+_0x04bc('0x29')+_0x360d68['token']})[_0x04bc('0x19')](function(_0x1584bc){if(_0x1584bc['sid']){return _0x12aa7e[_0x04bc('0x2a')]({'messageId':_0x1584bc[_0x04bc('0x2b')]});}})['catch'](function(_0x25d086){logger[_0x04bc('0x1c')](_0x04bc('0x2c'),_0x04bc('0x2d'),_0x04bc('0x21'),util['inspect'](_0x25d086,{'showHidden':![],'depth':null}));});}else{logger[_0x04bc('0x1c')](_0x04bc('0x2c'),_0x04bc('0x2d'),_0x04bc('0x21'),'Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken');}break;}}})[_0x04bc('0x2e')](function(){_0x965198();});}else{_0x965198();}}},'charset':'utf8mb4','collate':_0x04bc('0x2f')});};