diff --git a/pkg/channels/qq/qq.go b/pkg/channels/qq/qq.go index 1e6caa063..6fa14d5c3 100644 --- a/pkg/channels/qq/qq.go +++ b/pkg/channels/qq/qq.go @@ -354,7 +354,7 @@ func (c *QQChannel) SendMedia(ctx context.Context, msg bus.OutboundMediaMessage) return fmt.Errorf("qq send media: resolve local media ref %q: %w", part.Ref, err) } - fileInfo, err := c.uploadLocalMedia(ctx, chatKind, msg.ChatID, part.Type, resolved) + fileInfo, err := c.uploadLocalMedia(ctx, chatKind, msg.ChatID, part.Type, part.Filename, resolved) if err != nil { logger.ErrorCF("qq", "Failed to upload local media", map[string]any{ "type": part.Type, diff --git a/pkg/channels/qq/qq_test.go b/pkg/channels/qq/qq_test.go index fbf5f9bfb..bf5d5c5db 100644 --- a/pkg/channels/qq/qq_test.go +++ b/pkg/channels/qq/qq_test.go @@ -166,6 +166,9 @@ func TestSendMedia_LocalFileUploadsThenSendsRichMediaMessage(t *testing.T) { if fileData == "" { t.Fatal("file_data is empty, want base64-encoded local file contents") } + if payload["file_name"] != "report.pdf" { + t.Fatalf("file_name = %v, want %q", payload["file_name"], "report.pdf") + } if len(api.groupMessages) != 1 { t.Fatalf("group message count = %d, want 1", len(api.groupMessages)) diff --git a/pkg/channels/qq/upload.go b/pkg/channels/qq/upload.go index d93d72a0b..6001fa3b4 100644 --- a/pkg/channels/qq/upload.go +++ b/pkg/channels/qq/upload.go @@ -7,6 +7,8 @@ import ( "fmt" "net/http" "os" + "path/filepath" + "strings" "github.com/tencent-connect/botgo/constant" "github.com/tencent-connect/botgo/dto" @@ -33,6 +35,7 @@ func (c *QQChannel) uploadLocalMedia( chatKind string, chatID string, partType string, + filename string, localPath string, ) ([]byte, error) { content, err := os.ReadFile(localPath) @@ -40,8 +43,16 @@ func (c *QQChannel) uploadLocalMedia( return nil, fmt.Errorf("read local media: %w", err) } + filename = strings.TrimSpace(filename) + if filename == "" { + filename = filepath.Base(localPath) + } else { + filename = filepath.Base(filename) + } + payload := map[string]any{ "file_type": qqFileType(partType), + "file_name": filename, "srv_send_msg": false, "file_data": base64.StdEncoding.EncodeToString(content), }