mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 19:54:32 +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:
@@ -508,6 +508,46 @@ describe("handleTelegramAction", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("forwards optional button style", async () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
telegram: { botToken: "tok", capabilities: { inlineButtons: "all" } },
|
||||
},
|
||||
} as OpenClawConfig;
|
||||
await handleTelegramAction(
|
||||
{
|
||||
action: "sendMessage",
|
||||
to: "@testchannel",
|
||||
content: "Choose",
|
||||
buttons: [
|
||||
[
|
||||
{
|
||||
text: "Option A",
|
||||
callback_data: "cmd:a",
|
||||
style: "primary",
|
||||
},
|
||||
],
|
||||
],
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
expect(sendMessageTelegram).toHaveBeenCalledWith(
|
||||
"@testchannel",
|
||||
"Choose",
|
||||
expect.objectContaining({
|
||||
buttons: [
|
||||
[
|
||||
{
|
||||
text: "Option A",
|
||||
callback_data: "cmd:a",
|
||||
style: "primary",
|
||||
},
|
||||
],
|
||||
],
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("readTelegramButtons", () => {
|
||||
@@ -517,4 +557,35 @@ describe("readTelegramButtons", () => {
|
||||
});
|
||||
expect(result).toEqual([[{ text: "Option A", callback_data: "cmd:a" }]]);
|
||||
});
|
||||
|
||||
it("normalizes optional style", () => {
|
||||
const result = readTelegramButtons({
|
||||
buttons: [
|
||||
[
|
||||
{
|
||||
text: "Option A",
|
||||
callback_data: "cmd:a",
|
||||
style: " PRIMARY ",
|
||||
},
|
||||
],
|
||||
],
|
||||
});
|
||||
expect(result).toEqual([
|
||||
[
|
||||
{
|
||||
text: "Option A",
|
||||
callback_data: "cmd:a",
|
||||
style: "primary",
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects unsupported button style", () => {
|
||||
expect(() =>
|
||||
readTelegramButtons({
|
||||
buttons: [[{ text: "Option A", callback_data: "cmd:a", style: "secondary" }]],
|
||||
}),
|
||||
).toThrow(/style must be one of danger, success, primary/i);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user