- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
Menu
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
Send Notification with the Notification Module
In this guide, you'll learn how to send a notification using the Notification Module.
Use the Create Method#
In your resource, such as a subscriber, resolve the Notification Module's main service and use its create
method:
6import { INotificationModuleService } from "@medusajs/framework/types"7 8export default async function productCreateHandler({9 event: { data },10 container,11}: SubscriberArgs<{ id: string }>) {12 const notificationModuleService: INotificationModuleService =13 container.resolve(Modules.NOTIFICATION)14 15 await notificationModuleService.createNotifications({16 to: "shahednasser@gmail.com",17 channel: "email",18 template: "product-created",19 data,20 })21}22 23export const config: SubscriberConfig = {24 event: "product.created",25}
The create
method accepts an object or an array of objects having the following properties:
to
stringThe destination to send the notification to. When sending an email, it'll be the email address. When sending an SMS, it'll be the phone number.
channel
stringThe channel to send the notification through. For example,
email
or sms
. The module provider defined for that channel will be used to send the notification.template
stringThe ID of the template used for the notification. This is useful for providers like SendGrid, where you define templates within SendGrid and use their IDs here.
data
Record<string, unknown>The data to pass along to the template, if necessary.
For a full list of properties accepted, refer to this guide.
Was this page helpful?