fix: WeComBotMessage support xml

This commit is contained in:
xwisenwang 2026-03-08 19:13:28 +08:00
parent f135161377
commit adff4f8beb

View file

@ -32,52 +32,52 @@ type WeComBotChannel struct {
// WeComBotMessage represents the JSON message structure from WeCom Bot (AIBOT) // WeComBotMessage represents the JSON message structure from WeCom Bot (AIBOT)
type WeComBotMessage struct { type WeComBotMessage struct {
MsgID string `json:"msgid"` MsgID string `json:"msgid" xml:"MsgId"`
AIBotID string `json:"aibotid"` AIBotID string `json:"aibotid" xml:"AIBotID"`
ChatID string `json:"chatid"` // Session ID, only present for group chats ChatID string `json:"chatid" xml:"ChatId"` // Session ID, only present for group chats
ChatType string `json:"chattype"` // "single" for DM, "group" for group chat ChatType string `json:"chattype" xml:"ChatType"` // "single" for DM, "group" for group chat
From struct { From struct {
UserID string `json:"userid"` UserID string `json:"userid" xml:"UserId"`
} `json:"from"` } `json:"from" xml:"From"`
ResponseURL string `json:"response_url"` ResponseURL string `json:"response_url" xml:"ResponseURL"`
MsgType string `json:"msgtype"` // text, image, voice, file, mixed MsgType string `json:"msgtype" xml:"MsgType"` // text, image, voice, file, mixed
Text struct { Text struct {
Content string `json:"content"` Content string `json:"content" xml:"Content"`
} `json:"text"` } `json:"text" xml:"Text"`
Image struct { Image struct {
URL string `json:"url"` URL string `json:"url" xml:"ImageUrl"`
} `json:"image"` } `json:"image" xml:"Image"`
Voice struct { Voice struct {
Content string `json:"content"` // Voice to text content Content string `json:"content" xml:"Content"` // Voice to text content
} `json:"voice"` } `json:"voice" xml:"Voice"`
File struct { File struct {
URL string `json:"url"` URL string `json:"url" xml:"URL"`
} `json:"file"` } `json:"file" xml:"File"`
Mixed struct { Mixed struct {
MsgItem []struct { MsgItem []struct {
MsgType string `json:"msgtype"` MsgType string `json:"msgtype" xml:"MsgType"`
Text struct { Text struct {
Content string `json:"content"` Content string `json:"content" xml:"Content"`
} `json:"text"` } `json:"text" xml:"Text"`
Image struct { Image struct {
URL string `json:"url"` URL string `json:"url" xml:"ImageUrl"`
} `json:"image"` } `json:"image" xml:"Image"`
} `json:"msg_item"` } `json:"msg_item" xml:"MsgItem"`
} `json:"mixed"` } `json:"mixed" xml:"MixedMessage"`
Quote struct { Quote struct {
MsgType string `json:"msgtype"` MsgType string `json:"msgtype" xml:"MsgId"`
Text struct { Text struct {
Content string `json:"content"` Content string `json:"content" xml:"Content"`
} `json:"text"` } `json:"text" xml:"Text"`
} `json:"quote"` } `json:"quote" xml:"Quote"`
} }
// WeComBotReplyMessage represents the reply message structure // WeComBotReplyMessage represents the reply message structure
type WeComBotReplyMessage struct { type WeComBotReplyMessage struct {
MsgType string `json:"msgtype"` MsgType string `json:"msgtype" xml:"MsgType"`
Text struct { Text struct {
Content string `json:"content"` Content string `json:"content" xml:"Content"`
} `json:"text,omitempty"` } `json:"text,omitempty" xml:"Text,omitempty"`
} }
// NewWeComBotChannel creates a new WeCom Bot channel instance // 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" { if item.MsgType == "text" {
content += item.Text.Content content += item.Text.Content
} }
if item.MsgType == "image" {
content += " Don't support image yet: " + item.Image.URL
}
} }
case "image", "file": case "image", "file":
// For image and file, we don't have text content // For image and file, we don't have text content
content = "" content += "Don't support image or file yet: " + msg.MsgType
} }
// Build metadata // Build metadata