From 9a2b1a3f1a348a97d1537db19278a487ed881e64 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 850e09c..04cc89c 100644 --- a/nanobot/channels/telegram.py +++ b/nanobot/channels/telegram.py @@ -11,7 +11,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 @@ -173,6 +173,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 @@ -812,6 +813,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) @@ -822,6 +824,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( @@ -861,6 +864,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: