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:
co-authored by
Shahed Nasser
Stevche Radevski
parent
ac18b5d35f
commit
a430339d54
@@ -1,6 +1,34 @@
|
||||
import { BaseFilterable } from "../dal"
|
||||
import { OperatorMap } from "../dal/utils"
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
* The structure for attachments in a notification.
|
||||
*/
|
||||
export interface Attachment {
|
||||
/**
|
||||
* The content of the attachment, encoded as a base64 string.
|
||||
*/
|
||||
content: string
|
||||
/**
|
||||
* The filename of the attachment.
|
||||
*/
|
||||
filename: string
|
||||
/**
|
||||
* The MIME type of the attachment.
|
||||
*/
|
||||
content_type?: string
|
||||
/**
|
||||
* The disposition of the attachment, e.g., "inline" or "attachment".
|
||||
*/
|
||||
disposition?: string
|
||||
/**
|
||||
* The ID, if the attachment is meant to be referenced within the body of the message.
|
||||
*/
|
||||
id?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
@@ -15,6 +43,14 @@ export interface NotificationDTO {
|
||||
* The recipient of the notification. It can be email, phone number, or username, depending on the channel.
|
||||
*/
|
||||
to: string
|
||||
/**
|
||||
* The sender of the notification. It can be email, phone number, or username, depending on the channel.
|
||||
*/
|
||||
from?: string | null
|
||||
/**
|
||||
* Optional attachments for the notification.
|
||||
*/
|
||||
attachments?: Attachment[] | null
|
||||
/**
|
||||
* The channel through which the notification is sent, such as 'email' or 'sms'
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { Attachment } from "./common"
|
||||
|
||||
/**
|
||||
* @interface
|
||||
*
|
||||
@@ -8,6 +10,14 @@ export type ProviderSendNotificationDTO = {
|
||||
* The recipient of the notification. It can be email, phone number, or username, depending on the channel.
|
||||
*/
|
||||
to: string
|
||||
/**
|
||||
* The sender of the notification. It can be email, phone number, or username, depending on the channel.
|
||||
*/
|
||||
from?: string | null
|
||||
/**
|
||||
* Optional attachments for the notification.
|
||||
*/
|
||||
attachments?: Attachment[] | null
|
||||
/**
|
||||
* The channel through which the notification is sent, such as 'email' or 'sms'
|
||||
*/
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user