@mandarvl/mapi
v1.0.1
Published
Mapi SMS API client (lightweight TypeScript client)
Maintainers
Readme
@mandarvl/mapi
Lightweight TypeScript client for the Mapi SMS API (Madagascar operators).
Installation
npm install @mandarvl/mapiQuick usage
import Mapi from '@mandarvl/mapi';
const client = new Mapi(process.env.MAPI_API_KEY || 'msk_your-api-key');
// Send single SMS
await client.send('0340000000', 'Votre commande est prête.');
// Same message to many recipients (Excel/CSV, numbers in column A)
await client.sendUniqueSmsToRecipients('./destinataires.xlsx', 'Nos bureaux seront fermés lundi.');
// Personalized bulk (Excel/CSV with custom message in last column)
await client.sendBulkSms('./destinataires.xlsx');
// Message history
const messages = await client.getMessages(10, 0);
// OTP
await client.requestOtp('0340000000');
await client.verifyOtp('0340000000', '123456');
const otps = await client.getOtps(10, 0);
// Available SMS units
const balance = await client.getAvailableSms();Notes
- Store the key in
MAPI_API_KEY(or a secret manager). Never ship it in front-end or mobile code. - Auth uses the
Tokenheader with the raw API key (msk_…), noBearerprefix and noAuthorizationheader. - POST requests send
multipart/form-datawith capitalized field names (Recipient,Message,Channel, …). - Requires Node.js 18+ (global
fetch/FormData/Blob).
