fix: harden message hook session/group context and add integration coverage (#9859) (thanks @Drickon)

This commit is contained in:
Peter Steinberger
2026-03-02 22:34:27 +00:00
parent b5102ba4f9
commit 29dde80c3e
9 changed files with 310 additions and 46 deletions

View File

@@ -106,9 +106,6 @@ export async function dispatchReplyFromConfig(params: {
const sessionKey = ctx.SessionKey;
const startTime = diagnosticsEnabled ? Date.now() : 0;
const canTrackSession = diagnosticsEnabled && Boolean(sessionKey);
const isGroup = Boolean(ctx.GroupSubject || ctx.GroupChannel);
const groupId =
ctx.From?.includes(":group:") || ctx.From?.includes(":channel:") ? ctx.From : undefined;
const recordProcessed = (
outcome: "completed" | "skipped" | "error",
@@ -180,6 +177,8 @@ export async function dispatchReplyFromConfig(params: {
: "";
const channelId = (ctx.OriginatingChannel ?? ctx.Surface ?? ctx.Provider ?? "").toLowerCase();
const conversationId = ctx.OriginatingTo ?? ctx.To ?? ctx.From ?? undefined;
const isGroup = Boolean(ctx.GroupSubject || ctx.GroupChannel);
const groupId = isGroup ? conversationId : undefined;
// Trigger plugin hooks (fire-and-forget)
if (hookRunner?.hasHooks("message_received")) {