-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
77 lines (72 loc) · 1.96 KB
/
handler.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"use strict";
const nodemailer = require("nodemailer");
const aws = require("aws-sdk");
const { WebClient } = require("@slack/client");
module.exports.slackNewApplication = async event => {
const token = process.env.SLACK_TOKEN;
const web = new WebClient(token);
try {
await web.chat.postMessage({
channel: "application-notis",
attachments: [
{
text: "New application from me!",
footer: "New application for cohort 10033"
}
]
});
return {
statusCode: 200
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({
message: error.message
})
};
}
};
module.exports.email = async event => {
const testAccount = await nodemailer.createTestAccount();
// create Nodemailer SES transporter
const transporter =
process.env.NODE_ENV === "development"
? nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: testAccount.user, // generated ethereal user
pass: testAccount.pass // generated ethereal password
}
})
: nodemailer.createTransport({
SES: new aws.SES({
apiVersion: "2010-12-01"
})
});
const { email, firstName, lastName } = JSON.parse(event.body);
// send some mail
try {
await transporter.sendMail({
from: "[email protected]", // account to send from, verified through SES
to: email, // account to send to
subject: `Thanks for applying ${firstName}!`,
text: `Thank you for applying to Bridge, ${firstName}. We'll be in touch shortly!`
});
return {
statusCode: 200,
body: JSON.stringify({
message: "mail sent"
})
};
} catch (error) {
return {
statusCode: 500,
body: JSON.stringify({
message: "email failed to send"
})
};
}
};