Medusa
Send Medusa's order, shipping and account emails through Wakio templates.
npm install wakio
// medusa-config.ts
import { defineConfig } from "@medusajs/framework/utils"
module.exports = defineConfig({
modules: [
{
resolve: "@medusajs/medusa/notification",
options: {
providers: [
{
resolve: "wakio/medusa",
id: "wakio",
options: { apiKey: process.env.WAKIO_API_KEY, channels: ["email"] },
},
],
},
},
],
})
Send from a subscriber
The notification's template is the key of a Wakio template, and its data fills the template's placeholders.
// src/subscribers/order-placed.ts
import type { SubscriberArgs, SubscriberConfig } from "@medusajs/framework"
import { Modules } from "@medusajs/framework/utils"
export default async function orderPlaced({ event, container }: SubscriberArgs<{ id: string }>) {
const orders = container.resolve(Modules.ORDER)
const notifications = container.resolve(Modules.NOTIFICATION)
const order = await orders.retrieveOrder(event.data.id)
if (!order.email) return
await notifications.createNotifications({
to: order.email,
channel: "email",
template: "order-placed",
data: { order_number: String(order.display_id), total: String(order.total) },
})
}
export const config: SubscriberConfig = { event: "order.placed" }
Each value in data must be a string, number, true, false or null. Pass the fields your template uses, not the whole order: a nested object is refused, and the error names its key.
To send without a template, give the notification content with a subject and html or text. The Medusa provider does not support cc or bcc, and a notification with provider_data is refused.
Medusa does not pass providers an id for each notification, so Wakio cannot tell a retried subscriber from a new email. If a subscriber can run twice for one order, guard it in your own code.
Templates are set up with Wakio for now: email [email protected].