к предыдущему

This commit is contained in:
kislovdm
2026-04-10 19:09:15 +03:00
parent 763ca45ab2
commit 70f1cea78e
2 changed files with 9 additions and 6 deletions
+6 -3
View File
@@ -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: def _is_supported_telegram_message(message: dict[str, Any]) -> bool:
# Текстовые сообщения и команды.
text = message.get("text") text = message.get("text")
if isinstance(text, str) and text.strip(): if isinstance(text, str) and text.strip():
return True return True
photos = message.get("photo") 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 return True
video = message.get("video") 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 True
return False 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) max_update_id = upd_id if max_update_id is None else max(max_update_id, upd_id)
message = None message = None
for container in ("message", "edited_message", "channel_post", "edited_channel_post"): for container in ("message", "channel_post"):
candidate = upd.get(container) candidate = upd.get(container)
if isinstance(candidate, dict): if isinstance(candidate, dict):
message = candidate message = candidate
+3 -3
View File
@@ -132,8 +132,8 @@ class TelegramClient:
payload: dict[str, Any] = { payload: dict[str, Any] = {
"timeout": timeout, "timeout": timeout,
"limit": limit, "limit": limit,
# чтобы получать посты из каналов (channel_post) и обычные сообщения # Реагируем только на новые сообщения/посты (текст, фото, видео).
"allowed_updates": ["message", "edited_message", "channel_post", "edited_channel_post"], "allowed_updates": ["message", "channel_post"],
} }
if offset is not None: if offset is not None:
payload["offset"] = offset payload["offset"] = offset
@@ -145,7 +145,7 @@ class TelegramClient:
# Важно: не делаем getUpdates нигде больше (иначе 409 Conflict). # Важно: не делаем getUpdates нигде больше (иначе 409 Conflict).
# Наполняем кэш чатов только из этого потока. # Наполняем кэш чатов только из этого потока.
for upd in updates: 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) msg = upd.get(container)
if not isinstance(msg, dict): if not isinstance(msg, dict):
continue continue