feat: add exact custom card feedback reasons

This commit is contained in:
姚章浩
2026-07-21 21:21:41 +08:00
parent 4dc3f22784
commit a952232cc9
2 changed files with 57 additions and 9 deletions
+27 -9
View File
@@ -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
}
@@ -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