feat: sync AI compose and ChatBot features

This commit is contained in:
A 2026-07-03 19:43:20 +08:00
parent 35e5d38f4d
commit b7269b135f
75 changed files with 5426 additions and 123 deletions

View file

@ -5,9 +5,13 @@ import (
"errors"
"testing"
"github.com/gotd/td/clock"
"github.com/gotd/td/tg"
"go.uber.org/zap/zaptest"
aiapp "telesrv/internal/app/ai"
"telesrv/internal/domain"
"telesrv/internal/store/memory"
)
// TestWebPagePreviewMedia 验证 getWebPagePreview 的 media 决策:done 卡片→messageMediaWebPage,
@ -71,6 +75,54 @@ func TestWebPagePreviewMedia(t *testing.T) {
})
}
func TestAIComposeStyleWebPagePreview(t *testing.T) {
const userID int64 = 1001
ctx := WithUserID(context.Background(), userID)
aiSvc := aiapp.NewService(memory.NewAIComposeStore())
tone, err := aiSvc.CreateTone(ctx, domain.AIComposeToneInput{
UserID: userID,
EmojiID: 12345,
Title: "Sharp",
Prompt: "Make it crisp.",
})
if err != nil {
t.Fatalf("CreateTone: %v", err)
}
r := New(Config{}, Deps{AICompose: aiSvc}, zaptest.NewLogger(t), clock.System)
link := "https://t.me/addstyle/" + tone.Slug
media := r.webPagePreviewMedia(ctx, "try "+link, nil)
wrap, ok := media.(*tg.MessageMediaWebPage)
if !ok {
t.Fatalf("media = %T, want *tg.MessageMediaWebPage", media)
}
page, ok := wrap.Webpage.(*tg.WebPage)
if !ok {
t.Fatalf("webpage = %T, want *tg.WebPage", wrap.Webpage)
}
if typ, ok := page.GetType(); !ok || typ != "telegram_aicomposetone" {
t.Fatalf("type = %q ok=%v, want telegram_aicomposetone", typ, ok)
}
if title, ok := page.GetTitle(); !ok || title != "Sharp" {
t.Fatalf("title = %q ok=%v, want Sharp", title, ok)
}
attrs, ok := page.GetAttributes()
if !ok || len(attrs) != 1 {
t.Fatalf("attributes = %#v ok=%v, want one", attrs, ok)
}
attr, ok := attrs[0].(*tg.WebPageAttributeAiComposeTone)
if !ok || attr.EmojiID != 12345 {
t.Fatalf("attribute = %#v, want ai compose tone emoji", attrs[0])
}
got := r.webPageForURL(ctx, "https://t.me/addstyle?slug="+tone.Slug, 0)
if page, ok := got.Webpage.(*tg.WebPage); !ok {
t.Fatalf("getWebPage webpage = %T, want *tg.WebPage", got.Webpage)
} else if typ, ok := page.GetType(); !ok || typ != "telegram_aicomposetone" {
t.Fatalf("getWebPage type = %q ok=%v", typ, ok)
}
}
func isEmptyMedia(m tg.MessageMediaClass) bool {
_, ok := m.(*tg.MessageMediaEmpty)
return ok