Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from bundle
Use when building or fixing aiogram 3 bots that need aiogram_i18n with Fluent/FTL, topic-aware reply handling, Telegram quote and forward-origin context, and pr
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
scripts/topic_aware_reply_helpers.py
1from aiogram import F2from aiogram.filters import and_f, or_f3from aiogram.types import Message456def is_valid_reply(message: Message) -> bool:7if not message.reply_to_message:8return False910if not message.chat.is_forum or not message.is_topic_message:11return True1213return message.reply_to_message.message_id != message.message_thread_id141516def get_message_thread_id(message: Message) -> int | None:17chat = message.chat18if not chat:19return None2021if chat.is_forum:22if message.is_topic_message and message.message_thread_id:23return message.message_thread_id24return None2526if chat.linked_chat_id is None:27return None2829if message.message_thread_id is None:30return None3132if (33message.reply_to_message34and message.reply_to_message.from_user35and message.reply_to_message.from_user.is_bot36):37return None3839return message.message_thread_id404142IS_REPLY = or_f(43and_f(or_f(~F.chat.is_forum, ~F.is_topic_message), F.reply_to_message),44and_f(45F.chat.is_forum,46F.is_topic_message,47F.reply_to_message.message_id != F.message_thread_id,48),49)505152FILTER_REPLY_OR_NONE = or_f(53~F.reply_to_message,54and_f(55F.chat.is_forum,56F.reply_to_message.message_id == F.message_thread_id,57),58)59