feat(web): add group chat mention support
This commit is contained in:
@@ -43,6 +43,12 @@ export type WebConfig = {
|
||||
reconnect?: WebReconnectConfig;
|
||||
};
|
||||
|
||||
export type GroupChatConfig = {
|
||||
requireMention?: boolean;
|
||||
mentionPatterns?: string[];
|
||||
historyLimit?: number;
|
||||
};
|
||||
|
||||
export type WarelayConfig = {
|
||||
logging?: LoggingConfig;
|
||||
inbound?: {
|
||||
@@ -55,6 +61,7 @@ export type WarelayConfig = {
|
||||
command: string[];
|
||||
timeoutSeconds?: number;
|
||||
};
|
||||
groupChat?: GroupChatConfig;
|
||||
reply?: {
|
||||
mode: ReplyMode;
|
||||
text?: string;
|
||||
@@ -172,6 +179,13 @@ const WarelaySchema = z.object({
|
||||
messagePrefix: z.string().optional(),
|
||||
responsePrefix: z.string().optional(),
|
||||
timestampPrefix: z.union([z.boolean(), z.string()]).optional(),
|
||||
groupChat: z
|
||||
.object({
|
||||
requireMention: z.boolean().optional(),
|
||||
mentionPatterns: z.array(z.string()).optional(),
|
||||
historyLimit: z.number().int().positive().optional(),
|
||||
})
|
||||
.optional(),
|
||||
transcribeAudio: z
|
||||
.object({
|
||||
command: z.array(z.string()),
|
||||
|
||||
@@ -16,4 +16,10 @@ describe("sessions", () => {
|
||||
it("global scope returns global", () => {
|
||||
expect(deriveSessionKey("global", { From: "+1" })).toBe("global");
|
||||
});
|
||||
|
||||
it("keeps group chats distinct", () => {
|
||||
expect(
|
||||
deriveSessionKey("per-sender", { From: "12345-678@g.us" }),
|
||||
).toBe("group:12345-678@g.us");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,5 +59,12 @@ export async function saveSessionStore(
|
||||
export function deriveSessionKey(scope: SessionScope, ctx: MsgContext) {
|
||||
if (scope === "global") return "global";
|
||||
const from = ctx.From ? normalizeE164(ctx.From) : "";
|
||||
// Preserve group conversations as distinct buckets
|
||||
if (typeof ctx.From === "string" && ctx.From.includes("@g.us")) {
|
||||
return `group:${ctx.From}`;
|
||||
}
|
||||
if (typeof ctx.From === "string" && ctx.From.startsWith("group:")) {
|
||||
return ctx.From;
|
||||
}
|
||||
return from || "unknown";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user