@openclaw/voice-call 2026.5.2 → 2026.5.3-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +2 -0
- package/dist/call-status-CXldV5o8.js +32 -0
- package/dist/cli-metadata.js +12 -0
- package/dist/config-7w04YpHh.js +548 -0
- package/dist/config-compat-B0me39_4.js +129 -0
- package/dist/guarded-json-api-Btx5EE4w.js +591 -0
- package/dist/http-headers-BrnxBasF.js +10 -0
- package/dist/index.js +1284 -0
- package/dist/mock-CeKvfVEd.js +135 -0
- package/dist/plivo-B-a7KFoT.js +393 -0
- package/dist/realtime-handler-B63CIDP2.js +325 -0
- package/dist/realtime-transcription.runtime-B2h70y2W.js +2 -0
- package/dist/realtime-voice.runtime-Bkh4nvLn.js +2 -0
- package/dist/response-generator-BrcmwDZU.js +182 -0
- package/dist/response-model-CyF5K80p.js +12 -0
- package/dist/runtime-api.js +6 -0
- package/dist/runtime-entry-88ytYAQa.js +3119 -0
- package/dist/runtime-entry.js +2 -0
- package/dist/setup-api.js +37 -0
- package/dist/telnyx-jjBE8boz.js +260 -0
- package/dist/twilio-1OqbcXLL.js +676 -0
- package/dist/voice-mapping-BYDGdWGx.js +40 -0
- package/package.json +14 -6
- package/api.ts +0 -16
- package/cli-metadata.ts +0 -10
- package/config-api.ts +0 -12
- package/index.test.ts +0 -943
- package/index.ts +0 -794
- package/runtime-api.ts +0 -20
- package/runtime-entry.ts +0 -1
- package/setup-api.ts +0 -47
- package/src/allowlist.test.ts +0 -18
- package/src/allowlist.ts +0 -19
- package/src/cli.ts +0 -845
- package/src/config-compat.test.ts +0 -120
- package/src/config-compat.ts +0 -227
- package/src/config.test.ts +0 -479
- package/src/config.ts +0 -808
- package/src/core-bridge.ts +0 -14
- package/src/deep-merge.test.ts +0 -40
- package/src/deep-merge.ts +0 -23
- package/src/gateway-continue-operation.ts +0 -200
- package/src/http-headers.test.ts +0 -16
- package/src/http-headers.ts +0 -15
- package/src/manager/context.ts +0 -42
- package/src/manager/events.test.ts +0 -581
- package/src/manager/events.ts +0 -288
- package/src/manager/lifecycle.ts +0 -53
- package/src/manager/lookup.test.ts +0 -52
- package/src/manager/lookup.ts +0 -35
- package/src/manager/outbound.test.ts +0 -528
- package/src/manager/outbound.ts +0 -486
- package/src/manager/state.ts +0 -48
- package/src/manager/store.ts +0 -106
- package/src/manager/timers.test.ts +0 -129
- package/src/manager/timers.ts +0 -113
- package/src/manager/twiml.test.ts +0 -13
- package/src/manager/twiml.ts +0 -17
- package/src/manager.closed-loop.test.ts +0 -236
- package/src/manager.inbound-allowlist.test.ts +0 -188
- package/src/manager.notify.test.ts +0 -377
- package/src/manager.restore.test.ts +0 -183
- package/src/manager.test-harness.ts +0 -127
- package/src/manager.ts +0 -392
- package/src/media-stream.test.ts +0 -768
- package/src/media-stream.ts +0 -708
- package/src/providers/base.ts +0 -97
- package/src/providers/mock.test.ts +0 -78
- package/src/providers/mock.ts +0 -185
- package/src/providers/plivo.test.ts +0 -93
- package/src/providers/plivo.ts +0 -601
- package/src/providers/shared/call-status.test.ts +0 -24
- package/src/providers/shared/call-status.ts +0 -24
- package/src/providers/shared/guarded-json-api.test.ts +0 -106
- package/src/providers/shared/guarded-json-api.ts +0 -42
- package/src/providers/telnyx.test.ts +0 -340
- package/src/providers/telnyx.ts +0 -394
- package/src/providers/twilio/api.test.ts +0 -145
- package/src/providers/twilio/api.ts +0 -93
- package/src/providers/twilio/twiml-policy.test.ts +0 -84
- package/src/providers/twilio/twiml-policy.ts +0 -87
- package/src/providers/twilio/webhook.ts +0 -34
- package/src/providers/twilio.test.ts +0 -591
- package/src/providers/twilio.ts +0 -861
- package/src/providers/twilio.types.ts +0 -17
- package/src/realtime-defaults.ts +0 -3
- package/src/realtime-fast-context.test.ts +0 -88
- package/src/realtime-fast-context.ts +0 -165
- package/src/realtime-transcription.runtime.ts +0 -4
- package/src/realtime-voice.runtime.ts +0 -5
- package/src/response-generator.test.ts +0 -321
- package/src/response-generator.ts +0 -318
- package/src/response-model.test.ts +0 -71
- package/src/response-model.ts +0 -23
- package/src/runtime.test.ts +0 -536
- package/src/runtime.ts +0 -510
- package/src/telephony-audio.test.ts +0 -61
- package/src/telephony-audio.ts +0 -12
- package/src/telephony-tts.test.ts +0 -196
- package/src/telephony-tts.ts +0 -235
- package/src/test-fixtures.ts +0 -73
- package/src/tts-provider-voice.test.ts +0 -34
- package/src/tts-provider-voice.ts +0 -21
- package/src/tunnel.test.ts +0 -166
- package/src/tunnel.ts +0 -314
- package/src/types.ts +0 -291
- package/src/utils.test.ts +0 -17
- package/src/utils.ts +0 -14
- package/src/voice-mapping.test.ts +0 -34
- package/src/voice-mapping.ts +0 -68
- package/src/webhook/realtime-handler.test.ts +0 -598
- package/src/webhook/realtime-handler.ts +0 -485
- package/src/webhook/stale-call-reaper.test.ts +0 -88
- package/src/webhook/stale-call-reaper.ts +0 -38
- package/src/webhook/tailscale.test.ts +0 -214
- package/src/webhook/tailscale.ts +0 -129
- package/src/webhook-exposure.test.ts +0 -33
- package/src/webhook-exposure.ts +0 -84
- package/src/webhook-security.test.ts +0 -770
- package/src/webhook-security.ts +0 -994
- package/src/webhook.hangup-once.lifecycle.test.ts +0 -135
- package/src/webhook.test.ts +0 -1470
- package/src/webhook.ts +0 -908
- package/src/webhook.types.ts +0 -5
- package/src/websocket-test-support.ts +0 -72
- package/tsconfig.json +0 -16
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
|
|
3
|
-
const { fetchWithSsrFGuardMock } = vi.hoisted(() => ({
|
|
4
|
-
fetchWithSsrFGuardMock: vi.fn(),
|
|
5
|
-
}));
|
|
6
|
-
|
|
7
|
-
vi.mock("../../../api.js", () => ({
|
|
8
|
-
fetchWithSsrFGuard: fetchWithSsrFGuardMock,
|
|
9
|
-
}));
|
|
10
|
-
|
|
11
|
-
import { guardedJsonApiRequest } from "./guarded-json-api.js";
|
|
12
|
-
|
|
13
|
-
describe("guardedJsonApiRequest", () => {
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
vi.clearAllMocks();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it("uses the SSRF-guarded fetch and parses json responses", async () => {
|
|
19
|
-
const release = vi.fn(async () => {});
|
|
20
|
-
fetchWithSsrFGuardMock.mockResolvedValue({
|
|
21
|
-
response: new Response(JSON.stringify({ ok: true }), { status: 200 }),
|
|
22
|
-
release,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
await expect(
|
|
26
|
-
guardedJsonApiRequest({
|
|
27
|
-
url: "https://api.example.com/v1/calls",
|
|
28
|
-
method: "POST",
|
|
29
|
-
headers: { Authorization: "Bearer token" },
|
|
30
|
-
body: { hello: "world" },
|
|
31
|
-
allowedHostnames: ["api.example.com"],
|
|
32
|
-
auditContext: "voice-call:test",
|
|
33
|
-
errorPrefix: "request failed",
|
|
34
|
-
}),
|
|
35
|
-
).resolves.toEqual({ ok: true });
|
|
36
|
-
|
|
37
|
-
expect(fetchWithSsrFGuardMock).toHaveBeenCalledWith({
|
|
38
|
-
url: "https://api.example.com/v1/calls",
|
|
39
|
-
init: {
|
|
40
|
-
method: "POST",
|
|
41
|
-
headers: { Authorization: "Bearer token" },
|
|
42
|
-
body: JSON.stringify({ hello: "world" }),
|
|
43
|
-
},
|
|
44
|
-
policy: { allowedHostnames: ["api.example.com"] },
|
|
45
|
-
auditContext: "voice-call:test",
|
|
46
|
-
});
|
|
47
|
-
expect(release).toHaveBeenCalledTimes(1);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("returns undefined for empty bodies and allowed 404s", async () => {
|
|
51
|
-
const release = vi.fn(async () => {});
|
|
52
|
-
fetchWithSsrFGuardMock.mockResolvedValueOnce({
|
|
53
|
-
response: new Response(null, { status: 204 }),
|
|
54
|
-
release,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
await expect(
|
|
58
|
-
guardedJsonApiRequest({
|
|
59
|
-
url: "https://api.example.com/v1/calls/1",
|
|
60
|
-
method: "GET",
|
|
61
|
-
headers: {},
|
|
62
|
-
allowedHostnames: ["api.example.com"],
|
|
63
|
-
auditContext: "voice-call:test",
|
|
64
|
-
errorPrefix: "request failed",
|
|
65
|
-
}),
|
|
66
|
-
).resolves.toBeUndefined();
|
|
67
|
-
|
|
68
|
-
fetchWithSsrFGuardMock.mockResolvedValueOnce({
|
|
69
|
-
response: new Response("missing", { status: 404 }),
|
|
70
|
-
release,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
await expect(
|
|
74
|
-
guardedJsonApiRequest({
|
|
75
|
-
url: "https://api.example.com/v1/calls/2",
|
|
76
|
-
method: "GET",
|
|
77
|
-
headers: {},
|
|
78
|
-
allowNotFound: true,
|
|
79
|
-
allowedHostnames: ["api.example.com"],
|
|
80
|
-
auditContext: "voice-call:test",
|
|
81
|
-
errorPrefix: "request failed",
|
|
82
|
-
}),
|
|
83
|
-
).resolves.toBeUndefined();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("throws prefixed errors and still releases the response handle", async () => {
|
|
87
|
-
const release = vi.fn(async () => {});
|
|
88
|
-
fetchWithSsrFGuardMock.mockResolvedValue({
|
|
89
|
-
response: new Response("boom", { status: 500 }),
|
|
90
|
-
release,
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
await expect(
|
|
94
|
-
guardedJsonApiRequest({
|
|
95
|
-
url: "https://api.example.com/v1/calls/3",
|
|
96
|
-
method: "DELETE",
|
|
97
|
-
headers: {},
|
|
98
|
-
allowedHostnames: ["api.example.com"],
|
|
99
|
-
auditContext: "voice-call:test",
|
|
100
|
-
errorPrefix: "provider error",
|
|
101
|
-
}),
|
|
102
|
-
).rejects.toThrow("provider error: 500 boom");
|
|
103
|
-
|
|
104
|
-
expect(release).toHaveBeenCalledTimes(1);
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { fetchWithSsrFGuard } from "../../../api.js";
|
|
2
|
-
|
|
3
|
-
type GuardedJsonApiRequestParams = {
|
|
4
|
-
url: string;
|
|
5
|
-
method: "GET" | "POST" | "DELETE" | "PUT" | "PATCH";
|
|
6
|
-
headers: Record<string, string>;
|
|
7
|
-
body?: Record<string, unknown>;
|
|
8
|
-
allowNotFound?: boolean;
|
|
9
|
-
allowedHostnames: string[];
|
|
10
|
-
auditContext: string;
|
|
11
|
-
errorPrefix: string;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export async function guardedJsonApiRequest<T = unknown>(
|
|
15
|
-
params: GuardedJsonApiRequestParams,
|
|
16
|
-
): Promise<T> {
|
|
17
|
-
const { response, release } = await fetchWithSsrFGuard({
|
|
18
|
-
url: params.url,
|
|
19
|
-
init: {
|
|
20
|
-
method: params.method,
|
|
21
|
-
headers: params.headers,
|
|
22
|
-
body: params.body ? JSON.stringify(params.body) : undefined,
|
|
23
|
-
},
|
|
24
|
-
policy: { allowedHostnames: params.allowedHostnames },
|
|
25
|
-
auditContext: params.auditContext,
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
if (!response.ok) {
|
|
30
|
-
if (params.allowNotFound && response.status === 404) {
|
|
31
|
-
return undefined as T;
|
|
32
|
-
}
|
|
33
|
-
const errorText = await response.text();
|
|
34
|
-
throw new Error(`${params.errorPrefix}: ${response.status} ${errorText}`);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const text = await response.text();
|
|
38
|
-
return text ? (JSON.parse(text) as T) : (undefined as T);
|
|
39
|
-
} finally {
|
|
40
|
-
await release();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,340 +0,0 @@
|
|
|
1
|
-
import crypto from "node:crypto";
|
|
2
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import type { WebhookContext } from "../types.js";
|
|
4
|
-
import { TelnyxProvider } from "./telnyx.js";
|
|
5
|
-
|
|
6
|
-
const apiMocks = vi.hoisted(() => ({
|
|
7
|
-
fetchWithSsrFGuard: vi.fn(),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
vi.mock("../../api.js", () => ({
|
|
11
|
-
fetchWithSsrFGuard: apiMocks.fetchWithSsrFGuard,
|
|
12
|
-
}));
|
|
13
|
-
|
|
14
|
-
afterEach(() => {
|
|
15
|
-
apiMocks.fetchWithSsrFGuard.mockReset();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
function createCtx(params?: Partial<WebhookContext>): WebhookContext {
|
|
19
|
-
return {
|
|
20
|
-
headers: {},
|
|
21
|
-
rawBody: "{}",
|
|
22
|
-
url: "http://localhost/voice/webhook",
|
|
23
|
-
method: "POST",
|
|
24
|
-
query: {},
|
|
25
|
-
remoteAddress: "127.0.0.1",
|
|
26
|
-
...params,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function decodeBase64Url(input: string): Buffer {
|
|
31
|
-
const normalized = input.replace(/-/g, "+").replace(/_/g, "/");
|
|
32
|
-
const padLen = (4 - (normalized.length % 4)) % 4;
|
|
33
|
-
const padded = normalized + "=".repeat(padLen);
|
|
34
|
-
return Buffer.from(padded, "base64");
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function createSignedTelnyxCtx(params: {
|
|
38
|
-
privateKey: crypto.KeyObject;
|
|
39
|
-
rawBody: string;
|
|
40
|
-
}): WebhookContext {
|
|
41
|
-
const timestamp = String(Math.floor(Date.now() / 1000));
|
|
42
|
-
const signedPayload = `${timestamp}|${params.rawBody}`;
|
|
43
|
-
const signature = crypto
|
|
44
|
-
.sign(null, Buffer.from(signedPayload), params.privateKey)
|
|
45
|
-
.toString("base64");
|
|
46
|
-
|
|
47
|
-
return createCtx({
|
|
48
|
-
rawBody: params.rawBody,
|
|
49
|
-
headers: {
|
|
50
|
-
"telnyx-signature-ed25519": signature,
|
|
51
|
-
"telnyx-timestamp": timestamp,
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function expectReplayVerification(
|
|
57
|
-
results: Array<{ ok: boolean; isReplay?: boolean; verifiedRequestKey?: string }>,
|
|
58
|
-
) {
|
|
59
|
-
expect(results.map((result) => result.ok)).toEqual([true, true]);
|
|
60
|
-
expect(results.map((result) => Boolean(result.isReplay))).toEqual([false, true]);
|
|
61
|
-
const firstResult = results[0];
|
|
62
|
-
if (!firstResult?.verifiedRequestKey) {
|
|
63
|
-
throw new Error("expected Telnyx verification to produce a request key");
|
|
64
|
-
}
|
|
65
|
-
const secondResult = results[1];
|
|
66
|
-
if (!secondResult?.verifiedRequestKey) {
|
|
67
|
-
throw new Error("expected replayed Telnyx verification to preserve the request key");
|
|
68
|
-
}
|
|
69
|
-
const firstKey = firstResult.verifiedRequestKey;
|
|
70
|
-
const secondKey = secondResult.verifiedRequestKey;
|
|
71
|
-
expect(firstKey.length).toBeGreaterThan(0);
|
|
72
|
-
expect(secondKey).toBe(firstKey);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function requireJwkX(jwk: JsonWebKey) {
|
|
76
|
-
if (typeof jwk.x !== "string" || jwk.x.length === 0) {
|
|
77
|
-
throw new Error("expected Ed25519 JWK export to expose x");
|
|
78
|
-
}
|
|
79
|
-
return jwk.x;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function expectWebhookVerificationSucceeds(params: {
|
|
83
|
-
publicKey: string;
|
|
84
|
-
privateKey: crypto.KeyObject;
|
|
85
|
-
}) {
|
|
86
|
-
const provider = new TelnyxProvider(
|
|
87
|
-
{ apiKey: "KEY123", connectionId: "CONN456", publicKey: params.publicKey },
|
|
88
|
-
{ skipVerification: false },
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const rawBody = JSON.stringify({
|
|
92
|
-
event_type: "call.initiated",
|
|
93
|
-
payload: { call_control_id: "x" },
|
|
94
|
-
});
|
|
95
|
-
const result = provider.verifyWebhook(
|
|
96
|
-
createSignedTelnyxCtx({ privateKey: params.privateKey, rawBody }),
|
|
97
|
-
);
|
|
98
|
-
expect(result.ok).toBe(true);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
describe("TelnyxProvider.verifyWebhook", () => {
|
|
102
|
-
it("fails closed when public key is missing and skipVerification is false", () => {
|
|
103
|
-
const provider = new TelnyxProvider(
|
|
104
|
-
{ apiKey: "KEY123", connectionId: "CONN456", publicKey: undefined },
|
|
105
|
-
{ skipVerification: false },
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
const result = provider.verifyWebhook(createCtx());
|
|
109
|
-
expect(result.ok).toBe(false);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it("allows requests when skipVerification is true (development only)", () => {
|
|
113
|
-
const provider = new TelnyxProvider(
|
|
114
|
-
{ apiKey: "KEY123", connectionId: "CONN456", publicKey: undefined },
|
|
115
|
-
{ skipVerification: true },
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
const result = provider.verifyWebhook(createCtx());
|
|
119
|
-
expect(result.ok).toBe(true);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("fails when signature headers are missing (with public key configured)", () => {
|
|
123
|
-
const provider = new TelnyxProvider(
|
|
124
|
-
{ apiKey: "KEY123", connectionId: "CONN456", publicKey: "public-key" },
|
|
125
|
-
{ skipVerification: false },
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
const result = provider.verifyWebhook(createCtx({ headers: {} }));
|
|
129
|
-
expect(result.ok).toBe(false);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("verifies a valid signature with a raw Ed25519 public key (Base64)", () => {
|
|
133
|
-
const { publicKey, privateKey } = crypto.generateKeyPairSync("ed25519");
|
|
134
|
-
|
|
135
|
-
const jwk = publicKey.export({ format: "jwk" }) as JsonWebKey;
|
|
136
|
-
expect(jwk.kty).toBe("OKP");
|
|
137
|
-
expect(jwk.crv).toBe("Ed25519");
|
|
138
|
-
|
|
139
|
-
const rawPublicKey = decodeBase64Url(requireJwkX(jwk));
|
|
140
|
-
const rawPublicKeyBase64 = rawPublicKey.toString("base64");
|
|
141
|
-
expectWebhookVerificationSucceeds({ publicKey: rawPublicKeyBase64, privateKey });
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("verifies a valid signature with a DER SPKI public key (Base64)", () => {
|
|
145
|
-
const { publicKey, privateKey } = crypto.generateKeyPairSync("ed25519");
|
|
146
|
-
const spkiDer = publicKey.export({ format: "der", type: "spki" }) as Buffer;
|
|
147
|
-
const spkiDerBase64 = spkiDer.toString("base64");
|
|
148
|
-
expectWebhookVerificationSucceeds({ publicKey: spkiDerBase64, privateKey });
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it("returns replay status when the same signed request is seen twice", () => {
|
|
152
|
-
const { publicKey, privateKey } = crypto.generateKeyPairSync("ed25519");
|
|
153
|
-
const spkiDer = publicKey.export({ format: "der", type: "spki" }) as Buffer;
|
|
154
|
-
const provider = new TelnyxProvider(
|
|
155
|
-
{ apiKey: "KEY123", connectionId: "CONN456", publicKey: spkiDer.toString("base64") },
|
|
156
|
-
{ skipVerification: false },
|
|
157
|
-
);
|
|
158
|
-
|
|
159
|
-
const rawBody = JSON.stringify({
|
|
160
|
-
event_type: "call.initiated",
|
|
161
|
-
payload: { call_control_id: "call-replay-test" },
|
|
162
|
-
nonce: crypto.randomUUID(),
|
|
163
|
-
});
|
|
164
|
-
const ctx = createSignedTelnyxCtx({ privateKey, rawBody });
|
|
165
|
-
|
|
166
|
-
const first = provider.verifyWebhook(ctx);
|
|
167
|
-
const second = provider.verifyWebhook(ctx);
|
|
168
|
-
|
|
169
|
-
expectReplayVerification([first, second]);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
describe("TelnyxProvider.parseWebhookEvent", () => {
|
|
174
|
-
it("uses verified request key for manager dedupe", () => {
|
|
175
|
-
const provider = new TelnyxProvider({
|
|
176
|
-
apiKey: "KEY123",
|
|
177
|
-
connectionId: "CONN456",
|
|
178
|
-
publicKey: undefined,
|
|
179
|
-
});
|
|
180
|
-
const result = provider.parseWebhookEvent(
|
|
181
|
-
createCtx({
|
|
182
|
-
rawBody: JSON.stringify({
|
|
183
|
-
data: {
|
|
184
|
-
id: "evt-123",
|
|
185
|
-
event_type: "call.initiated",
|
|
186
|
-
payload: { call_control_id: "call-1" },
|
|
187
|
-
},
|
|
188
|
-
}),
|
|
189
|
-
}),
|
|
190
|
-
{ verifiedRequestKey: "telnyx:req:abc" },
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
expect(result.events).toHaveLength(1);
|
|
194
|
-
const event = result.events[0];
|
|
195
|
-
if (!event) {
|
|
196
|
-
throw new Error("expected Telnyx parseWebhookEvent to produce one event");
|
|
197
|
-
}
|
|
198
|
-
expect(event.dedupeKey).toBe("telnyx:req:abc");
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
it("maps call direction and phone numbers from Call Control callbacks", () => {
|
|
202
|
-
const provider = new TelnyxProvider({
|
|
203
|
-
apiKey: "KEY123",
|
|
204
|
-
connectionId: "CONN456",
|
|
205
|
-
publicKey: undefined,
|
|
206
|
-
});
|
|
207
|
-
const result = provider.parseWebhookEvent(
|
|
208
|
-
createCtx({
|
|
209
|
-
rawBody: JSON.stringify({
|
|
210
|
-
data: {
|
|
211
|
-
id: "evt-inbound",
|
|
212
|
-
event_type: "call.initiated",
|
|
213
|
-
payload: {
|
|
214
|
-
call_control_id: "call-1",
|
|
215
|
-
direction: "incoming",
|
|
216
|
-
from: "+15551111111",
|
|
217
|
-
to: "+15550000000",
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
}),
|
|
221
|
-
}),
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
expect(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
|
-
);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it("reads transcription text from Telnyx transcription_data payloads", () => {
|
|
236
|
-
const provider = new TelnyxProvider({
|
|
237
|
-
apiKey: "KEY123",
|
|
238
|
-
connectionId: "CONN456",
|
|
239
|
-
publicKey: undefined,
|
|
240
|
-
});
|
|
241
|
-
const result = provider.parseWebhookEvent(
|
|
242
|
-
createCtx({
|
|
243
|
-
rawBody: JSON.stringify({
|
|
244
|
-
data: {
|
|
245
|
-
id: "evt-transcription",
|
|
246
|
-
event_type: "call.transcription",
|
|
247
|
-
payload: {
|
|
248
|
-
call_control_id: "call-1",
|
|
249
|
-
transcription_data: {
|
|
250
|
-
transcript: "hello this is a test speech",
|
|
251
|
-
is_final: false,
|
|
252
|
-
confidence: 0.977219,
|
|
253
|
-
},
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
}),
|
|
257
|
-
}),
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
expect(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
|
-
);
|
|
269
|
-
});
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
describe("TelnyxProvider answer control", () => {
|
|
273
|
-
it("answers inbound call-control legs with a deterministic command id", async () => {
|
|
274
|
-
const release = vi.fn(async () => {});
|
|
275
|
-
apiMocks.fetchWithSsrFGuard.mockResolvedValue({
|
|
276
|
-
response: new Response(JSON.stringify({ data: {} }), { status: 200 }),
|
|
277
|
-
release,
|
|
278
|
-
});
|
|
279
|
-
const provider = new TelnyxProvider({
|
|
280
|
-
apiKey: "KEY123",
|
|
281
|
-
connectionId: "CONN456",
|
|
282
|
-
publicKey: undefined,
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
await provider.answerCall({
|
|
286
|
-
callId: "call-1",
|
|
287
|
-
providerCallId: "call-control-1",
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
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
|
-
);
|
|
301
|
-
expect(release).toHaveBeenCalledTimes(1);
|
|
302
|
-
});
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
describe("TelnyxProvider speak control", () => {
|
|
306
|
-
it("passes custom Telnyx voice ids to the speak action", async () => {
|
|
307
|
-
const release = vi.fn(async () => {});
|
|
308
|
-
apiMocks.fetchWithSsrFGuard.mockResolvedValue({
|
|
309
|
-
response: new Response(JSON.stringify({ data: {} }), { status: 200 }),
|
|
310
|
-
release,
|
|
311
|
-
});
|
|
312
|
-
const provider = new TelnyxProvider({
|
|
313
|
-
apiKey: "KEY123",
|
|
314
|
-
connectionId: "CONN456",
|
|
315
|
-
publicKey: undefined,
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
await provider.playTts({
|
|
319
|
-
callId: "call-1",
|
|
320
|
-
providerCallId: "call-control-1",
|
|
321
|
-
text: "hello",
|
|
322
|
-
voice: "Telnyx.Qwen3TTS.12345678-1234-1234-1234-123456789abc",
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
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
|
-
);
|
|
338
|
-
expect(release).toHaveBeenCalledTimes(1);
|
|
339
|
-
});
|
|
340
|
-
});
|