From 43baf719de63ca360c9193f3f9c7e14717f4a96b Mon Sep 17 00:00:00 2001 From: flobo3 Date: Sat, 21 Mar 2026 16:23:05 +0300 Subject: [PATCH] feat(telegram): add react_emoji config for incoming messages --- nanobot/channels/telegram.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/nanobot/channels/telegram.py b/nanobot/channels/telegram.py index d3c9073fa..d5a8e381a 100644 --- a/nanobot/channels/telegram.py +++ b/nanobot/channels/telegram.py @@ -10,7 +10,7 @@ from typing import Any, Literal from loguru import logger from pydantic import Field -from telegram import BotCommand, ReplyParameters, Update +from telegram import BotCommand, ReactionTypeEmoji, ReplyParameters, Update from telegram.error import TimedOut from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters from telegram.request import HTTPXRequest @@ -164,6 +164,7 @@ class TelegramConfig(Base): allow_from: list[str] = Field(default_factory=list) proxy: str | None = None reply_to_message: bool = False + react_emoji: str = "👀" group_policy: Literal["open", "mention"] = "mention" connection_pool_size: int = 32 pool_timeout: float = 5.0 @@ -770,6 +771,7 @@ class TelegramChannel(BaseChannel): "session_key": session_key, } self._start_typing(str_chat_id) + await self._add_reaction(str_chat_id, message.message_id, self.config.react_emoji) buf = self._media_group_buffers[key] if content and content != "[empty message]": buf["contents"].append(content) @@ -780,6 +782,7 @@ class TelegramChannel(BaseChannel): # Start typing indicator before processing self._start_typing(str_chat_id) + await self._add_reaction(str_chat_id, message.message_id, self.config.react_emoji) # Forward to the message bus await self._handle_message( @@ -819,6 +822,19 @@ class TelegramChannel(BaseChannel): if task and not task.done(): task.cancel() + async def _add_reaction(self, chat_id: str, message_id: int, emoji: str) -> None: + """Add emoji reaction to a message (best-effort, non-blocking).""" + if not self._app or not emoji: + return + try: + await self._app.bot.set_message_reaction( + chat_id=int(chat_id), + message_id=message_id, + reaction=[ReactionTypeEmoji(emoji=emoji)], + ) + except Exception as e: + logger.debug("Telegram reaction failed: {}", e) + async def _typing_loop(self, chat_id: str) -> None: """Repeatedly send 'typing' action until cancelled.""" try: