Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
Created August 14, 2020 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaidspaghetti/5e7db61bce38a3d4c364a36d04e4c7b6 to your computer and use it in GitHub Desktop.
Save isaidspaghetti/5e7db61bce38a3d4c364a36d04e4c7b6 to your computer and use it in GitHub Desktop.
//backend/routes/index.js:59
router.post('/email-transcript', async (req, res) => {
const messages = req.body.messages;
const { firstName, lastName, email, createdAt } = req.body;
let transcript = messages.map((message) => {
return (`<li>FROM: ${message.user.id}</li>\n<li>MESSAGE: ${message.text}</li>\n`);
});
sgMail.setApiKey(sendgridApiKey);
const msg = {
to: 'recipient@example.com',
from: 'sendgridVerifiedEmail@example.com',
subject: 'Stream Chat: Your client started a Support Chat Session',
html: `Hello, \n Your client, ${firstName} ${lastName} started a chat with the support team chat widget on ${createdAt}. \n
Here is the transcript of the chat: \n ${transcript} END OF TRANSCRIPT \n You can reach your client at ${email}. \n This message was sent to you from Stream Chat`,
};
try {
sgMail.send(msg);
res.status(200).end;
}
catch{ (err) => console.log(err.response.body); }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment