mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:58:25 +00:00
Telegram/Discord: honor outbound mediaMaxMb uploads (#38065)
* Telegram: default media cap to 100MB * Telegram: honor outbound mediaMaxMb * Discord: add shared media upload cap * Discord: pass mediaMaxMb to outbound sends * Telegram: cover outbound media cap sends * Discord: cover media upload cap config * Docs: update Telegram media cap guide * Docs: update Telegram config reference * Changelog: note media upload cap fix * Docs: note Discord upload cap behavior
This commit is contained in:
@@ -145,6 +145,10 @@ export async function sendMessageDiscord(
|
||||
accountId: accountInfo.accountId,
|
||||
});
|
||||
const chunkMode = resolveChunkMode(cfg, "discord", accountInfo.accountId);
|
||||
const mediaMaxBytes =
|
||||
typeof accountInfo.config.mediaMaxMb === "number"
|
||||
? accountInfo.config.mediaMaxMb * 1024 * 1024
|
||||
: 8 * 1024 * 1024;
|
||||
const textWithTables = convertMarkdownTables(text ?? "", tableMode);
|
||||
const textWithMentions = rewriteDiscordKnownMentions(textWithTables, {
|
||||
accountId: accountInfo.accountId,
|
||||
@@ -211,6 +215,7 @@ export async function sendMessageDiscord(
|
||||
mediaCaption ?? "",
|
||||
opts.mediaUrl,
|
||||
opts.mediaLocalRoots,
|
||||
mediaMaxBytes,
|
||||
undefined,
|
||||
request,
|
||||
accountInfo.config.maxLinesPerMessage,
|
||||
@@ -271,6 +276,7 @@ export async function sendMessageDiscord(
|
||||
textWithMentions,
|
||||
opts.mediaUrl,
|
||||
opts.mediaLocalRoots,
|
||||
mediaMaxBytes,
|
||||
opts.replyTo,
|
||||
request,
|
||||
accountInfo.config.maxLinesPerMessage,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ChannelType, PermissionFlagsBits, Routes } from "discord-api-types/v10";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { loadWebMedia } from "../web/media.js";
|
||||
import {
|
||||
__resetDiscordDirectoryCacheForTest,
|
||||
rememberDiscordDirectoryUser,
|
||||
@@ -265,6 +266,33 @@ describe("sendMessageDiscord", () => {
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(loadWebMedia).toHaveBeenCalledWith(
|
||||
"file:///tmp/photo.jpg",
|
||||
expect.objectContaining({ maxBytes: 8 * 1024 * 1024 }),
|
||||
);
|
||||
});
|
||||
|
||||
it("uses configured discord mediaMaxMb for uploads", async () => {
|
||||
const { rest, postMock } = makeDiscordRest();
|
||||
postMock.mockResolvedValue({ id: "msg", channel_id: "789" });
|
||||
|
||||
await sendMessageDiscord("channel:789", "photo", {
|
||||
rest,
|
||||
token: "t",
|
||||
mediaUrl: "file:///tmp/photo.jpg",
|
||||
cfg: {
|
||||
channels: {
|
||||
discord: {
|
||||
mediaMaxMb: 32,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(loadWebMedia).toHaveBeenCalledWith(
|
||||
"file:///tmp/photo.jpg",
|
||||
expect.objectContaining({ maxBytes: 32 * 1024 * 1024 }),
|
||||
);
|
||||
});
|
||||
|
||||
it("sends media with empty text without content field", async () => {
|
||||
|
||||
@@ -415,6 +415,7 @@ async function sendDiscordMedia(
|
||||
text: string,
|
||||
mediaUrl: string,
|
||||
mediaLocalRoots: readonly string[] | undefined,
|
||||
maxBytes: number | undefined,
|
||||
replyTo: string | undefined,
|
||||
request: DiscordRequest,
|
||||
maxLinesPerMessage?: number,
|
||||
@@ -423,7 +424,10 @@ async function sendDiscordMedia(
|
||||
chunkMode?: ChunkMode,
|
||||
silent?: boolean,
|
||||
) {
|
||||
const media = await loadWebMedia(mediaUrl, buildOutboundMediaLoadOptions({ mediaLocalRoots }));
|
||||
const media = await loadWebMedia(
|
||||
mediaUrl,
|
||||
buildOutboundMediaLoadOptions({ maxBytes, mediaLocalRoots }),
|
||||
);
|
||||
const chunks = text ? buildDiscordTextChunks(text, { maxLinesPerMessage, chunkMode }) : [];
|
||||
const caption = chunks[0] ?? "";
|
||||
const messageReference = replyTo ? { message_id: replyTo, fail_if_not_exists: false } : undefined;
|
||||
|
||||
Reference in New Issue
Block a user