Skip to content

fix(zulip): 增加内容检测fallback解决Generic bot收不到mention flag问题#484

Open
wedone wants to merge 1 commit into
HKUDS:devfrom
wedone:fix/zulip-upload-and-send
Open

fix(zulip): 增加内容检测fallback解决Generic bot收不到mention flag问题#484
wedone wants to merge 1 commit into
HKUDS:devfrom
wedone:fix/zulip-upload-and-send

Conversation

@wedone
Copy link
Copy Markdown
Contributor

@wedone wedone commented May 14, 2026

Description

背景说明:

PR #480 中声称实现了 Zulip channel 响应 @mention 的功能。该 PR 通过 _is_mentioned() 检查 flags 中的 mention 标志来判断 bot 是否被 @。

然而实际部署测试发现,该实现未能正常工作——在频道中 @bot 无响应。根因如下:

Zulip 官方文档说明:

An outgoing webhook bot can read direct messages where the bot is a participant, and channel messages where the bot is mentioned. When the bot is DM'd or mentioned, it POSTs the message content to a URL of your choice.

这意味着要响应频道中的 @mention,官方推荐的方式是使用 Outgoing webhook bot,并且需要搭配 Zulip Botserver来接收 POST 请求。

而 DeepTutor 的 Zulip channel 使用的是 Generic bot + Event Queue API 架构。实际测试发现:使用 Generic bot 时,Zulip 服务端返回的事件 flags 字段为空数组,导致 _is_mentioned() 方法无法检测到 @mention。

修复方案:

_is_mentioned() 方法中增加内容检测 fallback 机制:

  1. 首先检查 flags 中的 mention 标志(mentionedwildcard_mentionedstream_wildcard_mentionedtopic_wildcard_mentioned
  2. 如果 flags 中没有 mention 标志,则扫描消息内容是否包含 @**机器人全名** 模式
  3. 如果匹配到 @mention 模式,则认为 bot 被提及

优势:

  • 无需引入 Outgoing webhook bot 和 Zulip Botserver
  • 仅需修改少量代码即可实现 Generic bot 响应频道 @mention 的功能

Related Issues

  • Closes #...
  • Related to #...

Module(s) Affected

  • agents
  • api
  • config
  • core
  • knowledge
  • logging
  • services (tutorbot channels)
  • tools
  • utils
  • web (Frontend)
  • docs (Documentation)
  • scripts
  • tests

Checklist

  • I have read and followed the contribution guidelines.
  • My code follows the project's coding standards.
  • I have run pre-commit run --all-files and fixed any issues.
  • I have added relevant tests for my changes.
  • I have updated the documentation (if necessary).
  • My changes do not introduce any new security vulnerabilities.

Additional Notes

测试验证:

已通过容器部署验证:

DEBUG   Zulip _is_mentioned: detected via content match, pattern=@**test**
INFO    Processing message from zulip:...: **[频道名 > 主题]** @**test** 测试

Bot 成功响应频道中的 @mention 并回复消息。

新增测试用例:

  • test_content_mention_fallback: 验证内容检测 fallback 基本功能
  • test_content_mention_not_at_start: 验证 @mention 不在消息开头时也能检测
  • test_content_mention_no_match_partial: 验证部分名称匹配不会误触发
  • test_content_mention_empty_full_name: 验证 bot 全名为空时跳过检测
  • test_flags_take_precedence_over_content: 验证 flags 检测优先级高于内容检测

@wedone wedone force-pushed the fix/zulip-upload-and-send branch from f52778d to 69bf9f6 Compare May 17, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant