Skip to content

Commit cd9b2c0

Browse files
committed
fix: restore voice media uploads
1 parent 0e5f4ea commit cd9b2c0

5 files changed

Lines changed: 56 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Docs: https://docs.openclaw.ai
5959
- Gateway/protocol: lazy-compile protocol validators on first use instead of compiling every AJV schema during cold import, reducing startup CPU and RSS. (#82064) Thanks @samzong.
6060
- Discord: report unresolved configured bot-token SecretRefs during startup instead of treating the account as unconfigured. (#82009) Thanks @giodl73-repo.
6161
- Discord: pass an explicit Ogg muxer to ffmpeg when transcoding voice-message audio through staged temp files, restoring TTS voice-message delivery. Fixes #82074. Thanks @hwlbb.
62+
- Discord/Feishu: allow Discord voice uploads through RFC2544 fake-IP proxy DNS and pass Feishu's voice ffmpeg transcode through an explicit Ogg muxer. (#82088) Thanks @hwlbb and @6peng888.
6263
- CLI/config: preserve numeric-looking object keys such as Discord guild IDs during `config patch` recursive merges. (#81999) Thanks @giodl73-repo.
6364
- Gateway/OpenAI-compatible HTTP: forward `response_format` from `/v1/chat/completions` requests through agent stream params to upstream Chat Completions and Responses transports, restoring structured-output support. Fixes #82003. (#82004) Thanks @Lellansin.
6465
- Control UI/WebChat: let sidebar markdown code-block Copy buttons use the same delegated clipboard handler as chat messages. (#58709) Thanks @tikitoki.

‎extensions/discord/src/voice-message.test.ts‎

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ import type { VoiceMessageMetadata } from "./voice-message.js";
66

77
const runFfprobeMock = vi.hoisted(() => vi.fn<(...args: unknown[]) => Promise<string>>());
88
const runFfmpegMock = vi.hoisted(() => vi.fn<(...args: unknown[]) => Promise<void>>());
9+
const fetchWithSsrFGuardMock = vi.hoisted(() =>
10+
vi.fn(
11+
async (params: {
12+
url: string;
13+
init?: RequestInit;
14+
policy?: { allowRfc2544BenchmarkRange?: boolean; allowIpv6UniqueLocalRange?: boolean };
15+
auditContext?: string;
16+
}) => ({
17+
response: await globalThis.fetch(params.url, params.init),
18+
release: async () => {},
19+
}),
20+
),
21+
);
922

1023
vi.mock("openclaw/plugin-sdk/temp-path", async () => {
1124
return {
@@ -31,10 +44,7 @@ vi.mock("openclaw/plugin-sdk/media-runtime", async () => {
3144

3245
vi.mock("openclaw/plugin-sdk/ssrf-runtime", async () => {
3346
return {
34-
fetchWithSsrFGuard: async (params: { url: string; init?: RequestInit }) => ({
35-
response: await globalThis.fetch(params.url, params.init),
36-
release: async () => {},
37-
}),
47+
fetchWithSsrFGuard: fetchWithSsrFGuardMock,
3848
};
3949
});
4050

@@ -196,6 +206,7 @@ describe("sendDiscordVoiceMessage", () => {
196206

197207
beforeEach(() => {
198208
vi.restoreAllMocks();
209+
fetchWithSsrFGuardMock.mockClear();
199210
});
200211

201212
function createRest(post = vi.fn(async () => ({ id: "msg-1", channel_id: "channel-1" }))) {
@@ -269,6 +280,35 @@ describe("sendDiscordVoiceMessage", () => {
269280

270281
expect(uploadUrlRequests).toBe(2);
271282
expect(fetchMock).toHaveBeenCalledTimes(4);
283+
expect(fetchWithSsrFGuardMock).toHaveBeenCalledTimes(4);
284+
expect(
285+
fetchWithSsrFGuardMock.mock.calls.map(([params]) => ({
286+
auditContext: params.auditContext,
287+
allowRfc2544BenchmarkRange: params.policy?.allowRfc2544BenchmarkRange,
288+
allowIpv6UniqueLocalRange: params.policy?.allowIpv6UniqueLocalRange,
289+
})),
290+
).toEqual([
291+
{
292+
auditContext: "discord.voice.upload-url",
293+
allowRfc2544BenchmarkRange: true,
294+
allowIpv6UniqueLocalRange: true,
295+
},
296+
{
297+
auditContext: "discord.voice.attachment-upload",
298+
allowRfc2544BenchmarkRange: true,
299+
allowIpv6UniqueLocalRange: true,
300+
},
301+
{
302+
auditContext: "discord.voice.upload-url",
303+
allowRfc2544BenchmarkRange: true,
304+
allowIpv6UniqueLocalRange: true,
305+
},
306+
{
307+
auditContext: "discord.voice.attachment-upload",
308+
allowRfc2544BenchmarkRange: true,
309+
allowIpv6UniqueLocalRange: true,
310+
},
311+
]);
272312
expect(post).toHaveBeenCalledWith("/channels/channel-1/messages", {
273313
body: {
274314
flags: 8192,

‎extensions/discord/src/voice-message.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { MEDIA_FFMPEG_MAX_AUDIO_DURATION_SECS } from "openclaw/plugin-sdk/media-
2323
import { unlinkIfExists } from "openclaw/plugin-sdk/media-runtime";
2424
import type { RetryRunner } from "openclaw/plugin-sdk/retry-runtime";
2525
import { writeExternalFileWithinRoot } from "openclaw/plugin-sdk/security-runtime";
26-
import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
26+
import { fetchWithSsrFGuard, type SsrFPolicy } from "openclaw/plugin-sdk/ssrf-runtime";
2727
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
2828
import { resolvePreferredOpenClawTmpDir } from "openclaw/plugin-sdk/temp-path";
2929
import { DiscordError, RateLimitError, type RequestClient } from "./internal/discord.js";
@@ -33,6 +33,10 @@ const DISCORD_VOICE_MESSAGE_FLAG = 1 << 13;
3333
const SUPPRESS_NOTIFICATIONS_FLAG = 1 << 12;
3434
const WAVEFORM_SAMPLES = 256;
3535
const DISCORD_OPUS_SAMPLE_RATE_HZ = 48_000;
36+
const DISCORD_VOICE_UPLOAD_SSRF_POLICY: SsrFPolicy = {
37+
allowRfc2544BenchmarkRange: true,
38+
allowIpv6UniqueLocalRange: true,
39+
};
3640

3741
async function runFfmpegToOutput(params: {
3842
outputPath: string;
@@ -335,6 +339,7 @@ async function requestVoiceUploadUrl(params: {
335339
const { response: res, release } = await fetchWithSsrFGuard({
336340
url,
337341
init: uploadUrlInit,
342+
policy: DISCORD_VOICE_UPLOAD_SSRF_POLICY,
338343
auditContext: "discord.voice.upload-url",
339344
});
340345
try {
@@ -360,6 +365,7 @@ async function uploadVoiceAttachment(params: {
360365
},
361366
body: new Uint8Array(params.audioBuffer),
362367
},
368+
policy: DISCORD_VOICE_UPLOAD_SSRF_POLICY,
363369
auditContext: "discord.voice.attachment-upload",
364370
});
365371

‎extensions/feishu/src/media.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,10 @@ describe("sendMediaFeishu msg_type routing", () => {
301301
});
302302

303303
const ffmpegArgs = mockCallArg<string[]>(runFfmpegMock, 0, 0);
304-
for (const arg of ["-c:a", "libopus", "-ar", "48000", "-b:a", "64k"]) {
304+
for (const arg of ["-c:a", "libopus", "-ar", "48000", "-b:a", "64k", "-f", "ogg"]) {
305305
expect(ffmpegArgs).toContain(arg);
306306
}
307+
expect(ffmpegArgs.slice(-3, -1)).toEqual(["-f", "ogg"]);
307308
const fileData = callData<{ file?: Buffer; file_name?: string; file_type?: string }>(
308309
fileCreateMock,
309310
);

‎extensions/feishu/src/media.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,8 @@ async function transcodeToFeishuVoiceOpus(params: {
959959
"libopus",
960960
"-b:a",
961961
FEISHU_VOICE_BITRATE,
962+
"-f",
963+
"ogg",
962964
outputPath,
963965
]);
964966
},

0 commit comments

Comments
 (0)