Local Notification Module Provider
The Local Notification Module Provider simulates sending a notification, but only logs the notification's details in the terminal. This is useful for development.
Register the Local Notification Module#
feed channel.Add the module into the providers array of the Notification Module:
Local Notification Module Options#
| Option | Description |
|---|---|
| The channels this notification module is used to send notifications for. While the local notification module doesn't actually send the notification, it's important to specify its channels to make sure it's used when a notification for that channel is created. |
Send Notifications to the Admin Notification Panel#
The Local Notification Module Provider can also be used to send notifications to the Medusa Admin's notification panel. You can send notifications to the admin dashboard when a certain action occurs using a subscriber, a custom workflow or a workflow hook.
For example, to send an admin notification whenever an order is placed, create a subscriber at src/subscribers/order-placed.ts with the following content:
5import { Modules } from "@medusajs/framework/utils"6 7export default async function orderPlacedHandler({8 event: { data },9 container,10}: SubscriberArgs<{ id: string }>) {11 const notificationModuleService = container.resolve(Modules.NOTIFICATION)12 13 await notificationModuleService.createNotifications({14 to: "",15 channel: "feed",16 template: "admin-ui",17 data: {18 title: "New order",19 description: `A new order has been placed`,20 },21 })22}23 24export const config: SubscriberConfig = {25 event: "order.placed",26}
In this subscriber, you:
- Resolve the Notification Module's main service from the Medusa container.
- Use the
createNotificationsmethod of the Notification Module's main service to create a notification to be sent to the admin dashboard. By specifying thefeedchannel, the Local Notification Module Provider is used to send the notification. - The
templateproperty of thecreateNotificationsmethod's parameter must be set toadmin-ui. - The
dataproperty allows you to customize the content of the admin notification. It must containtitleanddescriptionproperties.
Test Sending Notification#
To test this out, start the Medusa application:
Then, place an order. The subscriber will run, sending a notification to the Medusa Admin's notification panel.