Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(telegram): gate general topic creation

cyh36eaa0179e37
diff --git a/modules/im/telegram.py b/modules/im/telegram.py
index a08ef51d8..0611665db 100644
--- a/modules/im/telegram.py
+++ b/modules/im/telegram.py
@@ -267,6 +267,11 @@ class TelegramBot(BaseIMClient):
thread_id = str(context.thread_id or message.get("message_thread_id") or "").strip()
return thread_id in {"", "1"}
+ def _has_topic_seed_content(self, context: MessageContext, text: str) -> bool:
+ if (text or "").strip():
+ return True
+ return bool(getattr(context, "files", None))
+
def _should_auto_create_topic(self, context: MessageContext, message: dict[str, Any], text: str) -> bool:
if not self.config.forum_auto_topic:
return False
@@ -274,6 +279,8 @@ class TelegramBot(BaseIMClient):
return False
if not self._is_general_forum_context(context, message):
return False
+ if not self._has_topic_seed_content(context, text):
+ return False
if message.get("reply_to_message"):
return False
if text.startswith("/"):
diff --git a/tests/test_telegram_bot.py b/tests/test_telegram_bot.py
index 759a6a299..1a12e3ea8 100644
--- a/tests/test_telegram_bot.py
+++ b/tests/test_telegram_bot.py
@@ -154,6 +154,43 @@ def test_should_auto_create_topic_for_forum_general_without_thread_id() -> None:
assert bot._should_auto_create_topic(context, message, "hello from general") is True
+def test_should_not_auto_create_topic_for_empty_general_service_update() -> None:
+ bot = TelegramBot(TelegramConfig(bot_token="123456:test-token", forum_auto_topic=True))
+ context = MessageContext(
+ user_id="42",
+ channel_id="-100123",
+ thread_id=None,
+ message_id="77",
+ platform="telegram",
+ platform_specific={"chat_type": "supergroup", "is_forum": True, "is_topic_message": False},
+ )
+ message = {
+ "chat": {"id": -100123, "type": "supergroup", "title": "Core Forum", "is_forum": True},
+ "message_id": 77,
+ "pinned_message": {"message_id": 12},
+ }
+
+ assert bot._should_auto_create_topic(context, message, "") is False
+
+
+def test_should_auto_create_topic_for_general_photo_without_text() -> None:
+ bot = TelegramBot(TelegramConfig(bot_token="123456:test-token", forum_auto_topic=True))
+ message = {
+ "chat": {"id": -100123, "type": "supergroup", "title": "Core Forum", "is_forum": True},
+ "message_id": 77,
+ "photo": [{"file_id": "small"}, {"file_id": "large", "file_size": 42}],
+ }
+ context = bot._build_message_context(
+ {
+ **message,
+ "from": {"id": 42},
+ }
+ )
+
+ assert context is not None
+ assert bot._should_auto_create_topic(context, message, "") is True
+
+
def test_start_new_topic_session_allows_forum_context_without_thread_id() -> None:
bot = TelegramBot(TelegramConfig(bot_token="123456:test-token", forum_auto_topic=True))
context = MessageContext(