refactor: add inbound context helpers

This commit is contained in:
Peter Steinberger
2026-01-17 04:04:17 +00:00
parent a2b5b1f0cb
commit 388b2bce01
9 changed files with 224 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
import { describe, expect, it } from "vitest";
import type { MsgContext } from "../auto-reply/templating.js";
import { resolveConversationLabel } from "./conversation-label.js";
describe("resolveConversationLabel", () => {
it("prefers ConversationLabel when present", () => {
const ctx: MsgContext = { ConversationLabel: "Pinned Label", ChatType: "group" };
expect(resolveConversationLabel(ctx)).toBe("Pinned Label");
});
it("uses SenderName for direct chats when available", () => {
const ctx: MsgContext = { ChatType: "direct", SenderName: "Ada", From: "telegram:99" };
expect(resolveConversationLabel(ctx)).toBe("Ada");
});
it("derives Telegram-like group labels with numeric id suffix", () => {
const ctx: MsgContext = { ChatType: "group", GroupSubject: "Ops", From: "telegram:group:42" };
expect(resolveConversationLabel(ctx)).toBe("Ops id:42");
});
it("does not append ids for #rooms/channels", () => {
const ctx: MsgContext = { ChatType: "channel", GroupSubject: "#general", From: "slack:channel:C123" };
expect(resolveConversationLabel(ctx)).toBe("#general");
});
it("appends ids for WhatsApp-like group ids when a subject exists", () => {
const ctx: MsgContext = { ChatType: "group", GroupSubject: "Family", From: "whatsapp:group:123@g.us" };
expect(resolveConversationLabel(ctx)).toBe("Family id:123@g.us");
});
});