fix: allow media-only sends
This commit is contained in:
@@ -221,6 +221,43 @@ describe("handleTelegramAction", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("allows media-only messages without content", async () => {
|
||||
const cfg = {
|
||||
channels: { telegram: { botToken: "tok" } },
|
||||
} as ClawdbotConfig;
|
||||
await handleTelegramAction(
|
||||
{
|
||||
action: "sendMessage",
|
||||
to: "123456",
|
||||
mediaUrl: "https://example.com/note.ogg",
|
||||
},
|
||||
cfg,
|
||||
);
|
||||
expect(sendMessageTelegram).toHaveBeenCalledWith(
|
||||
"123456",
|
||||
"",
|
||||
expect.objectContaining({
|
||||
token: "tok",
|
||||
mediaUrl: "https://example.com/note.ogg",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("requires content when no mediaUrl is provided", async () => {
|
||||
const cfg = {
|
||||
channels: { telegram: { botToken: "tok" } },
|
||||
} as ClawdbotConfig;
|
||||
await expect(
|
||||
handleTelegramAction(
|
||||
{
|
||||
action: "sendMessage",
|
||||
to: "123456",
|
||||
},
|
||||
cfg,
|
||||
),
|
||||
).rejects.toThrow(/content required/i);
|
||||
});
|
||||
|
||||
it("respects sendMessage gating", async () => {
|
||||
const cfg = {
|
||||
channels: {
|
||||
|
||||
@@ -130,8 +130,13 @@ export async function handleTelegramAction(
|
||||
throw new Error("Telegram sendMessage is disabled.");
|
||||
}
|
||||
const to = readStringParam(params, "to", { required: true });
|
||||
const content = readStringParam(params, "content", { required: true });
|
||||
const mediaUrl = readStringParam(params, "mediaUrl");
|
||||
// Allow content to be omitted when sending media-only (e.g., voice notes)
|
||||
const content =
|
||||
readStringParam(params, "content", {
|
||||
required: !mediaUrl,
|
||||
allowEmpty: true,
|
||||
}) ?? "";
|
||||
const buttons = readTelegramButtons(params);
|
||||
if (buttons && !hasInlineButtonsCapability({ cfg, accountId: accountId ?? undefined })) {
|
||||
throw new Error(
|
||||
|
||||
Reference in New Issue
Block a user