feat(notification-sendgrid): include ability to handle attachments (#8729)

* feat(notification-sendgrid): include ability to handle attachments array if passed to dynamicTemplateData.attachments

* docs: update sendgrid page.mdx

include attachments documentation in example

* ability to set from email, must be verified sender

* docs: update to include optional from property

* first-class optional vars for from & attachments

* docs: update for optional first-class vars

* Update www/apps/resources/app/architectural-modules/notification/sendgrid/page.mdx

Co-authored-by: Shahed Nasser <shahednasser@gmail.com>

---------

Co-authored-by: Stevche Radevski <sradevski@live.com>
Co-authored-by: Shahed Nasser <shahednasser@gmail.com>
This commit is contained in:
420coupe
2024-08-28 02:39:41 -04:00
committed by GitHub
parent ac18b5d35f
commit a430339d54
4 changed files with 89 additions and 16 deletions

View File

@@ -46,13 +46,26 @@ export class SendgridNotificationService extends AbstractNotificationProviderSer
)
}
const message = {
const attachments = Array.isArray(notification.attachments)
? notification.attachments.map((attachment) => ({
content: attachment.content, // Base64 encoded string of the file
filename: attachment.filename,
content_type: attachment.content_type, // MIME type (e.g., 'application/pdf')
disposition: attachment.disposition ?? "attachment", // Default to 'attachment'
id: attachment.id ?? undefined, // Optional: unique identifier for inline attachments
}))
: undefined
const from = notification.from?.trim() || this.config_.from
const message: sendgrid.MailDataRequired = {
to: notification.to,
from: this.config_.from,
from: from,
templateId: notification.template,
dynamicTemplateData: notification.data as
| { [key: string]: any }
| undefined,
attachments: attachments,
}
try {