Skip to content

docs: add Telegram bot local setup guide#38

Open
itasimo wants to merge 1 commit into
mainfrom
itasimo/guide-local-bot-setup
Open

docs: add Telegram bot local setup guide#38
itasimo wants to merge 1 commit into
mainfrom
itasimo/guide-local-bot-setup

Conversation

@itasimo

@itasimo itasimo commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

A new documentation file is added at docs/infrastructure/03-Guides/telegram-bot-local-setup.md. It provides a complete guide for running the Postgres-backed API and Telegram bot locally, covering prerequisites, Docker service setup, environment variable configuration, backend secret generation, database migrations, Telegram permission SQL, and an optional cross-platform automation Bash script.

Changes

Telegram Bot Local Setup Guide

Layer / File(s) Summary
Overview, prerequisites, and supporting services
docs/infrastructure/03-Guides/telegram-bot-local-setup.md
Defines the document scope, lists local prerequisites, and instructs how to start Postgres and Redis+InfluxDB via Docker and the telegram/docker-compose.yml. Includes a note on aligning Redis/InfluxDB auth with telegram/.env.
Manual backend and bot setup steps
docs/infrastructure/03-Guides/telegram-bot-local-setup.md
Covers creating .env files for both backend/ and telegram/, generating backend secrets, running migrations and the dev server, starting the bot, inserting Telegram role/permission rows via SQL into tg.permissions, a recommended Postgres DSN for manual DB access, and a readiness checklist.
Optional automation Bash script
docs/infrastructure/03-Guides/telegram-bot-local-setup.md
Adds an embedded Bash script with Windows/POSIX detection, dependency validation, port-kill helper, Docker service startup with readiness polling via redis-cli, backend bootstrapping (install + migrate), and background launch of backend and bot using nohup writing to backend.log and bot.log. Ends with a Windows/WSL shell requirement note.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title accurately describes the main change: adding a comprehensive guide for setting up the Telegram bot locally.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/infrastructure/03-Guides/telegram-bot-local-setup.md`:
- Around line 265-268: The kill_process_on_port function call with port 3000
will terminate any process on that port, not just the ones started by this
script, which is destructive for an optional setup script. Modify the cleanup
section to either store the PID of the process started by this script (such as
the telegram bot service) when it launches and kill only that specific process
by PID during cleanup, or add a confirmation prompt before force-killing
anything on port 3000 to prevent accidentally terminating unrelated
applications.
- Around line 287-296: The service readiness checks for Postgres (wait_for_port
127.0.0.1 5432), Redis (wait_for_port 127.0.0.1 6379), and InfluxDB
(wait_for_http http://127.0.0.1:8086/health) currently only log warnings when
services fail to respond and allow the script to continue. Instead of continuing
on failure, modify these checks to exit the script with a non-zero status code
when any critical service fails to become ready within the timeout period. This
will ensure failures are caught early and reported at the point of failure
rather than causing cryptic errors later during migrations or bot startup. Also
apply this same fix to the similar service checks mentioned at lines 328-331.
- Around line 298-306: The Redis readiness probe in the bash script snippet uses
a literal placeholder `{your_redis_password}` instead of an actual password
variable, which will cause authentication to fail. Replace the hardcoded
placeholder `{your_redis_password}` in the redis-cli command with an environment
variable like `$REDIS_PASSWORD` so that the actual password is used during
authentication. Additionally, document that users need to set this environment
variable before running the script, or consider using the Redis service name
from the Docker Compose configuration instead of assuming the container name is
`redis_db`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a0841767-40d7-4dc4-99c3-1f990083186e

📥 Commits

Reviewing files that changed from the base of the PR and between 599a0a4 and 56a747f.

📒 Files selected for processing (1)
  • docs/infrastructure/03-Guides/telegram-bot-local-setup.md

Comment on lines +265 to +268
# --- Environment Cleanup ---
echo "Cleaning up local ports..."
kill_process_on_port 3000

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Avoid killing arbitrary listeners on port 3000.

This can terminate an unrelated local app that happens to be using the same port. For an optional setup script, that’s too destructive; restrict cleanup to the processes this script started, or prompt before force-killing anything.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/infrastructure/03-Guides/telegram-bot-local-setup.md` around lines 265 -
268, The kill_process_on_port function call with port 3000 will terminate any
process on that port, not just the ones started by this script, which is
destructive for an optional setup script. Modify the cleanup section to either
store the PID of the process started by this script (such as the telegram bot
service) when it launches and kill only that specific process by PID during
cleanup, or add a confirmation prompt before force-killing anything on port 3000
to prevent accidentally terminating unrelated applications.

