feat: add DingTalk answer feedback workflow
This commit is contained in:
+44
-30
@@ -25,19 +25,22 @@ const (
|
||||
// It must never contain full question/answer text, error_message, WeKnora
|
||||
// session/request IDs, or provider_message_id.
|
||||
type TurnSummary struct {
|
||||
ID string `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Channel string `json:"channel"`
|
||||
Status TurnStatus `json:"status"`
|
||||
ConversationType string `json:"conversation_type"`
|
||||
ConversationTitle string `json:"conversation_title,omitempty"`
|
||||
ActorExternalID string `json:"actor_external_id,omitempty"`
|
||||
ActorDisplayName string `json:"actor_display_name,omitempty"`
|
||||
QuestionSummary string `json:"question_summary"`
|
||||
AnswerSummary string `json:"answer_summary"`
|
||||
ReferenceCount int `json:"reference_count"`
|
||||
AnswerDeliveryStatus string `json:"answer_delivery_status,omitempty"`
|
||||
AnswerDeliveryMethod string `json:"answer_delivery_method,omitempty"`
|
||||
ID string `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Channel string `json:"channel"`
|
||||
Status TurnStatus `json:"status"`
|
||||
ConversationType string `json:"conversation_type"`
|
||||
ConversationTitle string `json:"conversation_title,omitempty"`
|
||||
ActorExternalID string `json:"actor_external_id,omitempty"`
|
||||
ActorDisplayName string `json:"actor_display_name,omitempty"`
|
||||
QuestionSummary string `json:"question_summary"`
|
||||
AnswerSummary string `json:"answer_summary"`
|
||||
ReferenceCount int `json:"reference_count"`
|
||||
AnswerDeliveryStatus string `json:"answer_delivery_status,omitempty"`
|
||||
AnswerDeliveryMethod string `json:"answer_delivery_method,omitempty"`
|
||||
FeedbackUpCount int `json:"feedback_up_count"`
|
||||
FeedbackDownCount int `json:"feedback_down_count"`
|
||||
FeedbackUnresolvedCount int `json:"feedback_unresolved_count"`
|
||||
}
|
||||
|
||||
// SafeReference is a reference with only safe fields exposed.
|
||||
@@ -72,27 +75,38 @@ type MessageMeta struct {
|
||||
FailureCode string `json:"failure_code,omitempty"`
|
||||
}
|
||||
|
||||
// AnswerFeedback is the safe current feedback state for one actor. Provider
|
||||
// tracking IDs, internal IDs and raw callback fields are intentionally absent.
|
||||
type AnswerFeedback struct {
|
||||
ActorExternalID string `json:"actor_external_id"`
|
||||
ActorDisplayName string `json:"actor_display_name,omitempty"`
|
||||
Value string `json:"value"`
|
||||
ReasonCode string `json:"reason_code"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// TurnDetail is the full detail view of a turn. It must never include
|
||||
// error_message, WeKnora session/request ID, provider_message_id,
|
||||
// sessionWebhook, tokens, raw API/error, or Reference.Content/Raw.
|
||||
type TurnDetail struct {
|
||||
ID string `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Channel string `json:"channel"`
|
||||
Status TurnStatus `json:"status"`
|
||||
ConversationType string `json:"conversation_type"`
|
||||
ConversationTitle string `json:"conversation_title,omitempty"`
|
||||
ActorExternalID string `json:"actor_external_id,omitempty"`
|
||||
ActorDisplayName string `json:"actor_display_name,omitempty"`
|
||||
Question string `json:"question"`
|
||||
Answer string `json:"answer"`
|
||||
References []SafeReference `json:"references,omitempty"`
|
||||
Media []SafeMedia `json:"media,omitempty"`
|
||||
RequestMessage *MessageMeta `json:"request_message,omitempty"`
|
||||
AnswerMessage *MessageMeta `json:"answer_message,omitempty"`
|
||||
ReferenceCount int `json:"reference_count"`
|
||||
AnswerDeliveryStatus string `json:"answer_delivery_status,omitempty"`
|
||||
AnswerDeliveryMethod string `json:"answer_delivery_method,omitempty"`
|
||||
ID string `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Channel string `json:"channel"`
|
||||
Status TurnStatus `json:"status"`
|
||||
ConversationType string `json:"conversation_type"`
|
||||
ConversationTitle string `json:"conversation_title,omitempty"`
|
||||
ActorExternalID string `json:"actor_external_id,omitempty"`
|
||||
ActorDisplayName string `json:"actor_display_name,omitempty"`
|
||||
Question string `json:"question"`
|
||||
Answer string `json:"answer"`
|
||||
References []SafeReference `json:"references,omitempty"`
|
||||
Media []SafeMedia `json:"media,omitempty"`
|
||||
RequestMessage *MessageMeta `json:"request_message,omitempty"`
|
||||
AnswerMessage *MessageMeta `json:"answer_message,omitempty"`
|
||||
ReferenceCount int `json:"reference_count"`
|
||||
AnswerDeliveryStatus string `json:"answer_delivery_status,omitempty"`
|
||||
AnswerDeliveryMethod string `json:"answer_delivery_method,omitempty"`
|
||||
Feedback []AnswerFeedback `json:"feedback,omitempty"`
|
||||
}
|
||||
|
||||
// ListTurnsRequest is the input for listing turns.
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestFeedbackProjectionJSONUsesOnlySafeFields(t *testing.T) {
|
||||
updated := time.Date(2026, 7, 21, 15, 0, 0, 0, time.UTC)
|
||||
detail := TurnDetail{Feedback: []AnswerFeedback{{
|
||||
ActorExternalID: "user-1", ActorDisplayName: "Alice", Value: "down", ReasonCode: "not_resolved", UpdatedAt: updated,
|
||||
}}}
|
||||
raw, err := json.Marshal(detail)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body := string(raw)
|
||||
for _, want := range []string{`"feedback"`, `"actor_external_id":"user-1"`, `"actor_display_name":"Alice"`, `"value":"down"`, `"reason_code":"not_resolved"`, `"updated_at"`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("feedback JSON missing %s: %s", want, body)
|
||||
}
|
||||
}
|
||||
for _, forbidden := range []string{"out_track", "provider_message", "answer_message_id", "actor_id", "token", "callback", "params"} {
|
||||
if strings.Contains(strings.ToLower(body), forbidden) {
|
||||
t.Errorf("feedback JSON leaked %q: %s", forbidden, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTurnSummaryFeedbackCountsJSON(t *testing.T) {
|
||||
raw, err := json.Marshal(TurnSummary{FeedbackUpCount: 2, FeedbackDownCount: 3, FeedbackUnresolvedCount: 1})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body := string(raw)
|
||||
for _, want := range []string{`"feedback_up_count":2`, `"feedback_down_count":3`, `"feedback_unresolved_count":1`} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("summary JSON missing %s: %s", want, body)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user