Receive updates via Bot API when Telethon MTProto is blocked - #5
Open
kinton wants to merge 1 commit into
Open
Conversation
Cloud Agent and similar networks allow HTTPS Bot API but reset raw MTProto, so importing bot_telethon used to crash before the bot could start. Connect Telethon lazily, keep send/update workers alive without it, and long-poll getUpdates as a receive fallback. Co-authored-by: Kovalenko K. <kintonkk@gmail.com>
kinton
marked this pull request as ready for review
August 31, 2026 23:00
This was referenced Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
This Cloud Agent environment can reach
api.telegram.orgover HTTPS, but raw MTProto to Telegram DCs is reset (IncompleteReadError/ HTTP 404 on port 443). The bot used to connect Telethon at import time, sopython main.pycrashed before it could serve anything.What
try_start_telethon()), skip it whenTELEGRAM_FORCE_BOTAPI=1or when the handshake failsgetUpdatesas a receive fallback and dispatch into the existing route workers (commands, callbacks, inline, Stars pre-checkout)/start, menus, and search work without Telethon. Large file upload via Telethon still needs MTProtoHow to run here
Then message
@YourInstaFeedDevelopingBot.Tests
python app/routes/test_botapi_receiver.py— command/callback routing helpers (ok)main.pywithTELEGRAM_FORCE_BOTAPI=1: process stays up, logsReceiving via Bot API long pollinggetMe→YourInstaFeedDevelopingBot, webhook empty