Ignore non-Telegram tool streaming contexts

Make Telegram tool lifecycle hooks no-op for contexts that do not expose a raw data dict or do not carry the Telegram bot marker. This keeps global tool extension dispatch safe for non-Telegram contexts, including Responses API tool-call regression tests, without changing behavior for real Telegram sessions.

Alessandro committed Jun 11, 2026 at 19:14 UTC 8e270c5ab7661640b8436b6d36d7943ea1b80f48
2 files changed +14 -2
plugins/_telegram_integration/extensions/python/tool_execute_after/_50_telegram_response.py
+7 -1
@@ -16,7 +16,13 @@ class TelegramResponseIntercept(Extension):
16 if not self.agent:
17 return
18 context = self.agent.context
19 - if not context.data.get(CTX_TG_BOT):
19 + context_data = getattr(context, "data", None)
20 + telegram_bot = (
21 + context_data.get(CTX_TG_BOT)
22 + if isinstance(context_data, dict)
23 + else context.get_data(CTX_TG_BOT)
24 + )
25 + if not telegram_bot:
26 return
27
28 from plugins._telegram_integration.helpers import draft_stream
plugins/_telegram_integration/extensions/python/tool_execute_before/_45_telegram_draft_tool.py
+7 -1
@@ -10,7 +10,13 @@ class TelegramDraftToolStart(Extension):
10 if (tool_name or "").strip().lower() == "response":
11 return
12 context = self.agent.context
13 - if not context.data.get(CTX_TG_BOT):
13 + context_data = getattr(context, "data", None)
14 + telegram_bot = (
15 + context_data.get(CTX_TG_BOT)
16 + if isinstance(context_data, dict)
17 + else context.get_data(CTX_TG_BOT)
18 + )
19 + if not telegram_bot:
20 return
21
22 from plugins._telegram_integration.helpers import draft_stream