From 052b8f1b0a9a0f07512d5fadc3887a897857d197 Mon Sep 17 00:00:00 2001 From: zhaoyunxing Date: Wed, 18 Mar 2026 22:17:40 +0800 Subject: [PATCH] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- pkg/channels/dingtalk/dingtalk.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/pkg/channels/dingtalk/dingtalk.go b/pkg/channels/dingtalk/dingtalk.go index 9929b5855..8e0db8bbf 100644 --- a/pkg/channels/dingtalk/dingtalk.go +++ b/pkg/channels/dingtalk/dingtalk.go @@ -198,14 +198,20 @@ func (c *DingTalkChannel) onChatBotMessageReceived( } // Try to create and deliver card (optional feature) - // If it fails, log the error but continue with normal message handling - if cardID, err := c.tryCardCreateAndDeliver(ctx, data); err != nil { - logger.WarnC("dingtalk", "Failed to create or deliver card, falling back to direct reply") - // Store the session webhook for this chat so we can reply later - c.sessionWebhooks.Store(chatID, data.SessionWebhook) + // Only attempt this if a card template is configured; otherwise, fall back silently + if c.config.CardTemplateID != "" { + // If it fails, log the error but continue with normal message handling + if cardID, err := c.tryCardCreateAndDeliver(ctx, data); err != nil { + logger.WarnC("dingtalk", "Failed to create or deliver card, falling back to direct reply") + // Store the session webhook for this chat so we can reply later + c.sessionWebhooks.Store(chatID, data.SessionWebhook) + } else { + chatID = data.MsgId + c.cardInstanceIDs.Store(chatID, cardID) + } } else { - chatID = data.MsgId - c.cardInstanceIDs.Store(chatID, cardID) + // Card feature not configured; just store the session webhook for direct replies + c.sessionWebhooks.Store(chatID, data.SessionWebhook) } // Handle the message through the base channel