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.
This commit is contained in:
Artemii
2026-02-16 17:33:54 +00:00
committed by Peter Steinberger
parent bcab2469de
commit d4c057f8c1
2 changed files with 30 additions and 0 deletions

View File

@@ -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",

View File

@@ -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),