feat: add beta googlechat channel

This commit is contained in:
iHildy
2026-01-23 16:45:37 -06:00
committed by Peter Steinberger
parent 60661441b1
commit b76cd6695d
58 changed files with 3216 additions and 51 deletions

View File

@@ -5,6 +5,7 @@ import { resolveSignalAccount } from "../signal/accounts.js";
import { resolveSlackAccount, resolveSlackReplyToMode } from "../slack/accounts.js";
import { buildSlackThreadingToolContext } from "../slack/threading-tool-context.js";
import { resolveTelegramAccount } from "../telegram/accounts.js";
import { normalizeAccountId } from "../routing/session-key.js";
import { normalizeE164 } from "../utils.js";
import { resolveWhatsAppAccount } from "../web/accounts.js";
import { normalizeWhatsAppTarget } from "../whatsapp/normalize.js";
@@ -12,6 +13,8 @@ import { requireActivePluginRegistry } from "../plugins/runtime.js";
import {
resolveDiscordGroupRequireMention,
resolveDiscordGroupToolPolicy,
resolveGoogleChatGroupRequireMention,
resolveGoogleChatGroupToolPolicy,
resolveIMessageGroupRequireMention,
resolveIMessageGroupToolPolicy,
resolveSlackGroupRequireMention,
@@ -210,6 +213,64 @@ const DOCKS: Record<ChatChannelId, ChannelDock> = {
}),
},
},
googlechat: {
id: "googlechat",
capabilities: {
chatTypes: ["direct", "group", "thread"],
reactions: true,
media: true,
threads: true,
blockStreaming: true,
},
outbound: { textChunkLimit: 4000 },
config: {
resolveAllowFrom: ({ cfg, accountId }) => {
const channel = cfg.channels?.googlechat as
| {
accounts?: Record<string, { dm?: { allowFrom?: Array<string | number> } }>;
dm?: { allowFrom?: Array<string | number> };
}
| undefined;
const normalized = normalizeAccountId(accountId);
const account =
channel?.accounts?.[normalized] ??
channel?.accounts?.[
Object.keys(channel?.accounts ?? {}).find(
(key) => key.toLowerCase() === normalized.toLowerCase(),
) ?? ""
];
return (account?.dm?.allowFrom ?? channel?.dm?.allowFrom ?? []).map((entry) =>
String(entry),
);
},
formatAllowFrom: ({ allowFrom }) =>
allowFrom
.map((entry) => String(entry).trim())
.filter(Boolean)
.map((entry) =>
entry
.replace(/^(googlechat|google-chat|gchat):/i, "")
.replace(/^user:/i, "")
.replace(/^users\//i, "")
.toLowerCase(),
),
},
groups: {
resolveRequireMention: resolveGoogleChatGroupRequireMention,
resolveToolPolicy: resolveGoogleChatGroupToolPolicy,
},
threading: {
resolveReplyToMode: ({ cfg }) => cfg.channels?.googlechat?.replyToMode ?? "off",
buildToolContext: ({ context, hasRepliedRef }) => {
const threadId = context.MessageThreadId ?? context.ReplyToId;
return {
currentChannelId: context.To?.trim() || undefined,
currentThreadTs: threadId != null ? String(threadId) : undefined,
hasRepliedRef,
};
},
},
},
slack: {
id: "slack",
capabilities: {

View File

@@ -155,6 +155,15 @@ export function resolveDiscordGroupRequireMention(params: GroupMentionParams): b
return true;
}
export function resolveGoogleChatGroupRequireMention(params: GroupMentionParams): boolean {
return resolveChannelGroupRequireMention({
cfg: params.cfg,
channel: "googlechat",
groupId: params.groupId,
accountId: params.accountId,
});
}
export function resolveSlackGroupRequireMention(params: GroupMentionParams): boolean {
const account = resolveSlackAccount({
cfg: params.cfg,

View File

@@ -32,6 +32,9 @@ export type ChannelSetupInput = {
httpHost?: string;
httpPort?: string;
webhookPath?: string;
webhookUrl?: string;
audienceType?: string;
audience?: string;
useEnv?: boolean;
homeserver?: string;
userId?: string;
@@ -121,6 +124,11 @@ export type ChannelAccountSnapshot = {
tokenSource?: string;
botTokenSource?: string;
appTokenSource?: string;
credentialSource?: string;
audienceType?: string;
audience?: string;
webhookPath?: string;
webhookUrl?: string;
baseUrl?: string;
allowUnmentionedGroups?: boolean;
cliPath?: string | null;

View File

@@ -9,6 +9,8 @@ import {
describe("channel registry", () => {
it("normalizes aliases", () => {
expect(normalizeChatChannelId("imsg")).toBe("imessage");
expect(normalizeChatChannelId("gchat")).toBe("googlechat");
expect(normalizeChatChannelId("google-chat")).toBe("googlechat");
expect(normalizeChatChannelId("web")).toBeNull();
});

View File

@@ -8,6 +8,7 @@ export const CHAT_CHANNEL_ORDER = [
"telegram",
"whatsapp",
"discord",
"googlechat",
"slack",
"signal",
"imessage",
@@ -57,6 +58,16 @@ const CHAT_CHANNEL_META: Record<ChatChannelId, ChannelMeta> = {
blurb: "very well supported right now.",
systemImage: "bubble.left.and.bubble.right",
},
googlechat: {
id: "googlechat",
label: "Google Chat",
selectionLabel: "Google Chat (Chat API)",
detailLabel: "Google Chat",
docsPath: "/channels/googlechat",
docsLabel: "googlechat",
blurb: "Google Workspace Chat app with HTTP webhook.",
systemImage: "message.badge",
},
slack: {
id: "slack",
label: "Slack",
@@ -91,6 +102,8 @@ const CHAT_CHANNEL_META: Record<ChatChannelId, ChannelMeta> = {
export const CHAT_CHANNEL_ALIASES: Record<string, ChatChannelId> = {
imsg: "imessage",
"google-chat": "googlechat",
gchat: "googlechat",
};
const normalizeChannelKey = (raw?: string | null): string | undefined => {

View File

@@ -35,6 +35,9 @@ const optionNamesAdd = [
"httpHost",
"httpPort",
"webhookPath",
"webhookUrl",
"audienceType",
"audience",
"useEnv",
"homeserver",
"userId",
@@ -168,7 +171,10 @@ export function registerChannelsCli(program: Command) {
.option("--http-url <url>", "Signal HTTP daemon base URL")
.option("--http-host <host>", "Signal HTTP host")
.option("--http-port <port>", "Signal HTTP port")
.option("--webhook-path <path>", "BlueBubbles webhook path")
.option("--webhook-path <path>", "Webhook path (Google Chat/BlueBubbles)")
.option("--webhook-url <url>", "Google Chat webhook URL")
.option("--audience-type <type>", "Google Chat audience type (app-url|project-number)")
.option("--audience <value>", "Google Chat audience value (app URL or project number)")
.option("--homeserver <url>", "Matrix homeserver URL")
.option("--user-id <id>", "Matrix user ID")
.option("--access-token <token>", "Matrix access token")

View File

@@ -36,6 +36,9 @@ export function applyChannelAccountConfig(params: {
httpHost?: string;
httpPort?: string;
webhookPath?: string;
webhookUrl?: string;
audienceType?: string;
audience?: string;
useEnv?: boolean;
homeserver?: string;
userId?: string;
@@ -70,6 +73,9 @@ export function applyChannelAccountConfig(params: {
httpHost: params.httpHost,
httpPort: params.httpPort,
webhookPath: params.webhookPath,
webhookUrl: params.webhookUrl,
audienceType: params.audienceType,
audience: params.audience,
useEnv: params.useEnv,
homeserver: params.homeserver,
userId: params.userId,

View File

@@ -33,6 +33,9 @@ export type ChannelsAddOptions = {
httpHost?: string;
httpPort?: string;
webhookPath?: string;
webhookUrl?: string;
audienceType?: string;
audience?: string;
useEnv?: boolean;
homeserver?: string;
userId?: string;
@@ -198,6 +201,9 @@ export async function channelsAddCommand(
httpHost: opts.httpHost,
httpPort: opts.httpPort,
webhookPath: opts.webhookPath,
webhookUrl: opts.webhookUrl,
audienceType: opts.audienceType,
audience: opts.audience,
homeserver: opts.homeserver,
userId: opts.userId,
accessToken: opts.accessToken,
@@ -238,6 +244,9 @@ export async function channelsAddCommand(
httpHost: opts.httpHost,
httpPort: opts.httpPort,
webhookPath: opts.webhookPath,
webhookUrl: opts.webhookUrl,
audienceType: opts.audienceType,
audience: opts.audience,
homeserver: opts.homeserver,
userId: opts.userId,
accessToken: opts.accessToken,

View File

@@ -35,7 +35,11 @@ function detectAutoKind(input: string): ChannelResolveKind {
if (!trimmed) return "group";
if (trimmed.startsWith("@")) return "user";
if (/^<@!?/.test(trimmed)) return "user";
if (/^(user|discord|slack|matrix|msteams|teams|zalo|zalouser):/i.test(trimmed)) {
if (
/^(user|discord|slack|matrix|msteams|teams|zalo|zalouser|googlechat|google-chat|gchat):/i.test(
trimmed,
)
) {
return "user";
}
return "group";

View File

@@ -1,4 +1,5 @@
import type { DiscordConfig } from "./types.discord.js";
import type { GoogleChatConfig } from "./types.googlechat.js";
import type { IMessageConfig } from "./types.imessage.js";
import type { MSTeamsConfig } from "./types.msteams.js";
import type { SignalConfig } from "./types.signal.js";
@@ -27,6 +28,7 @@ export type ChannelsConfig = {
whatsapp?: WhatsAppConfig;
telegram?: TelegramConfig;
discord?: DiscordConfig;
googlechat?: GoogleChatConfig;
slack?: SlackConfig;
signal?: SignalConfig;
imessage?: IMessageConfig;

View File

@@ -0,0 +1,97 @@
import type {
BlockStreamingCoalesceConfig,
DmPolicy,
GroupPolicy,
ReplyToMode,
} from "./types.base.js";
import type { DmConfig } from "./types.messages.js";
export type GoogleChatDmConfig = {
/** If false, ignore all incoming Google Chat DMs. Default: true. */
enabled?: boolean;
/** Direct message access policy (default: pairing). */
policy?: DmPolicy;
/** Allowlist for DM senders (user ids or emails). */
allowFrom?: Array<string | number>;
};
export type GoogleChatGroupConfig = {
/** If false, disable the bot in this space. (Alias for allow: false.) */
enabled?: boolean;
/** Legacy allow toggle; prefer enabled. */
allow?: boolean;
/** Require mentioning the bot to trigger replies. */
requireMention?: boolean;
/** Allowlist of users that can invoke the bot in this space. */
users?: Array<string | number>;
/** Optional system prompt for this space. */
systemPrompt?: string;
};
export type GoogleChatActionConfig = {
reactions?: boolean;
};
export type GoogleChatAccountConfig = {
/** Optional display name for this account (used in CLI/UI lists). */
name?: string;
/** Optional provider capability tags used for agent/runtime guidance. */
capabilities?: string[];
/** Allow channel-initiated config writes (default: true). */
configWrites?: boolean;
/** If false, do not start this Google Chat account. Default: true. */
enabled?: boolean;
/** Allow bot-authored messages to trigger replies (default: false). */
allowBots?: boolean;
/** Default mention requirement for space messages (default: true). */
requireMention?: boolean;
/**
* Controls how space messages are handled:
* - "open": spaces bypass allowlists; mention-gating applies
* - "disabled": block all space messages
* - "allowlist": only allow spaces present in channels.googlechat.groups
*/
groupPolicy?: GroupPolicy;
/** Optional allowlist for space senders (user ids or emails). */
groupAllowFrom?: Array<string | number>;
/** Per-space configuration keyed by space id or name. */
groups?: Record<string, GoogleChatGroupConfig>;
/** Service account JSON (inline string or object). */
serviceAccount?: string | Record<string, unknown>;
/** Service account JSON file path. */
serviceAccountFile?: string;
/** Webhook audience type (app-url or project-number). */
audienceType?: "app-url" | "project-number";
/** Audience value (app URL or project number). */
audience?: string;
/** Google Chat webhook path (default: /googlechat). */
webhookPath?: string;
/** Google Chat webhook URL (used to derive the path). */
webhookUrl?: string;
/** Optional bot user resource name (users/...). */
botUser?: string;
/** Max space messages to keep as history context (0 disables). */
historyLimit?: number;
/** Max DM turns to keep as history context. */
dmHistoryLimit?: number;
/** Per-DM config overrides keyed by user id. */
dms?: Record<string, DmConfig>;
/** Outbound text chunk size (chars). Default: 4000. */
textChunkLimit?: number;
blockStreaming?: boolean;
/** Merge streamed block replies before sending. */
blockStreamingCoalesce?: BlockStreamingCoalesceConfig;
mediaMaxMb?: number;
/** Control reply threading when reply tags are present (off|first|all). */
replyToMode?: ReplyToMode;
/** Per-action tool gating (default: true for all). */
actions?: GoogleChatActionConfig;
dm?: GoogleChatDmConfig;
};
export type GoogleChatConfig = {
/** Optional per-account Google Chat configuration (multi-account). */
accounts?: Record<string, GoogleChatAccountConfig>;
/** Optional default account id when multiple accounts are configured. */
defaultAccount?: string;
} & GoogleChatAccountConfig;

View File

@@ -23,6 +23,7 @@ export type HookMappingConfig = {
| "whatsapp"
| "telegram"
| "discord"
| "googlechat"
| "slack"
| "signal"
| "imessage"

View File

@@ -12,6 +12,7 @@ export type QueueModeByProvider = {
whatsapp?: QueueMode;
telegram?: QueueMode;
discord?: QueueMode;
googlechat?: QueueMode;
slack?: QueueMode;
signal?: QueueMode;
imessage?: QueueMode;

View File

@@ -10,6 +10,7 @@ export * from "./types.channels.js";
export * from "./types.clawdbot.js";
export * from "./types.cron.js";
export * from "./types.discord.js";
export * from "./types.googlechat.js";
export * from "./types.gateway.js";
export * from "./types.hooks.js";
export * from "./types.imessage.js";

View File

@@ -260,6 +260,75 @@ export const DiscordConfigSchema = DiscordAccountSchema.extend({
accounts: z.record(z.string(), DiscordAccountSchema.optional()).optional(),
});
export const GoogleChatDmSchema = z
.object({
enabled: z.boolean().optional(),
policy: DmPolicySchema.optional().default("pairing"),
allowFrom: z.array(z.union([z.string(), z.number()])).optional(),
})
.strict()
.superRefine((value, ctx) => {
requireOpenAllowFrom({
policy: value.policy,
allowFrom: value.allowFrom,
ctx,
path: ["allowFrom"],
message:
'channels.googlechat.dm.policy="open" requires channels.googlechat.dm.allowFrom to include "*"',
});
});
export const GoogleChatGroupSchema = z
.object({
enabled: z.boolean().optional(),
allow: z.boolean().optional(),
requireMention: z.boolean().optional(),
users: z.array(z.union([z.string(), z.number()])).optional(),
systemPrompt: z.string().optional(),
})
.strict();
export const GoogleChatAccountSchema = z
.object({
name: z.string().optional(),
capabilities: z.array(z.string()).optional(),
enabled: z.boolean().optional(),
configWrites: z.boolean().optional(),
allowBots: z.boolean().optional(),
requireMention: z.boolean().optional(),
groupPolicy: GroupPolicySchema.optional().default("allowlist"),
groupAllowFrom: z.array(z.union([z.string(), z.number()])).optional(),
groups: z.record(z.string(), GoogleChatGroupSchema.optional()).optional(),
serviceAccount: z.union([z.string(), z.record(z.string(), z.unknown())]).optional(),
serviceAccountFile: z.string().optional(),
audienceType: z.enum(["app-url", "project-number"]).optional(),
audience: z.string().optional(),
webhookPath: z.string().optional(),
webhookUrl: z.string().optional(),
botUser: z.string().optional(),
historyLimit: z.number().int().min(0).optional(),
dmHistoryLimit: z.number().int().min(0).optional(),
dms: z.record(z.string(), DmConfigSchema.optional()).optional(),
textChunkLimit: z.number().int().positive().optional(),
blockStreaming: z.boolean().optional(),
blockStreamingCoalesce: BlockStreamingCoalesceSchema.optional(),
mediaMaxMb: z.number().positive().optional(),
replyToMode: ReplyToModeSchema.optional(),
actions: z
.object({
reactions: z.boolean().optional(),
})
.strict()
.optional(),
dm: GoogleChatDmSchema.optional(),
})
.strict();
export const GoogleChatConfigSchema = GoogleChatAccountSchema.extend({
accounts: z.record(z.string(), GoogleChatAccountSchema.optional()).optional(),
defaultAccount: z.string().optional(),
});
export const SlackDmSchema = z
.object({
enabled: z.boolean().optional(),

View File

@@ -3,6 +3,7 @@ import { z } from "zod";
import {
BlueBubblesConfigSchema,
DiscordConfigSchema,
GoogleChatConfigSchema,
IMessageConfigSchema,
MSTeamsConfigSchema,
SignalConfigSchema,
@@ -29,6 +30,7 @@ export const ChannelsSchema = z
whatsapp: WhatsAppConfigSchema.optional(),
telegram: TelegramConfigSchema.optional(),
discord: DiscordConfigSchema.optional(),
googlechat: GoogleChatConfigSchema.optional(),
slack: SlackConfigSchema.optional(),
signal: SignalConfigSchema.optional(),
imessage: IMessageConfigSchema.optional(),

View File

@@ -6,6 +6,7 @@ const ENVELOPE_CHANNELS = [
"Signal",
"Slack",
"Discord",
"Google Chat",
"iMessage",
"Teams",
"Matrix",

View File

@@ -76,6 +76,11 @@ export type {
GroupToolPolicyConfig,
MarkdownConfig,
MarkdownTableMode,
GoogleChatAccountConfig,
GoogleChatConfig,
GoogleChatDmConfig,
GoogleChatGroupConfig,
GoogleChatActionConfig,
MSTeamsChannelConfig,
MSTeamsConfig,
MSTeamsReplyStyle,
@@ -83,6 +88,7 @@ export type {
} from "../config/types.js";
export {
DiscordConfigSchema,
GoogleChatConfigSchema,
IMessageConfigSchema,
MSTeamsConfigSchema,
SignalConfigSchema,
@@ -141,6 +147,7 @@ export { resolveControlCommandGate } from "../channels/command-gating.js";
export {
resolveBlueBubblesGroupRequireMention,
resolveDiscordGroupRequireMention,
resolveGoogleChatGroupRequireMention,
resolveIMessageGroupRequireMention,
resolveSlackGroupRequireMention,
resolveTelegramGroupRequireMention,

View File

@@ -22,6 +22,7 @@ const MARKDOWN_CAPABLE_CHANNELS = new Set<string>([
"telegram",
"signal",
"discord",
"googlechat",
"tui",
INTERNAL_MESSAGE_CHANNEL,
]);