refactor: prune legacy group prefixes

This commit is contained in:
Peter Steinberger
2026-01-17 08:46:19 +00:00
parent ab49fe0e92
commit 13b931c006
44 changed files with 160 additions and 179 deletions

View File

@@ -109,7 +109,7 @@ describe("group intro prompts", () => {
await getReplyFromConfig(
{
Body: "status update",
From: "group:dev",
From: "discord:group:dev",
To: "+1888",
ChatType: "group",
GroupSubject: "Release Squad",
@@ -172,7 +172,7 @@ describe("group intro prompts", () => {
await getReplyFromConfig(
{
Body: "ping",
From: "group:tg",
From: "telegram:group:tg",
To: "+1777",
ChatType: "group",
GroupSubject: "Dev Chat",

View File

@@ -211,7 +211,7 @@ describe("trigger handling", () => {
const res = await getReplyFromConfig(
{
Body: "/elevated on",
From: "group:123@g.us",
From: "whatsapp:group:123@g.us",
To: "whatsapp:+2000",
Provider: "whatsapp",
SenderE164: "+1000",

View File

@@ -128,7 +128,7 @@ describe("trigger handling", () => {
const res = await getReplyFromConfig(
{
Body: "/elevated off",
From: "group:123@g.us",
From: "whatsapp:group:123@g.us",
To: "whatsapp:+2000",
Provider: "whatsapp",
SenderE164: "+1000",
@@ -172,7 +172,7 @@ describe("trigger handling", () => {
const res = await getReplyFromConfig(
{
Body: "/elevated on",
From: "group:123@g.us",
From: "whatsapp:group:123@g.us",
To: "whatsapp:+2000",
Provider: "whatsapp",
SenderE164: "+1000",

View File

@@ -135,7 +135,7 @@ describe("trigger handling", () => {
const ctx = {
Body: "hi",
From: "group:whatsapp:demo",
From: "whatsapp:group:demo",
To: "+2000",
ChatType: "group" as const,
Provider: "whatsapp" as const,

View File

@@ -75,7 +75,7 @@ describe("buildThreadingToolContext", () => {
const sessionCtx = {
Provider: "imessage",
ChatType: "group",
From: "group:7",
From: "imessage:group:7",
To: "chat_id:7",
} as TemplateContext;

View File

@@ -22,7 +22,7 @@ describe("resolveGroupRequireMention", () => {
};
const ctx: TemplateContext = {
Provider: "discord",
From: "group:123",
From: "discord:group:123",
GroupChannel: "#general",
GroupSpace: "145",
};

View File

@@ -6,6 +6,26 @@ import { isInternalMessageChannel } from "../../utils/message-channel.js";
import { normalizeGroupActivation } from "../group-activation.js";
import type { TemplateContext } from "../templating.js";
function extractGroupId(raw: string | undefined | null): string | undefined {
const trimmed = (raw ?? "").trim();
if (!trimmed) return undefined;
const parts = trimmed.split(":").filter(Boolean);
if (parts.length >= 3 && (parts[1] === "group" || parts[1] === "channel")) {
return parts.slice(2).join(":") || undefined;
}
if (
parts.length >= 2 &&
parts[0]?.toLowerCase() === "whatsapp" &&
trimmed.toLowerCase().includes("@g.us")
) {
return parts.slice(1).join(":") || undefined;
}
if (parts.length >= 2 && (parts[0] === "group" || parts[0] === "channel")) {
return parts.slice(1).join(":") || undefined;
}
return trimmed;
}
export function resolveGroupRequireMention(params: {
cfg: ClawdbotConfig;
ctx: TemplateContext;
@@ -15,7 +35,7 @@ export function resolveGroupRequireMention(params: {
const rawChannel = groupResolution?.channel ?? ctx.Provider?.trim();
const channel = normalizeChannelId(rawChannel);
if (!channel) return true;
const groupId = groupResolution?.id ?? ctx.From?.replace(/^group:/, "");
const groupId = groupResolution?.id ?? extractGroupId(ctx.From);
const groupChannel = ctx.GroupChannel?.trim() ?? ctx.GroupSubject?.trim();
const groupSpace = ctx.GroupSpace?.trim();
const requireMention = getChannelDock(channel)?.groups?.resolveRequireMention?.({
@@ -61,7 +81,7 @@ export function buildGroupIntro(params: {
activation === "always"
? "Activation: always-on (you receive every group message)."
: "Activation: trigger-only (you are invoked only when explicitly mentioned; recent context may be included).";
const groupId = params.sessionCtx.From?.replace(/^group:/, "");
const groupId = params.sessionEntry?.groupId ?? extractGroupId(params.sessionCtx.From);
const groupChannel = params.sessionCtx.GroupChannel?.trim() ?? subject;
const groupSpace = params.sessionCtx.GroupSpace?.trim();
const providerIdsLine = providerId

View File

@@ -9,7 +9,7 @@ describe("finalizeInboundContext", () => {
Body: "a\\nb\r\nc",
RawBody: "raw\\nline",
ChatType: "channel",
From: "group:123@g.us",
From: "whatsapp:group:123@g.us",
GroupSubject: "Test",
};

View File

@@ -227,6 +227,7 @@ export async function initSessionState(params: {
displayName: baseEntry?.displayName,
chatType: baseEntry?.chatType,
channel: baseEntry?.channel,
groupId: baseEntry?.groupId,
subject: baseEntry?.subject,
room: baseEntry?.room,
space: baseEntry?.space,
@@ -256,6 +257,7 @@ export async function initSessionState(params: {
const nextSubject = nextRoom ? undefined : subject;
sessionEntry.chatType = groupResolution.chatType ?? "group";
sessionEntry.channel = channel;
sessionEntry.groupId = groupResolution.id;
if (nextSubject) sessionEntry.subject = nextSubject;
if (nextRoom) sessionEntry.room = nextRoom;
if (space) sessionEntry.space = space;

View File

@@ -293,8 +293,7 @@ export function buildStatusMessage(args: StatusArgs): string {
entry?.chatType === "group" ||
entry?.chatType === "channel" ||
Boolean(args.sessionKey?.includes(":group:")) ||
Boolean(args.sessionKey?.includes(":channel:")) ||
Boolean(args.sessionKey?.startsWith("group:"));
Boolean(args.sessionKey?.includes(":channel:"));
const groupActivationValue = isGroupSession
? (args.groupActivation ?? entry?.groupActivation ?? "mention")
: undefined;