diff --git a/bot.py b/bot.py index b24efe2..88100e2 100644 --- a/bot.py +++ b/bot.py @@ -2413,25 +2413,24 @@ class Bot: await self._load_room_settings(room.room_id) - # In DMs respond to all files; in groups only if bot was recently @mentioned + # In DMs respond to all files; in groups, silently ingest (respond only if mentioned) is_dm = room.member_count == 2 + group_mentioned = False if not is_dm: body = (event.body or "").strip() bot_display = self.client.user_id.split(":")[0].lstrip("@") - # Also match display name (e.g. 'Claude') since Element uses it in mentions bot_displayname = (getattr(self, '_display_name', '') or bot_display).lower() body_lower = body.lower() - mentioned = ( + group_mentioned = ( BOT_USER in body or f"@{bot_display}" in body_lower or bot_display.lower() in body_lower or bot_displayname in body_lower ) - if not mentioned: - return if not self.llm: - await self._send_text(room.room_id, "LLM not configured (LITELLM_BASE_URL not set).") + if is_dm or group_mentioned: + await self._send_text(room.room_id, "LLM not configured (LITELLM_BASE_URL not set).") return # Download file @@ -2497,6 +2496,11 @@ class Bot: del docs[:-5] label = "PDF" if is_pdf else "Word document" if is_docx else "file" + + # In group rooms without mention, silently ingest — respond on next @mention + if not is_dm and not group_mentioned: + logger.info("Silently ingested %s in group room %s", filename, room.room_id) + return user_message = f'The user sent a {label} named "{filename}". Here is the extracted text:\n\n{extracted}\n\nPlease summarize or answer questions about this document.' await self.client.room_typing(room.room_id, typing_state=True) @@ -2536,14 +2540,12 @@ class Bot: # Also match display name (e.g. 'Claude') since Element uses it in mentions bot_displayname = (getattr(self, '_display_name', '') or bot_display).lower() body_lower = body.lower() - mentioned = ( + group_mentioned = ( BOT_USER in body or f"@{bot_display}" in body_lower or bot_display.lower() in body_lower or bot_displayname in body_lower ) - if not mentioned: - return if not self.llm: await self._send_text(room.room_id, "LLM not configured (LITELLM_BASE_URL not set).") @@ -2608,6 +2610,11 @@ class Bot: del docs[:-5] label = "PDF" if is_pdf else "Word document" if is_docx else "file" + + # In group rooms without mention, silently ingest — respond on next @mention + if not is_dm and not group_mentioned: + logger.info("Silently ingested encrypted %s in group room %s", filename, room.room_id) + return user_message = f'The user sent a {label} named "{filename}". Here is the extracted text:\n\n{extracted}\n\nPlease summarize or answer questions about this document.' await self.client.room_typing(room.room_id, typing_state=True)