// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package convertlib
import "fmt"
type imageConverter struct{}
func (imageConverter) Convert(ctx *ConvertContext) string {
parsed, err := ParseJSONObject(ctx.RawContent)
if err != nil {
return invalidJSONPlaceholder("image")
}
if key, _ := parsed["image_key"].(string); key != "" {
return fmt.Sprintf("[Image: %s]", key)
}
return "[Image]"
}
type fileConverter struct{}
func (fileConverter) Convert(ctx *ConvertContext) string {
parsed, err := ParseJSONObject(ctx.RawContent)
if err != nil {
return invalidJSONPlaceholder("file")
}
key, _ := parsed["file_key"].(string)
if key == "" {
return "[File]"
}
name, _ := parsed["file_name"].(string)
if name == "" {
name = key
}
return fmt.Sprintf(``, cardEscapeAttr(key), cardEscapeAttr(name))
}
type audioMsgConverter struct{}
// Convert renders an audio message: when body.content carries a file_key it
// emits (duration omitted when absent);
// otherwise it falls back to [Voice: Xs] (duration only) or [Voice].
func (audioMsgConverter) Convert(ctx *ConvertContext) string {
parsed, err := ParseJSONObject(ctx.RawContent)
if err != nil {
return invalidJSONPlaceholder("audio")
}
if key, _ := parsed["file_key"].(string); key != "" {
result := fmt.Sprintf(`