mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 22:40:58 +00:00
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)
96 lines
2.5 KiB
TypeScript
96 lines
2.5 KiB
TypeScript
import type { Block, KnownBlock } from "@slack/web-api";
|
|
|
|
type PlainTextObject = { text?: string };
|
|
|
|
type SlackBlockWithFields = {
|
|
type?: string;
|
|
text?: PlainTextObject & { type?: string };
|
|
title?: PlainTextObject;
|
|
alt_text?: string;
|
|
elements?: Array<{ text?: string; type?: string }>;
|
|
};
|
|
|
|
function cleanCandidate(value: string | undefined): string | undefined {
|
|
if (typeof value !== "string") {
|
|
return undefined;
|
|
}
|
|
const normalized = value.replace(/\s+/g, " ").trim();
|
|
return normalized.length > 0 ? normalized : undefined;
|
|
}
|
|
|
|
function readSectionText(block: SlackBlockWithFields): string | undefined {
|
|
return cleanCandidate(block.text?.text);
|
|
}
|
|
|
|
function readHeaderText(block: SlackBlockWithFields): string | undefined {
|
|
return cleanCandidate(block.text?.text);
|
|
}
|
|
|
|
function readImageText(block: SlackBlockWithFields): string | undefined {
|
|
return cleanCandidate(block.alt_text) ?? cleanCandidate(block.title?.text);
|
|
}
|
|
|
|
function readVideoText(block: SlackBlockWithFields): string | undefined {
|
|
return cleanCandidate(block.title?.text) ?? cleanCandidate(block.alt_text);
|
|
}
|
|
|
|
function readContextText(block: SlackBlockWithFields): string | undefined {
|
|
if (!Array.isArray(block.elements)) {
|
|
return undefined;
|
|
}
|
|
const textParts = block.elements
|
|
.map((element) => cleanCandidate(element.text))
|
|
.filter((value): value is string => Boolean(value));
|
|
return textParts.length > 0 ? textParts.join(" ") : undefined;
|
|
}
|
|
|
|
export function buildSlackBlocksFallbackText(blocks: (Block | KnownBlock)[]): string {
|
|
for (const raw of blocks) {
|
|
const block = raw as SlackBlockWithFields;
|
|
switch (block.type) {
|
|
case "header": {
|
|
const text = readHeaderText(block);
|
|
if (text) {
|
|
return text;
|
|
}
|
|
break;
|
|
}
|
|
case "section": {
|
|
const text = readSectionText(block);
|
|
if (text) {
|
|
return text;
|
|
}
|
|
break;
|
|
}
|
|
case "image": {
|
|
const text = readImageText(block);
|
|
if (text) {
|
|
return text;
|
|
}
|
|
return "Shared an image";
|
|
}
|
|
case "video": {
|
|
const text = readVideoText(block);
|
|
if (text) {
|
|
return text;
|
|
}
|
|
return "Shared a video";
|
|
}
|
|
case "file": {
|
|
return "Shared a file";
|
|
}
|
|
case "context": {
|
|
const text = readContextText(block);
|
|
if (text) {
|
|
return text;
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
return "Shared a Block Kit message";
|
|
}
|