feat(telegram): add silent_tool_hints config to disable notifications for tool hints (#2252)

This commit is contained in:
Flo 2026-03-20 09:31:09 +03:00 committed by GitHub
parent 7ceb07303b
commit 8cd51708a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 2 deletions

View File

@ -262,7 +262,8 @@ Connect nanobot to your favorite chat platform. Want to build your own? See the
"telegram": { "telegram": {
"enabled": true, "enabled": true,
"token": "YOUR_BOT_TOKEN", "token": "YOUR_BOT_TOKEN",
"allowFrom": ["YOUR_USER_ID"] "allowFrom": ["YOUR_USER_ID"],
"silentToolHints": false
} }
} }
} }

View File

@ -167,6 +167,7 @@ class TelegramConfig(Base):
group_policy: Literal["open", "mention"] = "mention" group_policy: Literal["open", "mention"] = "mention"
connection_pool_size: int = 32 connection_pool_size: int = 32
pool_timeout: float = 5.0 pool_timeout: float = 5.0
silent_tool_hints: bool = False
class TelegramChannel(BaseChannel): class TelegramChannel(BaseChannel):
@ -415,13 +416,15 @@ class TelegramChannel(BaseChannel):
# Send text content # Send text content
if msg.content and msg.content != "[empty message]": if msg.content and msg.content != "[empty message]":
is_progress = msg.metadata.get("_progress", False) is_progress = msg.metadata.get("_progress", False)
is_tool_hint = msg.metadata.get("_tool_hint", False)
disable_notification = self.config.silent_tool_hints and is_tool_hint
for chunk in split_message(msg.content, TELEGRAM_MAX_MESSAGE_LEN): for chunk in split_message(msg.content, TELEGRAM_MAX_MESSAGE_LEN):
# Final response: simulate streaming via draft, then persist # Final response: simulate streaming via draft, then persist
if not is_progress: if not is_progress:
await self._send_with_streaming(chat_id, chunk, reply_params, thread_kwargs) await self._send_with_streaming(chat_id, chunk, reply_params, thread_kwargs)
else: else:
await self._send_text(chat_id, chunk, reply_params, thread_kwargs) await self._send_text(chat_id, chunk, reply_params, thread_kwargs, disable_notification=disable_notification)
async def _call_with_retry(self, fn, *args, **kwargs): async def _call_with_retry(self, fn, *args, **kwargs):
"""Call an async Telegram API function with retry on pool/network timeout.""" """Call an async Telegram API function with retry on pool/network timeout."""
@ -444,6 +447,7 @@ class TelegramChannel(BaseChannel):
text: str, text: str,
reply_params=None, reply_params=None,
thread_kwargs: dict | None = None, thread_kwargs: dict | None = None,
disable_notification: bool = False,
) -> None: ) -> None:
"""Send a plain text message with HTML fallback.""" """Send a plain text message with HTML fallback."""
try: try:
@ -452,6 +456,7 @@ class TelegramChannel(BaseChannel):
self._app.bot.send_message, self._app.bot.send_message,
chat_id=chat_id, text=html, parse_mode="HTML", chat_id=chat_id, text=html, parse_mode="HTML",
reply_parameters=reply_params, reply_parameters=reply_params,
disable_notification=disable_notification,
**(thread_kwargs or {}), **(thread_kwargs or {}),
) )
except Exception as e: except Exception as e:
@ -462,6 +467,7 @@ class TelegramChannel(BaseChannel):
chat_id=chat_id, chat_id=chat_id,
text=text, text=text,
reply_parameters=reply_params, reply_parameters=reply_params,
disable_notification=disable_notification,
**(thread_kwargs or {}), **(thread_kwargs or {}),
) )
except Exception as e2: except Exception as e2: