Integration Module 2.0 for Medusa is outRead the announcement
N

Notifications

Unified multi-channel notification studio for Medusa v2: visual and raw template builder, event mappings, consent ledger, abandoned cart recovery, broadcasts, and Email, WhatsApp, Telegram, SMS, Slack and sandbox providers.

npm install @vicacha-devs/medusa-plugin-notifications
Built by
Version
0.1.1
Last updated
4 days ago
Monthly downloads
Loading downloads

()

Unified Multi-Channel Notification Studio, Visual Block & Raw Template Builder, DB Event Orchestrator, TCPA/10DLC Consent Ledger, Abandoned Cart Recovery, Customer Group Broadcasts, and Multi-Driver Transport Provider Suite for Medusa v2 ().

Combines a full-featured database-driven Notification Studio Module () with 6 Medusa Transport Providers (, , , , , ), a Decoupled Medusa Admin UI () across 7 routes with 10-locale i18n (including RTL Arabic), a Typed SDK & React Hooks layer, and strictly optional PDF attachment & B2B buyer contact resolution.


Table of Contents


1. Overview & Highlights

CapabilityDescription
Dual Architecture1. Standalone Notification Studio Module (): Visual Block Tree Builder, Raw HTML/Text/JSON templates, DB-driven Event-to-Template Mappings, PII-redacted Delivery Ledger, TCPA/10DLC Consent Ledger, Customer Group Broadcasts, and Dummy OTP Sandbox.
2. 6 Built-in Providers: , , , , , and .
Dual-Mode Template EngineBuild templates visually using a 12-block hierarchical tree (, , , , , , , , , , , ) or write Raw HTML/Text/JSON with multi-pass interpolation (, , Go-style , and ).
11+ System Presets & 1-Click CloneShips with read-only presets across Email, WhatsApp/OpenWA, Telegram, SMS, and Slack (, , , , , etc.) that clone into editable database rows ( + ) with 1 click.
Multi-Driver WhatsApp & OpenWA supports Official Meta Cloud API ( — approved WABA templates, interactive buttons, session text) AND Self-Hosted Gateways ( with on port via & with , WAHA, and Evolution API v2) for free-form rich text and PDF invoice attachments.
Telegram Merchant Topics & Customer Bot supports Merchant Supergroup / Forum Topic Alerts ( or with routing + Admin verification gate) AND Customer Direct Messages ( linked via bot webhook, buttons, and PDF uploads) with 30 msg/s global & 1 msg/s per-chat rate limiting.
Multi-Driver SMS, Consent & Cart Recovery supports Twilio (SMS/MMS + Messaging Service SID + error classification), Signal House, MSG91 Flow, SMSAPI, and Generic HTTP Webhook, backed by GSM-7 / UCS-2 segment calculation, TCPA/10DLC / consent tracking, and a 15-minute Abandoned Cart Recovery job with a 24h per-phone cooldown.
Zero-Hard-Dependency PDF AttachmentsAutomatically attaches generated PDF Invoices, Packing Slips, or Credit Notes from () to Email, WhatsApp/OpenWA, and Telegram notifications when is configured, and resolves B2B accounting contacts.
10 Built-In Locales (Backend + Admin UI)Ships with , , , , , , , , , and dictionaries for both notification template rendering () and the Medusa Admin UI ( with RTL support for Arabic).

2. Installation & Configuration

1. Install the package

2. Configure

3. Run Database Migrations

npx medusa db:migrate

3. Architecture & Data Model ( DML Models)

All database tables managed by () use the prefix to prevent naming collisions.

ModelTable NameID PrefixPurpose
Stores multi-channel templates (, , , , , , , , , ).
Hierarchical visual block tree nodes (, , , , ).
Database-driven event routing rules (, , , , , , , , , , ).
Idempotent, PII-masked audit ledger (, , , , , , , , , , , ). Enforced by partial unique index .
TCPA/10DLC & bot opt-in ledger (, , , , , , ).
Customer Group or custom recipient broadcast campaigns (, , , , , , , , , ).
Operational channel & driver configuration (, , , , , , ).
Captured local/staging notifications and extracted OTP codes (, , , , , , , ).

