Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zlwaterfield/bb04f8543662cf5affb748becca4843c to your computer and use it in GitHub Desktop.
Save zlwaterfield/bb04f8543662cf5affb748becca4843c to your computer and use it in GitHub Desktop.
// 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);
@satyak450
Copy link

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!

@fandashtic
Copy link

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).

@devdarren7
Copy link

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