From 7da39c7c5468bc17bd25f0397d06f3fd78ea165a Mon Sep 17 00:00:00 2001 From: constkolesnyak Date: Tue, 21 Apr 2026 17:42:28 +0200 Subject: [PATCH] Cache notification messages for reaction context (#1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Notifications sent via NotificationService._deliver_telegram() bypassed TelegramChannel.send() and went directly through bot.send_message(), so they were never stored in _message_cache. When a user reacted to a notification, the reaction handler couldn't find the original text and only showed "[Reaction: 👎]" without context. Now _deliver_telegram caches sent messages via channel._cache_message() so reactions on notifications include the message text. Co-authored-by: Claude Opus 4.6 --- nerve/notifications/service.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/nerve/notifications/service.py b/nerve/notifications/service.py index fee4e61..0ab6d94 100644 --- a/nerve/notifications/service.py +++ b/nerve/notifications/service.py @@ -809,11 +809,18 @@ def _resolve_telegram_chat_id(self) -> int | None: logger.warning("No telegram_chat_id configured for notifications") return None - def _get_telegram_bot(self): - """Get the Telegram bot instance, or None if unavailable.""" + def _get_telegram_channel(self): + """Get the TelegramChannel instance, or None if unavailable.""" channel = self.engine.router.get_channel("telegram") if not channel or not hasattr(channel, '_app') or channel._app is None: return None + return channel + + def _get_telegram_bot(self): + """Get the Telegram bot instance, or None if unavailable.""" + channel = self._get_telegram_channel() + if not channel: + return None return channel._app.bot async def _deliver_telegram( @@ -862,12 +869,20 @@ async def _deliver_telegram( else: rendered = value button_labels.append((rendered, value)) - return await self._send_telegram_inline( + msg_id = await self._send_telegram_inline( chat_id, notification_id, text, button_labels, silent=silent, ) else: msg = await self._send_telegram_html(bot, chat_id, text, silent=silent) - return str(msg.message_id) + msg_id = str(msg.message_id) + + # Cache for reaction context lookups + if msg_id: + channel = self._get_telegram_channel() + if channel: + channel._cache_message(int(msg_id), chat_id, text) + + return msg_id @staticmethod async def _send_telegram_html(