






















@@ -27,6 +27,24 @@ function createCtx(params?: Partial<WebhookContext>): WebhookContext {
2727};
2828}
292930+function requireFetchRequest() {
31+const request = apiMocks.fetchWithSsrFGuard.mock.calls[0]?.[0] as
32+| {
33+url?: string;
34+auditContext?: string;
35+policy?: unknown;
36+init?: {
37+method?: string;
38+body?: unknown;
39+};
40+}
41+| undefined;
42+if (!request) {
43+throw new Error("expected Telnyx provider to call fetchWithSsrFGuard");
44+}
45+return request;
46+}
47+3048function decodeBase64Url(input: string): Buffer {
3149const normalized = input.replace(/-/g, "+").replace(/_/g, "/");
3250const padLen = (4 - (normalized.length % 4)) % 4;
@@ -222,14 +240,11 @@ describe("TelnyxProvider.parseWebhookEvent", () => {
222240);
223241224242expect(result.events).toHaveLength(1);
225-expect(result.events[0]).toEqual(
226-expect.objectContaining({
227-type: "call.initiated",
228-direction: "inbound",
229-from: "+15551111111",
230-to: "+15550000000",
231-}),
232-);
243+const event = result.events[0];
244+expect(event?.type).toBe("call.initiated");
245+expect(event?.direction).toBe("inbound");
246+expect(event?.from).toBe("+15551111111");
247+expect(event?.to).toBe("+15550000000");
233248});
234249235250it("reads transcription text from Telnyx transcription_data payloads", () => {
@@ -258,14 +273,14 @@ describe("TelnyxProvider.parseWebhookEvent", () => {
258273);
259274260275expect(result.events).toHaveLength(1);
261-expect(result.events[0]).toEqual(
262- expect.objectContaining({
263- type: "call.speech",
264- transcript: "hello this is a test speech",
265- isFinal: false,
266- confidence: 0.977219,
267- }),
268-);
276+const event = result.events[0];
277+expect(event?.type).toBe("call.speech");
278+if (event?.type !== "call.speech") {
279+throw new Error("expected Telnyx transcription callback to produce a speech event");
280+}
281+expect(event?.transcript).toBe("hello this is a test speech");
282+expect(event?.isFinal).toBe(false);
283+expect(event?.confidence).toBe(0.977219);
269284});
270285});
271286@@ -287,17 +302,13 @@ describe("TelnyxProvider answer control", () => {
287302providerCallId: "call-control-1",
288303});
289304290-expect(apiMocks.fetchWithSsrFGuard).toHaveBeenCalledWith(
291-expect.objectContaining({
292-url: "https://api.telnyx.com/v2/calls/call-control-1/actions/answer",
293-auditContext: "voice-call.telnyx.api",
294-policy: { allowedHostnames: ["api.telnyx.com"] },
295-init: expect.objectContaining({
296-method: "POST",
297-body: JSON.stringify({ command_id: "openclaw-answer-call-1" }),
298-}),
299-}),
300-);
305+expect(apiMocks.fetchWithSsrFGuard).toHaveBeenCalledTimes(1);
306+const request = requireFetchRequest();
307+expect(request.url).toBe("https://api.telnyx.com/v2/calls/call-control-1/actions/answer");
308+expect(request.auditContext).toBe("voice-call.telnyx.api");
309+expect(request.policy).toEqual({ allowedHostnames: ["api.telnyx.com"] });
310+expect(request.init?.method).toBe("POST");
311+expect(request.init?.body).toBe(JSON.stringify({ command_id: "openclaw-answer-call-1" }));
301312expect(release).toHaveBeenCalledTimes(1);
302313});
303314});
@@ -322,19 +333,15 @@ describe("TelnyxProvider speak control", () => {
322333voice: "Telnyx.Qwen3TTS.12345678-1234-1234-1234-123456789abc",
323334});
324335325-expect(apiMocks.fetchWithSsrFGuard).toHaveBeenCalledWith(
326-expect.objectContaining({
327-url: "https://api.telnyx.com/v2/calls/call-control-1/actions/speak",
328-auditContext: "voice-call.telnyx.api",
329-policy: { allowedHostnames: ["api.telnyx.com"] },
330-init: expect.objectContaining({
331-method: "POST",
332-body: expect.stringContaining(
333-'"voice":"Telnyx.Qwen3TTS.12345678-1234-1234-1234-123456789abc"',
334-),
335-}),
336-}),
337-);
336+expect(apiMocks.fetchWithSsrFGuard).toHaveBeenCalledTimes(1);
337+const request = requireFetchRequest();
338+expect(request.url).toBe("https://api.telnyx.com/v2/calls/call-control-1/actions/speak");
339+expect(request.auditContext).toBe("voice-call.telnyx.api");
340+expect(request.policy).toEqual({ allowedHostnames: ["api.telnyx.com"] });
341+expect(request.init?.method).toBe("POST");
342+expect(typeof request.init?.body).toBe("string");
343+const body = JSON.parse(request.init?.body as string) as { voice?: string };
344+expect(body.voice).toBe("Telnyx.Qwen3TTS.12345678-1234-1234-1234-123456789abc");
338345expect(release).toHaveBeenCalledTimes(1);
339346});
340347});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。