fix: include sender info for iMessage/Signal group messages

This commit is contained in:
Peter Steinberger
2026-01-17 02:51:58 +00:00
parent 96a1d03f08
commit 1481a3d90f
3 changed files with 116 additions and 3 deletions
@@ -184,4 +184,77 @@ describe("dispatchReplyFromConfig", () => {
expect(replyResolver).toHaveBeenCalledTimes(1);
});
it("appends sender meta for non-direct chats when missing", async () => {
mocks.tryFastAbortFromMessage.mockResolvedValue({
handled: false,
aborted: false,
});
const cfg = {} as ClawdbotConfig;
const dispatcher = createDispatcher();
const ctx: MsgContext = {
Provider: "imessage",
ChatType: "group",
Body: "[iMessage group:1] hello",
SenderName: "+15555550123",
SenderId: "+15555550123",
};
const replyResolver = vi.fn(async (resolvedCtx: MsgContext) => {
expect(resolvedCtx.Body).toContain("\n[from: +15555550123]");
return { text: "ok" } satisfies ReplyPayload;
});
await dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyResolver });
expect(replyResolver).toHaveBeenCalledTimes(1);
});
it("does not append sender meta when Body already includes a from line", async () => {
mocks.tryFastAbortFromMessage.mockResolvedValue({
handled: false,
aborted: false,
});
const cfg = {} as ClawdbotConfig;
const dispatcher = createDispatcher();
const ctx: MsgContext = {
Provider: "whatsapp",
ChatType: "group",
Body: "[WhatsApp group:1] hello\\n[from: Bob (+222)]",
SenderName: "Bob",
SenderId: "+222",
};
const replyResolver = vi.fn(async (resolvedCtx: MsgContext) => {
expect(resolvedCtx.Body.match(/\\n\[from:/g)?.length ?? 0).toBe(1);
return { text: "ok" } satisfies ReplyPayload;
});
await dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyResolver });
expect(replyResolver).toHaveBeenCalledTimes(1);
});
it("does not append sender meta for other providers (scope is signal/imessage only)", async () => {
mocks.tryFastAbortFromMessage.mockResolvedValue({
handled: false,
aborted: false,
});
const cfg = {} as ClawdbotConfig;
const dispatcher = createDispatcher();
const ctx: MsgContext = {
Provider: "slack",
OriginatingChannel: "slack",
ChatType: "group",
Body: "[Slack #room 2026-01-01T00:00Z] hi",
SenderName: "Bob",
SenderId: "U123",
};
const replyResolver = vi.fn(async (resolvedCtx: MsgContext) => {
expect(resolvedCtx.Body).not.toContain("[from:");
return { text: "ok" } satisfies ReplyPayload;
});
await dispatchReplyFromConfig({ ctx, cfg, dispatcher, replyResolver });
expect(replyResolver).toHaveBeenCalledTimes(1);
});
});