forked from kartikey54/VaccineAvailabilityNotifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notifier.js
52 lines (46 loc) · 1.52 KB
/
notifier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
let nodemailer = require('nodemailer');
let nodemailerTransporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: String(process.env.EMAIL),
pass: String(process.env.APPLICATION_PASSWORD)
}
});
function createTemplate(slotDetails, date){
let message = `Hi,
<br/>
Vaccine is available on <strong> ${date} </strong> in the following centers:
<br/><br/>
`
for(const slot of slotDetails){
let slotBody = `<strong> Center Name: ${slot.name} </strong> <br/>
Location: ${slot.block_name}, ${slot.state_name}, ${slot.pincode} <br/>
From ${slot.from} to ${slot.to} <br/>
Fee Type: ${slot.fee_type} <br/>
Fee: ${slot.fee} rupees <br/>
Available Capacity: ${slot.available_capacity} doses available <br/>
Vaccine: ${slot.vaccine} <br/>
Slots Available: <br/>`
for(const x of slot.slots){
slotBody = `${slotBody} ${x} <br/>`
}
slotBody = `${slotBody} <br/><br/>`
message = `${message} ${slotBody}`
}
return message
}
exports.sendEmail = function (email, subjectLine, slotDetails, date, callback) {
let message = createTemplate(slotDetails, date)
let options = {
from: String('Vaccine Checker ' + process.env.EMAIL),
to: email,
subject: subjectLine,
html: message
};
nodemailerTransporter.sendMail(options, (error, info) => {
if (error) {
return callback(error);
}
callback(error, info);
});
};