
























1+import { describeAccountSnapshot } from "openclaw/plugin-sdk/account-helpers";
2+import { formatNormalizedAllowFromEntries } from "openclaw/plugin-sdk/allow-from";
3+import {
4+adaptScopedAccountAccessor,
5+createScopedChannelConfigAdapter,
6+} from "openclaw/plugin-sdk/channel-config-helpers";
7+import type { ChannelPlugin } from "openclaw/plugin-sdk/channel-core";
8+import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
9+import {
10+type GoogleChatConfigAccessorAccount,
11+listGoogleChatAccountIds,
12+resolveDefaultGoogleChatAccountId,
13+resolveGoogleChatConfigAccessorAccount,
14+resolveGoogleChatAccount,
15+type ResolvedGoogleChatAccount,
16+} from "./accounts.js";
17+import { googlechatSetupAdapter } from "./setup-core.js";
18+import { googlechatSetupWizard } from "./setup-surface.js";
19+20+export const GOOGLECHAT_CHANNEL_ID = "googlechat" as const;
21+22+export const googlechatMeta = {
23+id: GOOGLECHAT_CHANNEL_ID,
24+label: "Google Chat",
25+selectionLabel: "Google Chat (Chat API)",
26+docsPath: "/channels/googlechat",
27+docsLabel: "googlechat",
28+blurb: "Google Workspace Chat app with HTTP webhook.",
29+aliases: ["gchat", "google-chat"],
30+order: 55,
31+detailLabel: "Google Chat",
32+systemImage: "message.badge",
33+markdownCapable: true,
34+};
35+36+export const formatGoogleChatAllowFromEntry = (entry: string) =>
37+normalizeLowercaseStringOrEmpty(
38+entry
39+.trim()
40+.replace(/^(googlechat|google-chat|gchat):/i, "")
41+.replace(/^user:/i, "")
42+.replace(/^users\//i, ""),
43+);
44+45+const googleChatConfigAdapter = createScopedChannelConfigAdapter<
46+ResolvedGoogleChatAccount,
47+GoogleChatConfigAccessorAccount
48+>({
49+sectionKey: GOOGLECHAT_CHANNEL_ID,
50+listAccountIds: listGoogleChatAccountIds,
51+resolveAccount: adaptScopedAccountAccessor(resolveGoogleChatAccount),
52+resolveAccessorAccount: resolveGoogleChatConfigAccessorAccount,
53+defaultAccountId: resolveDefaultGoogleChatAccountId,
54+clearBaseFields: [
55+"serviceAccount",
56+"serviceAccountFile",
57+"audienceType",
58+"audience",
59+"webhookPath",
60+"webhookUrl",
61+"botUser",
62+"name",
63+],
64+resolveAllowFrom: (account) => account.config.dm?.allowFrom,
65+formatAllowFrom: (allowFrom) =>
66+formatNormalizedAllowFromEntries({
67+ allowFrom,
68+normalizeEntry: formatGoogleChatAllowFromEntry,
69+}),
70+resolveDefaultTo: (account) => account.config.defaultTo,
71+});
72+73+type GoogleChatPluginBase = Pick<
74+ChannelPlugin<ResolvedGoogleChatAccount>,
75+| "id"
76+| "meta"
77+| "setup"
78+| "setupWizard"
79+| "capabilities"
80+| "streaming"
81+| "reload"
82+| "configSchema"
83+| "config"
84+>;
85+86+export function createGoogleChatPluginBase(
87+params: {
88+configSchema?: ChannelPlugin<ResolvedGoogleChatAccount>["configSchema"];
89+} = {},
90+): GoogleChatPluginBase {
91+return {
92+id: GOOGLECHAT_CHANNEL_ID,
93+meta: { ...googlechatMeta },
94+setup: googlechatSetupAdapter,
95+setupWizard: googlechatSetupWizard,
96+capabilities: {
97+chatTypes: ["direct", "group", "thread"],
98+reactions: true,
99+threads: true,
100+media: true,
101+nativeCommands: false,
102+blockStreaming: true,
103+},
104+streaming: {
105+blockStreamingCoalesceDefaults: { minChars: 1500, idleMs: 1000 },
106+},
107+reload: { configPrefixes: ["channels.googlechat"] },
108+ ...(params.configSchema ? { configSchema: params.configSchema } : {}),
109+config: {
110+ ...googleChatConfigAdapter,
111+isConfigured: (account) => account.credentialSource !== "none",
112+describeAccount: (account) =>
113+describeAccountSnapshot({
114+ account,
115+configured: account.credentialSource !== "none",
116+extra: {
117+credentialSource: account.credentialSource,
118+},
119+}),
120+},
121+};
122+}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。