37afec24503d6b12a76ecec7e222be2d4c45a0d5
[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 _0xbd08=['WhatsappAccount','find','type','twilio','accountSid','authToken','messages','create','whatsapp:','phone','remote','/status?token=','token','sid','WhatsappMessage,\x20%s,\x20%s,\x20%s','afterCreate','inspect','Missing\x20parameters:\x20phone,\x20accountSid\x20or\x20authToken','utf8mb4_unicode_ci','lodash','util','moment','request-promise','path','rimraf','../../config/environment','define','whatsapp_messages','messageId','body','FULLTEXT','models','get','direction','toLowerCase','secret','UserId','findOne','WhatsappInteractionId','then','update','createdAt','catch','error','out'];(function(_0x321bb2,_0x202794){var _0x9c12ed=function(_0x263dd3){while(--_0x263dd3){_0x321bb2['push'](_0x321bb2['shift']());}};_0x9c12ed(++_0x202794);}(_0xbd08,0x1d5));var _0x8bd0=function(_0x565ed7,_0x398228){_0x565ed7=_0x565ed7-0x0;var _0x183ad7=_0xbd08[_0x565ed7];return _0x183ad7;};'use strict';var _=require(_0x8bd0('0x0'));var util=require(_0x8bd0('0x1'));var logger=require('../../config/logger')('api');var moment=require(_0x8bd0('0x2'));var BPromise=require('bluebird');var rp=require(_0x8bd0('0x3'));var fs=require('fs');var path=require(_0x8bd0('0x4'));var rimraf=require(_0x8bd0('0x5'));var config=require(_0x8bd0('0x6'));var attributes=require('./whatsappMessage.attributes');module['exports']=function(_0x5bb714,_0x25dfe6){return _0x5bb714[_0x8bd0('0x7')]('WhatsappMessage',attributes,{'tableName':_0x8bd0('0x8'),'paranoid':![],'indexes':[{'name':_0x8bd0('0x9'),'fields':[_0x8bd0('0x9')]},{'name':'fti_whatsapp_messages','fields':[_0x8bd0('0xa')],'type':_0x8bd0('0xb')}],'timestamps':!![],'hooks':{'afterCreate':function(_0x19e133,_0x1f2655,_0x1dc81d){var _0x445326=_0x5bb714[_0x8bd0('0xc')];var _0x1e670a=_0x19e133[_0x8bd0('0xd')]({'plain':!![]});if(_0x1e670a[_0x8bd0('0xe')][_0x8bd0('0xf')]()==='in'||_0x1e670a[_0x8bd0('0xe')][_0x8bd0('0xf')]()==='out'&&!_0x1e670a[_0x8bd0('0x10')]&&!_['isNil'](_0x1e670a[_0x8bd0('0x11')])){_0x445326['WhatsappInteraction'][_0x8bd0('0x12')]({'where':{'id':_0x1e670a[_0x8bd0('0x13')]}})[_0x8bd0('0x14')](function(_0x7c83c8){if(_0x7c83c8){_0x7c83c8[_0x8bd0('0x15')]({'lastMsgAt':_0x1e670a[_0x8bd0('0x16')],'lastMsgDirection':_0x1e670a[_0x8bd0('0xe')][_0x8bd0('0xf')]()});}})[_0x8bd0('0x17')](function(_0x2a8e75){console[_0x8bd0('0x18')](_0x2a8e75);});}if(_0x1e670a[_0x8bd0('0xe')]===_0x8bd0('0x19')&&!_0x1e670a['secret']){var _0x4c3ed2;_0x445326[_0x8bd0('0x1a')][_0x8bd0('0x1b')]({'where':{'id':_0x1e670a['WhatsappAccountId']},'raw':!![]})[_0x8bd0('0x14')](function(_0x2abf9f){_0x4c3ed2=_0x2abf9f;if(_0x4c3ed2&&_0x4c3ed2[_0x8bd0('0x1c')]){switch(_0x4c3ed2[_0x8bd0('0x1c')]){case _0x8bd0('0x1d'):var _0x201127=require(_0x8bd0('0x1d'));if(_0x4c3ed2[_0x8bd0('0x1e')]&&_0x4c3ed2['authToken']&&_0x4c3ed2['phone']){var _0x14144b=new _0x201127(_0x4c3ed2['accountSid'],_0x4c3ed2[_0x8bd0('0x1f')]);_0x14144b[_0x8bd0('0x20')][_0x8bd0('0x21')]({'body':_0x1e670a['body'],'to':_0x8bd0('0x22')+_0x1e670a[_0x8bd0('0x23')],'from':'whatsapp:'+_0x4c3ed2[_0x8bd0('0x23')],'statusCallback':_0x4c3ed2[_0x8bd0('0x24')]+'/api/whatsapp/messages/'+_0x1e670a['id']+_0x8bd0('0x25')+_0x4c3ed2[_0x8bd0('0x26')]})[_0x8bd0('0x14')](function(_0x1e0942){if(_0x1e0942['sid']){return _0x19e133[_0x8bd0('0x15')]({'messageId':_0x1e0942[_0x8bd0('0x27')]});}})['catch'](function(_0xeeb22f){logger[_0x8bd0('0x18')](_0x8bd0('0x28'),_0x8bd0('0x29'),'twilio',util[_0x8bd0('0x2a')](_0xeeb22f,{'showHidden':![],'depth':null}));});}else{logger[_0x8bd0('0x18')]('WhatsappMessage,\x20%s,\x20%s,\x20%s',_0x8bd0('0x29'),_0x8bd0('0x1d'),_0x8bd0('0x2b'));}break;}}})['finally'](function(){_0x1dc81d();});}else{_0x1dc81d();}}},'charset':'utf8mb4','collate':_0x8bd0('0x2c')});};