From 7e0198a64ca9261dd233eaf1e9dde9ff89b562f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AC=E6=98=8E?= <83812544+Ed1s0nZ@users.noreply.github.com> Date: Mon, 2 Mar 2026 00:58:40 +0800 Subject: [PATCH] Add files via upload --- internal/robot/ding.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/internal/robot/ding.go b/internal/robot/ding.go index b391fe0c..eefebf66 100644 --- a/internal/robot/ding.go +++ b/internal/robot/ding.go @@ -98,9 +98,23 @@ func handleDingMessage(ctx context.Context, msg *chatbot.BotCallbackDataModel, h userID = msg.ConversationId } reply := h.HandleMessage("dingtalk", userID, content) + // 使用 markdown 类型以便正确展示标题、列表、代码块等格式 + title := reply + if idx := strings.IndexAny(reply, "\n"); idx > 0 { + title = strings.TrimSpace(reply[:idx]) + } + if len(title) > 50 { + title = title[:50] + "…" + } + if title == "" { + title = "回复" + } body := map[string]interface{}{ - "msgtype": "text", - "text": map[string]string{"content": reply}, + "msgtype": "markdown", + "markdown": map[string]string{ + "title": title, + "text": reply, + }, } bodyBytes, _ := json.Marshal(body) req, err := http.NewRequestWithContext(ctx, http.MethodPost, msg.SessionWebhook, bytes.NewReader(bodyBytes))