Comment on lines +287 to +296
echo "Waiting for Docker services to be reachable..."
if ! wait_for_port 127.0.0.1 5432 60; then
echo "Warning: Postgres not responding on 127.0.0.1:5432" >&2
fi
if ! wait_for_port 127.0.0.1 6379 60; then
echo "Warning: Redis not responding on 127.0.0.1:6379" >&2
fi
if ! wait_for_http http://127.0.0.1:8086/health 60; then
echo "Warning: InfluxDB not responding on http://127.0.0.1:8086/health" >&2
fi

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Fail fast when a prerequisite service never becomes ready.

The script only logs warnings for Postgres/Redis/InfluxDB/backend timeouts and then keeps going into migrations or bot startup. That turns the real failure into a later, harder-to-diagnose crash. Exit non-zero here instead of continuing.

Also applies to: 328-331

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/infrastructure/03-Guides/telegram-bot-local-setup.md` around lines 287 -
296, The service readiness checks for Postgres (wait_for_port 127.0.0.1 5432),
Redis (wait_for_port 127.0.0.1 6379), and InfluxDB (wait_for_http
http://127.0.0.1:8086/health) currently only log warnings when services fail to
respond and allow the script to continue. Instead of continuing on failure,
modify these checks to exit the script with a non-zero status code when any
critical service fails to become ready within the timeout period. This will
ensure failures are caught early and reported at the point of failure rather
than causing cryptic errors later during migrations or bot startup. Also apply
this same fix to the similar service checks mentioned at lines 328-331.

Comment on lines +298 to +306
echo "Waiting for Redis initialization..."
REDIS_CONTAINER=$(docker ps --format '{{.Names}}' | grep -E 'redis_db' | head -n 1 || true)
if [ -z "$REDIS_CONTAINER" ]; then
REDIS_CONTAINER="redis_db"
fi

for i in {1..60}; do
if docker exec "$REDIS_CONTAINER" redis-cli -a {your_redis_password} ping >/dev/null 2>&1; then
break

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Fix the Redis readiness probe.

redis-cli is using a literal {your_redis_password} placeholder, so this check will never authenticate in the documented setup. It also assumes a redis_db container name that may not match the Compose service.

Suggested fix
-REDIS_CONTAINER=$(docker ps --format '{{.Names}}' | grep -E 'redis_db' | head -n 1 || true)
-if [ -z "$REDIS_CONTAINER" ]; then
-  REDIS_CONTAINER="redis_db"
-fi
+REDIS_CONTAINER=$(docker ps --format '{{.Names}}' | grep -E 'redis_db' | head -n 1 || true)
+if [ -z "$REDIS_CONTAINER" ]; then
+  echo "Warning: could not identify the Redis container" >&2
+fi
@@
-  if docker exec "$REDIS_CONTAINER" redis-cli -a {your_redis_password} ping >/dev/null 2>&1; then
+  if docker exec "$REDIS_CONTAINER" redis-cli -a "$REDIS_PASSWORD" ping >/dev/null 2>&1; then
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/infrastructure/03-Guides/telegram-bot-local-setup.md` around lines 298 -
306, The Redis readiness probe in the bash script snippet uses a literal
placeholder `{your_redis_password}` instead of an actual password variable,
which will cause authentication to fail. Replace the hardcoded placeholder
`{your_redis_password}` in the redis-cli command with an environment variable
like `$REDIS_PASSWORD` so that the actual password is used during
authentication. Additionally, document that users need to set this environment
variable before running the script, or consider using the Redis service name
from the Docker Compose configuration instead of assuming the container name is
`redis_db`.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant