From 06d0e43b507c35e23cfcc590f599310d94d83526 Mon Sep 17 00:00:00 2001 From: wdvxdr1123 Date: Sun, 8 Mar 2026 17:51:55 +0800 Subject: [PATCH] feat: add support for Markdown messages in QQ channel --- docs/channels/qq/README.zh.md | 4 +++- pkg/channels/qq/qq.go | 13 +++++++++++-- pkg/config/config.go | 1 + 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/docs/channels/qq/README.zh.md b/docs/channels/qq/README.zh.md index bd774960f..05c454d56 100644 --- a/docs/channels/qq/README.zh.md +++ b/docs/channels/qq/README.zh.md @@ -11,7 +11,8 @@ PicoClaw 通过 QQ 开放平台的官方机器人 API 提供对 QQ 的支持。 "enabled": true, "app_id": "YOUR_APP_ID", "app_secret": "YOUR_APP_SECRET", - "allow_from": [] + "allow_from": [], + "allow_markdown": false } } } @@ -23,6 +24,7 @@ PicoClaw 通过 QQ 开放平台的官方机器人 API 提供对 QQ 的支持。 | app_id | string | 是 | QQ 机器人应用的 App ID | | app_secret | string | 是 | QQ 机器人应用的 App Secret | | allow_from | array | 否 | 用户ID白名单,空表示允许所有用户 | +| allow_markdown| bool| 否 | 是否允许使用 Markdown 格式发送消息 | ## 设置流程 diff --git a/pkg/channels/qq/qq.go b/pkg/channels/qq/qq.go index 112964143..59441d2bd 100644 --- a/pkg/channels/qq/qq.go +++ b/pkg/channels/qq/qq.go @@ -122,12 +122,21 @@ func (c *QQChannel) Send(ctx context.Context, msg bus.OutboundMessage) error { } // construct message - msgToCreate := &dto.MessageToCreate{ + msgToCreate := dto.MessageToCreate{ Content: msg.Content, + MsgType: dto.TextMsg, + } + if c.config.AllowMarkdown { + msgToCreate = dto.MessageToCreate{ + MsgType: dto.MarkdownMsg, + Markdown: &dto.Markdown{ + Content: msg.Content, + }, + } } // send C2C message - _, err := c.api.PostC2CMessage(ctx, msg.ChatID, msgToCreate) + _, err := c.api.PostC2CMessage(ctx, msg.ChatID, &msgToCreate) if err != nil { logger.ErrorCF("qq", "Failed to send C2C message", map[string]any{ "error": err.Error(), diff --git a/pkg/config/config.go b/pkg/config/config.go index fcbfc8e78..e10ae1cfc 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -309,6 +309,7 @@ type QQConfig struct { AppID string `json:"app_id" env:"PICOCLAW_CHANNELS_QQ_APP_ID"` AppSecret string `json:"app_secret" env:"PICOCLAW_CHANNELS_QQ_APP_SECRET"` AllowFrom FlexibleStringSlice `json:"allow_from" env:"PICOCLAW_CHANNELS_QQ_ALLOW_FROM"` + AllowMarkdown bool `json:"allow_markdown" env:"PICOCLAW_CHANNELS_QQ_ALLOW_MARKDOWN"` GroupTrigger GroupTriggerConfig `json:"group_trigger,omitempty"` ReasoningChannelID string `json:"reasoning_channel_id" env:"PICOCLAW_CHANNELS_QQ_REASONING_CHANNEL_ID"` }