Untested version

This commit is contained in:
Senad Uka
2019-03-20 05:59:23 +01:00
parent 6821054494
commit f53d60ab0f

View File

@@ -1,10 +1,8 @@
const scrapTheItems = require("./scraptheitems");
const convertToDate = require("./convertToDate");
const sgMail = require("@sendgrid/mail");
// should be process.env.SENDGRID_API_KEY
sgMail.setApiKey(
"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"
);
const AWS = require('aws-sdk');
AWS.config.update({region: 'eu-central-1'});
async function sendNotification(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>`,
""
);
const msg = {
to: email,
from: "test@example.com",
subject: "Market Alert",
text: "New items on olx",
html: message
// Create sendEmail params
var params = {
Destination: { /* required */
CcAddresses: [
],
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) {
await sgMail.send(msg);
const sendPromise = new AWS.SES({apiVersion: '2010-12-01'}).sendEmail(params).promise();
await sendPromise;
return { id, date: String(convertToDate(lastDate)) };
}
}
module.exports = sendNotification;