1 import { CardList } from "docs-ui"
2
3 export const metadata = {
4 title: `Notification Module`,
5 }
6
7 # {metadata.title}
8
9 In this document, you'll learn about the Notification Module and its providers.
10
11 <Note title="Looking for managed email service?">
12
13 Cloud offers [Medusa Emails](!cloud!/emails), a managed email service that allows you to send transactional emails with zero configuration. It is built on top of the Notification Module and provides an easy way to manage email notifications in your Cloud projects with insights and deliverability features.
14
15 </Note>
16
17 ## What is the Notification Module?
18
19 The Notification Module exposes the functionalities to send a notification to a customer or user. For example, sending an order confirmation email. Medusa uses the Notification Module in its core commerce features for notification operations, and you can use it in your custom features as well.
20
21 ---
22
23 ## How to Use the Notification Module?
24
25 You can use the Notification Module as part of the [workflows](!docs!/learn/fundamentals/workflows) you build for your custom features. A workflow is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.
26
27 In a step of your workflow, you can resolve the Notification Module's service and use its methods to send notifications.
28
29 For example:
30
31 ```ts
32 import { Modules } from "@medusajs/framework/utils"
33 import {
34 createStep,
35 createWorkflow,
36 } from "@medusajs/framework/workflows-sdk"
37
38 const step1 = createStep(
39 "step-1",
40 async ({}, { container }) => {
41 const notificationModuleService = container.resolve(
42 Modules.NOTIFICATION
43 )
44
45 await notificationModuleService.createNotifications({
46 to: "customer@gmail.com",
47 channel: "email",
48 template: "product-created",
49 data,
50 })
51 }
52 )
53
54 export const workflow = createWorkflow(
55 "workflow-1",
56 () => {
57 step1()
58 }
59 )
60 ```
61
62 In the example above, you create a workflow that has a step. In the step, you resolve the service of the Notification Module from the [Medusa container](!docs!/learn/fundamentals/medusa-container).
63
64 Then, you use the `createNotifications` method of the Notification Module to send an email notification.
65
66 Find a full example of sending a notification in the [Send Notification guide](./send-notification/page.mdx).
67
68 ---
69
70 ## What is a Notification Module Provider?
71
72 A Notification Module Provider implements the underlying logic of sending notification. It either integrates a third-party service or uses custom logic to send the notification.
73
74 By default, Medusa uses the [Local Notification Module](./local/page.mdx) which only simulates sending the notification by logging a message in the terminal.
75
76 Medusa provides other Notification Modules that actually send notifications, such as the [SendGrid Notification Module Provider](./send-notification/page.mdx). You can also [Create a Notification Module Provider](/references/notification-provider-module).
77
78 <CardList
79 items={[
80 {
81 title: "Local",
82 href: "/infrastructure-modules/notification/local",
83 badge: {
84 variant: "neutral",
85 children: "For Development"
86 }
87 },
88 {
89 title: "SendGrid",
90 href: "/infrastructure-modules/notification/sendgrid",
91 badge: {
92 variant: "green",
93 children: "For Production"
94 }
95 },
96 {
97 title: "Mailchimp",
98 href: "/integrations/guides/mailchimp",
99 badge: {
100 variant: "blue",
101 children: "Tutorial",
102 }
103 },
104 {
105 title: "Resend",
106 href: "/integrations/guides/resend",
107 badge: {
108 variant: "blue",
109 children: "Tutorial",
110 }
111 },
112 {
113 title: "Slack",
114 href: "/integrations/guides/slack",
115 badge: {
116 variant: "blue",
117 children: "Tutorial",
118 }
119 },
120 {
121 title: "Twilio SMS",
122 href: "/how-to-tutorials/tutorials/phone-auth#step-3-integrate-twilio-sms",
123 badge: {
124 variant: "blue",
125 children: "Tutorial",
126 }
127 }
128 ]}
129 itemsPerRow={2}
130 />
131
132 ---
133
134 ## Notification Module Provider Channels
135
136 When you send a notification, you specify the channel to send it through, such as `email` or `sms`.
137
138 You register providers of the Notification Module in `medusa-config.ts`. For each provider, you pass a `channels` option specifying which channels the provider can be used in. Only one provider can be setup for each channel.
139
140 For example:
141
142 ```ts title="medusa-config.ts" highlights={[["19"]]}
143 import { Modules } from "@medusajs/framework/utils"
144
145 // ...
146
147 module.exports = {
148 // ...
149 modules: [
150 // ...
151 {
152 resolve: "@medusajs/medusa/notification",
153 options: {
154 providers: [
155 // ...
156 {
157 resolve: "@medusajs/medusa/notification-local",
158 id: "notification",
159 options: {
160 channels: ["email"],
161 },
162 },
163 ],
164 },
165 },
166 ],
167 }
168 ```
169
170 The `channels` option is an array of strings indicating the channels this provider is used for.