Skip to content

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:

text
BULKSMSBD_API_KEY=your-key
BULKSMSBD_SENDER_IDS=SENDER
GREENWEB_API_KEY=your-key
GREENWEB_SENDER_IDS=SENDER

Leave 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:

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.

bash
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.

URLDescription
http://localhost:8080HTTP API. See HTTP API.
http://localhost:8080/healthLiveness. GET returns { "status": "ok" }.
http://localhost:8080/metricsPrometheus text.
http://localhost:8080/portalDashboard.

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.

VariableDefaultDescription
REDIS_URLredis://localhost:6379Redis connection string. Set redis://redis:6379 when Redis is the Compose service named redis.
PORT8080 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_KEYnoneWhen set, BulkSMSBd is enabled.
BULKSMSBD_SENDER_IDSnoneComma-separated sender IDs. Required when BULKSMSBD_API_KEY is set. BULKSMSBD_SENDER_ID sets one ID.
BULKSMSBD_API_SECRETnoneOptional BulkSMSBd secret.
BULKSMSBD_BASE_URLhttps://api.bulksmsbd.com/v1Vendor base URL.
GREENWEB_API_KEYnoneWhen set, GreenWeb is enabled.
GREENWEB_SENDER_IDSnoneComma-separated sender IDs. Required when GREENWEB_API_KEY is set. GREENWEB_SENDER_ID sets one ID.
GREENWEB_BASE_URLhttps://api.greenweb.com.bd/api.phpVendor base URL.
SANDBOX_ENABLEDunsettrue, yes, or 1 registers the sandbox provider.
SANDBOX_SENDER_IDSSANDBOXUsed when the sandbox provider is enabled.
ROUTING_STRATEGYSee belowpriority_failover, weighted_distribution, health_aware, rule_based, or fixed.
ROUTING_WEIGHTSnoneproviderId:weight pairs, separated by commas. Example: bulksmsbd:80,greenweb:20.
ROUTING_RULESnoneprefix:providerId pairs, separated by commas. default:providerId is the fallback rule. Example: 017:bulksmsbd,default:bulksmsbd.
PULSE_INTERVAL_MINUTES5Delay 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_STRATEGY does not update the profile. Change the strategy in the dashboard, or delete the sms-data volume 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.

CommandDescription
bun run src/worker/index.tsAnother queue consumer.
bun run src/jobs/index.tsReads each active built-in provider balance and repeats on PULSE_INTERVAL_MINUTES.
yaml
  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