fix(wecom): strip @mention from group chat messages to fix slash commands

WeCom AI Bot does not strip @mention from text.content in group chats,
causing all slash commands (/stop, /clear, /help) to fail — the content
arrives as "@BotName /stop" instead of "/stop".

- Add stripAtMentionBasic (stateless) and stripAtMention (with bot name
  caching) to handle multi-word bot display names
- Support bot_name in channel credentials for immediate precision
- Apply stripping in both WebSocket and webhook adapters, text and mixed
- Add mention_test.go with 21 test cases
This commit is contained in:
nullkey
2026-04-02 03:15:51 +08:00
committed by lyingbug
parent b66552749d
commit 39831fb61c
4 changed files with 254 additions and 9 deletions
+9 -2
View File
@@ -167,13 +167,20 @@ func (a *WebhookAdapter) ParseCallback(c *gin.Context) (*im.IncomingMessage, err
// Determine chat type
chatType := im.ChatTypeDirect
chatID := ""
if msg.ChatID != "" {
isGroup := msg.ChatID != ""
if isGroup {
chatType = im.ChatTypeGroup
chatID = msg.ChatID
}
switch msg.MsgType {
case "text":
// Strip @mention in group chat (same issue as long connection mode).
// Webhook adapter has no persistent state, so use the standalone helper.
textContent := msg.Content
if isGroup {
textContent = stripAtMentionBasic(textContent)
}
return &im.IncomingMessage{
Platform: im.PlatformWeCom,
MessageType: im.MessageTypeText,
@@ -181,7 +188,7 @@ func (a *WebhookAdapter) ParseCallback(c *gin.Context) (*im.IncomingMessage, err
UserName: msg.FromUserName,
ChatID: chatID,
ChatType: chatType,
Content: strings.TrimSpace(msg.Content),
Content: strings.TrimSpace(textContent),
MessageID: msg.MsgID,
}, nil