mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 04:41:25 +00:00
fix(slack): drop mismatched Socket Mode events (#889)
Filter Slack Socket Mode events by api_app_id/team_id. Refs: #828 Contributor: @roshanasingh4 Co-authored-by: Roshan Singh <roshanasingh4@users.noreply.github.com>
This commit is contained in:
@@ -22,6 +22,7 @@ export type SlackMonitorContext = {
|
||||
|
||||
botUserId: string;
|
||||
teamId: string;
|
||||
apiAppId: string;
|
||||
|
||||
historyLimit: number;
|
||||
channelHistories: Map<string, HistoryEntry[]>;
|
||||
@@ -58,6 +59,7 @@ export type SlackMonitorContext = {
|
||||
|
||||
logger: ReturnType<typeof getChildLogger>;
|
||||
markMessageSeen: (channelId: string | undefined, ts?: string) => boolean;
|
||||
shouldDropMismatchedSlackEvent: (body: unknown) => boolean;
|
||||
resolveSlackSystemEventSessionKey: (params: {
|
||||
channelId?: string | null;
|
||||
channelType?: string | null;
|
||||
@@ -90,6 +92,7 @@ export function createSlackMonitorContext(params: {
|
||||
|
||||
botUserId: string;
|
||||
teamId: string;
|
||||
apiAppId: string;
|
||||
|
||||
historyLimit: number;
|
||||
sessionScope: SessionScope;
|
||||
@@ -290,6 +293,25 @@ export function createSlackMonitorContext(params: {
|
||||
return true;
|
||||
};
|
||||
|
||||
const shouldDropMismatchedSlackEvent = (body: unknown) => {
|
||||
if (!body || typeof body !== "object") return false;
|
||||
const raw = body as { api_app_id?: unknown; team_id?: unknown };
|
||||
const incomingApiAppId = typeof raw.api_app_id === "string" ? raw.api_app_id : "";
|
||||
const incomingTeamId = typeof raw.team_id === "string" ? raw.team_id : "";
|
||||
|
||||
if (params.apiAppId && incomingApiAppId && incomingApiAppId !== params.apiAppId) {
|
||||
logVerbose(
|
||||
`slack: drop event with api_app_id=${incomingApiAppId} (expected ${params.apiAppId})`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
if (params.teamId && incomingTeamId && incomingTeamId !== params.teamId) {
|
||||
logVerbose(`slack: drop event with team_id=${incomingTeamId} (expected ${params.teamId})`);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
return {
|
||||
cfg: params.cfg,
|
||||
accountId: params.accountId,
|
||||
@@ -298,6 +320,7 @@ export function createSlackMonitorContext(params: {
|
||||
runtime: params.runtime,
|
||||
botUserId: params.botUserId,
|
||||
teamId: params.teamId,
|
||||
apiAppId: params.apiAppId,
|
||||
historyLimit: params.historyLimit,
|
||||
channelHistories,
|
||||
sessionScope: params.sessionScope,
|
||||
@@ -320,6 +343,7 @@ export function createSlackMonitorContext(params: {
|
||||
removeAckAfterReply: params.removeAckAfterReply,
|
||||
logger,
|
||||
markMessageSeen,
|
||||
shouldDropMismatchedSlackEvent,
|
||||
resolveSlackSystemEventSessionKey,
|
||||
isChannelAllowed,
|
||||
resolveChannelName,
|
||||
|
||||
Reference in New Issue
Block a user