fix(zulip): 增加内容检测fallback解决Generic bot收不到mention flag问题#484
Open
wedone wants to merge 1 commit into
Open
Conversation
f52778d to
69bf9f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
背景说明:
PR #480 中声称实现了 Zulip channel 响应 @mention 的功能。该 PR 通过
_is_mentioned()检查flags中的 mention 标志来判断 bot 是否被 @。然而实际部署测试发现,该实现未能正常工作——在频道中 @bot 无响应。根因如下:
Zulip 官方文档说明:
这意味着要响应频道中的 @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 机制:flags中的 mention 标志(mentioned、wildcard_mentioned、stream_wildcard_mentioned、topic_wildcard_mentioned)@**机器人全名**模式优势:
Related Issues
Module(s) Affected
agentsapiconfigcoreknowledgeloggingservices(tutorbot channels)toolsutilsweb(Frontend)docs(Documentation)scriptstestsChecklist
pre-commit run --all-filesand fixed any issues.Additional Notes
测试验证:
已通过容器部署验证:
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 检测优先级高于内容检测