Node.js
No official SDK package yet. Use the native fetch API or any HTTP client.
Installation
npm install axios # or use native fetch (Node 18+)
Setup
// notifo.js
const BASE_URL = 'https://api.notifo.cloud';
const API_KEY = process.env.NOTIFO_API_KEY;
const headers = {
'Content-Type': 'application/json',
'X-Api-Key': API_KEY,
};
export async function sendText(channel, to, text, opts = {}) {
const res = await fetch(`${BASE_URL}/v1/notify/${channel}/text`, {
method: 'POST',
headers,
body: JSON.stringify({ to, text, ...opts }),
});
if (!res.ok) throw new Error(`Notifo error ${res.status}: ${await res.text()}`);
return res.json();
}
export async function sendMedia(channel, to, type, url, opts = {}) {
const res = await fetch(`${BASE_URL}/v1/notify/${channel}/media`, {
method: 'POST',
headers,
body: JSON.stringify({ to, type, url, ...opts }),
});
if (!res.ok) throw new Error(`Notifo error ${res.status}: ${await res.text()}`);
return res.json();
}
export async function sendBulk(channel, messages) {
const res = await fetch(`${BASE_URL}/v1/notify/${channel}/bulk`, {
method: 'POST',
headers,
body: JSON.stringify({ messages }),
});
if (!res.ok) throw new Error(`Notifo error ${res.status}: ${await res.text()}`);
return res.json();
}
Usage
import { sendText, sendMedia, sendBulk } from './notifo.js';
// Send a text message
const msg = await sendText('whatsapp', '+905551234567', 'Hello from Notifo!');
console.log(msg.id, msg.status);
// Send an image
await sendMedia('whatsapp', '+905551234567', 'image', 'https://example.com/photo.jpg', {
caption: 'Check this out!',
});
// Send in bulk
const results = await sendBulk('whatsapp', [
{ to: '+905551111111', text: 'Hi Alice' },
{ to: '+905552222222', text: 'Hi Bob' },
]);
// Idempotent send
await sendText('whatsapp', '+905551234567', 'Your OTP: 123456', {
idempotencyKey: 'otp-user-42-ts-1700000000',
});
Webhook verification (Express)
const crypto = require('crypto');
const express = require('express');
const app = express();
app.post(
'/webhooks/notifo',
express.raw({ type: 'application/json' }),
(req, res) => {
const sig = req.headers['x-notifo-signature'];
const rawBody = req.body; // Buffer
const secretHash = crypto.createHash('sha256').update(process.env.NOTIFO_WEBHOOK_SECRET).digest('hex');
const expected = 'sha256=' + crypto.createHmac('sha256', secretHash).update(rawBody).digest('hex');
if (!crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected))) {
return res.status(401).send('Invalid signature');
}
const event = JSON.parse(rawBody);
console.log(`[${event.event}] message=${event.messageId} status=${event.status}`);
res.sendStatus(200);
}
);