From fc31b88e37b2890101278c7a1601d183308aeca1 Mon Sep 17 00:00:00 2001 From: kilhyeonjun Date: Mon, 6 Jul 2026 15:41:21 +0900 Subject: [PATCH 1/7] feat(telegram): support copy text buttons --- plugins/platforms/telegram/adapter.py | 106 ++++++++- tests/gateway/test_telegram_copy_buttons.py | 202 ++++++++++++++++++ website/docs/user-guide/messaging/telegram.md | 24 +++ 3 files changed, 324 insertions(+), 8 deletions(-) create mode 100644 tests/gateway/test_telegram_copy_buttons.py diff --git a/plugins/platforms/telegram/adapter.py b/plugins/platforms/telegram/adapter.py index 239b26de1712..19f671557851 100644 --- a/plugins/platforms/telegram/adapter.py +++ b/plugins/platforms/telegram/adapter.py @@ -154,6 +154,10 @@ async def _shutdown_abandoned_app(app) -> None: try: from telegram import Update, Bot, Message, InlineKeyboardButton, InlineKeyboardMarkup + try: + from telegram import CopyTextButton + except ImportError: + CopyTextButton = None try: from telegram import LinkPreviewOptions except ImportError: @@ -176,6 +180,7 @@ async def _shutdown_abandoned_app(app) -> None: Message = Any InlineKeyboardButton = Any InlineKeyboardMarkup = Any + CopyTextButton = None LinkPreviewOptions = None Application = Any CommandHandler = Any @@ -251,7 +256,7 @@ def check_telegram_requirements() -> bool: so the adapter's class-level type aliases get rebound. """ global TELEGRAM_AVAILABLE, Update, Bot, Message, InlineKeyboardButton - global InlineKeyboardMarkup, LinkPreviewOptions, Application + global InlineKeyboardMarkup, CopyTextButton, LinkPreviewOptions, Application global CommandHandler, CallbackQueryHandler, TelegramMessageHandler global ContextTypes, filters, ParseMode, ChatType, HTTPXRequest if TELEGRAM_AVAILABLE: @@ -264,6 +269,10 @@ def check_telegram_requirements() -> bool: try: from telegram import Update as _Update, Bot as _Bot, Message as _Message from telegram import InlineKeyboardButton as _IKB, InlineKeyboardMarkup as _IKM + try: + from telegram import CopyTextButton as _CTB + except ImportError: + _CTB = None try: from telegram import LinkPreviewOptions as _LPO except ImportError: @@ -283,6 +292,7 @@ def check_telegram_requirements() -> bool: Message = _Message InlineKeyboardButton = _IKB InlineKeyboardMarkup = _IKM + CopyTextButton = _CTB LinkPreviewOptions = _LPO Application = _App CommandHandler = _CH @@ -347,6 +357,48 @@ def _separate_chunk_indicator_from_fence(text: str) -> str: return _CHUNK_INDICATOR_ON_FENCE_RE.sub(r'```\n\g', text) +# --------------------------------------------------------------------------- +# Telegram copy-to-clipboard buttons +# --------------------------------------------------------------------------- + +_COPY_BUTTON_LINE_RE = re.compile( + r'^\s*COPY_BUTTON:\s*(?P