From 3ba93ba8e392419ccd5ed46d0ed46baf38a9054b Mon Sep 17 00:00:00 2001 From: chengyongru Date: Tue, 20 Oct 2026 17:38:00 +0800 Subject: [PATCH] fix(qq): add gateway-free QR connection gallery preview --- nanobot/channels/qq/webui/QQConnectFlow.tsx | 35 +++------------ .../channels/qq/webui/QQConnectFlowView.tsx | 43 +++++++++++++++++++ webui/src/dev/gallery/Gallery.tsx | 3 +- webui/src/dev/gallery/channel-fixtures.ts | 2 +- webui/src/dev/gallery/channels-qq.tsx | 33 ++++++++++++++ .../src/dev/gallery/locales/previews/en.json | 5 +++ .../src/dev/gallery/locales/previews/es.json | 5 +++ .../src/dev/gallery/locales/previews/fr.json | 5 +++ .../src/dev/gallery/locales/previews/id.json | 5 +++ .../src/dev/gallery/locales/previews/ja.json | 5 +++ .../src/dev/gallery/locales/previews/ko.json | 5 +++ .../dev/gallery/locales/previews/pt-BR.json | 5 +++ .../src/dev/gallery/locales/previews/vi.json | 5 +++ .../dev/gallery/locales/previews/zh-CN.json | 5 +++ .../dev/gallery/locales/previews/zh-TW.json | 5 +++ webui/src/tests/component-gallery.test.tsx | 22 ++++++++++ 16 files changed, 156 insertions(+), 32 deletions(-) create mode 100644 nanobot/channels/qq/webui/QQConnectFlowView.tsx create mode 100644 webui/src/dev/gallery/channels-qq.tsx diff --git a/nanobot/channels/qq/webui/QQConnectFlow.tsx b/nanobot/channels/qq/webui/QQConnectFlow.tsx index 4512ce621..65eef910e 100644 --- a/nanobot/channels/qq/webui/QQConnectFlow.tsx +++ b/nanobot/channels/qq/webui/QQConnectFlow.tsx @@ -1,9 +1,8 @@ -import { useTranslation } from "react-i18next"; - import type { ChannelPluginConnectFlowProps } from "@/channel-plugins/types"; -import { channelTranslator } from "@/channel-plugins/i18n"; import { ChannelQrConnectFlow } from "@/components/settings/channels/ChannelQrConnectFlow"; +import { QQConnectFlowView, useQQConnectLabels } from "./QQConnectFlowView"; + export function QQConnectFlow({ token, feature, @@ -11,12 +10,7 @@ export function QQConnectFlow({ connectRequestId, onFeaturesUpdate, }: ChannelPluginConnectFlowProps) { - const { t } = useTranslation(); - const tx = channelTranslator(t, "qq"); - // Every scan rotates the App Secret, so warn before the user scans again. - const rescanWarning = feature.configured - ? tx("custom.scanAgainWarning", "") - : ""; + const labels = useQQConnectLabels(); return ( ( -
- {rescanWarning ? ( -

- {rescanWarning} -

- ) : null} - {connectButton} -
- )} - labels={{ - qrAlt: tx("custom.qrAlt", "QQ login QR code"), - scanTitle: tx("custom.scanTitle", "Scan with mobile QQ"), - scanDescription: "", - waiting: tx("custom.waiting", "Waiting for QQ scan..."), - connected: tx("custom.connected", "QQ is connected."), - stopped: tx("custom.stopped", "QQ login stopped."), - connecting: tx("custom.connecting", "Connecting..."), - scanAgain: t("settings.channels.scanAgain", { defaultValue: "Scan again" }), - connect: t("settings.channels.connect", { defaultValue: "Connect" }), - }} + labels={labels} onFeaturesUpdate={onFeaturesUpdate} + renderView={(props) => } /> ); } diff --git a/nanobot/channels/qq/webui/QQConnectFlowView.tsx b/nanobot/channels/qq/webui/QQConnectFlowView.tsx new file mode 100644 index 000000000..9277b260d --- /dev/null +++ b/nanobot/channels/qq/webui/QQConnectFlowView.tsx @@ -0,0 +1,43 @@ +import { useTranslation } from "react-i18next"; + +import { channelTranslator } from "@/channel-plugins/i18n"; +import { ChannelQrConnectFlowView, type ChannelQrConnectFlowViewProps, type ChannelQrConnectLabels } from "@/components/settings/channels/ChannelQrConnectFlowView"; + +export type QQConnectFlowViewProps = Omit & { + configured?: boolean; +}; + +export function useQQConnectLabels(): ChannelQrConnectLabels { + const { t } = useTranslation(); + const tx = channelTranslator(t, "qq"); + return { + qrAlt: tx("custom.qrAlt", "QQ login QR code"), + scanTitle: tx("custom.scanTitle", "Scan with mobile QQ"), + scanDescription: "", + waiting: tx("custom.waiting", "Waiting for QQ scan..."), + connected: tx("custom.connected", "QQ is connected."), + stopped: tx("custom.stopped", "QQ login stopped."), + connecting: tx("custom.connecting", "Connecting..."), + scanAgain: t("settings.channels.scanAgain", { defaultValue: "Scan again" }), + connect: t("settings.channels.connect", { defaultValue: "Connect" }), + }; +} + +export function QQConnectFlowView({ configured, ...props }: QQConnectFlowViewProps) { + const { t } = useTranslation(); + const tx = channelTranslator(t, "qq"); + const labels = useQQConnectLabels(); + const rescanWarning = configured ? tx("custom.scanAgainWarning", "") : ""; + return ( +
+ {rescanWarning ? ( +

+ {rescanWarning} +

+ ) : null} + {connectButton} +
+ )} + />; +} diff --git a/webui/src/dev/gallery/Gallery.tsx b/webui/src/dev/gallery/Gallery.tsx index b579a95f9..52682d486 100644 --- a/webui/src/dev/gallery/Gallery.tsx +++ b/webui/src/dev/gallery/Gallery.tsx @@ -20,12 +20,13 @@ import { runtimeSettingsExamples } from "./runtime-settings"; import { channelExamples, withChannelEntries } from "./channels"; import { feishuWhatsAppChannelExamples } from "./channels-feishu-whatsapp"; import { linearChannelExamples } from "./channels-linear"; +import { qqChannelExamples } from "./channels-qq"; import { weixinChannelExamples } from "./channels-weixin"; import { foundationPath, type ComponentSource } from "./inventory"; import { useGalleryTranslation } from "./i18n"; export const examples = [...foundationExamples, ...sharedExamples, ...settingsExamples, ...providerExamples, ...conversationExamples, ...shellExamples, ...standaloneExamples, ...remoteExamples, ...contentExamples, ...runtimeSettingsExamples, - ...channelExamples, ...withChannelEntries([...feishuWhatsAppChannelExamples, ...linearChannelExamples, ...weixinChannelExamples])]; + ...channelExamples, ...withChannelEntries([...feishuWhatsAppChannelExamples, ...linearChannelExamples, ...qqChannelExamples, ...weixinChannelExamples])]; const examplesByPath = new Map(examples.flatMap((example) => example.files.map((file) => [file, example] as const))); const groupKeys: Record = { All: "all", "Shared views & shell": "shared", Icons: "icons", Hosts: "hosts", Settings: "settings", diff --git a/webui/src/dev/gallery/channel-fixtures.ts b/webui/src/dev/gallery/channel-fixtures.ts index a73d48613..0237d1d65 100644 --- a/webui/src/dev/gallery/channel-fixtures.ts +++ b/webui/src/dev/gallery/channel-fixtures.ts @@ -12,7 +12,7 @@ export const channelFeatures: Record = { "mochat": {"name": "mochat","display_name": "MoChat","webui": "webui/index.ts","type": "channel","enabled": false,"installed": true,"configured": false,"ready": false,"status": "not_enabled","install_supported": true,"requires_restart": false,"runtime_status": "stopped","config_values": {},"configured_fields": [],"setup": {"fields": [{"key": "channels.mochat.baseUrl","field": "baseUrl","kind": "string","choices": [],"required": false,"default_value": "https://mochat.io"},{"key": "channels.mochat.clawToken","field": "clawToken","kind": "secret","choices": [],"required": true},{"key": "channels.mochat.agentUserId","field": "agentUserId","kind": "string","choices": [],"required": false},{"key": "channels.mochat.sessions","field": "sessions","kind": "list","choices": [],"required": false},{"key": "channels.mochat.panels","field": "panels","kind": "list","choices": [],"required": false},{"key": "channels.mochat.allowFrom","field": "allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.mochat.socketUrl","field": "socketUrl","kind": "string","choices": [],"required": false},{"key": "channels.mochat.socketPath","field": "socketPath","kind": "string","choices": [],"required": false,"default_value": "/socket.io"},{"key": "channels.mochat.socketDisableMsgpack","field": "socketDisableMsgpack","kind": "bool","choices": [],"required": false,"default_value": "false"},{"key": "channels.mochat.socketReconnectDelayMs","field": "socketReconnectDelayMs","kind": "int","choices": [],"required": false,"default_value": "1000"},{"key": "channels.mochat.socketMaxReconnectDelayMs","field": "socketMaxReconnectDelayMs","kind": "int","choices": [],"required": false,"default_value": "10000"},{"key": "channels.mochat.socketConnectTimeoutMs","field": "socketConnectTimeoutMs","kind": "int","choices": [],"required": false,"default_value": "10000"},{"key": "channels.mochat.refreshIntervalMs","field": "refreshIntervalMs","kind": "int","choices": [],"required": false,"default_value": "30000"},{"key": "channels.mochat.watchTimeoutMs","field": "watchTimeoutMs","kind": "int","choices": [],"required": false,"default_value": "25000"},{"key": "channels.mochat.watchLimit","field": "watchLimit","kind": "int","choices": [],"required": false,"default_value": "100"},{"key": "channels.mochat.retryDelayMs","field": "retryDelayMs","kind": "int","choices": [],"required": false,"default_value": "500"},{"key": "channels.mochat.maxRetryAttempts","field": "maxRetryAttempts","kind": "int","choices": [],"required": false,"default_value": "0"},{"key": "channels.mochat.mention.requireInGroups","field": "mention.requireInGroups","kind": "bool","choices": [],"required": false,"default_value": "false"},{"key": "channels.mochat.groups","field": "groups","kind": "json","choices": [],"required": false,"default_value": "{}"},{"key": "channels.mochat.replyDelayMode","field": "replyDelayMode","kind": "string","choices": [],"required": false,"default_value": "non-mention"},{"key": "channels.mochat.replyDelayMs","field": "replyDelayMs","kind": "int","choices": [],"required": false,"default_value": "120000"}],"requirements": [{"alternatives": [["channels.mochat.clawToken"]]}],"official_url": "https://mochat.io/"}}, "msteams": {"name": "msteams","display_name": "Microsoft Teams","webui": "webui/index.ts","type": "channel","enabled": false,"installed": true,"configured": false,"ready": false,"status": "not_enabled","install_supported": true,"requires_restart": false,"runtime_status": "stopped","config_values": {},"configured_fields": [],"setup": {"fields": [{"key": "channels.msteams.appId","field": "appId","kind": "string","choices": [],"required": true},{"key": "channels.msteams.appPassword","field": "appPassword","kind": "secret","choices": [],"required": true},{"key": "channels.msteams.tenantId","field": "tenantId","kind": "string","choices": [],"required": false},{"key": "channels.msteams.path","field": "path","kind": "string","choices": [],"required": false,"default_value": "/api/messages"},{"key": "channels.msteams.allowFrom","field": "allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.msteams.host","field": "host","kind": "string","choices": [],"required": false,"default_value": "0.0.0.0"},{"key": "channels.msteams.port","field": "port","kind": "int","choices": [],"required": false,"default_value": "3978"},{"key": "channels.msteams.replyInThread","field": "replyInThread","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.msteams.mentionOnlyResponse","field": "mentionOnlyResponse","kind": "string","choices": [],"required": false,"default_value": "Hi — what can I help with?"},{"key": "channels.msteams.validateInboundAuth","field": "validateInboundAuth","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.msteams.refTtlDays","field": "refTtlDays","kind": "int","choices": [],"required": false,"default_value": "30"},{"key": "channels.msteams.pruneWebChatRefs","field": "pruneWebChatRefs","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.msteams.pruneNonPersonalRefs","field": "pruneNonPersonalRefs","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.msteams.refTouchIntervalS","field": "refTouchIntervalS","kind": "int","choices": [],"required": false,"default_value": "300"},{"key": "channels.msteams.trustedServiceUrlHosts","field": "trustedServiceUrlHosts","kind": "list","choices": [],"required": false}],"requirements": [{"alternatives": [["channels.msteams.appId"]]},{"alternatives": [["channels.msteams.appPassword"]]}],"official_url": "https://dev.teams.microsoft.com/apps"}}, "napcat": {"name": "napcat","display_name": "NapCat","webui": "webui/index.ts","type": "channel","enabled": false,"installed": true,"configured": false,"ready": false,"status": "not_enabled","install_supported": true,"requires_restart": false,"runtime_status": "stopped","config_values": {},"configured_fields": [],"setup": {"fields": [{"key": "channels.napcat.wsUrl","field": "wsUrl","kind": "string","choices": [],"required": true,"default_value": "ws://127.0.0.1:3001"},{"key": "channels.napcat.accessToken","field": "accessToken","kind": "secret","choices": [],"required": false},{"key": "channels.napcat.allowFrom","field": "allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.napcat.groupPolicy","field": "groupPolicy","kind": "enum","choices": ["mention","open"],"required": false,"default_value": "mention"},{"key": "channels.napcat.groupPolicyOverrides","field": "groupPolicyOverrides","kind": "json","choices": [],"required": false,"default_value": "{}"},{"key": "channels.napcat.welcomeNewMembers","field": "welcomeNewMembers","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.napcat.maxImageBytes","field": "maxImageBytes","kind": "int","choices": [],"required": false,"default_value": "20971520"}],"requirements": [{"alternatives": [["channels.napcat.wsUrl"]]}],"official_url": "https://napneko.github.io/"}}, - "qq": {"name": "qq","display_name": "QQ","webui": "webui/index.ts","type": "channel","enabled": false,"installed": true,"configured": false,"ready": false,"status": "not_enabled","install_supported": true,"requires_restart": false,"runtime_status": "stopped","config_values": {},"configured_fields": [],"setup": {"fields": [{"key": "channels.qq.appId","field": "appId","kind": "string","choices": [],"required": true},{"key": "channels.qq.secret","field": "secret","kind": "secret","choices": [],"required": true},{"key": "channels.qq.allowFrom","field": "allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.qq.msgFormat","field": "msgFormat","kind": "enum","choices": ["markdown","plain"],"required": false,"default_value": "plain"},{"key": "channels.qq.ackMessage","field": "ackMessage","kind": "string","choices": [],"required": false,"default_value": "⏳ Processing..."},{"key": "channels.qq.showCompactionNotices","field": "showCompactionNotices","kind": "bool","choices": [],"required": false,"inheritable": true},{"key": "channels.qq.mediaDir","field": "mediaDir","kind": "string","choices": [],"required": false},{"key": "channels.qq.downloadChunkSize","field": "downloadChunkSize","kind": "int","choices": [],"required": false,"default_value": "262144"},{"key": "channels.qq.downloadMaxBytes","field": "downloadMaxBytes","kind": "int","choices": [],"required": false,"default_value": "209715200"}],"requirements": [{"alternatives": [["channels.qq.appId"]]},{"alternatives": [["channels.qq.secret"]]}],"official_url": "https://q.qq.com/"}}, + "qq": {"name": "qq","display_name": "QQ","webui": "webui/index.tsx","type": "channel","enabled": false,"installed": true,"configured": false,"ready": false,"status": "not_enabled","install_supported": true,"requires_restart": false,"runtime_status": "stopped","config_values": {},"configured_fields": [],"setup": {"fields": [{"key": "channels.qq.appId","field": "appId","kind": "string","choices": [],"required": true},{"key": "channels.qq.secret","field": "secret","kind": "secret","choices": [],"required": true},{"key": "channels.qq.allowFrom","field": "allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.qq.msgFormat","field": "msgFormat","kind": "enum","choices": ["markdown","plain"],"required": false,"default_value": "plain"},{"key": "channels.qq.ackMessage","field": "ackMessage","kind": "string","choices": [],"required": false,"default_value": "⏳ Processing..."},{"key": "channels.qq.showCompactionNotices","field": "showCompactionNotices","kind": "bool","choices": [],"required": false,"inheritable": true},{"key": "channels.qq.mediaDir","field": "mediaDir","kind": "string","choices": [],"required": false},{"key": "channels.qq.downloadChunkSize","field": "downloadChunkSize","kind": "int","choices": [],"required": false,"default_value": "262144"},{"key": "channels.qq.downloadMaxBytes","field": "downloadMaxBytes","kind": "int","choices": [],"required": false,"default_value": "209715200"}],"requirements": [{"alternatives": [["channels.qq.appId"]]},{"alternatives": [["channels.qq.secret"]]}],"official_url": "https://q.qq.com/"}}, "signal": {"name": "signal","display_name": "Signal","webui": "webui/index.ts","type": "channel","enabled": false,"installed": true,"configured": false,"ready": false,"status": "not_enabled","install_supported": true,"requires_restart": false,"runtime_status": "stopped","config_values": {},"configured_fields": [],"setup": {"fields": [{"key": "channels.signal.phoneNumber","field": "phoneNumber","kind": "string","choices": [],"required": true},{"key": "channels.signal.daemonHost","field": "daemonHost","kind": "string","choices": [],"required": false,"default_value": "localhost"},{"key": "channels.signal.daemonPort","field": "daemonPort","kind": "int","choices": [],"required": false,"default_value": "8080"},{"key": "channels.signal.dm.allowFrom","field": "dm.allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.signal.group.allowFrom","field": "group.allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.signal.groupMessageBufferSize","field": "groupMessageBufferSize","kind": "int","choices": [],"required": false,"default_value": "20"},{"key": "channels.signal.attachmentsDir","field": "attachmentsDir","kind": "string","choices": [],"required": false},{"key": "channels.signal.dm.enabled","field": "dm.enabled","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.signal.dm.policy","field": "dm.policy","kind": "enum","choices": ["allowlist","open"],"required": false,"default_value": "allowlist"},{"key": "channels.signal.group.enabled","field": "group.enabled","kind": "bool","choices": [],"required": false,"default_value": "false"},{"key": "channels.signal.group.policy","field": "group.policy","kind": "enum","choices": ["allowlist","open"],"required": false,"default_value": "allowlist"},{"key": "channels.signal.group.requireMention","field": "group.requireMention","kind": "bool","choices": [],"required": false,"default_value": "true"}],"requirements": [{"alternatives": [["channels.signal.phoneNumber"]]}],"official_url": "https://github.com/bbernhard/signal-cli-rest-api"}}, "slack": {"name": "slack","display_name": "Slack","webui": "webui/index.ts","type": "channel","enabled": false,"installed": true,"configured": false,"ready": false,"status": "not_enabled","install_supported": true,"requires_restart": false,"runtime_status": "stopped","config_values": {},"configured_fields": [],"setup": {"fields": [{"key": "channels.slack.appToken","field": "appToken","kind": "secret","choices": [],"required": true},{"key": "channels.slack.botToken","field": "botToken","kind": "secret","choices": [],"required": true},{"key": "channels.slack.groupPolicy","field": "groupPolicy","kind": "enum","choices": ["allowlist","mention","open"],"required": false,"default_value": "mention"},{"key": "channels.slack.mode","field": "mode","kind": "enum","choices": ["socket"],"required": false,"default_value": "socket"},{"key": "channels.slack.webhookPath","field": "webhookPath","kind": "string","choices": [],"required": false,"default_value": "/slack/events"},{"key": "channels.slack.replyInThread","field": "replyInThread","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.slack.reactEmoji","field": "reactEmoji","kind": "string","choices": [],"required": false,"default_value": "eyes"},{"key": "channels.slack.doneEmoji","field": "doneEmoji","kind": "string","choices": [],"required": false,"default_value": "white_check_mark"},{"key": "channels.slack.includeThreadContext","field": "includeThreadContext","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.slack.threadContextLimit","field": "threadContextLimit","kind": "int","choices": [],"required": false,"default_value": "20"},{"key": "channels.slack.allowFrom","field": "allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.slack.groupAllowFrom","field": "groupAllowFrom","kind": "list","choices": [],"required": false},{"key": "channels.slack.groupRequireMention","field": "groupRequireMention","kind": "bool","choices": [],"required": false,"default_value": "false"},{"key": "channels.slack.dm.enabled","field": "dm.enabled","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.slack.dm.policy","field": "dm.policy","kind": "enum","choices": ["allowlist","open"],"required": false,"default_value": "open"},{"key": "channels.slack.dm.allowFrom","field": "dm.allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.slack.proxy","field": "proxy","kind": "string","choices": [],"required": false}],"requirements": [{"alternatives": [["channels.slack.appToken"]]},{"alternatives": [["channels.slack.botToken"]]}],"official_url": "https://api.slack.com/apps","verifies_connection": true}}, "telegram": {"name": "telegram","display_name": "Telegram","webui": "webui/index.ts","type": "channel","enabled": false,"installed": true,"configured": false,"ready": false,"status": "not_enabled","install_supported": true,"requires_restart": false,"runtime_status": "stopped","config_values": {},"configured_fields": [],"setup": {"fields": [{"key": "channels.telegram.token","field": "token","kind": "secret","choices": [],"required": true},{"key": "channels.telegram.proxy","field": "proxy","kind": "string","choices": [],"required": false},{"key": "channels.telegram.allowFrom","field": "allowFrom","kind": "list","choices": [],"required": false},{"key": "channels.telegram.groupPolicy","field": "groupPolicy","kind": "enum","choices": ["allowlist","mention","open"],"required": false,"default_value": "mention"},{"key": "channels.telegram.mode","field": "mode","kind": "enum","choices": ["polling","webhook"],"required": false,"default_value": "polling"},{"key": "channels.telegram.replyToMessage","field": "replyToMessage","kind": "bool","choices": [],"required": false,"default_value": "false"},{"key": "channels.telegram.reactEmoji","field": "reactEmoji","kind": "string","choices": [],"required": false,"default_value": "👀"},{"key": "channels.telegram.connectionPoolSize","field": "connectionPoolSize","kind": "int","choices": [],"required": false,"default_value": "32"},{"key": "channels.telegram.poolTimeout","field": "poolTimeout","kind": "float","choices": [],"required": false,"default_value": "5.0"},{"key": "channels.telegram.streaming","field": "streaming","kind": "bool","choices": [],"required": false,"default_value": "true"},{"key": "channels.telegram.inlineKeyboards","field": "inlineKeyboards","kind": "bool","choices": [],"required": false,"default_value": "false"},{"key": "channels.telegram.richMessages","field": "richMessages","kind": "bool","choices": [],"required": false,"default_value": "false"},{"key": "channels.telegram.streamEditInterval","field": "streamEditInterval","kind": "float","choices": [],"required": false,"default_value": "0.6"},{"key": "channels.telegram.webhookUrl","field": "webhookUrl","kind": "string","choices": [],"required": false},{"key": "channels.telegram.webhookListenHost","field": "webhookListenHost","kind": "string","choices": [],"required": false,"default_value": "127.0.0.1"},{"key": "channels.telegram.webhookListenPort","field": "webhookListenPort","kind": "int","choices": [],"required": false,"default_value": "8081"},{"key": "channels.telegram.webhookPath","field": "webhookPath","kind": "string","choices": [],"required": false,"default_value": "/telegram"},{"key": "channels.telegram.webhookSecretToken","field": "webhookSecretToken","kind": "secret","choices": [],"required": false},{"key": "channels.telegram.webhookMaxConnections","field": "webhookMaxConnections","kind": "int","choices": [],"required": false,"default_value": "4"}],"requirements": [{"alternatives": [["channels.telegram.token"]]}],"official_url": "https://t.me/BotFather","verifies_connection": true}}, diff --git a/webui/src/dev/gallery/channels-qq.tsx b/webui/src/dev/gallery/channels-qq.tsx new file mode 100644 index 000000000..3359fd2dc --- /dev/null +++ b/webui/src/dev/gallery/channels-qq.tsx @@ -0,0 +1,33 @@ +import { useState } from "react"; + +import { QQConnectFlowView } from "../../../../nanobot/channels/qq/webui/QQConnectFlowView"; +import type { ChannelConnectPayload } from "@/lib/types"; +import { StatePicker, type ComponentExample } from "./example"; +import { useGalleryTranslation } from "./i18n"; + +const connectStates = ["idle", "starting", "pending", "succeeded", "expired", "failed", "cancelled", "error"] as const; +type ConnectState = typeof connectStates[number]; + +function QQConnectionPreview() { + const { t } = useGalleryTranslation(); + const [state, setState] = useState("pending"); + const connect: ChannelConnectPayload | null = state === "idle" || state === "starting" || state === "error" + ? null + : { session_id: "gallery-qq", status: state, qr_url: "https://example.invalid/qq-authorization" }; + return <> + + setState("pending")} onCancel={() => setState("cancelled")} onPoll={async () => connect} /> + ; +} + +export const qqChannelExamples: ComponentExample[] = [{ + title: "previews.qqConnect.title", + files: ["nanobot/channels/qq/webui/index.tsx", "nanobot/channels/qq/webui/QQConnectFlowView.tsx"], + description: "previews.qqConnect.description", + options: "previews.qqConnect.options", + code: "", + Preview: QQConnectionPreview, +}]; diff --git a/webui/src/dev/gallery/locales/previews/en.json b/webui/src/dev/gallery/locales/previews/en.json index 1d468b42a..6c4770266 100644 --- a/webui/src/dev/gallery/locales/previews/en.json +++ b/webui/src/dev/gallery/locales/previews/en.json @@ -370,6 +370,11 @@ "state": "{{channel}} connection state", "error": "Authorization is temporarily unavailable. Try again." }, + "qqConnect": { + "title": "QQConnectFlowView · QQ QR connection", + "description": "Explore QQ QR login, retries and the App Secret replacement warning.", + "options": "The view receives connection state and callbacks. Preview actions stay local; the runtime entry creates sessions and polls the QQ portal." + }, "feishuConnect": { "title": "FeishuConnectFlowView · Feishu QR authorization", "description": "Try the real Feishu QR flow with waiting, success, expiry, cancellation and errors.", diff --git a/webui/src/dev/gallery/locales/previews/es.json b/webui/src/dev/gallery/locales/previews/es.json index d92a1a35c..1265ef76e 100644 --- a/webui/src/dev/gallery/locales/previews/es.json +++ b/webui/src/dev/gallery/locales/previews/es.json @@ -370,6 +370,11 @@ "state": "Estado de conexión de {{channel}}", "error": "La autorización no está disponible temporalmente. Inténtalo de nuevo." }, + "qqConnect": { + "title": "QQConnectFlowView · Conexión QR de QQ", + "description": "Prueba el acceso por QR de QQ, los reintentos y el aviso de sustitución de App Secret.", + "options": "La vista recibe el estado y los callbacks. Las acciones de ejemplo solo cambian el estado local; la entrada de ejecución crea sesiones y consulta el portal de QQ." + }, "feishuConnect": { "title": "FeishuConnectFlowView · Autorización QR de Feishu", "description": "Prueba el flujo QR real de Feishu con espera, éxito, caducidad, cancelación y errores.", diff --git a/webui/src/dev/gallery/locales/previews/fr.json b/webui/src/dev/gallery/locales/previews/fr.json index be3e79494..17508b710 100644 --- a/webui/src/dev/gallery/locales/previews/fr.json +++ b/webui/src/dev/gallery/locales/previews/fr.json @@ -370,6 +370,11 @@ "state": "État de connexion {{channel}}", "error": "L’autorisation est temporairement indisponible. Réessayez." }, + "qqConnect": { + "title": "QQConnectFlowView · Connexion QR QQ", + "description": "Essayez la connexion QR QQ, les nouvelles tentatives et l’avertissement de remplacement de l’App Secret.", + "options": "La vue reçoit l’état et les callbacks. Les actions d’aperçu restent locales ; l’entrée du runtime crée les sessions et interroge le portail QQ." + }, "feishuConnect": { "title": "FeishuConnectFlowView · Autorisation Feishu par QR", "description": "Essayez le parcours QR Feishu avec attente, réussite, expiration, annulation et erreurs.", diff --git a/webui/src/dev/gallery/locales/previews/id.json b/webui/src/dev/gallery/locales/previews/id.json index 95d4eac02..9f0f4a22c 100644 --- a/webui/src/dev/gallery/locales/previews/id.json +++ b/webui/src/dev/gallery/locales/previews/id.json @@ -370,6 +370,11 @@ "state": "Status koneksi {{channel}}", "error": "Otorisasi sementara tidak tersedia. Coba lagi." }, + "qqConnect": { + "title": "QQConnectFlowView · Koneksi QR QQ", + "description": "Coba login QR QQ, percobaan ulang, dan peringatan penggantian App Secret.", + "options": "Tampilan menerima status koneksi dan callback. Tindakan pratinjau tetap lokal; bagian runtime membuat sesi dan melakukan polling ke portal QQ." + }, "feishuConnect": { "title": "FeishuConnectFlowView · Otorisasi QR Feishu", "description": "Coba alur QR Feishu asli dengan status menunggu, berhasil, kedaluwarsa, batal, dan kesalahan.", diff --git a/webui/src/dev/gallery/locales/previews/ja.json b/webui/src/dev/gallery/locales/previews/ja.json index b85ab0583..b41baf1b2 100644 --- a/webui/src/dev/gallery/locales/previews/ja.json +++ b/webui/src/dev/gallery/locales/previews/ja.json @@ -370,6 +370,11 @@ "state": "{{channel}} の接続状態", "error": "認証を一時的に利用できません。再試行してください。" }, + "qqConnect": { + "title": "QQConnectFlowView · QQ QR 接続", + "description": "QQ の QR ログイン、再試行、App Secret の置き換え警告を確認します。", + "options": "ビューは接続状態とコールバックを受け取ります。プレビューの操作はローカル状態のみを変更し、セッション作成と QQ のポーリングはランタイム側で行います。" + }, "feishuConnect": { "title": "FeishuConnectFlowView · Feishu QR 認証", "description": "実際の QR 認証画面で待機、成功、期限切れ、キャンセル、エラーを試せます。", diff --git a/webui/src/dev/gallery/locales/previews/ko.json b/webui/src/dev/gallery/locales/previews/ko.json index 9b4d46ecc..61cb17fcc 100644 --- a/webui/src/dev/gallery/locales/previews/ko.json +++ b/webui/src/dev/gallery/locales/previews/ko.json @@ -370,6 +370,11 @@ "state": "{{channel}} 연결 상태", "error": "일시적으로 인증할 수 없습니다. 다시 시도하세요." }, + "qqConnect": { + "title": "QQConnectFlowView · QQ QR 연결", + "description": "QQ QR 로그인, 재시도와 App Secret 교체 경고를 확인합니다.", + "options": "뷰는 연결 상태와 콜백을 받습니다. 미리보기 작업은 로컬 상태만 변경하며 세션 생성과 QQ 폴링은 런타임에서 처리합니다." + }, "feishuConnect": { "title": "FeishuConnectFlowView · Feishu QR 인증", "description": "실제 Feishu QR 화면에서 대기, 성공, 만료, 취소, 오류를 시험합니다.", diff --git a/webui/src/dev/gallery/locales/previews/pt-BR.json b/webui/src/dev/gallery/locales/previews/pt-BR.json index dfc9d2dc1..450c3b814 100644 --- a/webui/src/dev/gallery/locales/previews/pt-BR.json +++ b/webui/src/dev/gallery/locales/previews/pt-BR.json @@ -370,6 +370,11 @@ "state": "Status da conexão do {{channel}}", "error": "A autorização está temporariamente indisponível. Tente novamente." }, + "qqConnect": { + "title": "QQConnectFlowView · Conexão QR do QQ", + "description": "Explore o login QR do QQ, novas tentativas e o aviso de substituição do App Secret.", + "options": "A visualização recebe o estado e os callbacks. As ações da prévia ficam locais; a entrada do runtime cria sessões e consulta o portal do QQ." + }, "feishuConnect": { "title": "FeishuConnectFlowView · Autorização QR do Feishu", "description": "Teste o fluxo QR real do Feishu com espera, sucesso, expiração, cancelamento e erros.", diff --git a/webui/src/dev/gallery/locales/previews/vi.json b/webui/src/dev/gallery/locales/previews/vi.json index 603117eab..2e966beb2 100644 --- a/webui/src/dev/gallery/locales/previews/vi.json +++ b/webui/src/dev/gallery/locales/previews/vi.json @@ -370,6 +370,11 @@ "state": "Trạng thái kết nối {{channel}}", "error": "Tạm thời không thể ủy quyền. Vui lòng thử lại." }, + "qqConnect": { + "title": "QQConnectFlowView · Kết nối QR QQ", + "description": "Thử đăng nhập QR QQ, thử lại và cảnh báo thay thế App Secret.", + "options": "Giao diện nhận trạng thái kết nối và callback. Thao tác xem trước chỉ đổi trạng thái cục bộ; phần runtime tạo phiên và thăm dò cổng QQ." + }, "feishuConnect": { "title": "FeishuConnectFlowView · Ủy quyền QR Feishu", "description": "Thử luồng QR Feishu thực với chờ, thành công, hết hạn, hủy và lỗi.", diff --git a/webui/src/dev/gallery/locales/previews/zh-CN.json b/webui/src/dev/gallery/locales/previews/zh-CN.json index e4b2652b4..608008c31 100644 --- a/webui/src/dev/gallery/locales/previews/zh-CN.json +++ b/webui/src/dev/gallery/locales/previews/zh-CN.json @@ -370,6 +370,11 @@ "state": "{{channel}} 连接状态", "error": "授权暂不可用,请重试。" }, + "qqConnect": { + "title": "QQConnectFlowView · QQ 扫码连接", + "description": "查看 QQ 扫码、重试与 App Secret 替换提示。", + "options": "视图接收连接状态和操作回调。预览操作只改变本地状态;会话创建和 QQ 轮询由运行时入口负责。" + }, "feishuConnect": { "title": "FeishuConnectFlowView · 飞书扫码授权", "description": "试用飞书扫码、成功、过期与错误状态。", diff --git a/webui/src/dev/gallery/locales/previews/zh-TW.json b/webui/src/dev/gallery/locales/previews/zh-TW.json index cb34f063b..d2aabea61 100644 --- a/webui/src/dev/gallery/locales/previews/zh-TW.json +++ b/webui/src/dev/gallery/locales/previews/zh-TW.json @@ -370,6 +370,11 @@ "state": "{{channel}} 連線狀態", "error": "授權暫時無法使用,請重試。" }, + "qqConnect": { + "title": "QQConnectFlowView · QQ 掃碼連線", + "description": "查看 QQ 掃碼、重試與 App Secret 替換提示。", + "options": "檢視接收連線狀態和操作回呼。預覽操作只改變本機狀態;工作階段建立和 QQ 輪詢由執行階段入口負責。" + }, "feishuConnect": { "title": "FeishuConnectFlowView · 飛書掃碼授權", "description": "試用飛書掃碼、成功、到期與錯誤狀態。", diff --git a/webui/src/tests/component-gallery.test.tsx b/webui/src/tests/component-gallery.test.tsx index e0f0eed36..4346d3580 100644 --- a/webui/src/tests/component-gallery.test.tsx +++ b/webui/src/tests/component-gallery.test.tsx @@ -230,3 +230,25 @@ it("renders a registered channel's real secret fields and enable action without expect(fetch).toHaveBeenCalledTimes(1); expect(fetch.mock.calls[0][0]).toBe("/__nanobot_components"); }); + +it("previews QQ QR states and retries without connecting to the portal", async () => { + const source = "nanobot/channels/qq/webui/index.tsx"; + window.history.replaceState({}, "", `/gallery.html#${new URLSearchParams({ component: source })}`); + const fetch = vi.fn().mockResolvedValue({ ok: true, json: async () => inventory }); + vi.stubGlobal("fetch", fetch); + render(); + await screen.findByRole("heading", { name: "QQConnectFlowView · QQ QR connection" }); + const preview = within(screen.getByRole("region", { name: "Component preview" })); + expect(await preview.findByRole("img", { name: "QQ login QR code" })).toBeVisible(); + await userEvent.click(preview.getByRole("button", { name: "Cancel" })); + expect(preview.queryByRole("img", { name: "QQ login QR code" })).not.toBeInTheDocument(); + await userEvent.click(preview.getByRole("button", { name: "Connect" })); + expect(await preview.findByRole("img", { name: "QQ login QR code" })).toBeVisible(); + await userEvent.click(preview.getByRole("combobox", { name: "QQ connection state" })); + await userEvent.click(screen.getByRole("option", { name: "succeeded" })); + expect(preview.getByText("QQ is connected.")).toBeVisible(); + expect(preview.getByText(/previous App Secret stops working/)).toBeVisible(); + expect(preview.getByRole("button", { name: "Scan again" })).toBeVisible(); + expect(fetch).toHaveBeenCalledTimes(1); + expect(fetch.mock.calls[0][0]).toBe("/__nanobot_components"); +});