feat(chat): render commercial actions and persist greetings

This commit is contained in:
Codex
2026-07-23 14:52:34 +08:00
parent 3790fb813f
commit 05f625dd0b
26 changed files with 548 additions and 1 deletions
+32 -1
View File
@@ -20,6 +20,23 @@ export interface ChatMockState {
export async function registerChatMocks(page: Page, options: ChatMockOptions, state: ChatMockState) {
let sendCount = 0;
await page.route("**/api/chat/opening-message", async (route) => {
const body = route.request().postDataJSON() as {
openingMessage?: unknown;
} | undefined;
await route.fulfill({
json: apiEnvelope({
messageId: "mock-opening-message",
created: true,
openingMessage:
typeof body?.openingMessage === "string"
? body.openingMessage
: "Hello",
createdAt: "2026-07-23T00:00:00Z",
}),
});
});
await page.route("**/api/chat/history**", async (route) => {
const response = options.paidVoiceInsufficientCreditsFlow
? paidVoiceHistoryResponse
@@ -44,7 +61,21 @@ export async function registerChatMocks(page: Page, options: ChatMockOptions, st
await route.fulfill({ status: 401, json: { message: "expired" } });
return;
}
const response = options.paidImageFlow && message.includes("给我发图片")
const response = message.includes("private album offer test")
? {
...chatSendResponse,
reply: "You always know how to make me smile.",
messageId: "commercial-action-message",
commercialAction: {
actionId: "commercial-action-1",
type: "privateAlbumOffer",
copy: "There are more private photos waiting for you.",
ctaLabel: "Open private zone",
target: "privateZone",
ruleId: "private_album_after_appearance_praise",
},
}
: options.paidImageFlow && message.includes("给我发图片")
? paidImageChatSendResponse
: options.chatLimitTriggerAt != null && sendCount >= options.chatLimitTriggerAt
? createWeeklyLimitChatSendResponse(sendCount, options.chatLimitTriggerAt)