From a952232cc9a5ae7f9eef5a7d88cb567fb304aa46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9A=E7=AB=A0=E6=B5=A9?= Date: Tue, 21 Jul 2026 21:21:41 +0800 Subject: [PATCH] feat: add exact custom card feedback reasons --- internal/channels/dingtalk/feedback.go | 36 +++++++++++++++------ internal/channels/dingtalk/feedback_test.go | 30 +++++++++++++++++ 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/internal/channels/dingtalk/feedback.go b/internal/channels/dingtalk/feedback.go index c7b75f1..b32a5fe 100644 --- a/internal/channels/dingtalk/feedback.go +++ b/internal/channels/dingtalk/feedback.go @@ -11,15 +11,21 @@ import ( ) const ( - ActionNativeFeedback = "sys_action_like_component" - ActionFeedbackUp = "dobotai_feedback_up" - ActionFeedbackDown = "dobotai_feedback_down" - ActionReasonIncorrect = "dobotai_reason_incorrect" - ActionReasonNotResolved = "dobotai_reason_not_resolved" - ActionReasonIrrelevant = "dobotai_reason_irrelevant" - ActionReasonUnclear = "dobotai_reason_unclear" - ActionReasonOutdated = "dobotai_reason_outdated" - ActionReasonOther = "dobotai_reason_other" + ActionNativeFeedback = "sys_action_like_component" + ActionFeedbackUp = "dobotai_feedback_up" + ActionFeedbackDown = "dobotai_feedback_down" + ActionReasonIncorrect = "dobotai_reason_incorrect" + ActionReasonNotResolved = "dobotai_reason_not_resolved" + ActionReasonIrrelevant = "dobotai_reason_irrelevant" + ActionReasonUnclear = "dobotai_reason_unclear" + ActionReasonOutdated = "dobotai_reason_outdated" + ActionReasonOther = "dobotai_reason_other" + ActionReasonContentMismatch = "dobotai_reason_content_mismatch" + ActionReasonContentIncomplete = "dobotai_reason_content_incomplete" + ActionReasonIllogical = "dobotai_reason_illogical_expression" + ActionReasonFactualError = "dobotai_reason_factual_error" + ActionReasonSensitiveContent = "dobotai_reason_sensitive_content" + ActionReasonAnswerNotWanted = "dobotai_reason_answer_not_wanted" ) var nativeReasonByTag = map[string]string{ @@ -166,6 +172,18 @@ func oneFeedbackAction(action string) (string, string, bool) { return feedbackdomain.ValueDown, feedbackdomain.ReasonOutdated, true case ActionReasonOther: return feedbackdomain.ValueDown, feedbackdomain.ReasonOther, true + case ActionReasonContentMismatch: + return feedbackdomain.ValueDown, feedbackdomain.ReasonContentMismatch, true + case ActionReasonContentIncomplete: + return feedbackdomain.ValueDown, feedbackdomain.ReasonContentIncomplete, true + case ActionReasonIllogical: + return feedbackdomain.ValueDown, feedbackdomain.ReasonIllogical, true + case ActionReasonFactualError: + return feedbackdomain.ValueDown, feedbackdomain.ReasonFactualError, true + case ActionReasonSensitiveContent: + return feedbackdomain.ValueDown, feedbackdomain.ReasonSensitiveContent, true + case ActionReasonAnswerNotWanted: + return feedbackdomain.ValueDown, feedbackdomain.ReasonAnswerNotWanted, true default: return "", "", false } diff --git a/internal/channels/dingtalk/feedback_test.go b/internal/channels/dingtalk/feedback_test.go index 0ddfd79..c9f309f 100644 --- a/internal/channels/dingtalk/feedback_test.go +++ b/internal/channels/dingtalk/feedback_test.go @@ -162,6 +162,36 @@ func TestCardFeedbackRejectsMalformedNativeEvents(t *testing.T) { } } +func TestCardFeedbackMapsCustomExactReasons(t *testing.T) { + tests := []struct { + action string + reason string + }{ + {ActionReasonContentMismatch, feedbackdomain.ReasonContentMismatch}, + {ActionReasonContentIncomplete, feedbackdomain.ReasonContentIncomplete}, + {ActionReasonIllogical, feedbackdomain.ReasonIllogical}, + {ActionReasonFactualError, feedbackdomain.ReasonFactualError}, + {ActionReasonSensitiveContent, feedbackdomain.ReasonSensitiveContent}, + {ActionReasonAnswerNotWanted, feedbackdomain.ReasonAnswerNotWanted}, + } + for _, tc := range tests { + t.Run(tc.action, func(t *testing.T) { + service := &fakeFeedbackService{result: feedbackdomain.Result{Changed: true, Value: feedbackdomain.ValueDown, ReasonCode: tc.reason}} + handler, _ := NewCardFeedbackHandler(service) + response, err := handler.HandleSDK(context.Background(), cardRequest(tc.action)) + if err != nil { + t.Fatal(err) + } + if service.calls != 1 || service.command.Value != feedbackdomain.ValueDown || service.command.ReasonCode != tc.reason { + t.Fatalf("calls=%d command=%+v", service.calls, service.command) + } + if response == nil || response.UserPrivateData == nil || response.UserPrivateData.CardParamMap["feedbackReasonSelected"] != tc.reason { + t.Fatalf("response=%+v", response) + } + }) + } +} + func TestCardFeedbackMapsWhitelistedActions(t *testing.T) { tests := []struct { action string -- 2.52.0