From adff4f8beb5f668d8d408a99a1a461c8e2831a16 Mon Sep 17 00:00:00 2001 From: xwisenwang Date: Sun, 8 Mar 2026 19:13:28 +0800 Subject: [PATCH] fix: WeComBotMessage support xml --- pkg/channels/wecom/bot.go | 65 ++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/pkg/channels/wecom/bot.go b/pkg/channels/wecom/bot.go index 674236858..384ac4bba 100644 --- a/pkg/channels/wecom/bot.go +++ b/pkg/channels/wecom/bot.go @@ -32,52 +32,52 @@ type WeComBotChannel struct { // WeComBotMessage represents the JSON message structure from WeCom Bot (AIBOT) type WeComBotMessage struct { - MsgID string `json:"msgid"` - AIBotID string `json:"aibotid"` - ChatID string `json:"chatid"` // Session ID, only present for group chats - ChatType string `json:"chattype"` // "single" for DM, "group" for group chat + MsgID string `json:"msgid" xml:"MsgId"` + AIBotID string `json:"aibotid" xml:"AIBotID"` + ChatID string `json:"chatid" xml:"ChatId"` // Session ID, only present for group chats + ChatType string `json:"chattype" xml:"ChatType"` // "single" for DM, "group" for group chat From struct { - UserID string `json:"userid"` - } `json:"from"` - ResponseURL string `json:"response_url"` - MsgType string `json:"msgtype"` // text, image, voice, file, mixed + UserID string `json:"userid" xml:"UserId"` + } `json:"from" xml:"From"` + ResponseURL string `json:"response_url" xml:"ResponseURL"` + MsgType string `json:"msgtype" xml:"MsgType"` // text, image, voice, file, mixed Text struct { - Content string `json:"content"` - } `json:"text"` + Content string `json:"content" xml:"Content"` + } `json:"text" xml:"Text"` Image struct { - URL string `json:"url"` - } `json:"image"` + URL string `json:"url" xml:"ImageUrl"` + } `json:"image" xml:"Image"` Voice struct { - Content string `json:"content"` // Voice to text content - } `json:"voice"` + Content string `json:"content" xml:"Content"` // Voice to text content + } `json:"voice" xml:"Voice"` File struct { - URL string `json:"url"` - } `json:"file"` + URL string `json:"url" xml:"URL"` + } `json:"file" xml:"File"` Mixed struct { MsgItem []struct { - MsgType string `json:"msgtype"` + MsgType string `json:"msgtype" xml:"MsgType"` Text struct { - Content string `json:"content"` - } `json:"text"` + Content string `json:"content" xml:"Content"` + } `json:"text" xml:"Text"` Image struct { - URL string `json:"url"` - } `json:"image"` - } `json:"msg_item"` - } `json:"mixed"` + URL string `json:"url" xml:"ImageUrl"` + } `json:"image" xml:"Image"` + } `json:"msg_item" xml:"MsgItem"` + } `json:"mixed" xml:"MixedMessage"` Quote struct { - MsgType string `json:"msgtype"` + MsgType string `json:"msgtype" xml:"MsgId"` Text struct { - Content string `json:"content"` - } `json:"text"` - } `json:"quote"` + Content string `json:"content" xml:"Content"` + } `json:"text" xml:"Text"` + } `json:"quote" xml:"Quote"` } // WeComBotReplyMessage represents the reply message structure type WeComBotReplyMessage struct { - MsgType string `json:"msgtype"` + MsgType string `json:"msgtype" xml:"MsgType"` Text struct { - Content string `json:"content"` - } `json:"text,omitempty"` + Content string `json:"content" xml:"Content"` + } `json:"text,omitempty" xml:"Text,omitempty"` } // NewWeComBotChannel creates a new WeCom Bot channel instance @@ -368,10 +368,13 @@ func (c *WeComBotChannel) processMessage(ctx context.Context, msg WeComBotMessag if item.MsgType == "text" { content += item.Text.Content } + if item.MsgType == "image" { + content += " Don't support image yet: " + item.Image.URL + } } case "image", "file": // For image and file, we don't have text content - content = "" + content += "Don't support image or file yet: " + msg.MsgType } // Build metadata