4. Dual-Mode Template Renderer & i18n

Visual Block Tree Mode ()

Compiles a parent-child tree of rows into channel-specific outputs (responsive HTML + plain-text fallback for Email, Markdown + interactive buttons for WhatsApp, sanitized HTML + for Telegram, compact text + GSM-7/UCS-2 metrics for SMS, and Block Kit JSON for Slack):

  • 12 Supported Block Types: , , , , , , , , , , , .

Raw Template Mode ()

Allows merchants to author raw HTML, Markdown, plain text, or JSON directly while enjoying full multi-pass variable interpolation.

Multi-Pass Variable Interpolation

  1. Aliasing: Maps friendly keys (e.g., ) before interpolation.
  2. Two-Prefix Recursive Interpolation: Resolves against hydrated entity data and against the active locale dictionary.
  3. Go-Style Template Syntax: Resolves and (compatible with and templates).

System Presets ()

Includes built-in read-only presets across all channels (, , , , , , , , , , , , ). Any preset can be cloned into an editable DB template via ().

10 Built-In Locales

Both the backend renderer () and the Admin UI () include complete dictionaries for:

  • (English), (Spanish), (Polish), (German), (French), (Portuguese), (Italian), (Dutch), (Turkish), and (Arabic with automatic RTL layout).

5. 6 Notification Transport Providers

Provider IDModule Import PathChannelDrivers & Capabilities
Multi-profile ( via / ) Nodemailer SMTP transport (, e.g. Resend ) + HTTP Email API Relay (, ) with base64 PDF attachment support.
4 Drivers: (Official Meta Graph API v21/v25 approved WABA templates, interactive buttons, documents, session text with digits-only recipient formatting), ( & with + ), (WAHA , ), and (Evolution API v2 , ).
Supports Merchant Supergroup / Forum Topic Alerts ( or with and Admin verification gate) and Customer Direct Messages ( linked via bot webhook, , and multipart PDF uploads) with 30 msg/s global & 1 msg/s per-chat rate limiting.
5 Drivers: (SMS/MMS + Messaging Service SID + – permanent vs. retryable error classification), (10DLC SMS/MMS), (Flow API), (OAuth Bearer SMS), and (Generic HTTP Webhook), with GSM-7 (160/153 chars) and UCS-2 (70/67 chars) segment calculation.
Dispatches Slack Block Kit JSON ( + ) to SSRF-validated Slack Incoming Webhook URLs.
Intercepts notifications and automatically extracts 4–8 digit OTP codes into and in-memory storage for zero-cost local/staging inspection.

6. Event Orchestration, Subscribers & Scheduled Jobs

Subscribers ()

All subscribers invoke non-blockingly so store operations never fail if an external carrier is unreachable:

  • : , , , , , , , , .
  • : , , , (normalized to ), (normalized to ), .
  • : , , , , , , , , , .

Scheduled Jobs ()

  • (, schedule: ): Scans active incomplete carts older than (default min), verifies explicit TCPA opt-in in , enforces a strict 24-hour cooldown per phone number (), and dispatches notifications with a direct checkout recovery URL.
  • (, schedule: ): Prunes expired rows older than (default days) and processes due scheduled broadcast campaigns.

7. Optional & B2B Integration

Implemented in with zero hard dependency:

  1. Automatic PDF Document Attachments (): When an event mapping specifies (e.g., ), the orchestrator checks if () is registered in the Medusa container, generates or retrieves the base64 PDF buffers for the order, and attaches them to Email, WhatsApp (, , , ), or Telegram () dispatches.
  2. B2B Accounting Contact Resolution (): Resolves B2B company accounting email, phone, WhatsApp, and Telegram chat ID from an optional / module or / when is selected.

8. REST API Reference (Admin & Store)

Admin Endpoints ( & )

