remove user-secrets approach & prepare a pilot deploy

This commit is contained in:
hamid
2026-07-28 23:18:54 +03:30
parent 630c7907ec
commit 5885280b49
28 changed files with 639 additions and 142 deletions
+12
View File
@@ -0,0 +1,12 @@
node_modules
*.log
# Local secrets — the deployed values come from compose, and a copied .env would silently win on any
# key the compose environment doesn't set.
.env
.env.local
Dockerfile
.dockerignore
README.md
INTEGRATION-PROMPT.md
+9 -3
View File
@@ -1,4 +1,6 @@
# Copy to .env and fill in. Never commit .env.
# Copy to .env and fill in — for LOCAL runs (`npm start`) only. Never commit .env.
# The deployed stack sets every one of these in the root docker-compose.yml instead; nothing here is read
# inside the container.
# From @BotFather — the full token, e.g. 1234567890:AAH....
TELEGRAM_BOT_TOKEN=8968527151:AAFiCuNGkXjOiLZfT6urU8tkW8SCsWDM0ic
@@ -12,7 +14,10 @@ TELEGRAM_CHAT_IDS=1277103616,110209855
# REQUIRED. Shared secret the caller must send as the `X-Api-Key` header.
# Minimum 16 chars; the process refuses to start without it.
# Generate one: node -e "console.log(require('crypto').randomBytes(24).toString('hex'))"
# The same value goes into the .NET side's Seams:Sms:Telegram:ApiKey (user-secrets, never committed).
# The same value goes into the .NET side's Seams:Sms:Telegram:ApiKey (appsettings.Development.json).
#
# The value below is the PUBLISHED EXAMPLE — it is in git and in the README, so it is not a secret, and
# TelegramSmsSender deliberately refuses to authenticate with it. Replace it in your own .env.
API_KEY=ab8984974bc1fe5ce514d0fd74f71c8738b3aed92a7e4d86
# HTTP listener
@@ -27,6 +32,7 @@ REDACT_CODE_IN_LOGS=false
# this process tunnels its Telegram calls through it (HTTP CONNECT or SOCKS5, with optional
# user:pass@ credentials). Leave it unset for a direct connection — nothing else changes.
# local machine with a VPN client: http://127.0.0.1:10809 / socks5://127.0.0.1:10808
# VPS with a proxy container: http://proxy:1080 (the container name on the shared docker network)
# VPS with a proxy container: http://hysteria-client:8081 (the container name on caddy_net —
# what the deployed stack uses, set in the root docker-compose.yml)
# HTTPS_PROXY / ALL_PROXY are honoured as a fallback if TELEGRAM_PROXY_URL is unset.
# TELEGRAM_PROXY_URL=http://127.0.0.1:10809
+20
View File
@@ -0,0 +1,20 @@
# Balinyaar Telegram OTP relay — build context is `telegram-otp-bot/`.
#
# Zero dependencies (Node built-ins only), so there is no install step and no build stage: the image is
# the base runtime plus four source files.
FROM node:22-alpine
WORKDIR /app
COPY package.json ./
COPY src ./src
# The relay must accept connections from the API container, not just its own loopback. Everything else
# (bot token, chat ids, API key, proxy URL) is supplied by compose — src/env.js lets real environment
# variables win over any .env file, so nothing here depends on one existing.
ENV HOST=0.0.0.0
ENV PORT=5010
USER node
EXPOSE 5010
CMD ["node", "src/server.js"]
+20 -9
View File
@@ -1,15 +1,17 @@
# balinyaar-telegram-otp-bot
A **standalone, dev-only** Telegram relay. It is not part of `client/` or `server/` — it is its own
tiny Node project with **zero dependencies** (Node 18+ built-ins only: `node:http` + global `fetch`).
A **standalone** Telegram relay. It is not part of `client/` or `server/` — it is its own tiny Node
project with **zero dependencies** (Node 18+ built-ins only: `node:http` + global `fetch`).
Its whole job: expose an HTTP endpoint that the .NET API calls, and forward the message to a fixed
list of Telegram chat ids. That replaces "read the OTP out of the server log" during manual testing —
you get the code on your phone instead, without paying an Iranian SMS gateway.
list of Telegram chat ids. That replaces "read the OTP out of the server log" — you get the code on
your phone instead, without an Iranian SMS gateway contract.
> **Development only.** There is no per-user routing: *every* configured recipient receives *every*
> OTP, regardless of which phone number requested it. That is fine for a test group; it is not an SMS
> gateway. Do not point a real environment at this.
> **Broadcast, not routing.** *Every* configured recipient receives *every* OTP, regardless of which
> phone number requested it. That makes this a shared inbox for a small trusted group, not an SMS
> gateway. It is the OTP rail for local development **and** for the pre-launch `balinyaar.ir` demo
> deployment — it must be swapped for `Seams:Sms:Provider = kavenegar` before anyone outside that
> trusted group can request a code.
---
@@ -93,7 +95,7 @@ The two POST routes mirror the server's `ISmsSender` (`SendOtpAsync` / `SendAsyn
| `API_KEY` | — | **Required**, min 16 chars. Shared secret expected in `X-Api-Key`. Process exits without it. |
| `TELEGRAM_CHAT_IDS` | — | Comma-separated recipient chat ids. Empty ⇒ every send returns `503`. |
| `PORT` | `5010` | HTTP port. |
| `HOST` | `127.0.0.1` | Bind address. Keep it loopback unless the API runs on another machine. |
| `HOST` | `127.0.0.1` | Bind address. Loopback locally; the Dockerfile sets `0.0.0.0` so the API container can reach it. |
| `REDACT_CODE_IN_LOGS` | `false` | Keep the code out of *this process's* stdout (still delivered). |
| `TELEGRAM_PROXY_URL` | — | Optional outbound proxy for the Telegram hop — see below. |
@@ -101,7 +103,16 @@ The API key is the only access control — there is no IP allow-list and no TLS.
loopback when the API runs on the same machine; if you must expose it, put it behind something that
terminates TLS, or the key travels in clear text.
Values come from `.env` (git-ignored) or from real environment variables, which take precedence.
Values come from `.env` (git-ignored) or from real environment variables, which take precedence. In the
deployed stack there is no `.env` at all — the root `docker-compose.yml` supplies every variable directly
(and `.dockerignore` keeps a local `.env` out of the image, so it can't silently win).
## Running in Docker
The [`Dockerfile`](Dockerfile) here is built by the root [`docker-compose.yml`](../docker-compose.yml) as
the `otp-relay` service. Nothing is published to the host: the API reaches it as
`http://balinyaar-otp-relay:5010` over the shared `caddy_net` network, and its own hop to Telegram goes
through the proxy container on that same network. See [DEPLOY.md](../DEPLOY.md).
## Troubleshooting