mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 21:24:31 +00:00
refactor(slack): share system-event ingress and test harness
This commit is contained in:
44
src/slack/monitor/events/system-event-context.ts
Normal file
44
src/slack/monitor/events/system-event-context.ts
Normal 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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user