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#

Note: The Local Notification Module Provider is registered by default in your application. It's configured to run on the feed channel.

Add the module into the providers array of the Notification Module:

Note: Only one provider can be defined for a channel.
medusa-config.ts
1module.exports = defineConfig({2  // ...3  modules: [4    {5      resolve: "@medusajs/medusa/notification",6      options: {7        providers: [8          // ...9          {10            resolve: "@medusajs/medusa/notification-local",11            id: "local",12            options: {13              channels: ["email"],14            },15          },16        ],17      },18    },19  ],20})

Local Notification Module Options#

OptionDescription

channels

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:

src/subscribers/order-placed.ts
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 createNotifications method of the Notification Module's main service to create a notification to be sent to the admin dashboard. By specifying the feed channel, the Local Notification Module Provider is used to send the notification.
  • The template property of the createNotifications method's parameter must be set to admin-ui.
  • The data property allows you to customize the content of the admin notification. It must contain title and description properties.

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.

Was this page helpful?
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break