Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 36 additions & 105 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
# Medusa plugin notification emails
# Medusa plugin notification

A comprehensive notification plugin for Medusa v2 that provides a flexible, block-based template system for multiple channels (Email and Slack) with internationalization support, custom translations, and seamless integration with Medusa's notification module.
Medusa v2 plugin for building and sending transactional notifications from one place.
It provides a template system, admin builder, and rendering workflows for email and Slack.

## Features

- **Multi-Channel Templates**: Pre-built templates for Email and Slack channels
- **Block-Based System**: Templates are built using a flexible block system that can be stored in a database for future builder functionality
- **Email Templates**: Customizable email templates built with [React Email](https://react.email) for common use cases
- **Slack Templates**: Slack Block Kit compatible templates for Slack notifications
- **Template Service Architecture**: Unified `AbstractTemplateService` with channel-specific implementations (`EmailTemplateService`, `SlackTemplateService`)
- **Automatic Interpolation**: Smart variable interpolation system that processes `{{data.*}}` and `{{translations.*}}` placeholders recursively
- **Internationalization**: Built-in support for multiple locales (Polish, English)
- **Customizable**: Override translations and customize templates without modifying core files
- **Integration**: Integrates with Medusa's notification module
- **Admin Panel**: Preview and test templates directly from Medusa Admin
- **Type-Safe**: Full TypeScript support with exported types
- **HTML & Plain Text**: Automatically generates both HTML and plain text versions of emails
- Build and manage notification templates for two channels: email and Slack
- Use three template sources: built-in (`system`), database-managed (`db`), and code-registered (`external`)
- Build templates quickly with a reusable block system instead of writing full markup from scratch
- Edit `db` templates in Medusa Admin using a block-based builder
- Render notifications through dedicated workflows and pass output to Medusa notification providers
- Customize translations and register external templates without changing core plugin code

## Compatibility

- **Medusa Version**: `>= 2.8.8`
- **Node Version**: `>= 20`
- Medusa: `>= 2.8.8`
- Node.js: `>= 20`

## Installation

Expand All @@ -30,110 +25,46 @@ npm install @codee-sh/medusa-plugin-notification-emails
yarn add @codee-sh/medusa-plugin-notification-emails
```

## Quick Start
## Basic setup

### 1. Register the Plugin

Add to your `medusa-config.ts`:
Register plugin in `medusa-config.ts`:

```typescript
module.exports = defineConfig({
plugins: [
"@codee-sh/medusa-plugin-notification-emails"
]
})
```

### 2. Configure Notification Provider

Set up a notification provider - see [Configuration Documentation](./docs/configuration.md) for details.

### 3. Use Templates

The plugin includes built-in subscribers that automatically send email notifications for various events. You can also use templates directly in your code:

#### Email Templates

```typescript
import { emailService, TEMPLATES_NAMES } from "@codee-sh/medusa-plugin-notification-emails/templates/emails"

const { html, text, subject } = await emailService.render({
templateName: TEMPLATES_NAMES.ORDER_PLACED,
data: templateData,
options: { locale: "pl" }
{
resolve: "@codee-sh/medusa-plugin-notification-emails",
options: {
customTranslations: {},
extend: {
services: [],
},
},
},
],
})
```

#### Slack Templates

```typescript
import { slackService, TEMPLATES_NAMES } from "@codee-sh/medusa-plugin-notification-emails/templates/slack"

