mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:58:27 +00:00
Slack: fix CI typing for interaction handler
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import type { BlockAction, SlackActionMiddlewareArgs } from "@slack/bolt";
|
import type { SlackActionMiddlewareArgs } from "@slack/bolt";
|
||||||
import type { Block, KnownBlock } from "@slack/web-api";
|
import type { Block, KnownBlock } from "@slack/web-api";
|
||||||
import type { SlackMonitorContext } from "../context.js";
|
import type { SlackMonitorContext } from "../context.js";
|
||||||
import { enqueueSystemEvent } from "../../../infra/system-events.js";
|
import { enqueueSystemEvent } from "../../../infra/system-events.js";
|
||||||
@@ -55,8 +55,11 @@ function readOptionLabels(options: unknown): string[] | undefined {
|
|||||||
return labels.length > 0 ? labels : undefined;
|
return labels.length > 0 ? labels : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function summarizeAction(action: BlockAction): Omit<InteractionSummary, "actionId" | "blockId"> {
|
function summarizeAction(
|
||||||
const typed = action as BlockAction & {
|
action: Record<string, unknown>,
|
||||||
|
): Omit<InteractionSummary, "actionId" | "blockId"> {
|
||||||
|
const typed = action as {
|
||||||
|
type?: string;
|
||||||
selected_option?: SelectOption;
|
selected_option?: SelectOption;
|
||||||
selected_options?: SelectOption[];
|
selected_options?: SelectOption[];
|
||||||
selected_user?: string;
|
selected_user?: string;
|
||||||
@@ -92,7 +95,7 @@ function summarizeAction(action: BlockAction): Omit<InteractionSummary, "actionI
|
|||||||
selectedTime: typed.selected_time,
|
selectedTime: typed.selected_time,
|
||||||
selectedDateTime:
|
selectedDateTime:
|
||||||
typeof typed.selected_date_time === "number" ? typed.selected_date_time : undefined,
|
typeof typed.selected_date_time === "number" ? typed.selected_date_time : undefined,
|
||||||
inputValue: actionType === "plain_text_input" ? typed.value : undefined,
|
inputValue: typed.value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,19 +119,30 @@ export function registerSlackInteractionEvents(params: { ctx: SlackMonitorContex
|
|||||||
// with other Slack integrations or future features
|
// with other Slack integrations or future features
|
||||||
ctx.app.action(
|
ctx.app.action(
|
||||||
new RegExp(`^${OPENCLAW_ACTION_PREFIX}`),
|
new RegExp(`^${OPENCLAW_ACTION_PREFIX}`),
|
||||||
async (args: SlackActionMiddlewareArgs<BlockAction>) => {
|
async (args: SlackActionMiddlewareArgs) => {
|
||||||
const { ack, body, action, respond } = args;
|
const { ack, body, action, respond } = args;
|
||||||
|
const typedBody = body as unknown as {
|
||||||
|
user?: { id?: string };
|
||||||
|
channel?: { id?: string };
|
||||||
|
message?: { ts?: string; text?: string; blocks?: unknown[] };
|
||||||
|
};
|
||||||
|
|
||||||
// Acknowledge the action immediately to prevent the warning icon
|
// Acknowledge the action immediately to prevent the warning icon
|
||||||
await ack();
|
await ack();
|
||||||
|
|
||||||
// Extract action details using proper Bolt types
|
// Extract action details using proper Bolt types
|
||||||
const actionId = action.action_id;
|
const typedAction = action as unknown as Record<string, unknown> & {
|
||||||
const blockId = action.block_id;
|
action_id?: string;
|
||||||
const userId = body.user.id;
|
block_id?: string;
|
||||||
const channelId = body.channel?.id;
|
type?: string;
|
||||||
const messageTs = body.message?.ts;
|
text?: { text?: string };
|
||||||
const actionSummary = summarizeAction(action);
|
};
|
||||||
|
const actionId = typedAction.action_id ?? "unknown";
|
||||||
|
const blockId = typedAction.block_id;
|
||||||
|
const userId = typedBody.user?.id ?? "unknown";
|
||||||
|
const channelId = typedBody.channel?.id;
|
||||||
|
const messageTs = typedBody.message?.ts;
|
||||||
|
const actionSummary = summarizeAction(typedAction);
|
||||||
const eventPayload: InteractionSummary = {
|
const eventPayload: InteractionSummary = {
|
||||||
actionId,
|
actionId,
|
||||||
blockId,
|
blockId,
|
||||||
@@ -159,16 +173,16 @@ export function registerSlackInteractionEvents(params: { ctx: SlackMonitorContex
|
|||||||
contextKey,
|
contextKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
const originalBlocks = (body.message as { blocks?: unknown[] } | undefined)?.blocks;
|
const originalBlocks = typedBody.message?.blocks;
|
||||||
if (!Array.isArray(originalBlocks) || !channelId || !messageTs) {
|
if (!Array.isArray(originalBlocks) || !channelId || !messageTs) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.type !== "button") {
|
if (typedAction.type !== "button") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const buttonText = action.text?.text ?? actionId;
|
const buttonText = typedAction.text?.text ?? actionId;
|
||||||
let updatedBlocks = originalBlocks.map((block) => {
|
let updatedBlocks = originalBlocks.map((block) => {
|
||||||
const typedBlock = block as InteractionMessageBlock;
|
const typedBlock = block as InteractionMessageBlock;
|
||||||
if (typedBlock.type === "actions" && typedBlock.block_id === blockId) {
|
if (typedBlock.type === "actions" && typedBlock.block_id === blockId) {
|
||||||
@@ -203,7 +217,7 @@ export function registerSlackInteractionEvents(params: { ctx: SlackMonitorContex
|
|||||||
await ctx.app.client.chat.update({
|
await ctx.app.client.chat.update({
|
||||||
channel: channelId,
|
channel: channelId,
|
||||||
ts: messageTs,
|
ts: messageTs,
|
||||||
text: (body.message as { text?: string } | undefined)?.text ?? "",
|
text: typedBody.message?.text ?? "",
|
||||||
blocks: updatedBlocks as (Block | KnownBlock)[],
|
blocks: updatedBlocks as (Block | KnownBlock)[],
|
||||||
});
|
});
|
||||||
} catch {
|
} catch {
|
||||||
|
|||||||
Reference in New Issue
Block a user