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 => {