Skip to content

docker version - #12

Open
Dr-Muh wants to merge 3 commits into
Mr3rf1:mainfrom
Dr-Muh:main
Open

docker version#12
Dr-Muh wants to merge 3 commits into
Mr3rf1:mainfrom
Dr-Muh:main

Conversation

@Dr-Muh

@Dr-Muh Dr-Muh commented Jul 5, 2026

Copy link
Copy Markdown

Hi,
wanted to run this in my docker, so here is a docker image + everything needed to build etc
Best regards

Summary by Sourcery

Add a Dockerized entrypoint script and container setup for running the Telegram self‑destructive media saver as a service.

New Features:

  • Introduce SecPhoto-docker.py as a container-friendly Telegram client that saves self-destructive media, including albums and replied messages, to the user’s own messages.

Build:

  • Add a Python 3.11 Dockerfile that installs dependencies, mounts a data volume for session storage, and runs the new SecPhoto-docker.py entrypoint.
  • Add a docker-compose.yml service definition for the bot with persistent data volume, environment-based Telegram credentials, and restart policy.

Documentation:

  • Add a placeholder docker-guide file to document Docker usage in the future.

@sourcery-ai

sourcery-ai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Reviewer's Guide

Adds a Dockerized entrypoint script for the Telegram self‑destruct media saver, plus Dockerfile and docker‑compose setup to run it with persisted session data and environment‑driven configuration.

File-Level Changes

Change Details Files
Introduce a Docker-specific Python entrypoint that wraps the Telegram client logic, adds robust authentication and self‑destruct media handling including albums and replied messages, and uses environment variables and a volume path for session storage.
  • Read Telegram API credentials from TG_API_ID and TG_API_HASH environment variables and initialize a TelegramClient with an optional SOCKS5 proxy argument.
  • Implement interactive phone number, code, and 2FA authentication flow with validation and error reporting, including a help flag that prints usage and proxy instructions.
  • Add logic to detect and resolve locked sqlite session databases by deleting session/journal files and reconnecting.
  • Implement helpers to build sanitized filenames and rich HTML captions with chat/user metadata and timestamps.
  • Add detection of self‑destruct (ttl) media and handlers for single media and grouped albums, including debounce buffering so grouped_id messages are saved as one album.
  • On new messages, process both the message and any replied‑to message for self‑destruct media, forwarding saved files to the user’s Saved Messages and cleaning up temporary files.
  • Provide an asyncio-based main function wired to client.run_until_disconnected and a KeyboardInterrupt handler for graceful shutdown.
SecPhoto-docker.py
Add Docker image definition for running the script and persisting session data, plus a docker-compose service configuration driven by environment variables.
  • Create a slim Python 3.11 Dockerfile that installs dependencies from requirements.txt, copies the project, declares /app/data as a VOLUME, and runs SecPhoto-docker.py as the container CMD.
  • Add a docker-compose.yml service telegram-bot based on the secphoto:latest image, with interactive tty, restart policy, bound ./data volume to /app/data, and environment variables for TG_API_ID, TG_API_HASH, and TZ.
  • Add a placeholder docker-guide file to later document Docker usage for this project.
Dockerfile
docker-compose.yml
docker-guide

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've found 2 issues, and left some high level feedback:

  • Accessing TG_API_ID and TG_API_HASH at module import time will raise a raw KeyError if the variables are missing; consider validating these values in main() and emitting a clear, user-friendly error instead.
  • There are several broad except Exception blocks around core logic (authentication, chat handling, album processing) that only log the error string; narrowing these or at least logging more context (e.g. chat/message identifiers) would make debugging production issues much easier.
  • When scheduling album flush tasks you use asyncio.ensure_future in Python 3.11; switching to asyncio.create_task and keeping the task management in a small helper would align better with modern asyncio patterns and simplify cancellation handling.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Accessing TG_API_ID and TG_API_HASH at module import time will raise a raw KeyError if the variables are missing; consider validating these values in main() and emitting a clear, user-friendly error instead.
- There are several broad `except Exception` blocks around core logic (authentication, chat handling, album processing) that only log the error string; narrowing these or at least logging more context (e.g. chat/message identifiers) would make debugging production issues much easier.
- When scheduling album flush tasks you use `asyncio.ensure_future` in Python 3.11; switching to `asyncio.create_task` and keeping the task management in a small helper would align better with modern asyncio patterns and simplify cancellation handling.

## Individual Comments

### Comment 1
<location path="SecPhoto-docker.py" line_range="121" />
<code_context>
+                        print(f"Deleted: {f}")
+                    except Exception as err:
+                        print(f"Could not delete {f}: {err}")
+            client = TelegramClient(client.session.filename, api_id, api_hash)
+            await client.connect()
+        else:
</code_context>
<issue_to_address>
**issue (bug_risk):** Proxy configuration is lost when recreating the TelegramClient after a locked DB error.

In the recovery path you recreate `TelegramClient` without reapplying the original SOCKS5 proxy settings, which changes behavior in proxied environments and can break connectivity. Please persist the proxy configuration from the initial client (e.g., store it in a variable) and reuse it when reconstructing the client here.
</issue_to_address>

### Comment 2
<location path="docker-compose.yml" line_range="2-3" />
<code_context>
+services:
+  telegram-bot:
+    image: secphoto:latest
+    stdin_open: true   # docker run -i
+    tty: true          # docker run -t
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Compose file relies on a pre-built image but doesn’t define a build context.

Because `telegram-bot` only specifies `image: secphoto:latest` and no `build:` section, `docker compose up` will fail unless that image is already built and tagged locally. If you intend to build from the local Dockerfile, add a `build: .` directive (and optionally adjust or remove `image:`) so the service can be started directly via Compose.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread SecPhoto-docker.py
print(f"Deleted: {f}")
except Exception as err:
print(f"Could not delete {f}: {err}")
client = TelegramClient(client.session.filename, api_id, api_hash)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): Proxy configuration is lost when recreating the TelegramClient after a locked DB error.

In the recovery path you recreate TelegramClient without reapplying the original SOCKS5 proxy settings, which changes behavior in proxied environments and can break connectivity. Please persist the proxy configuration from the initial client (e.g., store it in a variable) and reuse it when reconstructing the client here.

Comment thread docker-compose.yml
Comment on lines +2 to +3
telegram-bot:
image: secphoto:latest

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Compose file relies on a pre-built image but doesn’t define a build context.

Because telegram-bot only specifies image: secphoto:latest and no build: section, docker compose up will fail unless that image is already built and tagged locally. If you intend to build from the local Dockerfile, add a build: . directive (and optionally adjust or remove image:) so the service can be started directly via Compose.

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