MethodPathDescription
List all templates ( presets, , and DB templates) with optional , , and filters.
Create a new DB template with blocks, or clone a read-only preset via .
Retrieve a single template and its hierarchical block tree ( and ).
Update template metadata, raw content, variable map, and replace its block tree.
Delete a custom database template () and its blocks.
Live-render any template or ad-hoc block tree against real entity data () or mock context (, , , , , , ) in any of the 10 locales.
List all event-to-template mappings (), supported events, recipient rules, and SMTP sender profiles.
Create a new Event → Channel → Template → Recipient Rule mapping.
Update an existing event mapping.
Delete an event mapping.
List operational channel configs (), SMTP sender profiles, and supported WhatsApp/SMS drivers.
Save channel driver/gateway settings (automatically resets if Telegram changes) or run to send a live test message.
List PII-masked delivery logs () with optional , , , , and filters.
List customer group broadcast campaigns () and consent ledger summary counts (, ).
Create and optionally immediately dispatch () a broadcast campaign to opted-in recipients.
List captured sandbox messages and extracted OTP codes ( + in-memory store).
Clear all captured sandbox messages.
Ad-hoc manual notification dispatch or full event simulation ( + ), with optional .
Health and capability summary endpoint for the Admin plugin surface.

Storefront & Webhook Endpoints ( & )

MethodPathDescription
Record customer SMS/WhatsApp/Telegram opt-in or opt-out consent (). Enforces Anti-IDOR check via .
Meta WhatsApp Cloud API webhook verification challenge (, , ).
Inbound webhook handler (with and timing-safe HMAC verification) for / / / (/ + delivery receipts), (, ), and / / (// and /).
Public storefront health endpoint.

9. Typed SDK & React Hooks

Typed SDK ()

Provides , pre-configured singletons (, ), and hierarchical query key factories (, ):

React Hooks ()

  • Template Hooks (): , , , , , .
  • Event Mapping Hooks (): , , , .
  • Channel Config Hooks (): , .
  • Dispatch, Logs, Broadcasts, Sandbox & Consent Hooks (): , , , , , , , .
  • Widget State Hook (): .

10. Decoupled Admin Notification Studio ()

The Medusa Admin extension uses and modular components (, each lines) across 7 dedicated routes plus an Order Details widget:

Route / ZoneFileLayoutPurpose
Overview dashboard with metrics and links to all 6 studio workspaces.
Visual Block Tree & Raw Template Builder, 1-click preset cloning, and live multi-locale entity preview.
Store Event → Channel → Template → Recipient Rule mapping orchestrator with PDF invoice attachment toggle.
Multi-driver gateway configuration (Meta Cloud / OpenWA / WAHA / Evolution, Telegram Supergroup verification gate, SMS carrier selector).
PII-masked, idempotent delivery ledger table with status badges and error inspection.
Customer group broadcast campaign dispatcher & history (main) + TCPA/10DLC consent summary (side).
Local/Staging Dummy OTP & multi-channel sandbox message inspector.
WidgetDisplays per-order notification history and 1-click manual resend across Email, WhatsApp, Telegram, or SMS with optional PDF invoice attachment.

11. Security Architecture

  1. Meta WhatsApp Graph API Digits-Only Formatting (): Strips the leading from E.164 phone numbers specifically when building Official Meta Cloud API payloads (, , ), preventing Meta's HTTP 200 silent drop bug while preserving standard E.164 () for Twilio, Signal House, and self-hosted gateways.
  2. PII Masking & Payload Redaction (, ): Every row masks recipient emails/phones (, ), stores a salted SHA-256 , and redacts secrets, tokens, passwords, OTP codes, and large base64 buffers from .
  3. SSRF Protection (): Validates all merchant-configured gateway URLs (OpenWA, WAHA, Evolution, Slack Webhooks, SMS Webhooks, MMS ) against private/loopback IPv4/IPv6 ranges and cloud metadata endpoints () in production.
  4. Timing-Safe Webhook HMAC Verification (): Uses on raw request bodies () for inbound provider webhooks ().
  5. Partial Unique Idempotency Index (): Prevents duplicate notifications for the same when , while allowing manual retries of dispatches.

12. Development & Testing