Skip to content

nimbasms/nimbasms-supabase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Nimba SMS Γ— Supabase πŸ“²

License: MIT Deno Supabase

Send SMS from your Supabase project through Nimba SMS β€” the West African leader in business mobile communication.

This repository ships a production-ready set of Supabase Edge Functions, SQL migrations and end-to-end examples for connecting Nimba SMS to Supabase Auth, Database triggers, and your front-end.


Features

  • πŸš€ Edge Functions for every Nimba endpoint β€” send-sms, sms-webhook, check-balance, get-sendernames, list-messages, list-contacts, create-contact, send-otp, confirm-otp, verify-otp
  • πŸ”‘ Two OTP flows out of the box β€” Nimba's managed verifications (send-otp / confirm-otp) and a custom hash-and-store flow (verify-otp)
  • πŸ“¦ Typed Deno client β€” NimbaSMSClient with timeouts, Basic auth, strict array payloads, typed errors
  • πŸ—„οΈ Audit trail in Postgres β€” one row per recipient in sms_logs, grouped by batch_id, status updated by Nimba's delivery-report webhook
  • πŸ” Row Level Security β€” users only see their own SMS history
  • πŸ‡¬πŸ‡³ Smart phone formatting β€” auto-prefixes Guinean numbers with 224
  • 🧩 Ready-to-fork examples β€” phone OTP sign-in (HTML + JS) and order confirmation via Postgres trigger
  • πŸ›‘οΈ Webhook signature verification β€” shared-secret authentication for inbound delivery reports

Prerequisites

Requirement Where
Nimba SMS account www.nimbasms.com
ACCOUNT_SID + AUTH_TOKEN
(labelled SERVICE_ID and SECRET_TOKEN on the Nimba dashboard)
Nimba dashboard β†’ API KEYS
Approved Sender ID Nimba dashboard β†’ Sender Names
Supabase project supabase.com
Supabase CLI β‰₯ 1.200 npm install -g supabase

Quickstart

# 1. Clone & link to your Supabase project
git clone https://github.com/nimbasms/nimbasms-supabase
cd nimbasms-supabase
supabase link --project-ref <your-project-ref>

# 2. Configure secrets
supabase secrets set \
  NIMBA_ACCOUNT_SID=your_account_sid \
  NIMBA_AUTH_TOKEN=your_auth_token \
  NIMBA_DEFAULT_SENDER=YourBrand \
  NIMBA_WEBHOOK_SECRET="$(openssl rand -hex 32)"

# 3. Push migrations
supabase db push

# 4. Deploy functions
supabase functions deploy \
  send-sms sms-webhook check-balance \
  get-sendernames list-messages list-contacts create-contact \
  send-otp confirm-otp verify-otp

# 5. Send a test
curl -X POST "https://<project-ref>.supabase.co/functions/v1/send-sms" \
  -H "Authorization: Bearer $SUPABASE_ANON_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": ["224623273737", "224621000000"],
    "sender_name": "MyApp",
    "message": "Hello from Supabase + Nimba SMS"
  }'

Detailed walkthrough β†’ docs/QUICKSTART.md.


The send contract

The Nimba REST API exposes a single sending endpoint, POST /v1/messages, that accepts a to array of 1..50 recipients in every call. This repo mirrors that contract exactly:

  • One Edge Function β€” send-sms β€” handles both single-recipient sends and batches; there is no separate "campaign" endpoint to learn.
  • to is an array of bare-digit phone numbers with country code (e.g. "224623273737"). A leading + is stripped. Local Guinean numbers (8–9 digits) automatically get the 224 prefix prepended.
  • Max 50 recipients per call. Split your audience client-side and call the function multiple times for larger broadcasts.
curl -X POST "$SUPABASE_URL/functions/v1/send-sms" \
  -H "Authorization: Bearer $SUPABASE_ANON_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "to": ["224623273737", "224621000000"],
    "sender_name": "MyApp",
    "message": "Hello from Supabase + Nimba SMS"
  }'

Usage examples

From supabase-js

import { createClient } from "@supabase/supabase-js";
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);

await supabase.functions.invoke("send-sms", {
  body: {
    to: ["224620000000"],
    sender_name: "MyApp",
    message: "Your order has been confirmed.",
  },
});

Broadcast (still one function β€” just pass more numbers)

await supabase.functions.invoke("send-sms", {
  body: {
    to: ["224620000000", "224621000000", "224622000000"],
    sender_name: "MyShop",
    message: "Don't miss our weekend offer!",
  },
});

For audiences >50, split client-side and call again:

for (const chunk of chunkArray(allRecipients, 50)) {
  await supabase.functions.invoke("send-sms", {
    body: { to: chunk, sender_name: "MyShop", message: "..." },
  });
}

Read your logs

const { data } = await supabase
  .from("sms_logs")
  .select("recipient, status, created_at, batch_id")
  .order("created_at", { ascending: false })
  .limit(20);

Use cases

  • πŸ“± Phone OTP sign-in β€” custom OTP flow on top of Supabase Auth β†’ see examples/phone-otp-auth and docs/AUTH_OTP_GUIDE.md
  • 🧾 Transactional notifications β€” order confirmations, shipping updates, password resets β†’ see examples/order-confirmation-trigger
  • πŸ“£ Marketing broadcasts β€” pass any number of recipients to send-sms (chunk to 50 client-side)
  • 🚨 Internal alerts β€” wire pg_net to send-sms from any Postgres trigger to notify ops on critical events

Project layout

supabase/
β”œβ”€ config.toml
β”œβ”€ functions/
β”‚  β”œβ”€ _shared/           ← NimbaSMSClient, CORS, types
β”‚  β”œβ”€ send-sms/          POST  /v1/messages
β”‚  β”œβ”€ sms-webhook/       ← inbound delivery reports
β”‚  β”œβ”€ check-balance/     GET   /v1/accounts
β”‚  β”œβ”€ get-sendernames/   GET   /v1/sendernames
β”‚  β”œβ”€ list-messages/     GET   /v1/messages
β”‚  β”œβ”€ list-contacts/     GET   /v1/contacts
β”‚  β”œβ”€ create-contact/    POST  /v1/contacts
β”‚  β”œβ”€ send-otp/          POST  /v1/verifications              (managed OTP)
β”‚  β”œβ”€ confirm-otp/       PATCH /v1/verifications/{id}         (managed OTP)
β”‚  └─ verify-otp/        ← custom OTP flow (hash + store)
└─ migrations/            ← sms_logs table + RLS policies
examples/
β”œβ”€ phone-otp-auth/        ← static HTML + JS demo
└─ order-confirmation-trigger/   ← pg_net + Postgres trigger
docs/
β”œβ”€ QUICKSTART.md
β”œβ”€ API_REFERENCE.md
└─ AUTH_OTP_GUIDE.md

Roadmap

  • Helper hook for Supabase Auth Phone provider once the platform supports custom SMS providers
  • Pre-built React / Vue / Svelte components for the OTP UI
  • groups Edge Function (GET /v1/groups) for contact-group management
  • Optional pg_cron job to backfill delivered_at by polling GET /messages/{id}

Open an issue if you'd like to drive any of these.


Contributing

Pull requests are welcome! Please:

  1. Open an issue first for non-trivial changes so we can align on scope.
  2. Keep Edge Functions free of heavy dependencies β€” prefer the Deno standard library and small esm.sh-hosted packages with pinned versions.
  3. Format code with deno fmt and run deno check on every file.

License

MIT Β© Nimba SMS. See LICENSE.

Support

About

Supabase Code module for communicating with Nimba SMS

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors