Self-hosting
The self-hosted server is the HTTP API. Clients in any language call POST /v1/sms/send. A Node.js or Bun application that uses the library calls SMSBridge.send() and does not run this server.
The image is ghcr.io/srejonkhan/sms-bridge. It listens on port 8080. The container serves the HTTP API, the dashboard, and one worker. Redis stores the queue. Configuration is a set of environment variables. Compose reads those variables from a .env file in the same directory as the Compose file.
The image delivers through BulkSMSBd, GreenWeb, and the sandbox provider.
Requirements
- Docker, with Compose
- Credentials for BulkSMSBd or GreenWeb, or
SANDBOX_ENABLED=true
Usage
Create a directory. In that directory, create .env:
BULKSMSBD_API_KEY=your-key
BULKSMSBD_SENDER_IDS=SENDER
GREENWEB_API_KEY=your-key
GREENWEB_SENDER_IDS=SENDERLeave a provider's variables empty to disable that provider. At least one provider is required. For a server that accepts messages and does not call a vendor, set SANDBOX_ENABLED=true and omit the vendor variables.
Create compose.yaml:
x-sms-bridge-env: &sms-bridge-env
REDIS_URL: redis://redis:6379
BULKSMSBD_API_KEY: ${BULKSMSBD_API_KEY:-}
BULKSMSBD_SENDER_IDS: ${BULKSMSBD_SENDER_IDS:-}
GREENWEB_API_KEY: ${GREENWEB_API_KEY:-}
GREENWEB_SENDER_IDS: ${GREENWEB_SENDER_IDS:-}
SANDBOX_ENABLED: ${SANDBOX_ENABLED:-}
ROUTING_STRATEGY: ${ROUTING_STRATEGY:-}
ROUTING_WEIGHTS: ${ROUTING_WEIGHTS:-}
ROUTING_RULES: ${ROUTING_RULES:-}
services:
redis:
image: redis:7-alpine
restart: unless-stopped
volumes:
- redis-data:/data
sms-bridge:
image: ghcr.io/srejonkhan/sms-bridge:latest
restart: unless-stopped
ports:
- "8080:8080"
environment: *sms-bridge-env
volumes:
- sms-data:/app/data
depends_on:
- redis
volumes:
redis-data:
sms-data:REDIS_URL is written in the Compose file. It points at the redis service on the Compose network. The provider values come from .env.
docker compose up -d
docker compose logs sms-bridge | grep "API Key"The first start creates the database and a profile. The log line contains API Key:. That value is the bearer token for the HTTP API.
| URL | Description |
|---|---|
http://localhost:8080 | HTTP API. See HTTP API. |
http://localhost:8080/health | Liveness. GET returns { "status": "ok" }. |
http://localhost:8080/metrics | Prometheus text. |
http://localhost:8080/portal | Dashboard. |
docker compose down stops the containers. The SQLite file remains in the sms-data volume. The path inside the container is /app/data/sms-bridge.db unless DB_PATH is set.
Environment variables
Variables that hold credentials are read from the process environment. In Compose, define them in .env. An empty value leaves that setting unset.
| Variable | Default | Description |
|---|---|---|
REDIS_URL | redis://localhost:6379 | Redis connection string. Set redis://redis:6379 when Redis is the Compose service named redis. |
PORT | 8080 in the image. 3000 when the process is started from a checkout. | TCP port. The published port in Compose has to match. |
DB_PATH | /app/data/sms-bridge.db in the image. ./data/sms-bridge.db from a checkout. | SQLite database file. |
BULKSMSBD_API_KEY | none | When set, BulkSMSBd is enabled. |
BULKSMSBD_SENDER_IDS | none | Comma-separated sender IDs. Required when BULKSMSBD_API_KEY is set. BULKSMSBD_SENDER_ID sets one ID. |
BULKSMSBD_API_SECRET | none | Optional BulkSMSBd secret. |
BULKSMSBD_BASE_URL | https://api.bulksmsbd.com/v1 | Vendor base URL. |
GREENWEB_API_KEY | none | When set, GreenWeb is enabled. |
GREENWEB_SENDER_IDS | none | Comma-separated sender IDs. Required when GREENWEB_API_KEY is set. GREENWEB_SENDER_ID sets one ID. |
GREENWEB_BASE_URL | https://api.greenweb.com.bd/api.php | Vendor base URL. |
SANDBOX_ENABLED | unset | true, yes, or 1 registers the sandbox provider. |
SANDBOX_SENDER_IDS | SANDBOX | Used when the sandbox provider is enabled. |
ROUTING_STRATEGY | See below | priority_failover, weighted_distribution, health_aware, rule_based, or fixed. |
ROUTING_WEIGHTS | none | providerId:weight pairs, separated by commas. Example: bulksmsbd:80,greenweb:20. |
ROUTING_RULES | none | prefix:providerId pairs, separated by commas. default:providerId is the fallback rule. Example: 017:bulksmsbd,default:bulksmsbd. |
PULSE_INTERVAL_MINUTES | 5 | Delay between balance sync runs. Used by the balance process described below. |
When ROUTING_STRATEGY is unset, the profile created on first start uses rule_based if ROUTING_RULES is set, otherwise weighted_distribution if ROUTING_WEIGHTS is set, otherwise priority_failover.
Note: The routing strategy is stored on that profile. A later change to
ROUTING_STRATEGYdoes not update the profile. Change the strategy in the dashboard, or delete thesms-datavolume before starting again. Deleting the volume deletes the database, including the profile API key.
A checkout of this repository may also load ./configs.yaml. A string in that file may be written as ${BULKSMSBD_API_KEY}. The named variable is required, and its value replaces the placeholder before the file is parsed. When the same provider is present in the file and in the environment, the environment supplies api_key, api_secret, sender_ids, and base_url for any of those fields that are set. The container image does not need configs.yaml.
Additional processes
The sms-bridge service runs one worker. Add a service from the same image to consume the queue with more processes, or to refresh balances. Reuse the sms-bridge-env anchor and the sms-data volume.
| Command | Description |
|---|---|
bun run src/worker/index.ts | Another queue consumer. |
bun run src/jobs/index.ts | Reads each active built-in provider balance and repeats on PULSE_INTERVAL_MINUTES. |
worker:
image: ghcr.io/srejonkhan/sms-bridge:latest
restart: unless-stopped
environment: *sms-bridge-env
volumes:
- sms-data:/app/data
command: ["bun", "run", "src/worker/index.ts"]
depends_on:
- redis