Skip to content

fix: resolve critical bugs from telepot→python-telegram-bot migration#12

Merged
t0mer merged 9 commits into
masterfrom
enhancement
Jun 1, 2026
Merged

fix: resolve critical bugs from telepot→python-telegram-bot migration#12
t0mer merged 9 commits into
masterfrom
enhancement

Conversation

@t0mer

@t0mer t0mer commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

This branch fixes 9 bugs identified during a code review of the
telepot → python-telegram-bot rewrite.

Changes

  • requirements.txt — replaced telepot (wrong library, never imported) with
    python-telegram-bot==13.15 (the library the code actually uses)

  • v13 API migration — all handler callbacks updated from the removed v12
    (bot, update) signature to the v13 (update, context) signature;
    RegexHandler (removed in v13) replaced with
    MessageHandler(Filters.regex(...)); all bot calls updated to
    context.bot.send_*

  • ALLOWED_IDS whitespace — each entry is now .strip()-ed so values like
    "123456, 789012" (space after comma, common in docker-compose) are parsed
    correctly

  • API_KEY validation — bot exits with a clear message at startup if
    API_KEY is not set, instead of passing None to Updater and crashing
    with an opaque library error

  • Container name parsing — replaced split('_')[0] with rsplit on the
    operation suffix; switched operation detection from in to endswith so
    container names containing underscores (e.g. my_app) resolve correctly

  • Docker name filter — filter changed from {'name': container_name} (a
    substring match) to {'name': '^/container_name$'} (anchored exact match)
    to prevent operating on the wrong container

  • error_handler crash — added update.message None guard; non-message
    updates (callback queries, inline queries, channel posts) previously caused
    original error

  • Hardcoded source path/start now reads os.path.abspath(__file__)
    instead of the hardcoded /opt/dockerbot/dockerbot.py; only functions with
    a #[ ... ]# help marker are listed, hiding internal helpers from users

  • Dockerfile — added python3 and python3-pip to the apt install step
    (ubuntu:24.10 ships neither by default); changed CMD from python to
    python3

Test plan

  • docker build completes without error
  • Bot starts and logs "Starting bot..." with a valid API_KEY
  • Bot exits with a clear message when API_KEY is unset
  • /start shows only user-facing commands (no internal helpers)
  • /list_containers lists containers; clicking a generated command
    restarts/stops/starts the correct container, including containers whose
    names contain underscores
  • Sending a command from an unauthorized user ID shows the No-Trespassing
    image; ALLOWED_IDS with spaces after commas works correctly

Copilot AI review requested due to automatic review settings June 1, 2026 23:15
@t0mer t0mer merged commit 646c42d into master Jun 1, 2026
1 of 2 checks passed
@t0mer

t0mer commented Jun 1, 2026

Copy link
Copy Markdown
Owner Author

Snyk checks have failed. 15 issues have been found so far.

Status Scan Engine Critical High Medium Low Total (15)
Open Source Security 0 5 9 1 15 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@t0mer t0mer deleted the enhancement branch June 1, 2026 23:16

Copilot AI 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.

Pull request overview

Fixes nine bugs from the prior telepotpython-telegram-bot migration: fixes the requirement, ports all handlers to v13's (update, context) API, hardens parsing (ALLOWED_IDS whitespace, container name rsplit, anchored docker name filter), validates API_KEY at startup, guards error_handler against non-message updates, dynamically resolves the source path for /start, and updates the Dockerfile for ubuntu:24.10.

Changes:

  • requirements.txt: replace unused telepot with python-telegram-bot==13.15.
  • dockerbot.py: full v13 API rewrite — per-command functions, authorization helper, error handler, container parsing via endswith/rsplit and anchored name filter, dynamic /start help generation.
  • Dockerfile: consolidated apt install (adds python3/python3-pip), WORKDIR, PYTHONUNBUFFERED/PYTHONDONTWRITEBYTECODE, switches ENTRYPOINT to CMD ["python3", ...].

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 5 comments.

File Description
requirements.txt Switches to the actual telegram lib used by code.
Dockerfile Restructured base image setup; adds python3, env vars, new speedtest.py path.
dockerbot.py Migrates to python-telegram-bot v13 handler signatures and fixes parsing/auth bugs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dockerbot.py
Comment on lines +39 to +48
number = command.rfind("def ")
if number != -1:
command = command[number+4:]
space_pos = command.find("(")
if space_pos != -1:
command_name = command[:space_pos]
help_text = getCommandHelp(line)
if help_text:
command = f"/{command_name} {help_text}\n"
list_of_results.append(command)
Comment thread Dockerfile
Comment on lines +26 to +27
RUN pip3 install --no-cache-dir --upgrade pip && \
pip3 install --no-cache-dir -r requirements.txt
Comment thread Dockerfile
pip3 install --no-cache-dir -r requirements.txt

# Install speedtest-cli script
RUN wget https://raw.githubusercontent.com/sivel/speedtest-cli/v2.1.3/speedtest.py -O /usr/local/lib/python3.12/site-packages/speedtest.py
Comment thread dockerbot.py
dp.add_handler(CommandHandler("stat", stat_command))
dp.add_handler(CommandHandler("list_containers", list_containers_command))

dp.add_handler(MessageHandler(Filters.regex(r"^/[a-zA-Z0-9_-]+_(restart|stop|start)$"), container_command))
Comment thread dockerbot.py
import sys
import docker
from telepot.loop import MessageLoop
import telegram
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.

2 participants