mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:34:31 +00:00
feat(telegram): support inline button styles (#18241)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 239cb3552e
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { AgentToolResult } from "@mariozechner/pi-agent-core";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import type { TelegramButtonStyle, TelegramInlineButtons } from "../../telegram/button-types.js";
|
||||
import {
|
||||
resolveTelegramInlineButtonsScope,
|
||||
resolveTelegramTargetChatType,
|
||||
@@ -23,14 +24,11 @@ import {
|
||||
readStringParam,
|
||||
} from "./common.js";
|
||||
|
||||
type TelegramButton = {
|
||||
text: string;
|
||||
callback_data: string;
|
||||
};
|
||||
const TELEGRAM_BUTTON_STYLES: readonly TelegramButtonStyle[] = ["danger", "success", "primary"];
|
||||
|
||||
export function readTelegramButtons(
|
||||
params: Record<string, unknown>,
|
||||
): TelegramButton[][] | undefined {
|
||||
): TelegramInlineButtons | undefined {
|
||||
const raw = params.buttons;
|
||||
if (raw == null) {
|
||||
return undefined;
|
||||
@@ -62,7 +60,21 @@ export function readTelegramButtons(
|
||||
`buttons[${rowIndex}][${buttonIndex}] callback_data too long (max 64 chars)`,
|
||||
);
|
||||
}
|
||||
return { text, callback_data: callbackData };
|
||||
const styleRaw = (button as { style?: unknown }).style;
|
||||
const style = typeof styleRaw === "string" ? styleRaw.trim().toLowerCase() : undefined;
|
||||
if (styleRaw !== undefined && !style) {
|
||||
throw new Error(`buttons[${rowIndex}][${buttonIndex}] style must be string`);
|
||||
}
|
||||
if (style && !TELEGRAM_BUTTON_STYLES.includes(style as TelegramButtonStyle)) {
|
||||
throw new Error(
|
||||
`buttons[${rowIndex}][${buttonIndex}] style must be one of ${TELEGRAM_BUTTON_STYLES.join(", ")}`,
|
||||
);
|
||||
}
|
||||
return {
|
||||
text,
|
||||
callback_data: callbackData,
|
||||
...(style ? { style: style as TelegramButtonStyle } : {}),
|
||||
};
|
||||
});
|
||||
});
|
||||
const filtered = rows.filter((row) => row.length > 0);
|
||||
|
||||
Reference in New Issue
Block a user