Created
October 26, 2019 22:15
-
-
Save zlwaterfield/bb04f8543662cf5affb748becca4843c to your computer and use it in GitHub Desktop.
Blog post snippet - https://medium.com/gofaros/a-guide-to-inbound-parse-with-sendgrid-nodejs-382a266f8c3f
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get signed_key | |
const msgKey = getSignedKey(req.body.text); | |
// Verify key | |
const keyContents = verifyKey(msgKey); | |
// Get the message that is being responded too | |
const prevMessage = await db.message.findById(keyContents.id); | |
// Validate the sender is in this conversation / allowed to respond | |
const verifiedSender = await verifySender(keyContents, prevMessage); | |
// Parse message data | |
const emailMessage = parseEmail(req.body.text); | |
// Validate first time (idempotent) | |
const date = parseMessageDate(req.body.headers); | |
await validateEvent(keyContents, verifiedSender.id, date); | |
// Create message object | |
const newMessage = buildMessage(emailMessage, prevMessage.convo_id, verifiedSender.id); | |
// create message on the conversation and send out notifications | |
createMessage(verifiedSender.id, prevMessage.convo_id, newMessage); |
It would be very helpful if you shared some of your parsing code (especially the parseEmail method where you get the body of the email).
It would be very helpful if you shared some of your parsing code (especially the parseEmail method where you get the body of the email).
You don't need anything besides an normal node js post route such as:
router.post('/add', async function(req, res, next) { console.log(req.body); }
and in your app.js file :
app.use(express.urlencoded({ extended: true, type: ["form-data", "multipart/form-data"] }));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be very helpful if you shared some of your parsing code (especially the parseEmail method where you get the body of the email). Thanks!