afromessage-sdk
v1.0.0
Published
Node.js SDK for AfroMessage API
Downloads
11
Maintainers
Readme
AfroMessage SDK (Node.js)
A simple Node.js SDK for integrating with AfroMessage SMS/OTP API.
Installation
npm install afromessage-sdkAfroMessage SDK (Node.js)
A simple Node.js SDK for integrating with the AfroMessage SMS & OTP API. Send SMS, bulk campaigns, and OTP challenges with just a few lines of code.
installation
npm install afromessage-sdkUsage
1. Import & Initialize
const AfroMessage = require("afromessage-sdk");
const client = new AfroMessage({
apiKey: "YOUR_API_KEY", // Replace with your AfroMessage API key
senderId: "YOUR_SENDER_ID", // e.g. short code or alphanumeric sender
});2. Send a Single SMS
(async () => {
try {
const response = await client.sms.send({
to: "+251911234567",
message: "Hello from AfroMessage SDK!",
});
console.log("✅ SMS Response:", response);
} catch (err) {
console.error("❌ Error sending SMS:", err.message);
}
})();3. Send Bulk SMS
(async () => {
try {
const response = await client.sms.bulkSend({
to: ["+251911234567", "+251988765432"],
message: "Bulk SMS test via AfroMessage SDK",
campaign: "Promo Campaign",
});
console.log("✅ Bulk SMS Response:", response);
} catch (err) {
console.error("❌ Error sending bulk SMS:", err.message);
}
})();4. Send OTP (Challenge)
(async () => {
try {
const otp = await client.challenge.send({
to: "+251911234567",
prefix: "Your code is",
suffix: "Do not share with anyone.",
length: 6, // digits in the OTP
});
console.log("✅ OTP Sent:", otp);
} catch (err) {
console.error("❌ Error sending OTP:", err.message);
}
})();5. Verify OTP
(async () => {
try {
const verify = await client.challenge.verify({
to: "+251911234567",
code: "123456", // The OTP the user enters
});
console.log("✅ OTP Verify Response:", verify);
} catch (err) {
console.error("❌ Error verifying OTP:", err.message);
}
})();API Coverage
📩 SMS
sms.send({ to, message })
sms.bulkSend({ to[], message, campaign })
🔑 OTP
challenge.send({ to, prefix, suffix, length })
challenge.verify({ to, code })
Contributing
Pull requests are welcome! For major changes, please open an issue first to discuss what you’d like to change.
