@openclaw/voice-call 2026.5.2 → 2026.5.3-beta.2

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.
Files changed (126) hide show
  1. package/dist/api.js +2 -0
  2. package/dist/call-status-CXldV5o8.js +32 -0
  3. package/dist/cli-metadata.js +12 -0
  4. package/dist/config-7w04YpHh.js +548 -0
  5. package/dist/config-compat-B0me39_4.js +129 -0
  6. package/dist/guarded-json-api-Btx5EE4w.js +591 -0
  7. package/dist/http-headers-BrnxBasF.js +10 -0
  8. package/dist/index.js +1284 -0
  9. package/dist/mock-CeKvfVEd.js +135 -0
  10. package/dist/plivo-B-a7KFoT.js +393 -0
  11. package/dist/realtime-handler-B63CIDP2.js +325 -0
  12. package/dist/realtime-transcription.runtime-B2h70y2W.js +2 -0
  13. package/dist/realtime-voice.runtime-Bkh4nvLn.js +2 -0
  14. package/dist/response-generator-BrcmwDZU.js +182 -0
  15. package/dist/response-model-CyF5K80p.js +12 -0
  16. package/dist/runtime-api.js +6 -0
  17. package/dist/runtime-entry-88ytYAQa.js +3119 -0
  18. package/dist/runtime-entry.js +2 -0
  19. package/dist/setup-api.js +37 -0
  20. package/dist/telnyx-jjBE8boz.js +260 -0
  21. package/dist/twilio-1OqbcXLL.js +676 -0
  22. package/dist/voice-mapping-BYDGdWGx.js +40 -0
  23. package/package.json +14 -6
  24. package/api.ts +0 -16
  25. package/cli-metadata.ts +0 -10
  26. package/config-api.ts +0 -12
  27. package/index.test.ts +0 -943
  28. package/index.ts +0 -794
  29. package/runtime-api.ts +0 -20
  30. package/runtime-entry.ts +0 -1
  31. package/setup-api.ts +0 -47
  32. package/src/allowlist.test.ts +0 -18
  33. package/src/allowlist.ts +0 -19
  34. package/src/cli.ts +0 -845
  35. package/src/config-compat.test.ts +0 -120
  36. package/src/config-compat.ts +0 -227
  37. package/src/config.test.ts +0 -479
  38. package/src/config.ts +0 -808
  39. package/src/core-bridge.ts +0 -14
  40. package/src/deep-merge.test.ts +0 -40
  41. package/src/deep-merge.ts +0 -23
  42. package/src/gateway-continue-operation.ts +0 -200
  43. package/src/http-headers.test.ts +0 -16
  44. package/src/http-headers.ts +0 -15
  45. package/src/manager/context.ts +0 -42
  46. package/src/manager/events.test.ts +0 -581
  47. package/src/manager/events.ts +0 -288
  48. package/src/manager/lifecycle.ts +0 -53
  49. package/src/manager/lookup.test.ts +0 -52
  50. package/src/manager/lookup.ts +0 -35
  51. package/src/manager/outbound.test.ts +0 -528
  52. package/src/manager/outbound.ts +0 -486
  53. package/src/manager/state.ts +0 -48
  54. package/src/manager/store.ts +0 -106
  55. package/src/manager/timers.test.ts +0 -129
  56. package/src/manager/timers.ts +0 -113
  57. package/src/manager/twiml.test.ts +0 -13
  58. package/src/manager/twiml.ts +0 -17
  59. package/src/manager.closed-loop.test.ts +0 -236
  60. package/src/manager.inbound-allowlist.test.ts +0 -188
  61. package/src/manager.notify.test.ts +0 -377
  62. package/src/manager.restore.test.ts +0 -183
  63. package/src/manager.test-harness.ts +0 -127
  64. package/src/manager.ts +0 -392
  65. package/src/media-stream.test.ts +0 -768
  66. package/src/media-stream.ts +0 -708
  67. package/src/providers/base.ts +0 -97
  68. package/src/providers/mock.test.ts +0 -78
  69. package/src/providers/mock.ts +0 -185
  70. package/src/providers/plivo.test.ts +0 -93
  71. package/src/providers/plivo.ts +0 -601
  72. package/src/providers/shared/call-status.test.ts +0 -24
  73. package/src/providers/shared/call-status.ts +0 -24
  74. package/src/providers/shared/guarded-json-api.test.ts +0 -106
  75. package/src/providers/shared/guarded-json-api.ts +0 -42
  76. package/src/providers/telnyx.test.ts +0 -340
  77. package/src/providers/telnyx.ts +0 -394
  78. package/src/providers/twilio/api.test.ts +0 -145
  79. package/src/providers/twilio/api.ts +0 -93
  80. package/src/providers/twilio/twiml-policy.test.ts +0 -84
  81. package/src/providers/twilio/twiml-policy.ts +0 -87
  82. package/src/providers/twilio/webhook.ts +0 -34
  83. package/src/providers/twilio.test.ts +0 -591
  84. package/src/providers/twilio.ts +0 -861
  85. package/src/providers/twilio.types.ts +0 -17
  86. package/src/realtime-defaults.ts +0 -3
  87. package/src/realtime-fast-context.test.ts +0 -88
  88. package/src/realtime-fast-context.ts +0 -165
  89. package/src/realtime-transcription.runtime.ts +0 -4
  90. package/src/realtime-voice.runtime.ts +0 -5
  91. package/src/response-generator.test.ts +0 -321
  92. package/src/response-generator.ts +0 -318
  93. package/src/response-model.test.ts +0 -71
  94. package/src/response-model.ts +0 -23
  95. package/src/runtime.test.ts +0 -536
  96. package/src/runtime.ts +0 -510
  97. package/src/telephony-audio.test.ts +0 -61
  98. package/src/telephony-audio.ts +0 -12
  99. package/src/telephony-tts.test.ts +0 -196
  100. package/src/telephony-tts.ts +0 -235
  101. package/src/test-fixtures.ts +0 -73
  102. package/src/tts-provider-voice.test.ts +0 -34
  103. package/src/tts-provider-voice.ts +0 -21
  104. package/src/tunnel.test.ts +0 -166
  105. package/src/tunnel.ts +0 -314
  106. package/src/types.ts +0 -291
  107. package/src/utils.test.ts +0 -17
  108. package/src/utils.ts +0 -14
  109. package/src/voice-mapping.test.ts +0 -34
  110. package/src/voice-mapping.ts +0 -68
  111. package/src/webhook/realtime-handler.test.ts +0 -598
  112. package/src/webhook/realtime-handler.ts +0 -485
  113. package/src/webhook/stale-call-reaper.test.ts +0 -88
  114. package/src/webhook/stale-call-reaper.ts +0 -38
  115. package/src/webhook/tailscale.test.ts +0 -214
  116. package/src/webhook/tailscale.ts +0 -129
  117. package/src/webhook-exposure.test.ts +0 -33
  118. package/src/webhook-exposure.ts +0 -84
  119. package/src/webhook-security.test.ts +0 -770
  120. package/src/webhook-security.ts +0 -994
  121. package/src/webhook.hangup-once.lifecycle.test.ts +0 -135
  122. package/src/webhook.test.ts +0 -1470
  123. package/src/webhook.ts +0 -908
  124. package/src/webhook.types.ts +0 -5
  125. package/src/websocket-test-support.ts +0 -72
  126. package/tsconfig.json +0 -16
