|
2 | 2 | import type { Block, KnownBlock } from "@slack/web-api"; |
3 | 3 | import { parseExecApprovalCommandText } from "openclaw/plugin-sdk/approval-reply-runtime"; |
4 | 4 | import { |
5 | | - reduceLegacyInteractiveReply, |
| 5 | + legacyInteractiveReplyToPresentation, |
6 | 6 | resolveMessagePresentationButtonAction, |
7 | 7 | resolveMessagePresentationOptionAction, |
8 | 8 | } from "openclaw/plugin-sdk/interactive-runtime"; |
@@ -248,119 +248,10 @@ export function buildSlackInteractiveBlocks( |
248 | 248 | interactive?: LegacyInteractiveReply, |
249 | 249 | options: SlackBlockRenderOptions = {}, |
250 | 250 | ): SlackBlock[] { |
251 | | - const initialState = { |
252 | | - blocks: [] as SlackBlock[], |
253 | | - buttonIndex: options.buttonIndexOffset ?? 0, |
254 | | - selectIndex: options.selectIndexOffset ?? 0, |
255 | | - }; |
256 | | - return reduceLegacyInteractiveReply(interactive, initialState, (state, block) => { |
257 | | - if (block.type === "text") { |
258 | | - const trimmed = block.text.trim(); |
259 | | - if (!trimmed) { |
260 | | - return state; |
261 | | - } |
262 | | - state.blocks.push({ |
263 | | - type: "section", |
264 | | - text: { |
265 | | - type: "mrkdwn", |
266 | | - text: truncateSlackText(trimmed, SLACK_SECTION_TEXT_MAX), |
267 | | - }, |
268 | | - }); |
269 | | - return state; |
270 | | - } |
271 | | - if (block.type === "buttons") { |
272 | | - // Index is position in the question's options; core emits one buttons block in option order. |
273 | | - const elements = block.buttons |
274 | | - .flatMap((button, choiceIndex) => { |
275 | | - const target = resolveSlackButtonTarget(button, choiceIndex); |
276 | | - if ( |
277 | | - !target || |
278 | | - (target.kind === "link" |
279 | | - ? !isWithinSlackLimit(target.url, SLACK_BUTTON_URL_MAX) |
280 | | - : !isWithinSlackLimit(target.value, SLACK_BUTTON_VALUE_MAX)) |
281 | | - ) { |
282 | | - return []; |
283 | | - } |
284 | | - const style = resolveSlackButtonStyle(button.style); |
285 | | - return [ |
286 | | - { |
287 | | - type: "button" as const, |
288 | | - // Slack emits block_actions even for URL buttons; link-only actions must be ignored. |
289 | | - action_id: |
290 | | - target.kind === "link" |
291 | | - ? buildSlackReplyLinkActionId(state.buttonIndex + 1, choiceIndex) |
292 | | - : target.kind === "approval" |
293 | | - ? buildSlackApprovalButtonActionId(state.buttonIndex + 1, choiceIndex) |
294 | | - : target.kind === "callback" |
295 | | - ? buildSlackCallbackButtonActionId(state.buttonIndex + 1, choiceIndex) |
296 | | - : target.kind === "question" |
297 | | - ? buildSlackQuestionButtonActionId(state.buttonIndex + 1, choiceIndex) |
298 | | - : buildSlackReplyButtonActionId(state.buttonIndex + 1, choiceIndex), |
299 | | - text: { |
300 | | - type: "plain_text" as const, |
301 | | - text: truncateSlackText(button.label, SLACK_ACTION_LABEL_MAX), |
302 | | - emoji: true, |
303 | | - }, |
304 | | - ...(target.kind === "link" ? { url: target.url } : { value: target.value }), |
305 | | - ...(style ? { style } : {}), |
306 | | - }, |
307 | | - ]; |
308 | | - }) |
309 | | - .slice(0, SLACK_ACTION_BLOCK_ELEMENTS_MAX); |
310 | | - if (elements.length === 0) { |
311 | | - return state; |
312 | | - } |
313 | | - state.blocks.push({ |
314 | | - type: "actions", |
315 | | - block_id: `openclaw_reply_buttons_${++state.buttonIndex}`, |
316 | | - elements, |
317 | | - }); |
318 | | - return state; |
319 | | - } |
320 | | - const optionsLocal = block.options |
321 | | - .flatMap((option) => { |
322 | | - const target = resolveSlackOptionTarget(option); |
323 | | - return target ? [{ label: option.label, ...target }] : []; |
324 | | - }) |
325 | | - .filter(isRenderableSlackOption) |
326 | | - .slice(0, SLACK_STATIC_SELECT_OPTIONS_MAX); |
327 | | - const optionKinds = new Set(optionsLocal.map((option) => option.kind)); |
328 | | - if (optionsLocal.length === 0 || optionKinds.size !== 1) { |
329 | | - return state; |
330 | | - } |
331 | | - state.blocks.push({ |
332 | | - type: "actions", |
333 | | - block_id: `openclaw_reply_select_${++state.selectIndex}`, |
334 | | - elements: [ |
335 | | - { |
336 | | - type: "static_select", |
337 | | - action_id: |
338 | | - optionsLocal[0]?.kind === "approval" |
339 | | - ? buildSlackApprovalSelectActionId(state.selectIndex) |
340 | | - : optionsLocal[0]?.kind === "callback" |
341 | | - ? buildSlackCallbackSelectActionId(state.selectIndex) |
342 | | - : buildSlackReplySelectActionId(state.selectIndex), |
343 | | - placeholder: { |
344 | | - type: "plain_text", |
345 | | - text: truncateSlackText( |
346 | | - normalizeOptionalString(block.placeholder) ?? "Choose an option", |
347 | | - SLACK_ACTION_LABEL_MAX, |
348 | | - ), |
349 | | - emoji: true, |
350 | | - }, |
351 | | - options: optionsLocal.map((option, _choiceIndex) => ({ |
352 | | - text: { |
353 | | - type: "plain_text", |
354 | | - text: truncateSlackText(option.label, SLACK_ACTION_LABEL_MAX), |
355 | | - emoji: true, |
356 | | - }, |
357 | | - value: option.value, |
358 | | - })), |
359 | | - }, |
360 | | - ], |
361 | | - }); |
362 | | - return state; |
363 | | - }).blocks; |
| 251 | + return buildSlackPresentationBlocks( |
| 252 | + interactive ? legacyInteractiveReplyToPresentation(interactive) : undefined, |
| 253 | + options, |
| 254 | + ); |
364 | 255 | } |
365 | 256 |
|
366 | 257 | /** Render portable presentation blocks as Slack Block Kit blocks. */ |
|
0 commit comments