fix: silently ingest files in group rooms without mention
Files uploaded to group rooms are now downloaded, parsed, and stored in _room_document_context even without @mention. When the user later mentions the bot, the document context is automatically included. Previously files were silently dropped if the caption didn't contain a mention, so the bot would say it can't access uploaded PDFs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
23
bot.py
23
bot.py
@@ -2413,24 +2413,23 @@ class Bot:
|
|||||||
|
|
||||||
await self._load_room_settings(room.room_id)
|
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
|
is_dm = room.member_count == 2
|
||||||
|
group_mentioned = False
|
||||||
if not is_dm:
|
if not is_dm:
|
||||||
body = (event.body or "").strip()
|
body = (event.body or "").strip()
|
||||||
bot_display = self.client.user_id.split(":")[0].lstrip("@")
|
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()
|
bot_displayname = (getattr(self, '_display_name', '') or bot_display).lower()
|
||||||
body_lower = body.lower()
|
body_lower = body.lower()
|
||||||
mentioned = (
|
group_mentioned = (
|
||||||
BOT_USER in body
|
BOT_USER in body
|
||||||
or f"@{bot_display}" in body_lower
|
or f"@{bot_display}" in body_lower
|
||||||
or bot_display.lower() in body_lower
|
or bot_display.lower() in body_lower
|
||||||
or bot_displayname in body_lower
|
or bot_displayname in body_lower
|
||||||
)
|
)
|
||||||
if not mentioned:
|
|
||||||
return
|
|
||||||
|
|
||||||
if not self.llm:
|
if not self.llm:
|
||||||
|
if is_dm or group_mentioned:
|
||||||
await self._send_text(room.room_id, "LLM not configured (LITELLM_BASE_URL not set).")
|
await self._send_text(room.room_id, "LLM not configured (LITELLM_BASE_URL not set).")
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -2497,6 +2496,11 @@ class Bot:
|
|||||||
del docs[:-5]
|
del docs[:-5]
|
||||||
|
|
||||||
label = "PDF" if is_pdf else "Word document" if is_docx else "file"
|
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.'
|
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)
|
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
|
# Also match display name (e.g. 'Claude') since Element uses it in mentions
|
||||||
bot_displayname = (getattr(self, '_display_name', '') or bot_display).lower()
|
bot_displayname = (getattr(self, '_display_name', '') or bot_display).lower()
|
||||||
body_lower = body.lower()
|
body_lower = body.lower()
|
||||||
mentioned = (
|
group_mentioned = (
|
||||||
BOT_USER in body
|
BOT_USER in body
|
||||||
or f"@{bot_display}" in body_lower
|
or f"@{bot_display}" in body_lower
|
||||||
or bot_display.lower() in body_lower
|
or bot_display.lower() in body_lower
|
||||||
or bot_displayname in body_lower
|
or bot_displayname in body_lower
|
||||||
)
|
)
|
||||||
if not mentioned:
|
|
||||||
return
|
|
||||||
|
|
||||||
if not self.llm:
|
if not self.llm:
|
||||||
await self._send_text(room.room_id, "LLM not configured (LITELLM_BASE_URL not set).")
|
await self._send_text(room.room_id, "LLM not configured (LITELLM_BASE_URL not set).")
|
||||||
@@ -2608,6 +2610,11 @@ class Bot:
|
|||||||
del docs[:-5]
|
del docs[:-5]
|
||||||
|
|
||||||
label = "PDF" if is_pdf else "Word document" if is_docx else "file"
|
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.'
|
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)
|
await self.client.room_typing(room.room_id, typing_state=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user