From d4c057f8c100a4e4d7e5d443bc10e606244f9d67 Mon Sep 17 00:00:00 2001 From: Artemii Date: Mon, 16 Feb 2026 17:33:54 +0000 Subject: [PATCH] feat(inbound-meta): expose sender_id in trusted system metadata Add sender_id (ctx.SenderId) to the openclaw.inbound_meta.v1 payload so agents can reference it for moderation actions (delete, ban, etc.) without relying on user-controlled text fields. message_id and chat_id were already present; sender_id was the missing piece needed for complete group moderation workflows. --- src/auto-reply/reply/inbound-meta.test.ts | 29 +++++++++++++++++++++++ src/auto-reply/reply/inbound-meta.ts | 1 + 2 files changed, 30 insertions(+) diff --git a/src/auto-reply/reply/inbound-meta.test.ts b/src/auto-reply/reply/inbound-meta.test.ts index a1daa577d0..2578c7ca72 100644 --- a/src/auto-reply/reply/inbound-meta.test.ts +++ b/src/auto-reply/reply/inbound-meta.test.ts @@ -32,6 +32,35 @@ describe("buildInboundMetaSystemPrompt", () => { expect(payload["channel"]).toBe("telegram"); }); + it("includes sender_id when provided", () => { + const prompt = buildInboundMetaSystemPrompt({ + MessageSid: "456", + SenderId: "289522496", + OriginatingTo: "telegram:-1001249586642", + OriginatingChannel: "telegram", + Provider: "telegram", + Surface: "telegram", + ChatType: "group", + } as TemplateContext); + + const payload = parseInboundMetaPayload(prompt); + expect(payload["sender_id"]).toBe("289522496"); + }); + + it("omits sender_id when not provided", () => { + const prompt = buildInboundMetaSystemPrompt({ + MessageSid: "789", + OriginatingTo: "telegram:5494292670", + OriginatingChannel: "telegram", + Provider: "telegram", + Surface: "telegram", + ChatType: "direct", + } as TemplateContext); + + const payload = parseInboundMetaPayload(prompt); + expect(payload["sender_id"]).toBeUndefined(); + }); + it("keeps message_id_full only when it differs from message_id", () => { const prompt = buildInboundMetaSystemPrompt({ MessageSid: "short-id", diff --git a/src/auto-reply/reply/inbound-meta.ts b/src/auto-reply/reply/inbound-meta.ts index 03c06b7e2b..2e8f81a9c1 100644 --- a/src/auto-reply/reply/inbound-meta.ts +++ b/src/auto-reply/reply/inbound-meta.ts @@ -24,6 +24,7 @@ export function buildInboundMetaSystemPrompt(ctx: TemplateContext): string { schema: "openclaw.inbound_meta.v1", message_id: messageId, message_id_full: messageIdFull && messageIdFull !== messageId ? messageIdFull : undefined, + sender_id: safeTrim(ctx.SenderId), chat_id: chatId, reply_to_id: replyToId, channel: safeTrim(ctx.OriginatingChannel) ?? safeTrim(ctx.Surface) ?? safeTrim(ctx.Provider),