fix(feishu): don't append media tags to interactive card JSON
Appending media tags like "[attachment]" to raw JSON content produces invalid JSON format. For interactive cards, the JSON already contains image information and media refs are downloaded separately. - Skip appendMediaTags for MsgTypeInteractive to preserve valid JSON - Add test case for interactive card with images
This commit is contained in:
parent
2e9cdf83b5
commit
c3e0724808
2 changed files with 14 additions and 0 deletions
|
|
@ -677,11 +677,18 @@ func (c *FeishuChannel) downloadResource(
|
||||||
}
|
}
|
||||||
|
|
||||||
// appendMediaTags appends media type tags to content (like Telegram's "[image: photo]").
|
// appendMediaTags appends media type tags to content (like Telegram's "[image: photo]").
|
||||||
|
// For interactive cards, media tags are not appended because content is raw JSON
|
||||||
|
// and appending would produce invalid JSON format.
|
||||||
func appendMediaTags(content, messageType string, mediaRefs []string) string {
|
func appendMediaTags(content, messageType string, mediaRefs []string) string {
|
||||||
if len(mediaRefs) == 0 {
|
if len(mediaRefs) == 0 {
|
||||||
return content
|
return content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't append tags to JSON content (interactive cards) - would produce invalid JSON
|
||||||
|
if messageType == larkim.MsgTypeInteractive {
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
|
||||||
var tag string
|
var tag string
|
||||||
switch messageType {
|
switch messageType {
|
||||||
case larkim.MsgTypeImage:
|
case larkim.MsgTypeImage:
|
||||||
|
|
|
||||||
|
|
@ -169,6 +169,13 @@ func TestAppendMediaTags(t *testing.T) {
|
||||||
mediaRefs: []string{"ref1"},
|
mediaRefs: []string{"ref1"},
|
||||||
want: "something [attachment]",
|
want: "something [attachment]",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "interactive card with images returns content unchanged",
|
||||||
|
content: `{"schema":"2.0","body":{"elements":[{"tag":"img","img_key":"img_123"}]}}`,
|
||||||
|
messageType: "interactive",
|
||||||
|
mediaRefs: []string{"ref1"},
|
||||||
|
want: `{"schema":"2.0","body":{"elements":[{"tag":"img","img_key":"img_123"}]}}`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue