Files
balance_bot/bot/handlers/form_utils/topic_replies.py
2026-01-23 04:45:55 +07:00

30 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from aiogram import Router, F
from aiogram.types import Message
from bot.data.topic_map import user_topic_map
router: Router = Router(name="topic_replies")
@router.message(F.is_topic_message, F.reply_to_message, ~F.from_user.is_bot)
async def forward_reply_to_user(message: Message):
thread_id = message.message_thread_id
if thread_id is None:
return # нет thread_id, выходим
# Найдем user_id по thread_id
user_id = None
for (uid, kind), tid in user_topic_map.items():
if tid == thread_id:
user_id = uid
break
if user_id is None:
return # Топик не зарегистрирован
reply_text = f"<b>Ответ администратора:</b>\n{message.html_text}"
try:
await message.bot.send_message(chat_id=user_id, text=reply_text, parse_mode="HTML")
except Exception as e:
await message.reply(f"⚠️ Не удалось отправить сообщение пользователю: {e}")