@sadikkhan02/adapter-msg91

中文文档
1.0.0发布于 2026/11/02MITTypeScriptESM + CJS零依赖

MSG91 SMS provider adapter for NotifyKit

原始使用文档
文档目录8 节
  1. Installation
  2. Configuration
  3. Environment Variables
  4. Usage
  5. DLT & Regulatory Compliance (India TCCCPR)
  6. Error Classification & DLQ Routing
  7. Credential Sanitization
  8. License

@sadikkhan02/adapter-msg91

India-optimized, TRAI/DLT compliant SMS adapter for NotifyKit using MSG91 Flow API.

This package provides a lightweight, enterprise SMS transport for NotifyKit using the MSG91 Flow API. Built using native Node.js fetch, it requires zero external vendor SDKs or heavy runtime dependencies. It supports Indian Telecom Commercial Communications Customer Preference Regulations (TCCCPR/DLT) template variables and sender IDs.


Installation

npm install @sadikkhan02/notifykit @sadikkhan02/adapter-msg91

Zero Vendor SDK: Uses Node's built-in fetch API. No third-party MSG91 SDK required.


Configuration

Environment Variables

VariableRequiredDescription
MSG91_AUTH_KEYYesMSG91 API Authentication Key
MSG91_FLOW_IDYesMSG91 Flow ID (maps to approved DLT Template ID)
MSG91_SENDER_IDYesApproved 6-character alphanumeric DLT Header/Sender ID (e.g. NOTIFY)

Usage

import { createNotifier } from '@sadikkhan02/notifykit';
import { Msg91SmsProvider } from '@sadikkhan02/adapter-msg91';

const smsProvider = new Msg91SmsProvider({
  authKey: process.env.MSG91_AUTH_KEY!,
  flowId: process.env.MSG91_FLOW_ID!,
  sender: process.env.MSG91_SENDER_ID!, // e.g. 'NOTIFY'
});

const notifier = createNotifier({
  providers: {
    sms: {
      type: 'msg91',
      adapter: smsProvider,
    },
  },
});

// Register SMS template matching your DLT Flow placeholders
notifier.registerTemplate(
  'otp-flow',
  'Your verification code is {{otp}}. Valid for 10 minutes. - NotifyKit',
);

// Enqueue SMS (returns immediately with jobId)
const { jobId } = await notifier.notify({
  to: { phone: '+919876543210' }, // International format with country code
  channels: ['sms'],
  template: 'otp-flow',
  data: {
    otp: '918234',
    // Dynamic variables pass directly to MSG91 Flow recipient payload
  },
});

// Start processing SMS queue
notifier.startWorker({ channels: ['sms'], concurrency: 5 });

DLT & Regulatory Compliance (India TCCCPR)

[!WARNING] In India, the Telecom Regulatory Authority of India (TRAI) mandates that all commercial and transactional SMS traffic must be registered on an approved Distributed Ledger Technology (DLT) platform (e.g., Vilpower, PingConnect, Airtel, Jio DLT).

  1. Entity Registration: Your organization must possess an active Principal Entity (PE) ID.
  2. Sender ID: Senders must be exact 6-character alphanumeric headers approved on the DLT portal.
  3. Template Approval: SMS content must exactly match an approved DLT Template ID. Variables ({#var#}) in DLT correspond to dynamic fields in NotifyKit's data payload.

Unregistered templates or sender mismatches are permanently rejected by Indian telecom operators.


Error Classification & DLQ Routing

Response / HTTP StatusCauseretryableBullMQ Action
429 Too Many RequestsMSG91 Flow API rate throttlingtrueRetried with exponential backoff
500, 502, 503, 504Gateway or MSG91 upstream outagetrueRetried with exponential backoff
ETIMEDOUT, ECONNRESETSocket / TLS handshake interruptiontrueRetried with exponential backoff
401 UnauthorizedInvalid authKeyfalseRouted directly to DLQ (no retry)
400 Bad RequestDLT template mismatch, invalid Flow ID, unapproved senderfalseRouted directly to DLQ (no retry)
422 UnprocessableInvalid mobile number formatfalseRouted directly to DLQ (no retry)

Credential Sanitization

All error logs and provider results automatically strip authKey headers, bearer tokens, and sensitive query parameters to prevent leakage in telemetry and monitoring systems.


License

MIT

版本与发布记录

@sadikkhan02/adapter-msg91 共发布 2 个版本,首次发布于 2026/11/02;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.0.0latest2026/11/021 天前
0.0.0-stage2026/11/021 天前

关于 @sadikkhan02/adapter-msg91 的常见问题

@sadikkhan02/adapter-msg91 是什么?

用于NotifyKit的MSG91 SMS提供程序适配器

如何安装 @sadikkhan02/adapter-msg91?

在项目目录运行 npm install @sadikkhan02/adapter-msg91,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@sadikkhan02/notifykit(^1.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@sadikkhan02/adapter-msg91 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@sadikkhan02/adapter-msg91 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@sadikkhan02/adapter-msg91 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@sadikkhan02/adapter-msg91 可以商用吗?

@sadikkhan02/adapter-msg91 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@sadikkhan02/adapter-msg91 还在维护吗?

最新版本 1.0.0 发布于 2026/11/02(1 天前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/11/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。