Skip to content

Commit 26d60db

Browse files
committed
Document Telegram session bootstrap
1 parent 8d3123b commit 26d60db

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,73 @@ Notes for this compose stack:
297297
- Telegram indexer: `TELEGRAM_API_ID`, `TELEGRAM_API_HASH`, `TELEGRAM_CHANNELS`, and either `TELEGRAM_SESSION_DATA` or persistent storage for `TELEGRAM_SESSION_FILE`
298298
- NEAR indexer: optional `FASTNEAR_API_KEY`, or set `APP_NEAR__PROVIDER=lake` if you do not want FastNEAR
299299

300+
### Telegram session bootstrap and rotation
301+
302+
`telegram-indexer` only performs phone/code/password login when
303+
`TELEGRAM_ALLOW_INTERACTIVE_LOGIN=true` and stdin is a real TTY. Otherwise it
304+
expects an already authorized session from `TELEGRAM_SESSION_FILE` or
305+
`TELEGRAM_SESSION_DATA`. `TELEGRAM_SESSION_DATA` can be either a base64-encoded
306+
SQLite session file or a legacy Grammers session payload; the service imports
307+
legacy payloads into the SQLite format on startup.
308+
309+
1. For a deployment with durable storage, run the indexer once interactively
310+
against the same database and the same session path you will use in
311+
production:
312+
313+
```bash
314+
docker run --rm -it \
315+
--name hos-api-telegram-auth \
316+
--network hos-api-local \
317+
-e DATABASE_URL=postgresql://hos:hos@hos-api-db:5432/hos_api \
318+
-e TELEGRAM_API_ID=... \
319+
-e TELEGRAM_API_HASH=... \
320+
-e TELEGRAM_CHANNELS=@nearprotocol \
321+
-e TELEGRAM_ALLOW_INTERACTIVE_LOGIN=true \
322+
-e TELEGRAM_SESSION_FILE=/var/lib/telegram/telegram_session.bin \
323+
-v hos-api-telegram-session:/var/lib/telegram \
324+
hos-api/telegram-indexer
325+
```
326+
327+
Enter the phone number, verification code, and two-factor password if Telegram
328+
asks for it. Once the session is authorized and the worker begins syncing, stop
329+
the container and start the long-running deployment without
330+
`TELEGRAM_ALLOW_INTERACTIVE_LOGIN`.
331+
332+
2. For an ephemeral platform without durable disk, create the session locally,
333+
encode it, and store it as a secret:
334+
335+
```bash
336+
mkdir -p .secrets/telegram
337+
338+
docker run --rm -it \
339+
--name hos-api-telegram-auth \
340+
--network hos-api-local \
341+
-e DATABASE_URL=postgresql://hos:hos@hos-api-db:5432/hos_api \
342+
-e TELEGRAM_API_ID=... \
343+
-e TELEGRAM_API_HASH=... \
344+
-e TELEGRAM_CHANNELS=@nearprotocol \
345+
-e TELEGRAM_ALLOW_INTERACTIVE_LOGIN=true \
346+
-e TELEGRAM_SESSION_FILE=/sessions/telegram_session.bin \
347+
-v "$PWD/.secrets/telegram:/sessions" \
348+
hos-api/telegram-indexer
349+
350+
base64 < .secrets/telegram/telegram_session.bin | tr -d '\n'
351+
```
352+
353+
Set the resulting single-line value as `TELEGRAM_SESSION_DATA` in the platform
354+
secret store, keep `TELEGRAM_SESSION_FILE` pointed at a writable path inside the
355+
container, and redeploy. On startup the service will materialize the SQLite
356+
session file from the secret before connecting.
357+
358+
3. To refresh or replace a session, stop the worker, repeat the same
359+
interactive bootstrap flow against the existing session path, then restart
360+
the worker. For secret-based deployments, re-encode the updated
361+
`telegram_session.bin`, replace `TELEGRAM_SESSION_DATA`, and redeploy.
362+
363+
If the worker starts without a valid authorized session, it retries
364+
authentication every 60 seconds for up to 60 attempts and logs that it is
365+
waiting so a session file or `TELEGRAM_SESSION_DATA` can be uploaded.
366+
300367
### Operational notes
301368

302369
- The API `/health` endpoint is useful for liveness, but it still returns HTTP 200 with a `degraded` payload when the database is unavailable. Treat it as a basic health signal, not your only database readiness gate.

0 commit comments

Comments
 (0)