AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug] webchat(内置平台)受 friend_message_needs_wake_prefix 限制,必须带唤醒前缀才能回复

Open Neo-millunnium opened this issue 4 months ago • 1 comments

问题描述

friend_message_needs_wake_prefix 配置项本意是控制 QQ 等外部平台的私聊消息是否需要唤醒前缀(/),但当前实现是一刀切的——所有私聊/好友类型的消息都受此限制,导致 webchat(WebUI 内置聊天平台)也必须带 / 前缀才能触发回复。

复现步骤

  1. 配置 friend_message_needs_wake_prefix: true
  2. 打开 AstrBot WebUI 前端聊天窗口
  3. 输入"你好"(不带 / 前缀)
  4. 消息被接收但无任何回复

根因

在 astrbot/core/pipeline/waking_check/stage.py 中,唤醒判断逻辑没有区分平台:

if event.is_private_chat() and not self.friend_message_needs_wake_prefix:

webchat 平台的消息类型为 MessageType.FRIEND_MESSAGE,is_private_chat() 返回 true,因此被 friend_message_needs_wake_prefix 规则拦截。

影响范围

所有使用 AstrBot WebUI 内置聊天功能的用户,只要开启了 friend_message_needs_wake_prefix: true,webchat 就无法正常回复。

修复建议

在唤醒判断时对 webchat 平台做豁免:

if event.is_private_chat() and (not self.friend_message_needs_wake_prefix or event.get_platform_id() == "webchat"):

环境信息

  • AstrBot 版本: v4.26.5
  • 最新提交: a1a7de1c57613f9f5fd80497c810fa68735bfcb9
  • 系统: Linux

Neo-millunnium avatar Jul 11 '26 18:07 Neo-millunnium

Hi @Neo-millunnium! I'm Dosu and I'm helping the AstrBotTeam team.

确认了你的分析是正确的。当前 WakingCheckStage 中的私聊唤醒逻辑没有对 webchat 做任何豁免 [1]:

if event.is_private_chat() and not self.friend_message_needs_wake_prefix:
    is_wake = True

有趣的是,webchat 在白名单检查阶段已经有了豁免处理 [2]:

if event.get_platform_name() == "webchat":
    # WebChat 豁免
    return

但这个豁免只影响白名单过滤,不影响唤醒检查。

你提出的修复建议方向是正确的。参考白名单阶段的写法,可以在唤醒检查中加入类似的 webchat 豁免逻辑,例如:

if event.is_private_chat() and (not self.friend_message_needs_wake_prefix or event.get_platform_name() == "webchat"):

注意这里用 get_platform_name() 比 get_platform_id() 更一致,因为白名单阶段用的就是 get_platform_name()。webchat 的 platform name 和 id 都是 "webchat" [3],所以两者都能工作。

目前没有找到已有的 PR 修复这个问题。

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about AstrBot with Dosu Add Dosu to your team

dosubot[bot] avatar Jul 11 '26 18:07 dosubot[bot]