mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 05:32:44 +00:00
fix(telegram): notify users on media download failures
Co-authored-by: Artale <117890364+arosstale@users.noreply.github.com>
This commit is contained in:
@@ -30,6 +30,7 @@ Docs: https://docs.openclaw.ai
|
|||||||
- Telegram/Polling: retry recoverable setup-time network failures in monitor startup and await runner teardown before retry to avoid overlapping polling sessions.
|
- Telegram/Polling: retry recoverable setup-time network failures in monitor startup and await runner teardown before retry to avoid overlapping polling sessions.
|
||||||
- Telegram/Polling: clear Telegram webhooks (`deleteWebhook`) before starting long-poll `getUpdates`, including retry handling for transient cleanup failures.
|
- Telegram/Polling: clear Telegram webhooks (`deleteWebhook`) before starting long-poll `getUpdates`, including retry handling for transient cleanup failures.
|
||||||
- Telegram/Webhook: add `channels.telegram.webhookPort` config support and pass it through plugin startup wiring to the monitor listener.
|
- Telegram/Webhook: add `channels.telegram.webhookPort` config support and pass it through plugin startup wiring to the monitor listener.
|
||||||
|
- Telegram/Media: send a user-facing Telegram reply when media download fails (non-size errors) instead of silently dropping the message.
|
||||||
- Signal/RPC: guard malformed Signal RPC JSON responses with a clear status-scoped error and add regression coverage for invalid JSON responses. (#22995) Thanks @adhitShet.
|
- Signal/RPC: guard malformed Signal RPC JSON responses with a clear status-scoped error and add regression coverage for invalid JSON responses. (#22995) Thanks @adhitShet.
|
||||||
- Gateway/Subagents: guard gateway and subagent session-key/message trim paths against undefined inputs to prevent early `Cannot read properties of undefined (reading 'trim')` crashes during subagent spawn and wait flows.
|
- Gateway/Subagents: guard gateway and subagent session-key/message trim paths against undefined inputs to prevent early `Cannot read properties of undefined (reading 'trim')` crashes during subagent spawn and wait flows.
|
||||||
- Agents/Workspace: guard `resolveUserPath` against undefined/null input to prevent `Cannot read properties of undefined (reading 'trim')` crashes when workspace paths are missing in embedded runner flows.
|
- Agents/Workspace: guard `resolveUserPath` against undefined/null input to prevent `Cannot read properties of undefined (reading 'trim')` crashes when workspace paths are missing in embedded runner flows.
|
||||||
|
|||||||
@@ -722,7 +722,16 @@ export const registerTelegramHandlers = ({
|
|||||||
logger.warn({ chatId, error: String(mediaErr) }, oversizeLogMessage);
|
logger.warn({ chatId, error: String(mediaErr) }, oversizeLogMessage);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw mediaErr;
|
logger.warn({ chatId, error: String(mediaErr) }, "media fetch failed");
|
||||||
|
await withTelegramApiErrorLogging({
|
||||||
|
operation: "sendMessage",
|
||||||
|
runtime,
|
||||||
|
fn: () =>
|
||||||
|
bot.api.sendMessage(chatId, "⚠️ Failed to download media. Please try again.", {
|
||||||
|
reply_to_message_id: msg.message_id,
|
||||||
|
}),
|
||||||
|
}).catch(() => {});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip sticker-only messages where the sticker was skipped (animated/video)
|
// Skip sticker-only messages where the sticker was skipped (animated/video)
|
||||||
|
|||||||
@@ -1883,6 +1883,46 @@ describe("createTelegramBot", () => {
|
|||||||
expect(replySpy).not.toHaveBeenCalled();
|
expect(replySpy).not.toHaveBeenCalled();
|
||||||
fetchSpy.mockRestore();
|
fetchSpy.mockRestore();
|
||||||
});
|
});
|
||||||
|
it("notifies users when media download fails for direct messages", async () => {
|
||||||
|
loadConfig.mockReturnValue({
|
||||||
|
channels: {
|
||||||
|
telegram: { dmPolicy: "open", allowFrom: ["*"] },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
sendMessageSpy.mockClear();
|
||||||
|
replySpy.mockClear();
|
||||||
|
const fetchSpy = vi
|
||||||
|
.spyOn(globalThis, "fetch")
|
||||||
|
.mockImplementation(async () =>
|
||||||
|
Promise.reject(new Error("MediaFetchError: Failed to fetch media")),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
createTelegramBot({ token: "tok" });
|
||||||
|
const handler = getOnHandler("message") as (ctx: Record<string, unknown>) => Promise<void>;
|
||||||
|
|
||||||
|
await handler({
|
||||||
|
message: {
|
||||||
|
chat: { id: 1234, type: "private" },
|
||||||
|
message_id: 411,
|
||||||
|
date: 1736380800,
|
||||||
|
photo: [{ file_id: "p1" }],
|
||||||
|
from: { id: 55, is_bot: false, first_name: "u" },
|
||||||
|
},
|
||||||
|
me: { username: "openclaw_bot" },
|
||||||
|
getFile: async () => ({ file_path: "photos/p1.jpg" }),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(sendMessageSpy).toHaveBeenCalledWith(
|
||||||
|
1234,
|
||||||
|
"⚠️ Failed to download media. Please try again.",
|
||||||
|
{ reply_to_message_id: 411 },
|
||||||
|
);
|
||||||
|
expect(replySpy).not.toHaveBeenCalled();
|
||||||
|
} finally {
|
||||||
|
fetchSpy.mockRestore();
|
||||||
|
}
|
||||||
|
});
|
||||||
it("processes remaining media group photos when one photo download fails", async () => {
|
it("processes remaining media group photos when one photo download fails", async () => {
|
||||||
onSpy.mockReset();
|
onSpy.mockReset();
|
||||||
replySpy.mockReset();
|
replySpy.mockReset();
|
||||||
|
|||||||
Reference in New Issue
Block a user