2020-10-09 08:18:18 -07:00
|
|
|
const beeline = require("honeycomb-beeline")({
|
|
|
|
writeKey: process.env["HONEYCOMB_WRITE_KEY"],
|
|
|
|
dataset:
|
|
|
|
process.env["NODE_ENV"] === "production"
|
|
|
|
? "Dress to Impress (2020)"
|
|
|
|
: "Dress to Impress (2020, dev)",
|
|
|
|
serviceName: "impress-2020-gql-server",
|
2021-08-08 00:23:57 -07:00
|
|
|
disableInstrumentationOnLoad: true,
|
2020-10-09 08:18:18 -07:00
|
|
|
});
|
2020-10-09 08:55:03 -07:00
|
|
|
import sendgridMail from "@sendgrid/mail";
|
|
|
|
|
|
|
|
sendgridMail.setApiKey(process.env.SENDGRID_API_KEY);
|
2020-10-09 08:18:18 -07:00
|
|
|
|
|
|
|
async function handle(req, res) {
|
2020-10-09 08:55:03 -07:00
|
|
|
const { content, email } = req.body;
|
|
|
|
if (!content) {
|
|
|
|
return res.status(400).send("Content must not be empty");
|
|
|
|
}
|
|
|
|
|
|
|
|
let contentSummary = content.trim();
|
|
|
|
if (contentSummary.length > 60) {
|
|
|
|
contentSummary = contentSummary.slice(0, 40) + "…";
|
|
|
|
}
|
|
|
|
|
2021-01-18 05:11:17 -08:00
|
|
|
const senderText = email || "<anonymous>";
|
|
|
|
|
|
|
|
console.info(`Sending from ${senderText}:\n${content}`);
|
|
|
|
|
|
|
|
const body = `${content}\n\nSent by ${senderText}`;
|
2020-10-09 08:55:03 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
await sendgridMail.send({
|
2020-10-09 09:20:09 -07:00
|
|
|
to: "matchu1993@gmail.com",
|
2020-10-09 08:55:03 -07:00
|
|
|
from: "impress-2020-feedback@openneo.net",
|
|
|
|
subject: `DTI feedback: ${contentSummary}`,
|
2020-10-22 23:35:01 -07:00
|
|
|
replyTo: email || undefined,
|
2021-01-18 05:11:17 -08:00
|
|
|
text: body,
|
2020-10-09 08:55:03 -07:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e);
|
2020-10-22 23:35:01 -07:00
|
|
|
if (e.response && e.response.body && e.response.body.errors) {
|
|
|
|
console.error(e.response.body.errors);
|
|
|
|
}
|
2020-10-09 08:55:03 -07:00
|
|
|
return res.status(500).send("Error sending message, see logs");
|
|
|
|
}
|
|
|
|
|
|
|
|
return res.status(200).send();
|
2020-10-09 08:18:18 -07:00
|
|
|
}
|
|
|
|
|
2021-05-13 01:13:21 -07:00
|
|
|
async function handleWithBeeline(req, res) {
|
2021-04-23 12:31:41 -07:00
|
|
|
beeline.withTrace(
|
|
|
|
{ name: "api/sendFeedback", operation_name: "api/sendFeedback" },
|
|
|
|
() => handle(req, res)
|
|
|
|
);
|
2021-05-13 01:13:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
export default handleWithBeeline;
|