mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 06:20:48 +00:00
69 lines
1.8 KiB
TypeScript
69 lines
1.8 KiB
TypeScript
import type { MessagePresentation } from "openclaw/plugin-sdk/interactive-runtime";
|
|
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
|
|
|
export function buildMSTeamsPresentationCard(params: {
|
|
presentation: MessagePresentation;
|
|
text?: string | null;
|
|
}) {
|
|
const body: Record<string, unknown>[] = [];
|
|
const text = normalizeOptionalString(params.text);
|
|
if (text) {
|
|
body.push({
|
|
type: "TextBlock",
|
|
text,
|
|
wrap: true,
|
|
});
|
|
}
|
|
const { presentation } = params;
|
|
if (presentation.title) {
|
|
body.push({
|
|
type: "TextBlock",
|
|
text: presentation.title,
|
|
weight: "Bolder",
|
|
size: "Medium",
|
|
wrap: true,
|
|
});
|
|
}
|
|
const actions: Record<string, unknown>[] = [];
|
|
for (const block of presentation.blocks) {
|
|
if (block.type === "text" || block.type === "context") {
|
|
body.push({
|
|
type: "TextBlock",
|
|
text: block.text,
|
|
wrap: true,
|
|
...(block.type === "context" ? { isSubtle: true, size: "Small" } : {}),
|
|
});
|
|
continue;
|
|
}
|
|
if (block.type === "divider") {
|
|
body.push({ type: "TextBlock", text: "---", wrap: true, isSubtle: true });
|
|
continue;
|
|
}
|
|
if (block.type === "buttons") {
|
|
for (const button of block.buttons) {
|
|
if (button.url) {
|
|
actions.push({
|
|
type: "Action.OpenUrl",
|
|
title: button.label,
|
|
url: button.url,
|
|
});
|
|
continue;
|
|
}
|
|
if (button.value) {
|
|
actions.push({
|
|
type: "Action.Submit",
|
|
title: button.label,
|
|
data: { value: button.value, label: button.label },
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return {
|
|
type: "AdaptiveCard",
|
|
version: "1.4",
|
|
body,
|
|
...(actions.length ? { actions } : {}),
|
|
};
|
|
}
|