feat: add message audit foundation

This commit is contained in:
姚章浩
2026-07-21 10:42:28 +08:00
parent 6412f28741
commit d857853ea3
14 changed files with 1063 additions and 17 deletions
+1
View File
@@ -172,6 +172,7 @@ func (h *Handler) Handle(ctx context.Context, cb BotCallback) error {
ExternalUserID: externalUserID,
ExternalMessageID: strings.TrimSpace(cb.MsgID),
SenderName: cb.SenderNick,
MessageType: strings.ToLower(strings.TrimSpace(cb.Msgtype)),
}
switch cb.ConversationType {
case conversationTypeGroup:
@@ -167,6 +167,9 @@ func TestHandleDirectTextCallsQAAndRepliesAnswer(t *testing.T) {
if req.Query != "hello world" {
t.Fatalf("Query = %q, want trimmed 'hello world'", req.Query)
}
if req.MessageType != "text" {
t.Fatalf("MessageType = %q, want text", req.MessageType)
}
if req.ExternalChatID != "" {
t.Fatalf("ExternalChatID should be empty for direct, got %q", req.ExternalChatID)
}
@@ -531,6 +534,9 @@ func TestHandleRichTextMixedDownloadsAndCallsQAWithRealQuery(t *testing.T) {
if !qa.called || len(qa.lastReq.Images) != 1 || qa.lastReq.Images[0] != image {
t.Fatalf("QA request did not receive image: %+v", qa.lastReq)
}
if qa.lastReq.MessageType != "picture" {
t.Fatalf("MessageType=%q, want raw DingTalk type picture", qa.lastReq.MessageType)
}
// Key assert: mixed uses real query, not default imageQuery
if qa.lastReq.Query != "请分析这张截图中的错误" {
t.Fatalf("richText mixed query=%q, want real query", qa.lastReq.Query)