const { blocks } = await slackService.render({
templateName: TEMPLATES_NAMES.INVENTORY_LEVEL,
data: templateData,
options: { locale: "en" }
})
```

**Note**: Templates use a block-based system where each template is defined as an array of blocks. The system automatically interpolates variables like `{{data.order.id}}` and `{{translations.headerTitle}}` throughout the blocks.

See [Templates Documentation](./docs/templates.md) for detailed usage examples.

## Available Templates

### Email Templates

- **[Order Placed](./docs/templates/order-placed.md)** (`order-placed`) - Order confirmation email template
- **Order Completed** (`order-completed`) - Order completion notification template
- **[Contact Form](./docs/templates/contact-form.md)** (`contact-form`) - Contact form submission email template
- **Order Updated** (`order-updated`) - Order update notification template
- **Inventory Level** (`inventory-level`) - Inventory level notification template

### Slack Templates

- **Inventory Level** (`inventory-level`) - Inventory level notification for Slack
- **Product** (`product`) - Product notification for Slack
- **Product Variant** (`product-variant`) - Product variant notification for Slack

See [Templates Documentation](./docs/templates.md) for general template information and [Blocks Documentation](./docs/blocks.md) for details on the block system.

## Built-in Subscribers

The plugin includes automatic email notifications for the following events:

- **`order.placed`** - Sends order confirmation email when an order is placed
- **`order.completed`** - Sends order completion notification when an order is completed

These subscribers automatically:
- Fetch order data from Medusa
- Render email templates using React Email
- Send notifications via Medusa's notification module
- Respect custom translations configured in plugin options

See [Configuration Documentation](./docs/configuration.md) for details on customizing subscriber behavior.

## Admin Panel

Access the template preview in Medusa Admin at `/app/notifications/render`. See [Admin Panel Documentation](./docs/admin.md) for details.
Then continue with configuration and usage guides in `docs/`.

## Documentation

- [Templates](./docs/templates.md) - Using templates and creating custom subscribers
- [Blocks System](./docs/blocks.md) - Understanding the block-based template system
- [Translations](./docs/translations.md) - Internationalization and custom translations
- [Configuration](./docs/configuration.md) - Plugin configuration options
- [Admin Panel](./docs/admin.md) - Admin interface usage
- [Creating Custom Templates](./docs/contributing/creating-templates.md) - Guide for creating new templates
- [Configuration](./docs/configuration.md)
- [Templates](./docs/templates.md)
- [Blocks](./docs/blocks.md)
- [Translations](./docs/translations.md)
- [Admin](./docs/admin.md)
- [Creating Templates](./docs/contributing/creating-templates.md)

## Exports

The plugin exports the following:
Public entrypoints:

- `@codee-sh/medusa-plugin-notification-emails/templates/emails` - Email template service and types
- `@codee-sh/medusa-plugin-notification-emails/templates/slack` - Slack template service and types
- `@codee-sh/medusa-plugin-notification-emails/templates/shared` - Shared template utilities
- `@codee-sh/medusa-plugin-notification-emails/utils` - Utility functions
- `@codee-sh/medusa-plugin-notification-emails/workflows`
- `@codee-sh/medusa-plugin-notification-emails/modules/*`
- `@codee-sh/medusa-plugin-notification-emails/providers/*`
- `@codee-sh/medusa-plugin-notification-emails/utils`
- `@codee-sh/medusa-plugin-notification-emails/admin`

## License

Expand Down
48 changes: 22 additions & 26 deletions docs/admin.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
# Admin Panel Documentation
# Admin Panel Guide

The plugin provides an admin interface for previewing and testing email templates.
This page describes the administrator experience in the plugin panel.

## Accessing the Admin Panel
## What you can do

Navigate to **Notifications > Preview Template** in your Medusa Admin dashboard, or directly access:
### Notifications

```
/app/notifications/render
```
- view notification history
- review notification details
- verify which events triggered notifications

## Features
### Templates

### Template Selection
- browse available templates
- create and edit template content
- organize block order and structure
- update text and content fields

Choose from available templates:
- **Order Placed**: Order confirmation email template
- **Contact Form**: Contact form submission email template
## Typical admin workflow

### Template Preview
1. Open templates and select the template you want to update.
2. Edit content and block layout.
3. Save changes.
4. Trigger or wait for a notification event.
5. Check notification history to confirm output.

Each template group provides:
## Related documentation

1. **Live Preview**: See how the email will look with sample data
2. **Locale Switching**: Test different language versions
3. **Custom Data**: Modify template data to see how it affects the output
4. **HTML/Text View**: Toggle between HTML and plain text versions

## Using the Preview

1. **Select Template**: Choose a template type from the dropdown
2. **Fill Data**: Enter or modify template data
3. **Choose Locale**: Select language (Polish or English)
4. **Preview**: View the rendered email template
5. **Test**: Use the preview to verify translations and formatting
- [Templates Documentation](./templates.md)
- [Blocks Documentation](./blocks.md)
- [Configuration Documentation](./configuration.md)
Loading