1. Installation & Environment Configuration
Install the official package or use standard fetch / axios. Store your EnvoiSMS API key (env_live_...) in a secure .env configuration file.
Integrate SMS delivery in Morocco using Node.js, TypeScript, and EnvoiSMS REST API. Covers Axios/Fetch, +212 validation, and Express webhook listeners.

Install the official package or use standard fetch / axios. Store your EnvoiSMS API key (env_live_...) in a secure .env configuration file.
Dispatching an outbound SMS is straightforward:
const res = await fetch('https://api.envoisms.ma/v1/messages', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.ENVOISMS_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
recipient: '+212612345678',
message: 'Your verification code is 492019.',
sender_id: 'MYBRAND'
})
});
const data = await res.json();Use libraries like libphonenumber-js to ensure the recipient number belongs to Moroccan mobile ranges (prefixes 6 and 7 under ANRT allocations) before triggering the API request.
Configure an Express route to process async delivery receipts. Verify the cryptographic signature using crypto.createHmac('sha256', secret).update(rawBody).digest('hex').
EnvoiSMS supports high throughput with queue workers (BullMQ, Celery). Monitor balance quotas via GET /v1/billing/quota to avoid service interruptions.
Local routes to IAM, Orange and Inwi, with automatic failover between routes and delivery status sent by webhook.
WhatsApp Business API from 0.65 MAD per message with optimal ROI.
Full compliance with Moroccan personal data protection regulations (CNDP).