mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
sendgrid parser
This commit is contained in:
@@ -8,23 +8,22 @@ export const webhookSendgrid = {
|
||||
extraLibs: null,
|
||||
template: (
|
||||
table
|
||||
) => `const sendgridParser: Parser = async({req, db,ref}) =>{
|
||||
// sendgrid webhook events docs : https://docs.sendgrid.com/for-developers/tracking-events/event#event-objects
|
||||
|
||||
// sengrid sends request body with an array of events
|
||||
// eg:
|
||||
// {
|
||||
// "email": "example@test.com",
|
||||
// "timestamp": 1513299569,
|
||||
// "smtp-id": "<14c5d75ce93.dfd.64b469@ismtpd-555>",
|
||||
// "event": "processed",
|
||||
// "category": "cat facts",
|
||||
// "sg_event_id": "sg_event_id",
|
||||
// "sg_message_id": "sg_message_id"
|
||||
// },
|
||||
|
||||
|
||||
};`,
|
||||
) => `const sendgridParser: Parser = async ({ req, db, ref }) => {
|
||||
const { body } = req
|
||||
const eventHandler = async (sgEvent) => {
|
||||
// Event handlers can be modiefed to preform different actions based on the sendgrid event
|
||||
// List of events & docs : https://docs.sendgrid.com/for-developers/tracking-events/event#events
|
||||
const { event, docPath } = sgEvent
|
||||
// event param is provided by default
|
||||
// however docPath or other custom parameter needs be passed in the custom_args variable in Sengrid Extension
|
||||
return db.doc(docPath).update({ sgStatus: event })
|
||||
}
|
||||
//
|
||||
if (Array.isArray(body)) {
|
||||
// when multiple events are passed in one call
|
||||
await Promise.allSettled(body.map(eventHandler))
|
||||
} else eventHandler(body)
|
||||
};`,
|
||||
},
|
||||
condition: {
|
||||
additionalVariables: null,
|
||||
|
||||
Reference in New Issue
Block a user