smsforwarder-api

command module
v0.0.0-...-fce5618 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: AGPL-3.0 Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README ΒΆ

smsforwarder-api

Multi-user backend for the SMS Forwarder app

Receives SMS uploaded by the phone client, authenticates the user, and fans each message out to that user's configured channels (Telegram). A single Go binary with an embedded SQLite store and a built-in operator console β€” no external services.

πŸ“± Client: SMSForwarder Β Β·Β  🌐 SMS Forwarder β€” forward SMS to Telegram

Go SQLite Telegram License

About

smsforwarder-api is the server half of SMS Forwarder. The phone uploads each incoming SMS to POST /api/sms; the server authenticates the device, stores the message briefly, and delivers it to the user's channels. Channel configuration lives here (not in the app), so channels can be added or changed without rebuilding the client.

It is relay-and-forget: an SMS body lives in the outbox only until it is delivered (or finally given up), then it is deleted. Only metadata is kept in the delivery log, visible to the operator. Modeled on the sibling secretary project β€” one binary, pure-Go SQLite (no CGO), no message queue, no ORM.

The official instance is operated by ShuttleLab at smsforwarder-api.shuttlelab.org, and the released app talks to it out of the box. Because the code is open source (AGPL-3.0), anyone can also run their own instance.

Key Features

  • Multi-user β€” open registration; every user's data is isolated (all queries scoped by user_id). A message can never be delivered to the wrong user.
  • Device-token auth β€” sign in once with username + password; the server issues a long-lived, per-device token (stored only as a SHA-256 hash) that the app sends as a Bearer credential. Tokens are individually revocable.
  • Telegram channel β€” one shared bot handles every user. Users bind by tapping a deep link and pressing Start (/bind flow); the bot writes their chat_id straight into the store. No tokens to copy. Optionally, the operator can set a broadcast target (PUBLISH_CHAT_ID, or the admin console settings page): a Telegram channel/group where every received SMS is also published, in addition to each user's own delivery.
  • Durable delivery β€” an outbox with an exponential-backoff retry engine survives restarts; long messages are auto-split under Telegram's 4096-char limit; delivery is idempotent via a per-message key.
  • Self-healing bindings β€” when Telegram reports a recipient is unreachable (403: bot blocked / can't initiate), the binding is cleared automatically so the app prompts the user to re-bind. There is also a one-click "reset all Telegram bindings" for when the shared bot is replaced.
  • Operator admin console β€” an embedded web UI (session-cookie login) for delivery logs, user management (ban / revoke devices / delete), per-table data maintenance, and bot settings. Binds to localhost by default.
  • No cloud dependencies β€” no GMS/FCM, no external DB. A single binary plus one SQLite file.

Tech Stack

  • Language: Go 1.25
  • Storage: modernc.org/sqlite (pure Go, no CGO), WAL mode
  • Telegram: github.com/go-telegram/bot (long polling)
  • HTTP / admin UI: standard library net/http + html/template
  • Passwords: bcrypt (golang.org/x/crypto)

Getting Started

Prerequisites

  • Go 1.25+

Run

cp .env.example .env      # optional; sane defaults otherwise
go run .                  # API on HTTP_ADDR (default 0.0.0.0:8090)

Configuration (env, see .env.example): DB_PATH, HTTP_ADDR, RATE_LIMIT_PER_MIN, BOT_TOKEN, BOT_USERNAME, PUBLISH_CHAT_ID, ADMIN_ADDR, ADMIN_USER, ADMIN_PASSWORD. The Telegram bot token/username may also be set in the admin console (DB overrides env; a changed token needs a restart). The broadcast destination (PUBLISH_CHAT_ID, a channel/group chat id) is also editable in the admin console and applies to the next SMS β€” no restart needed.

API

Method Path Auth Notes
GET /healthz – liveness
POST /api/register – {username, password}
POST /api/login – {username, password, device_label?} β†’ {device_token}
POST /api/logout Bearer revoke current device
GET /api/channels Bearer list
POST /api/channels Bearer {type, config, enabled?}
GET/PATCH/DELETE /api/channels/{id} Bearer read / edit / delete
POST /api/channels/{id}/test Bearer send a test message now
POST /api/channels/{id}/bind-code Bearer Telegram bind code + deep link
POST /api/sms Bearer {sender, content, timestamp(ms), client_msg_id}

Send Authorization: Bearer <device_token> (returned once at login). Channel config per type: telegram β†’ {"chat_id":<int>} (filled by /bind).

Admin console

Enabled when ADMIN_USER + ADMIN_PASSWORD are set; served on ADMIN_ADDR (default 127.0.0.1:8091). Keep it on localhost and reach it over an SSH tunnel:

ssh -L 8091:127.0.0.1:8091 <server>   # then open http://127.0.0.1:8091/admin

Deploy

Single binary + SQLite, same host as secretary. Expose it with a Cloudflare Tunnel (no public inbound port): add an ingress rule mapping smsforwarder-api.shuttlelab.org to http://127.0.0.1:8090, then run behind systemd.

go build -o smsforwarder-api .
# HTTP_ADDR=127.0.0.1:8090 (localhost only; the tunnel reaches it)
sudo systemctl restart smsforwarder-api
curl -s https://smsforwarder-api.shuttlelab.org/healthz   # {"ok":true}

Deploy with Docker

A Dockerfile + compose.yaml are included. The builder stage clones the upstream repository (https://github.com/socketz/smsforwarder-api, checked out at MODULE_REF, default main) and builds the binary with the same command as above β€” go build -o smsforwarder-api . β€” so no local checkout is copied into the image. The runtime image is hardened (non-root user), keeps the SQLite database on a named volume, and publishes only the public API loopback-only on the host. Configure everything from a project-root .env (all 8 variables from .env.example; compose interpolation falls back to the same defaults, so .env is optional). Pin a commit with docker compose build --build-arg MODULE_REF=<commit>.

cp .env.example .env   # edit BOT_TOKEN, BOT_USERNAME, ADMIN_USER, ADMIN_PASSWORD
docker compose up -d
curl -s http://127.0.0.1:8090/healthz   # {"ok":true}

Notes:

  • DB_PATH is forced to /data/smsforwarder.db inside the container; the host .env value for it is ignored. Data lives in the named volume smsforwarder-data β€” back it up (docker compose down then copy the volume, or docker run --rm -v smsforwarder-data:/data -v $PWD:/backup alpine tar czf /backup/data.tgz -C /data .).
  • Only port 8090 is published, bound to 127.0.0.1 (reverse proxy / tunnel on the host terminates TLS). The admin console (8091) is not published; reach it via docker compose exec api wget -qO- http://127.0.0.1:8091/admin/login. Never set ADMIN_ADDR to 0.0.0.0 unless it is fronted by TLS β€” the console is plaintext HTTP.
  • docker compose logs -f api for logs; docker compose restart api applies config and env changes.

License

Licensed under the GNU Affero General Public License v3.0 (AGPL-3.0) β€” see LICENSE. You may use, study, modify and redistribute it, but any distributed or network-served derivative (including a hosted instance) must also be released under AGPL-3.0.

Built by ShuttleLab

Documentation ΒΆ

Overview ΒΆ

Command smsforwarder-api is the backend for the SMS Forwarder app: it receives SMS uploaded by the phone client, authenticates the user, and fans each message out to that user's configured channels (Telegram). An optional operator admin console runs on a separate (localhost-by-default) address.

Directories ΒΆ

Path Synopsis
internal
admin
Package admin is the operator web console (separate from the public API, and by default bound to localhost).
Package admin is the operator web console (separate from the public API, and by default bound to localhost).
api
Package api wires the HTTP endpoints: auth, channel CRUD/test, and SMS upload.
Package api wires the HTTP endpoints: auth, channel CRUD/test, and SMS upload.
auth
Package auth handles password hashing and device-token authentication.
Package auth handles password hashing and device-token authentication.
channels
Package channels defines the channel Sender abstraction and per-type config handling.
Package channels defines the channel Sender abstraction and per-type config handling.
config
Package config loads bootstrap configuration from environment variables.
Package config loads bootstrap configuration from environment variables.
forward
Package forward is the delivery engine.
Package forward is the delivery engine.
ratelimit
Package ratelimit is a tiny per-user fixed-window limiter (in-memory).
Package ratelimit is a tiny per-user fixed-window limiter (in-memory).
store
Package store is the SQLite persistence layer.
Package store is the SQLite persistence layer.
tg
Package tg is the embedded shared Telegram bot.
Package tg is the embedded shared Telegram bot.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL