docs: update examples in sendgrid guide (#12504)

* initial

* docs: update examples in sendgrid guide

* add note for local file module
This commit is contained in:
Shahed Nasser
2025-05-15 19:13:15 +03:00
committed by GitHub
parent e91aa2493a
commit 04acc5d219
5 changed files with 13487 additions and 13322 deletions
@@ -14,11 +14,11 @@ export const metadata = {
# {metadata.title}
In this guide, you'll learn how to send a notification using the Notification Module.
In this guide, you'll learn about the different ways to send notifications using the Notification Module.
## Use the Create Method
## Using the Create Method
In your resource, such as a subscriber, resolve the Notification Module's main service and use its `create` method:
In your resource, such as a [subscriber](!docs!/learn/fundamentals/events-and-subscribers), resolve the Notification Module's main service and use its `create` method:
export const highlights = [
["12", "notificationModuleService", "Resolve the Notification Module."],
@@ -56,7 +56,7 @@ export default async function productCreateHandler({
container.resolve(Modules.NOTIFICATION)
await notificationModuleService.createNotifications({
to: "shahednasser@gmail.com",
to: "user@gmail.com",
channel: "email",
template: "product-created",
data,
@@ -103,3 +103,78 @@ The `create` method accepts an object or an array of objects having the followin
/>
For a full list of properties accepted, refer to [this guide](/references/notification-provider-module#create).
---
## Using the sendNotifcationStep
If you want to send a notification as part of a workflow, You can use the [sendNotifcationStep](!resources!/references/medusa-workflows/steps/sendNotificationsStep) in your workflow.
For example:
```ts title="src/workflows/send-email.ts"
import { createWorkflow } from "@medusajs/framework/workflows-sdk"
import {
sendNotificationsStep,
useQueryGraphStep,
} from "@medusajs/medusa/core-flows"
type WorkflowInput = {
id: string
}
export const sendEmailWorkflow = createWorkflow(
"send-email-workflow",
({ id }: WorkflowInput) => {
const { data: products } = useQueryGraphStep({
entity: "product",
fields: [
"*",
"variants.*",
],
filters: {
id,
},
})
sendNotificationsStep({
to: "user@gmail.com",
channel: "email",
template: "product-created",
data: {
product_title: product[0].title,
product_image: product[0].images[0]?.url,
},
})
}
)
```
For a full list of input properties accepted, refer to the [sendNotifcationStep](!resources!/references/medusa-workflows/steps/sendNotificationsStep) reference.
You can then execute this workflow in a subscriber, API route, or scheduled job.
For example, you can execute it when a product is created:
```ts title="src/subscribers/product-created.ts"
import type {
SubscriberArgs,
SubscriberConfig,
} from "@medusajs/framework"
import { sendEmailWorkflow } from "../workflows/send-email"
export default async function productCreateHandler({
event: { data },
container,
}: SubscriberArgs<{ id: string }>) {
await sendEmailWorkflow(container).run({
input: {
id: data.id,
},
})
}
export const config: SubscriberConfig = {
event: "product.created",
}
```