@@ -1,97 +0,0 @@
1
- import type {
2
- AnswerCallInput,
3
- GetCallStatusInput,
4
- GetCallStatusResult,
5
- HangupCallInput,
6
- InitiateCallInput,
7
- InitiateCallResult,
8
- PlayTtsInput,
9
- ProviderName,
10
- SendDtmfInput,
11
- WebhookParseOptions,
12
- ProviderWebhookParseResult,
13
- StartListeningInput,
14
- StopListeningInput,
15
- WebhookContext,
16
- WebhookVerificationResult,
17
- } from "../types.js";
18
-
19
- /**
20
- * Abstract base interface for voice call providers.
21
- *
22
- * Each provider (Telnyx, Twilio, etc.) implements this interface to provide
23
- * a consistent API for the call manager.
24
- *
25
- * Responsibilities:
26
- * - Webhook verification and event parsing
27
- * - Outbound call initiation and hangup
28
- * - Media control (TTS playback, STT listening)
29
- */
30
- export interface VoiceCallProvider {
31
- /** Provider identifier */
32
- readonly name: ProviderName;
33
-
34
- /**
35
- * Verify webhook signature/HMAC before processing.
36
- * Must be called before parseWebhookEvent.
37
- */
38
- verifyWebhook(ctx: WebhookContext): WebhookVerificationResult;
39
-
40
- /**
41
- * Parse provider-specific webhook payload into normalized events.
42
- * Returns events and optional response to send back to provider.
43
- */
44
- parseWebhookEvent(ctx: WebhookContext, options?: WebhookParseOptions): ProviderWebhookParseResult;
45
-
46
- /**
47
- * Consume one-time TwiML that must be served before shortcut handlers such as
48
- * realtime media streams take over the webhook response.
49
- */
50
- consumeInitialTwiML?: (ctx: WebhookContext) => string | null;
51
-
52
- /**
53
- * Initiate an outbound call.
54
- * @returns Provider call ID and status
55
- */
56
- initiateCall(input: InitiateCallInput): Promise<InitiateCallResult>;
57
-
58
- /**
59
- * Answer an accepted inbound call when the provider requires an explicit
60
- * answer command after the initial webhook.
61
- */
62
- answerCall?: (input: AnswerCallInput) => Promise<void>;
63
-
64
- /**
65
- * Hang up an active call.
66
- */
67
- hangupCall(input: HangupCallInput): Promise<void>;
68
-
69
- /**
70
- * Play TTS audio to the caller.
71
- * The provider should handle streaming if supported.
72
- */
73
- playTts(input: PlayTtsInput): Promise<void>;
74
-
75
- /**
76
- * Send DTMF digits to an active call.
77
- */
78
- sendDtmf?: (input: SendDtmfInput) => Promise<void>;
79
-
80
- /**
81
- * Start listening for user speech (activate STT).
82
- */
83
- startListening(input: StartListeningInput): Promise<void>;
84
-
85
- /**
86
- * Stop listening for user speech (deactivate STT).
87
- */
88
- stopListening(input: StopListeningInput): Promise<void>;
89
-
90
- /**
91
- * Query provider for current call status.
92
- * Used to verify persisted calls are still active on restart.
93
- * Must return `isUnknown: true` for transient errors (network, 5xx)
94
- * so the caller can keep the call and rely on timer-based fallback.
95
- */
96
- getCallStatus(input: GetCallStatusInput): Promise<GetCallStatusResult>;
97
- }
@@ -1,78 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import type { WebhookContext } from "../types.js";
3
- import { MockProvider } from "./mock.js";
4
-
5
- function createWebhookContext(rawBody: string): WebhookContext {
6
- return {
7
- headers: {},
8
- rawBody,
9
- url: "http://localhost/voice/webhook",
10
- method: "POST",
11
- query: {},
12
- };
13
- }
14
-
15
- describe("MockProvider", () => {
16
- it("preserves explicit falsy event values", () => {
17
- const provider = new MockProvider();
18
- const result = provider.parseWebhookEvent(
19
- createWebhookContext(
20
- JSON.stringify({
21
- events: [
22
- {
23
- id: "evt-error",
24
- type: "call.error",
25
- callId: "call-1",
26
- timestamp: 0,
27
- error: "",
28
- retryable: false,
29
- },
30
- {
31
- id: "evt-ended",
32
- type: "call.ended",
33
- callId: "call-2",
34
- reason: "",
35
- },
36
- {
37
- id: "evt-speech",
38
- type: "call.speech",
39
- callId: "call-3",
40
- transcript: "",
41
- isFinal: false,
42
- },
43
- ],
44
- }),
45
- ),
46
- );
47
-
48
- expect(result.events).toEqual([
49
- {
50
- id: "evt-error",
51
- type: "call.error",
52
- callId: "call-1",
53
- providerCallId: undefined,
54
- timestamp: 0,
55
- error: "",
56
- retryable: false,
57
- },
58
- {
59
- id: "evt-ended",
60
- type: "call.ended",
61
- callId: "call-2",
62
- providerCallId: undefined,
63
- timestamp: expect.any(Number),
64
- reason: "",
65
- },
66
- {
67
- id: "evt-speech",
68
- type: "call.speech",
69
- callId: "call-3",
70
- providerCallId: undefined,
71
- timestamp: expect.any(Number),
72
- transcript: "",
73
- isFinal: false,
74
- confidence: undefined,
75
- },
76
- ]);
77
- });
78
- });
@@ -1,185 +0,0 @@
1
- import crypto from "node:crypto";
2
- import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/text-runtime";
3
- import type {
4
- EndReason,
5
- GetCallStatusInput,
6
- GetCallStatusResult,
7
- HangupCallInput,
8
- InitiateCallInput,
9
- InitiateCallResult,
10
- NormalizedEvent,
11
- PlayTtsInput,
12
- WebhookParseOptions,
13
- ProviderWebhookParseResult,
14
- SendDtmfInput,
15
- StartListeningInput,
16
- StopListeningInput,
17
- WebhookContext,
18
- WebhookVerificationResult,
19
- } from "../types.js";
20
- import type { VoiceCallProvider } from "./base.js";
21
-
22
- /**
23
- * Mock voice call provider for local testing.
24
- *
25
- * Events are driven via webhook POST with JSON body:
26
- * - { events: NormalizedEvent[] } for bulk events
27
- * - { event: NormalizedEvent } for single event
28
- */
29
- export class MockProvider implements VoiceCallProvider {
30
- readonly name = "mock" as const;
31
-
32
- verifyWebhook(_ctx: WebhookContext): WebhookVerificationResult {
33
- return { ok: true };
34
- }
35
-
36
- parseWebhookEvent(
37
- ctx: WebhookContext,
38
- _options?: WebhookParseOptions,
39
- ): ProviderWebhookParseResult {
40
- try {
41
- const payload = JSON.parse(ctx.rawBody);
42
- const events: NormalizedEvent[] = [];
43
-
44
- if (Array.isArray(payload.events)) {
45
- for (const evt of payload.events) {
46
- const normalized = this.normalizeEvent(evt);
47
- if (normalized) {
48
- events.push(normalized);
49
- }
50
- }
51
- } else if (payload.event) {
52
- const normalized = this.normalizeEvent(payload.event);
53
- if (normalized) {
54
- events.push(normalized);
55
- }
56
- }
57
-
58
- return { events, statusCode: 200 };
59
- } catch {
60
- return { events: [], statusCode: 400 };
61
- }
62
- }
63
-
64
- private normalizeEvent(evt: Partial<NormalizedEvent>): NormalizedEvent | null {
65
- if (!evt.type || !evt.callId) {
66
- return null;
67
- }
68
-
69
- const base = {
70
- id: evt.id ?? crypto.randomUUID(),
71
- callId: evt.callId,
72
- providerCallId: evt.providerCallId,
73
- timestamp: evt.timestamp ?? Date.now(),
74
- };
75
-
76
- switch (evt.type) {
77
- case "call.initiated":
78
- case "call.ringing":
79
- case "call.answered":
80
- case "call.active":
81
- return { ...base, type: evt.type };
82
-
83
- case "call.speaking": {
84
- const payload = evt as Partial<NormalizedEvent & { text?: string }>;
85
- return {
86
- ...base,
87
- type: evt.type,
88
- text: payload.text ?? "",
89
- };
90
- }
91
-
92
- case "call.speech": {
93
- const payload = evt as Partial<
94
- NormalizedEvent & {
95
- transcript?: string;
96
- isFinal?: boolean;
97
- confidence?: number;
98
- }
99
- >;
100
- return {
101
- ...base,
102
- type: evt.type,
103
- transcript: payload.transcript ?? "",
104
- isFinal: payload.isFinal ?? true,
105
- confidence: payload.confidence,
106
- };
107
- }
108
-
109
- case "call.silence": {
110
- const payload = evt as Partial<NormalizedEvent & { durationMs?: number }>;
111
- return {
112
- ...base,
113
- type: evt.type,
114
- durationMs: payload.durationMs ?? 0,
115
- };
116
- }
117
-
118
- case "call.dtmf": {
119
- const payload = evt as Partial<NormalizedEvent & { digits?: string }>;
120
- return {
121
- ...base,
122
- type: evt.type,
123
- digits: payload.digits ?? "",
124
- };
125
- }
126
-
127
- case "call.ended": {
128
- const payload = evt as Partial<NormalizedEvent & { reason?: EndReason }>;
129
- return {
130
- ...base,
131
- type: evt.type,
132
- reason: payload.reason ?? "completed",
133
- };
134
- }
135
-
136
- case "call.error": {
137
- const payload = evt as Partial<NormalizedEvent & { error?: string; retryable?: boolean }>;
138
- return {
139
- ...base,
140
- type: evt.type,
141
- error: payload.error ?? "unknown error",
142
- retryable: payload.retryable,
143
- };
144
- }
145
-
146
- default:
147
- return null;
148
- }
149
- }
150
-
151
- async initiateCall(input: InitiateCallInput): Promise<InitiateCallResult> {
152
- return {
153
- providerCallId: `mock-${input.callId}`,
154
- status: "initiated",
155
- };
156
- }
157
-
158
- async hangupCall(_input: HangupCallInput): Promise<void> {
159
- // No-op for mock
160
- }
161
-
162
- async playTts(_input: PlayTtsInput): Promise<void> {
163
- // No-op for mock
164
- }
165
-
166
- async sendDtmf(_input: SendDtmfInput): Promise<void> {
167
- // No-op for mock
168
- }
169
-
170
- async startListening(_input: StartListeningInput): Promise<void> {
171
- // No-op for mock
172
- }
173
-
174
- async stopListening(_input: StopListeningInput): Promise<void> {
175
- // No-op for mock
176
- }
177
-
178
- async getCallStatus(input: GetCallStatusInput): Promise<GetCallStatusResult> {
179
- const id = normalizeLowercaseStringOrEmpty(input.providerCallId);
180
- if (id.includes("stale") || id.includes("ended") || id.includes("completed")) {
181
- return { status: "completed", isTerminal: true };
182
- }
183
- return { status: "in-progress", isTerminal: false };
184
- }
185
- }
@@ -1,93 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { PlivoProvider } from "./plivo.js";
3
-
4
- function requireEvent<T>(event: T | undefined, message: string): T {
5
- if (!event) {
6
- throw new Error(message);
7
- }
8
- return event;
9
- }
10
-
11
- function requireResponseBody(body: string | undefined): string {
12
- if (!body) {
13
- throw new Error("Plivo provider did not return a response body");
14
- }
15
- return body;
16
- }
17
-
18
- describe("PlivoProvider", () => {
19
- it("parses answer callback into call.answered and returns keep-alive XML", () => {
20
- const provider = new PlivoProvider({
21
- authId: "MA000000000000000000",
22
- authToken: "test-token",
23
- });
24
-
25
- const result = provider.parseWebhookEvent({
26
- headers: { host: "example.com" },
27
- rawBody:
28
- "CallUUID=call-uuid&CallStatus=in-progress&Direction=outbound&From=%2B15550000000&To=%2B15550000001&Event=StartApp",
29
- url: "https://example.com/voice/webhook?provider=plivo&flow=answer&callId=internal-call-id",
30
- method: "POST",
31
- query: { provider: "plivo", flow: "answer", callId: "internal-call-id" },
32
- });
33
-
34
- expect(result.events).toHaveLength(1);
35
- const event = requireEvent(result.events[0], "expected Plivo answer event");
36
- expect(event.type).toBe("call.answered");
37
- expect(event.callId).toBe("internal-call-id");
38
- expect(event.providerCallId).toBe("call-uuid");
39
- const responseBody = requireResponseBody(result.providerResponseBody);
40
- expect(responseBody).toContain("<Wait");
41
- expect(responseBody).toContain('length="300"');
42
- });
43
-
44
- it("uses verified request key when provided", () => {
45
- const provider = new PlivoProvider({
46
- authId: "MA000000000000000000",
47
- authToken: "test-token",
48
- });
49
-
50
- const result = provider.parseWebhookEvent(
51
- {
52
- headers: { host: "example.com", "x-plivo-signature-v3-nonce": "nonce-1" },
53
- rawBody:
54
- "CallUUID=call-uuid&CallStatus=in-progress&Direction=outbound&From=%2B15550000000&To=%2B15550000001&Event=StartApp",
55
- url: "https://example.com/voice/webhook?provider=plivo&flow=answer&callId=internal-call-id",
56
- method: "POST",
57
- query: { provider: "plivo", flow: "answer", callId: "internal-call-id" },
58
- },
59
- { verifiedRequestKey: "plivo:v3:verified" },
60
- );
61
-
62
- expect(result.events).toHaveLength(1);
63
- expect(requireEvent(result.events[0], "expected verified Plivo event").dedupeKey).toBe(
64
- "plivo:v3:verified",
65
- );
66
- });
67
-
68
- it("pins stored callback bases to publicUrl instead of request Host", () => {
69
- const provider = new PlivoProvider(
70
- {
71
- authId: "MA000000000000000000",
72
- authToken: "test-token",
73
- },
74
- {
75
- publicUrl: "https://voice.openclaw.ai/voice/webhook?provider=plivo",
76
- },
77
- );
78
-
79
- provider.parseWebhookEvent({
80
- headers: { host: "attacker.example" },
81
- rawBody:
82
- "CallUUID=call-uuid&CallStatus=in-progress&Direction=outbound&From=%2B15550000000&To=%2B15550000001&Event=StartApp",
83
- url: "https://attacker.example/voice/webhook?provider=plivo&flow=answer&callId=internal-call-id",
84
- method: "POST",
85
- query: { provider: "plivo", flow: "answer", callId: "internal-call-id" },
86
- });
87
-
88
- const callbackMap = (provider as unknown as { callUuidToWebhookUrl: Map<string, string> })
89
- .callUuidToWebhookUrl;
90
-
91
- expect(callbackMap.get("call-uuid")).toBe("https://voice.openclaw.ai/voice/webhook");
92
- });
93
- });