msg-nexus
v1.0.0
Published
Modular Node.js messaging SDK with multi-channel support and automatic fallback
Downloads
6
Maintainers
Readme
MsgNexus
MsgNexus is a powerful, modular messaging SDK for Node.js that allows you to send messages via SMS, WhatsApp, Voice, and Email using multiple providers. It supports automatic fallback and multi-channel sending, making it ideal for production-ready applications.
Features
- Multi-channel messaging: SMS, WhatsApp, Voice, Email
- Provider support:
- SMS/WhatsApp/Voice: MSG91, Twilio
- Email: Gmail, Outlook, SMTP, MSG91
- Template rendering: Use placeholders like
{{name}}and{{otp}} - Automatic fallback between providers
- Multi-channel sending in a single call
- Modular design, easy to extend with more providers
- Ready for NPM publishing and self-hosted use
Installation
npm install msg-nexusQuick Start
- Import and Configure Providers
import MsgNexus from "msg-nexus";
const hub = new MsgNexus({
providers: {
msg91: { authKey: "MSG91_KEY", senderId: "ABCDEF", country: "91" },
twilio: { accountSid: "TWILIO_SID", authToken: "TWILIO_TOKEN", from: "+1234567890" },
email: {
gmail: { user: "[email protected]", appPassword: "APP_PASSWORD" },
outlook: { user: "[email protected]", pass: "PASSWORD" },
msg91: { authKey: "MSG91_KEY", sender: "[email protected]" },
smtp: { host: "smtp.mailtrap.io", port: 587, auth: { user: "xxx", pass: "yyy" }, from: "[email protected]" }
}
},
options: { fallback: true, multiChannel: true }
});Usage Examples
- Sending SMS
await hub.send({
to: "+919876543210",
channels: ["sms"],
providers: ["msg91"],
template: "Hello {{name}}, your OTP is {{otp}}",
data: { name: "Rahul", otp: "123456" }
});- Sending WhatsApp Message
await hub.send({
to: "+919876543210",
channels: ["whatsapp"],
providers: ["twilio"],
template: "Hello {{name}}, your order #{{orderId}} is ready",
data: { name: "Rahul", orderId: "INV-1234" }
});- Sending Voice Call
await hub.send({
to: "+919876543210",
channels: ["voice"],
providers: ["twilio"],
messageUrl: "https://your-server.com/voice-message.xml"
});- Triggering Flow (MSG91 Only)
await hub.send({
to: ["+919876543210", "+919812345678"],
channels: ["flow"],
providers: ["msg91"],
flowId: "YOUR_FLOW_ID",
variables: [
{ name: "otp", value: "123456" },
{ name: "name", value: "Rahul" }
]
});Sending Email
- GMAIL
await hub.send({ channel: "email", provider: "gmail", to: "[email protected]", template: "Hello {{name}}, welcome to our platform!", data: { name: "Rahul" } });- Outlook
await hub.send({ channel: "email", provider: "outlook", to: "[email protected]", template: "Hello {{name}}, your invoice #{{invoice}} is ready", data: { name: "Rahul", invoice: "INV-1234" } });- SMTP
await hub.send({ channel: "email", provider: "smtp", to: "[email protected]", template: "Hello {{name}}, your order has been shipped", data: { name: "Rahul" } });- MSG91 (EMAIL)
await hub.send({ channel: "email", provider: "msg91", to: "[email protected]", template: "Hi {{name}}, your OTP is {{otp}}", data: { name: "Rahul", otp: "123456" } });
Multi-Channel Notification with Automatic Fallback
await hub.send({
to: ["+919876543210", "[email protected]"],
channels: ["sms", "whatsapp", "email"],
providers: ["twilio", "msg91", "gmail"],
template: "Hello {{name}}, your OTP is {{otp}}",
data: { name: "Rahul", otp: "123456" },
type: "transactional"
});Supported Channels
| Channel | Providers | Notes | |-----------|----------------------------|---------------------------------| | SMS | MSG91, Twilio | Transactional & OTP | | WhatsApp | MSG91, Twilio | Template messages supported | | Voice | MSG91, Twilio | Call messages | | Flow | MSG91 | Custom flows for SMS/WhatsApp | | Email | Gmail, Outlook, SMTP, MSG91| Subject + Body templates |
Extending Providers
You can add new providers by implementing a send(to, message, options) function in a separate file and importing it into msg-nexus.
BADGES
