npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

medusa-notification-provider

v0.0.9

Published

Medusa v2 notification plugin: FCM, WhatsApp, and Telegram order notifications.

Readme

medusa-notification-provider

Medusa v2 notification plugin: FCM push, WhatsApp Cloud API, and global Telegram order notifications.

Plugin Overview

medusa-notification-provider provides:

  • FCM provider (id: "fcm") — push via Firebase Cloud Messaging
  • WhatsApp provider (id: "whatsapp") — session text via Meta Cloud API (type: "text")
  • Telegram order notifications — singleton channel config, admin settings UI, workflow + BullMQ queue for order.placed / order.fulfillment_created / order.canceled

Medusa Version

Built for Medusa v2 (@medusajs/framework / @medusajs/medusa 2.12.4).

Installation & Setup

1) Install

npm install medusa-notification-provider firebase-admin bullmq ioredis zod

2) Register in medusa-config.ts

import { defineConfig } from "@medusajs/framework/utils"

export default defineConfig({
  plugins: [
    {
      resolve: "medusa-notification-provider",
      options: {},
    },
  ],
  modules: [
    {
      resolve: "@medusajs/medusa/notification",
      options: {
        providers: [
          {
            resolve: "medusa-notification-provider/providers/fcm",
            id: "fcm",
            options: {
              channels: ["push"],
              projectId: "<firebase-project-id>",
              clientEmail: "<service-account-email>",
              privateKey: "<service-account-private-key>",
            },
          },
          {
            resolve: "medusa-notification-provider/providers/whatsapp",
            id: "whatsapp",
            options: {
              channels: ["sms"],
              enabled: true,
              accessToken: "<meta-access-token>",
              wabaId: "<whatsapp-business-account-id>",
              phoneNumberId: "<phone-number-id>",
              graphAPIVersion: "v21.0",
            },
          },
        ],
      },
    },
    {
      resolve: "medusa-notification-provider/modules/telegram-notification",
    },
  ],
})

3) Environment variables (Telegram)

| Variable | Required | Purpose | |---|---|---| | TELEGRAM_BOT_TOKEN | Yes (for send/test) | Bot token from BotFather. Never logged or stored in DB. | | REDIS_URL | Yes (for order queue) | Redis for BullMQ. Enqueue failures are caught and logged as failed without blocking order flows. |

4) Database migrations

Module migrations ship with the plugin (telegram_config, telegram_notification_log).

  • Plugin local Medusa app (when changing schema): npx medusa db:generate telegram-notification
  • Host app: npx medusa db:migrate (auto-discovers registered module migrations)

Telegram Order Notifications

Behavior

  1. Admin configures one global Telegram channel ID and clicks Send Test Message.
  2. On success, verified = true. Real order notifications only send when verified.
  3. Subscribers for order.placed, order.fulfillment_created, and order.canceled run send-telegram-notification workflow.
  4. Workflow loads the order via query.graph, applies idempotency + verification gates, formats HTML, enqueues to BullMQ.
  5. In-process worker (MVP) sends with global limiter 30 msg/sec and per-chat throttle 1 msg/sec. Messages are delayed, never dropped, on rate limit.
  6. If REDIS_URL is unset (common in local), messages are sent directly (no queue) so order events still notify.

Idempotency

  • App check: skip if a pending or sent log exists for (order_id, event_type).
  • DB backstop: partial unique index on (order_id, event_type) where status is pending or sent.
  • Unique violation on pending insert is treated as already handled (skip), not as failure.

Admin UI

Sidebar route Telegram Notifications (src/admin/routes/telegram-notifications/page.tsx):

  • Channel ID input + format hint + help for finding -100… IDs
  • Save / Send Test Message (button disabled ~3s after each test click)
  • Verified badge

Admin API

| Method | Path | Description | |---|---|---| | GET | /admin/telegram-settings | Singleton config (no bot token) | | POST | /admin/telegram-settings | Save channel_id; resets verified when changed | | POST | /admin/telegram-settings/verify | Direct Telegram send (bypasses queue, no log row); sets verified on success; returns Telegram error text on failure |

Channel ID validation (Zod + UI): ^(-100\d{10,13}|@[a-zA-Z0-9_]{5,32})$

Worker placement (MVP)

BullMQ worker runs in-process with the Medusa API server (lazy-init on first enqueue). Server restarts drop in-flight throttle timing; queue processing is tied to API uptime. A dedicated worker process is out of scope for v1.

FCM / WhatsApp Providers

Unchanged. Configure via Notification module provider options as in the install example above.

FCM options

| Option | Required | Description | |---|---|---| | projectId | Yes | Firebase project ID | | clientEmail | Yes | Service account email | | privateKey | Yes | Service account private key (\\n normalized) |

WhatsApp options

| Option | Required | Default | Description | |---|---|---|---| | enabled | No | true | Enable/disable sends | | accessToken | Yes | - | Meta Graph access token | | wabaId | Yes | - | WhatsApp Business Account ID | | phoneNumberId | Yes | - | Sender phone number ID | | graphAPIVersion | No | v21.0 | Graph API version |

OTP / SMS via the Medusa notification module uses channel: "sms" and content.text. Map that channel to this provider. The client always sends a Cloud API session text payload (type: "text"). Recipients must be E.164 (+917567273055); Graph to is sent as digits only (917567273055).

Session text is delivered only inside Meta's 24-hour customer care window (the user must have messaged the business number first). Outside that window Graph returns (#131047) Re-engagement message.

Health routes

  • GET /admin/plugin — admin health
  • GET /store/plugin — store health

Testing

npm test

Covers channel ID validation, HTML escaping, message formatting, verification/idempotency gates, enqueue failure when Redis is missing, and WhatsApp session-text payload / Graph error parsing.

Troubleshooting

Telegram: bot is not a member / chat not found

Add the bot as Channel Admin with Post Messages, then use the correct -100… ID from Telegram Web.

Telegram: channel saved but no order messages

Send a successful Test Message first (verified must be true). Changing channel_id resets verification.

Telegram: REDIS_URL is not configured

Order notifications need Redis for the queue. Test messages bypass the queue and only need TELEGRAM_BOT_TOKEN.

FCM / WhatsApp

See provider-specific errors in server logs; ensure credentials and recipient format (+ for WhatsApp phones) are correct.

OTP / SMS via Medusa notification module sends content.text. The WhatsApp provider reads content.text first, then data.body / data.title.

Issue: WhatsApp OTP marked success but not delivered

Problem: Notification row is success with a wamid, but the user never sees the OTP. They often check SMS, while the provider sends WhatsApp.

Root Cause: Graph API to was sent as +91…. Meta can return HTTP 200 + message id, then fail delivery. Session type: "text" also only delivers inside the 24-hour window.

Solution: toWhatsAppRecipient strips the number to country-code digits before send. Graph errors now include error_data.details. Requests without a message id are treated as failure.

Prevention:

  • Keep channels: ["sms"] on the WhatsApp provider
  • Pass E.164 phones (+917567273055)
  • Ask the recipient to check WhatsApp (including Message requests / Business chats)
  • For OTP to users who have never messaged the business, an approved authentication template is required (not session text)