import type { ChannelOnboardingAdapter } from "openclaw/plugin-sdk"; const CHANNEL_ID = "qqbot" as const; export const qqbotOnboardingAdapter: ChannelOnboardingAdapter = { channel: CHANNEL_ID, getStatus: async ({ cfg }) => { const channelCfg = (cfg.channels as Record | undefined)?.[CHANNEL_ID] as | Record | undefined; const configured = Boolean(channelCfg?.appId && channelCfg?.clientSecret); return { channel: CHANNEL_ID, configured, statusLines: [`QQ: ${configured ? "已配置" : "需要填写凭证"}`], selectionHint: configured ? "recommended · configured" : "需要 QQ 开放平台应用凭证", quickstartScore: configured ? 1 : 10, }; }, configure: async ({ cfg, prompter }) => { const channelCfg = (cfg.channels as Record | undefined)?.[CHANNEL_ID] as | Record | undefined; const existingAppId = (channelCfg?.appId as string | undefined) ?? ""; const appId = String( await prompter.text({ message: "输入 QQ 机器人 AppID", initialValue: existingAppId, validate: (val) => (val?.trim() ? undefined : "必填"), }), ).trim(); const existingClientSecret = (channelCfg?.clientSecret as string | undefined) ?? ""; const clientSecret = String( await prompter.text({ message: "输入 QQ 机器人 AppSecret(clientSecret)", initialValue: existingClientSecret, validate: (val) => (val?.trim() ? undefined : "必填"), }), ).trim(); const next = applyQQBotConfig(cfg, { appId, clientSecret }); return { cfg: next }; }, disable: (cfg) => { const next = { ...cfg } as Record; const channels = { ...(next.channels as Record | undefined) }; const existing = channels[CHANNEL_ID] as Record | undefined; if (existing) { channels[CHANNEL_ID] = { ...existing, enabled: false }; next.channels = channels; } return next as Parameters[0]; }, }; function applyQQBotConfig( cfg: Record, updates: { appId: string; clientSecret: string }, ): Record { const next = { ...cfg }; const channels = { ...(next.channels as Record | undefined) }; const existing = (channels[CHANNEL_ID] as Record | undefined) ?? {}; channels[CHANNEL_ID] = { ...existing, appId: updates.appId, clientSecret: updates.clientSecret, enabled: true, }; next.channels = channels; return next; }