feat(im): add markdown replies for QQBot

main
YS-zdck 2026-08-01 22:11:54 +08:00 committed by lyingbug
parent b39f00633c
commit cb5e59b917
3 changed files with 40 additions and 8 deletions

View File

@ -108,3 +108,30 @@ func TestNewClientAllowsWhitelistedPrivateDeployment(t *testing.T) {
t.Fatalf("expected whitelisted private qqbot endpoints to pass: %v", err)
}
}
func TestSendMessageRequestUsesMarkdownMessage(t *testing.T) {
req := sendMessageRequest{
Content: "fallback",
MsgType: 2,
Markdown: &markdownMessage{Content: "# title\n**answer**"},
MsgID: "msg-1",
MsgSeq: 1,
}
raw, err := json.Marshal(req)
if err != nil {
t.Fatal(err)
}
var payload map[string]any
if err := json.Unmarshal(raw, &payload); err != nil {
t.Fatal(err)
}
if payload["msg_type"] != float64(2) {
t.Fatalf("msg_type = %v, want 2", payload["msg_type"])
}
markdown, ok := payload["markdown"].(map[string]any)
if !ok || markdown["content"] != "# title\n**answer**" {
t.Fatalf("markdown payload = %#v", payload["markdown"])
}
}

View File

@ -123,10 +123,10 @@ func (c *Client) SendGroupMessage(ctx context.Context, groupOpenID, content, msg
func (c *Client) sendText(ctx context.Context, path, content, msgID string) error {
body := sendMessageRequest{
Content: content,
MsgType: 0,
MsgID: msgID,
MsgSeq: 1,
MsgType: 2,
Markdown: &markdownMessage{Content: content},
MsgID: msgID,
MsgSeq: 1,
}
return c.doJSON(ctx, http.MethodPost, c.apiBaseURL+path, body, nil)
}

View File

@ -76,8 +76,13 @@ type qqAttachment struct {
}
type sendMessageRequest struct {
Content string `json:"content"`
MsgType int `json:"msg_type"`
MsgID string `json:"msg_id,omitempty"`
MsgSeq int `json:"msg_seq,omitempty"`
Content string `json:"content,omitempty"`
MsgType int `json:"msg_type"`
Markdown *markdownMessage `json:"markdown,omitempty"`
MsgID string `json:"msg_id,omitempty"`
MsgSeq int `json:"msg_seq,omitempty"`
}
type markdownMessage struct {
Content string `json:"content,omitempty"`
}