Untested version
This commit is contained in:
@@ -1,10 +1,8 @@
|
|||||||
const scrapTheItems = require("./scraptheitems");
|
const scrapTheItems = require("./scraptheitems");
|
||||||
const convertToDate = require("./convertToDate");
|
const convertToDate = require("./convertToDate");
|
||||||
const sgMail = require("@sendgrid/mail");
|
const AWS = require('aws-sdk');
|
||||||
// should be process.env.SENDGRID_API_KEY
|
AWS.config.update({region: 'eu-central-1'});
|
||||||
sgMail.setApiKey(
|
|
||||||
"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"
|
|
||||||
);
|
|
||||||
|
|
||||||
async function sendNotification(marketAlert) {
|
async function sendNotification(marketAlert) {
|
||||||
const { id, email, olx_url, last_date } = marketAlert;
|
const { id, email, olx_url, last_date } = marketAlert;
|
||||||
@@ -18,16 +16,43 @@ async function sendNotification(marketAlert) {
|
|||||||
(mes, item) => mes + `<strong>${item.url} i ${item.price}</strong>`,
|
(mes, item) => mes + `<strong>${item.url} i ${item.price}</strong>`,
|
||||||
""
|
""
|
||||||
);
|
);
|
||||||
const msg = {
|
|
||||||
to: email,
|
// Create sendEmail params
|
||||||
from: "test@example.com",
|
var params = {
|
||||||
subject: "Market Alert",
|
Destination: { /* required */
|
||||||
text: "New items on olx",
|
CcAddresses: [
|
||||||
html: message
|
],
|
||||||
|
ToAddresses: [
|
||||||
|
email
|
||||||
|
]
|
||||||
|
},
|
||||||
|
Message: { /* required */
|
||||||
|
Body: { /* required */
|
||||||
|
Html: {
|
||||||
|
Charset: "UTF-8",
|
||||||
|
Data: message
|
||||||
|
},
|
||||||
|
Text: {
|
||||||
|
Charset: "UTF-8",
|
||||||
|
Data: message // TODO: convert to text
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Subject: {
|
||||||
|
Charset: 'UTF-8',
|
||||||
|
Data: 'Javimi alert'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Source: 'info@saburly.com', /* required */
|
||||||
|
ReplyToAddresses: [
|
||||||
|
'info@saburly.com',
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (message) {
|
if (message) {
|
||||||
await sgMail.send(msg);
|
const sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise();
|
||||||
|
await sendPromise;
|
||||||
return { id, date: String(convertToDate(lastDate)) };
|
return { id, date: String(convertToDate(lastDate)) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = sendNotification;
|
module.exports = sendNotification;
|
||||||
|
|||||||
Reference in New Issue
Block a user