@sneekin/sdk
v0.3.2
Published
Node.js SDK for the Sneek Messaging API
Downloads
163
Readme
@sneekin/sdk
Node.js SDK for the Sneek Send API — deliver OTPs and transactional messages over SMS, WhatsApp, and email through Sneek's pre-approved DLT sender, WhatsApp BSP number, and warmed email domain.
Sneek delivers; your app generates and verifies its own OTP codes.
Installation
npm install @sneekin/sdkQuick start
import { Sneek } from '@sneekin/sdk';
const sneek = new Sneek({
apiUrl: process.env.SNEEK_API_URL ?? 'https://api.sneek.in',
apiKey: process.env.SNEEK_API_KEY!, // snk_live_… or snk_test_…
});
// Generic send (body OR template)
await sneek.messages.send({
to: '+919876543210',
body: 'Your OTP to login to ConfHub is 482917. Do not share it.',
channel: 'sms', // 'auto' | 'sms' | 'whatsapp' | 'email'
});
// Channel helpers
await sneek.sendSMS('+919876543210', 'Your code is 482917');
await sneek.sendWhatsApp('+919876543210', 'Your code is 482917');
await sneek.sendEmail('[email protected]', 'Your code is 482917');
// OTP body-formatting helper (you generate the code yourself)
await sneek.sendOTP({
to: '+919876543210',
code: '482917',
appName: 'ConfHub',
channel: 'auto',
});
// DLT/provider templates (server-rendered)
await sneek.messages.send({
to: '+919876543210',
channel: 'sms',
template: 'otp_login',
variables: { appName: 'ConfHub', otp: '482917' },
});Message intent (type)
Declare whether a message is an OTP or a plain communication so Sneek picks the correct approved provider template — instead of guessing from the body text:
// Auth / OTP template
await sneek.messages.send({ to, body: 'Your code is 482917', type: 'otp' });
// Utility / communication template
await sneek.messages.send({
to,
body: 'Your booking BK-7781 is confirmed.',
type: 'transactional',
});type accepts 'otp' or 'transactional'. When omitted, Sneek infers intent
from the body (which can misclassify digit groups like BK-7781 as an OTP), so
passing type explicitly is recommended. sendOTP(...) always tags
type: 'otp' for you.
Authentication
Every request is sent with Authorization: Bearer <apiKey>. Mint keys from the
Sneek admin (/o/<org>/applications/<id> → API keys). Keys are shown once;
store them in your environment / secret manager. snk_test_… keys hit dev
adapters; snk_live_… keys deliver for real.
Errors & retries
- Non-2xx responses throw
SneekApiErrorwith{ status, type, title, detail }(RFC-7807 problem-details). - Transient
5xxand network failures are retried with exponential backoff (maxRetries, default 2;retryBaseMs, default 200ms).
Idempotency & rate limits
Pass idempotencyKey to make a send safely repeatable — the first call is
processed and its result is replayed for any retry with the same key (per
application), so a dropped connection never sends twice. This pairs with the
SDK's automatic 5xx retries.
await sneek.messages.send({
to: '+919876543210',
type: 'otp',
body: 'Your code is 482917',
idempotencyKey: 'order-4815-otp',
});Sends are rate-limited per application (your plan's per-minute / per-day quota),
per recipient, and per source IP. Exceeding a limit throws SneekApiError with
status === 429; the problem body carries retry_after (seconds).
import { SneekApiError } from '@sneekin/sdk';
try {
await sneek.sendSMS('+91…', 'hi');
} catch (err) {
if (err instanceof SneekApiError && err.status === 401) {
// invalid / revoked key
}
}API
| Method | Description |
| --- | --- |
| messages.send(input) | Send a message (body or template; optional type intent). Returns 202 accepted envelope. |
| messages.get(id) | Fetch a previously-sent message by id. |
| sendSMS/sendWhatsApp/sendEmail(to, body, clientRef?) | Channel-pinned helpers. |
| sendOTP({ to, code, appName?, channel?, template?, variables? }) | Format + send an OTP body. |
License
UNLICENSED — © Abblor Tech Pvt Ltd.
