refactor(slack): share system-event ingress and test harness

This commit is contained in:
Peter Steinberger
2026-02-26 04:01:19 +01:00
parent 4ada143794
commit e16e8f5af2
6 changed files with 144 additions and 138 deletions

View File

@@ -0,0 +1,44 @@
import { logVerbose } from "../../../globals.js";
import { authorizeSlackSystemEventSender } from "../auth.js";
import { resolveSlackChannelLabel } from "../channel-config.js";
import type { SlackMonitorContext } from "../context.js";
export type SlackAuthorizedSystemEventContext = {
channelLabel: string;
sessionKey: string;
};
export async function authorizeAndResolveSlackSystemEventContext(params: {
ctx: SlackMonitorContext;
senderId?: string;
channelId?: string;
channelType?: string | null;
eventKind: string;
}): Promise<SlackAuthorizedSystemEventContext | undefined> {
const { ctx, senderId, channelId, channelType, eventKind } = params;
const auth = await authorizeSlackSystemEventSender({
ctx,
senderId,
channelId,
channelType,
});
if (!auth.allowed) {
logVerbose(
`slack: drop ${eventKind} sender ${senderId ?? "unknown"} channel=${channelId ?? "unknown"} reason=${auth.reason ?? "unauthorized"}`,
);
return undefined;
}
const channelLabel = resolveSlackChannelLabel({
channelId,
channelName: auth.channelName,
});
const sessionKey = ctx.resolveSlackSystemEventSessionKey({
channelId,
channelType: auth.channelType,
});
return {
channelLabel,
sessionKey,
};
}