Skip to content

Instantly share code, notes, and snippets.

@rndD
Last active February 5, 2024 11:18
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rndD/bbcde87f397e85b5c95b3e3c7b95cd4a to your computer and use it in GitHub Desktop.
Save rndD/bbcde87f397e85b5c95b3e3c7b95cd4a to your computer and use it in GitHub Desktop.
Sendgrid webhook events ts type
// @see https://docs.sendgrid.com/for-developers/tracking-events/event
// There are is a mistake in the offical doc. Category is array of strings. I took it from the real webhook call.
type BaseSendgridEvent = {
email: string;
timestamp: number;
'smtp-id': string;
category: string | string[];
sg_event_id: string;
sg_message_id: string;
} & Partial<Record<string, string>>; // custom args. @see https://docs.sendgrid.com/for-developers/sending-email/unique-arguments
type SendgridProcessedEvent = BaseSendgridEvent & {
event: 'processed';
};
type SendgridDeliveredEvent = BaseSendgridEvent & {
event: 'delivered';
ip: string;
response: string;
};
type SendgridDeferredEvent = BaseSendgridEvent & {
event: 'deferred';
ip: string;
response: string;
attempt: string;
};
type SendgridOpenEvent = BaseSendgridEvent & {
event: 'open';
sg_machine_open: boolean;
ip: string;
useragent: string;
};
type SendgridClickEvent = BaseSendgridEvent & {
event: 'click';
ip: string;
useragent: string;
url: string;
};
type SendgridBounceEvent = BaseSendgridEvent & {
event: 'bounce';
ip: string;
bounce_classification: string;
reason: string;
status: string;
};
type SendgridDroppedEvent = BaseSendgridEvent & {
event: 'dropped';
reason: string;
status: string;
};
type SendgridSpamReportEvent = BaseSendgridEvent & {
event: 'spamreport';
};
type SendgridUnsubscribeEvent = BaseSendgridEvent & {
event: 'unsubscribe';
};
type SendgridGroupUnsubscribeEvent = BaseSendgridEvent & {
event: 'group_unsubscribe';
useragent: string;
ip: string;
url: string;
asm_group_id: number;
};
type SendgridGroupResubscribeEvent = BaseSendgridEvent & {
event: 'group_resubscribe';
useragent: string;
ip: string;
url: string;
asm_group_id: number;
};
export type SendgridEvent =
| SendgridProcessedEvent
| SendgridDeliveredEvent
| SendgridDeferredEvent
| SendgridOpenEvent
| SendgridClickEvent
| SendgridBounceEvent
| SendgridDroppedEvent
| SendgridSpamReportEvent
| SendgridUnsubscribeEvent
| SendgridGroupUnsubscribeEvent
| SendgridGroupResubscribeEvent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment