Files
openclaw/src/slack/monitor/events/system-event-context.ts
2026-02-26 04:01:33 +01:00

45 lines
1.2 KiB
TypeScript

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,
};
}