Files
openclaw/extensions/slack/src/blocks-input.ts
scoootscooob 8746362f5e refactor(slack): move Slack channel code to extensions/slack/src/ (#45621)
Move all Slack channel implementation files from src/slack/ to
extensions/slack/src/ and replace originals with shim re-exports.
This follows the extension migration pattern for channel plugins.

- Copy all .ts files to extensions/slack/src/ (preserving directory
  structure: monitor/, http/, monitor/events/, monitor/message-handler/)
- Transform import paths: external src/ imports use relative paths
  back to src/, internal slack imports stay relative within extension
- Replace all src/slack/ files with shim re-exports pointing to
  the extension copies
- Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." so
  the DTS build can follow shim chains into extensions/
- Update write-plugin-sdk-entry-dts.ts re-export path accordingly
- Preserve extensions/slack/index.ts, package.json, openclaw.plugin.json,
  src/channel.ts, src/runtime.ts, src/channel.test.ts (untouched)
2026-03-14 02:47:04 -07:00

46 lines
1.3 KiB
TypeScript

import type { Block, KnownBlock } from "@slack/web-api";
const SLACK_MAX_BLOCKS = 50;
function parseBlocksJson(raw: string) {
try {
return JSON.parse(raw);
} catch {
throw new Error("blocks must be valid JSON");
}
}
function assertBlocksArray(raw: unknown) {
if (!Array.isArray(raw)) {
throw new Error("blocks must be an array");
}
if (raw.length === 0) {
throw new Error("blocks must contain at least one block");
}
if (raw.length > SLACK_MAX_BLOCKS) {
throw new Error(`blocks cannot exceed ${SLACK_MAX_BLOCKS} items`);
}
for (const block of raw) {
if (!block || typeof block !== "object" || Array.isArray(block)) {
throw new Error("each block must be an object");
}
const type = (block as { type?: unknown }).type;
if (typeof type !== "string" || type.trim().length === 0) {
throw new Error("each block must include a non-empty string type");
}
}
}
export function validateSlackBlocksArray(raw: unknown): (Block | KnownBlock)[] {
assertBlocksArray(raw);
return raw as (Block | KnownBlock)[];
}
export function parseSlackBlocksInput(raw: unknown): (Block | KnownBlock)[] | undefined {
if (raw == null) {
return undefined;
}
const parsed = typeof raw === "string" ? parseBlocksJson(raw) : raw;
return validateSlackBlocksArray(parsed);
}