diff --git a/src/reverse_bridge.py b/src/reverse_bridge.py index d143a19..76ce5b6 100644 --- a/src/reverse_bridge.py +++ b/src/reverse_bridge.py @@ -49,16 +49,19 @@ def _format_forward_text(*, sender: dict[str, Any] | None, text: str) -> str: def _is_supported_telegram_message(message: dict[str, Any]) -> bool: + # Текстовые сообщения и команды. text = message.get("text") if isinstance(text, str) and text.strip(): return True photos = message.get("photo") - if isinstance(photos, list) and any(isinstance(p, dict) and p.get("file_id") for p in photos): + has_photo = isinstance(photos, list) and any(isinstance(p, dict) and p.get("file_id") for p in photos) + if has_photo: return True video = message.get("video") - if isinstance(video, dict) and video.get("file_id"): + has_video = isinstance(video, dict) and video.get("file_id") + if has_video: return True return False @@ -134,7 +137,7 @@ class TelegramToMaxBridge: max_update_id = upd_id if max_update_id is None else max(max_update_id, upd_id) message = None - for container in ("message", "edited_message", "channel_post", "edited_channel_post"): + for container in ("message", "channel_post"): candidate = upd.get(container) if isinstance(candidate, dict): message = candidate diff --git a/src/telegram_api.py b/src/telegram_api.py index 33c7c92..66d3e7f 100644 --- a/src/telegram_api.py +++ b/src/telegram_api.py @@ -132,8 +132,8 @@ class TelegramClient: payload: dict[str, Any] = { "timeout": timeout, "limit": limit, - # чтобы получать посты из каналов (channel_post) и обычные сообщения - "allowed_updates": ["message", "edited_message", "channel_post", "edited_channel_post"], + # Реагируем только на новые сообщения/посты (текст, фото, видео). + "allowed_updates": ["message", "channel_post"], } if offset is not None: payload["offset"] = offset @@ -145,7 +145,7 @@ class TelegramClient: # Важно: не делаем getUpdates нигде больше (иначе 409 Conflict). # Наполняем кэш чатов только из этого потока. for upd in updates: - for container in ("message", "edited_message", "channel_post", "edited_channel_post"): + for container in ("message", "channel_post"): msg = upd.get(container) if not isinstance(msg, dict): continue