@sinch/functions-runtime 0.5.10 → 0.5.13
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/bin/sinch-runtime.js +6 -4
- package/dist/bin/sinch-runtime.js.map +1 -1
- package/dist/{chunk-LU5JRQ64.js → chunk-IRSTA74R.js} +293 -62
- package/dist/chunk-IRSTA74R.js.map +1 -0
- package/dist/chunk-X44DQ6CI.js +52 -0
- package/dist/chunk-X44DQ6CI.js.map +1 -0
- package/dist/index.d.ts +67 -19
- package/dist/index.js +2 -1
- package/dist/voice/v2.d.ts +1597 -0
- package/dist/voice/v2.js +1259 -0
- package/dist/voice/v2.js.map +1 -0
- package/package.json +7 -2
- package/dist/chunk-LU5JRQ64.js.map +0 -1
|
@@ -0,0 +1,1597 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
interface ClientContext {
|
|
4
|
+
/** Function configuration. Only `projectId` is read. */
|
|
5
|
+
config?: {
|
|
6
|
+
/** Sinch project id */
|
|
7
|
+
projectId?: string;
|
|
8
|
+
};
|
|
9
|
+
/** Hostname this function is served on. Used to resolve relative stream paths. */
|
|
10
|
+
host?: string;
|
|
11
|
+
/** Environment variables. Defaults to `process.env`. */
|
|
12
|
+
env?: Record<string, string | undefined>;
|
|
13
|
+
}
|
|
14
|
+
type StreamCodec = "PCM";
|
|
15
|
+
/** Audio sampling rate (Hz) for a STREAM endpoint. */
|
|
16
|
+
export type SampleRate = 8000 | 16000 | 24000 | 44100 | 48000 | 96000;
|
|
17
|
+
interface CallHeader {
|
|
18
|
+
/** Header name (1-255 characters) */
|
|
19
|
+
key: string;
|
|
20
|
+
/** Header value (up to 255 characters) */
|
|
21
|
+
value?: string;
|
|
22
|
+
}
|
|
23
|
+
interface PhoneEndpoint {
|
|
24
|
+
/** Discriminator */
|
|
25
|
+
type: "PHONE";
|
|
26
|
+
/** Phone destination */
|
|
27
|
+
phone: {
|
|
28
|
+
/** E.164 phone number, e.g. `+15551234567` */
|
|
29
|
+
number: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
interface SipEndpoint {
|
|
33
|
+
/** Discriminator */
|
|
34
|
+
type: "SIP";
|
|
35
|
+
/** SIP destination */
|
|
36
|
+
sip: {
|
|
37
|
+
/** SIP URI (`sip:` or `sips:`) */
|
|
38
|
+
endpoint: string;
|
|
39
|
+
/** Transport protocol */
|
|
40
|
+
transport?: "UDP" | "TCP" | "TLS";
|
|
41
|
+
/** Custom SIP headers */
|
|
42
|
+
callHeaders?: CallHeader[];
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
interface StreamOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Stream protocol version. The schema (spec line 2871) types this as a plain integer with
|
|
48
|
+
* a default of `1` and names no other accepted value; `1` is what this library emits.
|
|
49
|
+
*/
|
|
50
|
+
version: number;
|
|
51
|
+
/** Audio codec. Only `PCM` is supported. */
|
|
52
|
+
codec: StreamCodec;
|
|
53
|
+
/** Audio sampling rate in Hz */
|
|
54
|
+
sampleRate: SampleRate;
|
|
55
|
+
}
|
|
56
|
+
interface StreamEndpoint {
|
|
57
|
+
/** Discriminator */
|
|
58
|
+
type: "STREAM";
|
|
59
|
+
/** Stream destination */
|
|
60
|
+
stream: {
|
|
61
|
+
/** WebSocket URL (`ws://` or `wss://`) reachable from the public internet */
|
|
62
|
+
endpoint: string;
|
|
63
|
+
/** Codec and sample-rate negotiation */
|
|
64
|
+
streamOptions?: StreamOptions;
|
|
65
|
+
/** Headers delivered on the WebSocket upgrade and in the `connect` message */
|
|
66
|
+
callHeaders?: CallHeader[];
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
interface VoiceRelayEndpoint {
|
|
70
|
+
/** Discriminator */
|
|
71
|
+
type: "VOICE_RELAY";
|
|
72
|
+
/** Relay destination */
|
|
73
|
+
voiceRelay: {
|
|
74
|
+
/** WebSocket URL that accepts the relay connection, e.g. `wss://acme.com/agent` */
|
|
75
|
+
endpoint: string;
|
|
76
|
+
/**
|
|
77
|
+
* Allow barge-in during TTS playback. Defaults to `true` on the platform; when `false`
|
|
78
|
+
* an interruption signal is still delivered over the socket.
|
|
79
|
+
*/
|
|
80
|
+
enableInterruptions?: boolean;
|
|
81
|
+
/** Platform TTS voice, e.g. `Emma` or `Brian` */
|
|
82
|
+
ttsVoice: string;
|
|
83
|
+
/** BCP-47 language tag for speech-to-text, e.g. `en-US` */
|
|
84
|
+
sttLanguage: string;
|
|
85
|
+
/** Headers delivered on the WebSocket upgrade and in the `connect` message */
|
|
86
|
+
callHeaders?: CallHeader[];
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
type To = PhoneEndpoint | SipEndpoint | StreamEndpoint | VoiceRelayEndpoint;
|
|
90
|
+
interface SipOriginEndpoint {
|
|
91
|
+
/** Discriminator */
|
|
92
|
+
type: "SIP";
|
|
93
|
+
/** SIP origin */
|
|
94
|
+
sip: {
|
|
95
|
+
/** SIP URI (`sip:` or `sips:`) */
|
|
96
|
+
endpoint: string;
|
|
97
|
+
/** Caller identity shown to the callee, sent as the SIP `From` display name */
|
|
98
|
+
displayName?: string;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
type From = PhoneEndpoint | SipOriginEndpoint;
|
|
102
|
+
interface CallEvents {
|
|
103
|
+
/** Runs when the leg is answered */
|
|
104
|
+
onAnswer?: Command[];
|
|
105
|
+
/** Runs when the callee is busy */
|
|
106
|
+
onBusy?: Command[];
|
|
107
|
+
/** Runs when the callee rejects */
|
|
108
|
+
onReject?: Command[];
|
|
109
|
+
/** Runs when the dial timeout elapses without an answer */
|
|
110
|
+
onTimeout?: Command[];
|
|
111
|
+
/** Runs when the leg is hung up */
|
|
112
|
+
onHangup?: Command[];
|
|
113
|
+
/** Runs when the leg could not be set up */
|
|
114
|
+
onFailure?: Command[];
|
|
115
|
+
}
|
|
116
|
+
interface SayMessage {
|
|
117
|
+
/** Discriminator */
|
|
118
|
+
type: "SAY";
|
|
119
|
+
/** TTS payload */
|
|
120
|
+
say: {
|
|
121
|
+
/** Text, or an SSML document when `format` is `SSML` */
|
|
122
|
+
text: string;
|
|
123
|
+
/** Text format. Defaults to `TEXT`. */
|
|
124
|
+
format?: "TEXT" | "SSML";
|
|
125
|
+
/** Voice name, e.g. `Emma`. Required by the API. */
|
|
126
|
+
voiceName: string;
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
interface PlayMessage {
|
|
130
|
+
/** Discriminator */
|
|
131
|
+
type: "PLAY";
|
|
132
|
+
/** Audio payload */
|
|
133
|
+
play: {
|
|
134
|
+
/** URL of the audio file to play */
|
|
135
|
+
url: string;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
type Message = SayMessage | PlayMessage;
|
|
139
|
+
interface DialCommand {
|
|
140
|
+
/** Discriminator */
|
|
141
|
+
command: "dial";
|
|
142
|
+
/** Identifier for this leg (1-32 chars, no whitespace), unique among live legs */
|
|
143
|
+
callName?: string;
|
|
144
|
+
/** Call origin. Optional — on a STREAM leg it is informational only. */
|
|
145
|
+
from?: From;
|
|
146
|
+
/** Call destination */
|
|
147
|
+
to: To;
|
|
148
|
+
/** Seconds to wait for an answer. Maximum 60. */
|
|
149
|
+
dialTimeoutDurationSeconds?: number;
|
|
150
|
+
/** Maximum leg duration in seconds. Maximum 14400. */
|
|
151
|
+
maxCallDurationSeconds?: number;
|
|
152
|
+
/** Per-outcome command sequences */
|
|
153
|
+
events?: CallEvents;
|
|
154
|
+
}
|
|
155
|
+
interface MessagesCommand {
|
|
156
|
+
/** Discriminator */
|
|
157
|
+
command: "messages";
|
|
158
|
+
/** Name used to target this sequence from `stopMessages` */
|
|
159
|
+
messagesName?: string;
|
|
160
|
+
/** Ordered list of messages (1-10) */
|
|
161
|
+
messages: Message[];
|
|
162
|
+
/** Playback outcome handlers */
|
|
163
|
+
events?: {
|
|
164
|
+
/** Runs when every message has finished playing */
|
|
165
|
+
onFinish?: Command[];
|
|
166
|
+
/** Runs when playback fails */
|
|
167
|
+
onFailure?: Command[];
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
interface BridgeCallCommand {
|
|
171
|
+
/** Discriminator */
|
|
172
|
+
command: "bridgeCall";
|
|
173
|
+
/** Bridge name (1-32 chars, no whitespace) */
|
|
174
|
+
bridgeName: string;
|
|
175
|
+
}
|
|
176
|
+
interface HangupCommand {
|
|
177
|
+
/** Discriminator */
|
|
178
|
+
command: "hangup";
|
|
179
|
+
/** Leg to end. Ends the current leg when omitted. */
|
|
180
|
+
callName?: string;
|
|
181
|
+
}
|
|
182
|
+
interface AnswerCommand {
|
|
183
|
+
/** Discriminator */
|
|
184
|
+
command: "answer";
|
|
185
|
+
}
|
|
186
|
+
type MenuInputMethod = "DTMF";
|
|
187
|
+
interface MenuPrompt {
|
|
188
|
+
/** Ordered list of messages to play (1-10) */
|
|
189
|
+
messages: Message[];
|
|
190
|
+
/**
|
|
191
|
+
* Let input cut the prompt short. When disabled, input is still collected during playback
|
|
192
|
+
* and evaluated once it finishes.
|
|
193
|
+
*/
|
|
194
|
+
allowBargeIn?: boolean;
|
|
195
|
+
}
|
|
196
|
+
interface MenuItem {
|
|
197
|
+
/** Played when the menu is entered. Doubles as the repeat prompt when `repeatPrompt` is unset. */
|
|
198
|
+
prompt?: MenuPrompt;
|
|
199
|
+
/** Played again on each retry */
|
|
200
|
+
repeatPrompt?: MenuPrompt;
|
|
201
|
+
/** Seconds to wait for input before the attempt times out. 1-60, default 5. */
|
|
202
|
+
inputTimeoutDurationSeconds?: number;
|
|
203
|
+
/** How many times the menu repeats before `onFail` runs. 0-10, default 2. */
|
|
204
|
+
repeatCount?: number;
|
|
205
|
+
/** Fewest input characters collected before the input is evaluated. 1-100, default 1. */
|
|
206
|
+
minimumInputLength?: number;
|
|
207
|
+
/** Input character count that triggers evaluation. 1-100, default 1. */
|
|
208
|
+
maximumInputLength?: number;
|
|
209
|
+
/**
|
|
210
|
+
* Character sequence that ends input and triggers evaluation immediately, e.g. `#`.
|
|
211
|
+
* Digits, `*` and `#` only, up to 10 characters. Included in the evaluated input.
|
|
212
|
+
*/
|
|
213
|
+
terminatingSequence?: string;
|
|
214
|
+
/** Input methods accepted. Defaults to `['DTMF']`, which is also the only value. */
|
|
215
|
+
inputMethods?: MenuInputMethod[];
|
|
216
|
+
/**
|
|
217
|
+
* Input pattern to command list. Keys may be regular expressions and are evaluated in
|
|
218
|
+
* definition order — see {@link MenuItem} on why key order is load-bearing.
|
|
219
|
+
*/
|
|
220
|
+
matches?: Record<string, Command[]>;
|
|
221
|
+
/** Runs when no match was made within `repeatCount` attempts */
|
|
222
|
+
onFail?: Command[];
|
|
223
|
+
}
|
|
224
|
+
interface MenuCommand {
|
|
225
|
+
/** Discriminator */
|
|
226
|
+
command: "menu";
|
|
227
|
+
/** Menu entered first */
|
|
228
|
+
startMenu: string;
|
|
229
|
+
/** Every menu reachable from this command, by name */
|
|
230
|
+
menus: Record<string, MenuItem>;
|
|
231
|
+
}
|
|
232
|
+
interface GotoMenuCommand {
|
|
233
|
+
/** Discriminator */
|
|
234
|
+
command: "gotoMenu";
|
|
235
|
+
/** Menu to enter, as named in the enclosing `menu` command */
|
|
236
|
+
menuName: string;
|
|
237
|
+
}
|
|
238
|
+
interface PauseCommand {
|
|
239
|
+
/** Discriminator */
|
|
240
|
+
command: "pause";
|
|
241
|
+
/** How long to wait, in milliseconds. Minimum 1. */
|
|
242
|
+
durationMilliseconds: number;
|
|
243
|
+
}
|
|
244
|
+
/** How much of a message sequence `stopMessages` cancels */
|
|
245
|
+
export type StopMessagesFlags = "ONLY_PLAYING" | "ALL_FROM_NOW_ON";
|
|
246
|
+
interface StopMessagesCommand {
|
|
247
|
+
/** Discriminator */
|
|
248
|
+
command: "stopMessages";
|
|
249
|
+
/** Sequence to stop, as named by `messagesName` on the `messages` command */
|
|
250
|
+
messagesName: string;
|
|
251
|
+
/**
|
|
252
|
+
* Whether to stop only the playing message or the whole queue. The platform defaults to
|
|
253
|
+
* `ALL_FROM_NOW_ON`.
|
|
254
|
+
*/
|
|
255
|
+
flags?: StopMessagesFlags;
|
|
256
|
+
}
|
|
257
|
+
interface AmdEvents {
|
|
258
|
+
/** Runs when a human is detected */
|
|
259
|
+
onHuman?: Command[];
|
|
260
|
+
/** Runs when a machine is detected */
|
|
261
|
+
onMachine?: Command[];
|
|
262
|
+
/** Runs when the answering machine's beep is detected */
|
|
263
|
+
onBeep?: Command[];
|
|
264
|
+
/** Runs when detection produced no verdict */
|
|
265
|
+
onUnknown?: Command[];
|
|
266
|
+
}
|
|
267
|
+
interface AmdCommand {
|
|
268
|
+
/** Discriminator */
|
|
269
|
+
command: "amd";
|
|
270
|
+
/** Per-outcome command sequences */
|
|
271
|
+
events?: AmdEvents;
|
|
272
|
+
}
|
|
273
|
+
interface WebhookCommand {
|
|
274
|
+
/** Discriminator */
|
|
275
|
+
command: "webhook";
|
|
276
|
+
/** Name for this webhook event (1-64 chars, no whitespace) */
|
|
277
|
+
webhookName: string;
|
|
278
|
+
/** URL to call. 5-second timeout. */
|
|
279
|
+
url: string;
|
|
280
|
+
/** URL retried immediately when `url` fails */
|
|
281
|
+
fallbackUrl?: string;
|
|
282
|
+
}
|
|
283
|
+
/** Audio format of a recording. The platform defaults to `MP3`. */
|
|
284
|
+
export type RecordingFormat = "MP3" | "WAV";
|
|
285
|
+
/** Which streams a recording captures. The platform defaults to `COMBINED`. */
|
|
286
|
+
export type RecordingType = "COMBINED" | "INBOUND" | "OUTBOUND";
|
|
287
|
+
/** Storage service a recording is delivered to. The platform defaults to `AWS`. */
|
|
288
|
+
export type RecordingDestination = "AWS" | "GCP" | "AZURE";
|
|
289
|
+
interface TranscriptionOptions {
|
|
290
|
+
/** Transcribe the recording to text */
|
|
291
|
+
isEnabled: boolean;
|
|
292
|
+
/** BCP-47 language tag. The platform defaults to `en-US`. */
|
|
293
|
+
locale?: string;
|
|
294
|
+
}
|
|
295
|
+
interface RecordingOptions {
|
|
296
|
+
/** Audio format. The platform defaults to `MP3`. */
|
|
297
|
+
format?: RecordingFormat;
|
|
298
|
+
/** Streams captured. The platform defaults to `COMBINED`. */
|
|
299
|
+
recordingType?: RecordingType;
|
|
300
|
+
/** Storage service. `s3://` for AWS, `gs://` for GCP, `azure://` for Azure. */
|
|
301
|
+
destination: RecordingDestination;
|
|
302
|
+
/** Destination URL, e.g. `s3://voice-recordings-prod/calls` */
|
|
303
|
+
destinationUrl: string;
|
|
304
|
+
/**
|
|
305
|
+
* Colon-delimited credentials for the destination, e.g.
|
|
306
|
+
* `accessKeyId:secretAccessKey:eu-central-1`.
|
|
307
|
+
*
|
|
308
|
+
* As sensitive as an IAM key — see {@link ../commands.js#RecordingCredentials}.
|
|
309
|
+
*/
|
|
310
|
+
credentials: string;
|
|
311
|
+
/** Speech-to-text settings */
|
|
312
|
+
transcriptionOptions?: TranscriptionOptions;
|
|
313
|
+
}
|
|
314
|
+
interface RecordingEvents {
|
|
315
|
+
/**
|
|
316
|
+
* Runs when the recording stops. Does **not** mean the file reached the destination.
|
|
317
|
+
*/
|
|
318
|
+
onFinish?: Command[];
|
|
319
|
+
/** Runs when the recording could not be started */
|
|
320
|
+
onFailure?: Command[];
|
|
321
|
+
}
|
|
322
|
+
interface StartRecordingCommand {
|
|
323
|
+
/** Discriminator */
|
|
324
|
+
command: "startRecording";
|
|
325
|
+
/**
|
|
326
|
+
* Identifier for this recording (1-32 chars, no whitespace). Without it the recording can
|
|
327
|
+
* only be stopped by the call disconnecting.
|
|
328
|
+
*/
|
|
329
|
+
recordingName?: string;
|
|
330
|
+
/** Destination, encoding and transcription */
|
|
331
|
+
recordingOptions: RecordingOptions;
|
|
332
|
+
/** Per-outcome command sequences */
|
|
333
|
+
events?: RecordingEvents;
|
|
334
|
+
}
|
|
335
|
+
interface StopRecordingCommand {
|
|
336
|
+
/** Discriminator */
|
|
337
|
+
command: "stopRecording";
|
|
338
|
+
/** Recording to stop, as named by `recordingName` on the `startRecording` command */
|
|
339
|
+
recordingName: string;
|
|
340
|
+
}
|
|
341
|
+
type Command = DialCommand | MessagesCommand | BridgeCallCommand | HangupCommand | AnswerCommand | MenuCommand | GotoMenuCommand | PauseCommand | StopMessagesCommand | AmdCommand | WebhookCommand | StartRecordingCommand | StopRecordingCommand;
|
|
342
|
+
interface CallRequest {
|
|
343
|
+
/** Ordered command list. At least one command. */
|
|
344
|
+
commands: Command[];
|
|
345
|
+
}
|
|
346
|
+
/** `201` response from `POST /calls` */
|
|
347
|
+
export interface CallResponse {
|
|
348
|
+
/** Project that owns the session */
|
|
349
|
+
projectId: string;
|
|
350
|
+
/** Voice service that handled the request */
|
|
351
|
+
serviceId: string;
|
|
352
|
+
/** Identifier of the created session */
|
|
353
|
+
sessionId: string;
|
|
354
|
+
/** Present only when the request started a batch */
|
|
355
|
+
batchId?: string;
|
|
356
|
+
}
|
|
357
|
+
/** Addresses a live call for a PATCH. Either form is accepted by the API. */
|
|
358
|
+
export type PatchTarget = {
|
|
359
|
+
/** Call id, from a webhook payload or a session lookup */
|
|
360
|
+
callId: string;
|
|
361
|
+
} | {
|
|
362
|
+
/** Session id returned by `POST /calls` */
|
|
363
|
+
sessionId: string;
|
|
364
|
+
/** Leg name within that session */
|
|
365
|
+
callName: string;
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* Webhook event names emitted by Voice API v2.
|
|
369
|
+
*
|
|
370
|
+
* @remarks
|
|
371
|
+
* These are the sixteen names in the spec's event enum (lines 2264-2280), plus the open
|
|
372
|
+
* `call.webhook.<name>` family a `webhook` command raises. Earlier drafts documented a
|
|
373
|
+
* `webhook.` prefix; `Client.onCall` tolerates both.
|
|
374
|
+
*/
|
|
375
|
+
export type EventType = "call.incoming" | "call.answered" | "call.busy" | "call.rejected" | "call.timeout" | "call.hangup" | "call.failed" | "call.amd.human" | "call.amd.machine" | "call.amd.beep" | "call.amd.unknown" | "call.message.finished" | "call.message.failed" | "call.recording.finished" | "call.recording.failed" | "call.menu" | (string & Record<never, never>);
|
|
376
|
+
/** Payload delivered to the webhook endpoint */
|
|
377
|
+
export interface WebhookRequest {
|
|
378
|
+
/** Event that triggered this notification */
|
|
379
|
+
event: EventType;
|
|
380
|
+
/** Current state of the call. Shape varies by event; see the v2 `call` schema. */
|
|
381
|
+
call: Record<string, unknown>;
|
|
382
|
+
/** Present for `call.menu` and for `webhook` commands in a menu context */
|
|
383
|
+
menu?: {
|
|
384
|
+
/** Name of the menu that fired */
|
|
385
|
+
menuName: string;
|
|
386
|
+
/** The input sequence collected from the caller. Required by the schema (spec line 2321). */
|
|
387
|
+
input: string;
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Body returned from a webhook endpoint.
|
|
392
|
+
*
|
|
393
|
+
* @remarks
|
|
394
|
+
* This is an object with a `commands` array, not a bare array.
|
|
395
|
+
*/
|
|
396
|
+
export interface WebhookResponse {
|
|
397
|
+
/** Ordered command list. At least one command. */
|
|
398
|
+
commands: Command[];
|
|
399
|
+
/** Names the inbound leg. Ignored on responses to anything but `call.incoming`. */
|
|
400
|
+
callName?: string;
|
|
401
|
+
/** Call-level event handlers */
|
|
402
|
+
events?: {
|
|
403
|
+
/** Runs when the call hangs up */
|
|
404
|
+
onHangup?: Command[];
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
/** Sample rate used when none is given. Matches the agent SDK's `pcm_16000`, so no resampling. */
|
|
408
|
+
export declare const DEFAULT_SAMPLE_RATE: SampleRate;
|
|
409
|
+
/** TTS voice used when none is given. `voiceName` is required by the API. */
|
|
410
|
+
export declare const DEFAULT_VOICE = "Emma";
|
|
411
|
+
/**
|
|
412
|
+
* Transcription language used when none is given. `sttLanguage` is required on a VOICE_RELAY
|
|
413
|
+
* endpoint (spec line 2948) and is a BCP-47 tag; `en-US` is the schema's own example.
|
|
414
|
+
*/
|
|
415
|
+
export declare const DEFAULT_STT_LANGUAGE = "en-US";
|
|
416
|
+
/** A call destination: an E.164 number, a `sip:`/`wss:` URI, or a full endpoint object. */
|
|
417
|
+
export type Destination = string | To;
|
|
418
|
+
/** A call origin: an E.164 number, a `sip:` URI, or a full endpoint object. */
|
|
419
|
+
export type Origin = string | From;
|
|
420
|
+
/** Custom call headers, as a plain map or as the wire array */
|
|
421
|
+
type Headers$1 = Record<string, string> | CallHeader[];
|
|
422
|
+
/**
|
|
423
|
+
* Build a PHONE destination.
|
|
424
|
+
*
|
|
425
|
+
* @param number - E.164 phone number. Spaces and dashes are stripped.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* dialPhone('+15551234567'); // { type: 'PHONE', phone: { number: '+15551234567' } }
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
export declare function dialPhone(number: string): PhoneEndpoint;
|
|
433
|
+
/**
|
|
434
|
+
* Build a SIP destination.
|
|
435
|
+
*
|
|
436
|
+
* @param address - SIP URI (`sip:` or `sips:`)
|
|
437
|
+
* @param options - Transport protocol and custom SIP headers
|
|
438
|
+
*
|
|
439
|
+
* @example
|
|
440
|
+
* ```typescript
|
|
441
|
+
* dialSip('sip:agent@pbx.example.com', { transport: 'TLS' });
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
export declare function dialSip(address: string, options?: {
|
|
445
|
+
transport?: "UDP" | "TCP" | "TLS";
|
|
446
|
+
headers?: Headers$1;
|
|
447
|
+
}): SipEndpoint;
|
|
448
|
+
/**
|
|
449
|
+
* Build a STREAM destination — a WebSocket leg carrying real-time audio.
|
|
450
|
+
*
|
|
451
|
+
* `streamOptions` is always sent in full, never partially and never omitted: the schema's
|
|
452
|
+
* per-field default is 8 kHz (spec line 2904), which is not what any consumer of a stream
|
|
453
|
+
* this library builds expects.
|
|
454
|
+
*
|
|
455
|
+
* @param endpoint - WebSocket URL (`ws://` or `wss://`) reachable from the public internet
|
|
456
|
+
* @param options - Sample rate, and headers delivered on the WebSocket upgrade and in the `connect` message
|
|
457
|
+
*
|
|
458
|
+
* @example
|
|
459
|
+
* ```typescript
|
|
460
|
+
* dialStream('wss://example.com/audio', { headers: { 'x-contact-id': 'abc123' } });
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
export declare function dialStream(endpoint: string, options?: {
|
|
464
|
+
sampleRate?: SampleRate;
|
|
465
|
+
headers?: Headers$1;
|
|
466
|
+
}): StreamEndpoint;
|
|
467
|
+
/**
|
|
468
|
+
* Build a VOICE_RELAY destination — platform-side STT and TTS, text over the socket.
|
|
469
|
+
*
|
|
470
|
+
* The opposite trade to {@link dialStream}: Sinch owns the audio pipeline and the
|
|
471
|
+
* application never sees a sample. That also means the application never owns the TTS
|
|
472
|
+
* stream, which is why `@sinch/agents` uses STREAM rather than this.
|
|
473
|
+
*
|
|
474
|
+
* @param endpoint - WebSocket URL that accepts the relay connection. Required by the schema.
|
|
475
|
+
* @param options - Platform voice, transcription language, barge-in and headers
|
|
476
|
+
*/
|
|
477
|
+
export declare function dialRelay(endpoint: string, options?: {
|
|
478
|
+
ttsVoice?: string;
|
|
479
|
+
sttLanguage?: string;
|
|
480
|
+
enableInterruptions?: boolean;
|
|
481
|
+
headers?: Headers$1;
|
|
482
|
+
}): VoiceRelayEndpoint;
|
|
483
|
+
/**
|
|
484
|
+
* Anything that can stand in for a command list.
|
|
485
|
+
*
|
|
486
|
+
* Three spellings of one idea, because the six positions read differently: a builder value
|
|
487
|
+
* reads best when a flow is named and reused (`{ onAnswer: greeting }`), a callback reads
|
|
488
|
+
* best when it is defined in place (`.match('1', c => c.dial(sales))`), and a bare array is
|
|
489
|
+
* what hand-written command literals already are. Every nesting point in this module and in
|
|
490
|
+
* {@link ../client.js} takes this same type — that is the consistency that matters, rather
|
|
491
|
+
* than forcing one spelling on positions where it reads badly.
|
|
492
|
+
*/
|
|
493
|
+
export type Flow = CommandBuilder | Command[] | ((builder: CommandBuilder) => CommandBuilder | void);
|
|
494
|
+
/** Options for a single TTS message */
|
|
495
|
+
export interface SayOptions {
|
|
496
|
+
/** Voice name. Defaults to {@link DEFAULT_VOICE}. */
|
|
497
|
+
voiceName?: string;
|
|
498
|
+
/** Set to `SSML` when `text` is an SSML document */
|
|
499
|
+
format?: "TEXT" | "SSML";
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* The six per-outcome command lists on a `dial`.
|
|
503
|
+
*
|
|
504
|
+
* Supplying **any** of them switches the platform out of service-webhook mode for **all**
|
|
505
|
+
* of them — see {@link completeEvents}.
|
|
506
|
+
*/
|
|
507
|
+
export interface DialEvents {
|
|
508
|
+
/**
|
|
509
|
+
* Runs when the leg is answered.
|
|
510
|
+
*
|
|
511
|
+
* Required whenever any other event is named: an `events` block detaches the service
|
|
512
|
+
* webhook from every outcome, so a block without this one answers the leg into silence.
|
|
513
|
+
*/
|
|
514
|
+
onAnswer?: Flow;
|
|
515
|
+
/** Runs when the callee is busy. Defaults to hangup. */
|
|
516
|
+
onBusy?: Flow;
|
|
517
|
+
/** Runs when the callee rejects. Defaults to hangup. */
|
|
518
|
+
onReject?: Flow;
|
|
519
|
+
/** Runs when the dial timeout elapses without an answer. Defaults to hangup. */
|
|
520
|
+
onTimeout?: Flow;
|
|
521
|
+
/** Runs when the leg is hung up. Never defaulted unless `endOnHangup` names another leg. */
|
|
522
|
+
onHangup?: Flow;
|
|
523
|
+
/** Runs when the leg could not be set up. Defaults to hangup. */
|
|
524
|
+
onFailure?: Flow;
|
|
525
|
+
}
|
|
526
|
+
/** Everything a single `dial` command can carry */
|
|
527
|
+
export interface DialOptions extends DialEvents {
|
|
528
|
+
/** Caller identity presented to the callee */
|
|
529
|
+
from?: Origin;
|
|
530
|
+
/** Seconds to wait for an answer. Maximum 60. */
|
|
531
|
+
timeout?: number;
|
|
532
|
+
/** Maximum call duration in seconds. Maximum 14400. */
|
|
533
|
+
maxDuration?: number;
|
|
534
|
+
/** Identifier for this leg (1-32 chars, no whitespace), unique among live legs */
|
|
535
|
+
callName?: string;
|
|
536
|
+
/**
|
|
537
|
+
* Leg to end when *this* leg hangs up after connecting.
|
|
538
|
+
*
|
|
539
|
+
* This is the only thing that makes `onHangup` default at all. On a single-leg call there
|
|
540
|
+
* is nothing to end — the call is already over — so leaving this unset is what "onHangup
|
|
541
|
+
* is not defaulted" means in code.
|
|
542
|
+
*/
|
|
543
|
+
endOnHangup?: string;
|
|
544
|
+
/**
|
|
545
|
+
* Leg to end when this leg *never connects* — busy, rejected, timed out or failed.
|
|
546
|
+
*
|
|
547
|
+
* Unset means end this leg, which is right for the first leg of a call: whatever it would
|
|
548
|
+
* have been bridged to has not been dialled yet.
|
|
549
|
+
*/
|
|
550
|
+
endOnFailure?: string;
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* The four answering-machine-detection outcomes.
|
|
554
|
+
*
|
|
555
|
+
* @remarks
|
|
556
|
+
* These are the AMD *result* events, not a `dial`'s six lifecycle events: they mean the call is
|
|
557
|
+
* up and something answered, so none of them is a failure and none gets a hangup default.
|
|
558
|
+
*
|
|
559
|
+
* **They do share `dial`'s all-or-nothing rule.** Confirmed in `calling-ng`,
|
|
560
|
+
* `Svaml/Visitors/AddCallBehaviorWebhookVisitor.cs` (`Visit(Amd)`) with
|
|
561
|
+
* `Svaml/SvamlCommandFactory.cs` (`new Amd(command.Events is not null)`): sending an `events`
|
|
562
|
+
* object detaches the service webhook from **all four** outcomes, so naming `onHuman` alone
|
|
563
|
+
* silently stops machine, beep and unknown from being handled by anything. Nothing errors.
|
|
564
|
+
*
|
|
565
|
+
* The builder answers that by always emitting a complete four-outcome block once any one is
|
|
566
|
+
* named — see {@link completeAmdEvents} for why the unnamed ones default to an empty list and
|
|
567
|
+
* what that does and does not buy. Name all four, or name none and let the service webhook take
|
|
568
|
+
* `call.amd.*`.
|
|
569
|
+
*/
|
|
570
|
+
export interface AmdEventOptions {
|
|
571
|
+
/** Runs when a human is detected */
|
|
572
|
+
onHuman?: Flow;
|
|
573
|
+
/** Runs when a machine is detected */
|
|
574
|
+
onMachine?: Flow;
|
|
575
|
+
/** Runs when the answering machine's beep is detected */
|
|
576
|
+
onBeep?: Flow;
|
|
577
|
+
/** Runs when detection produced no verdict */
|
|
578
|
+
onUnknown?: Flow;
|
|
579
|
+
}
|
|
580
|
+
/** Options for a `webhook` command */
|
|
581
|
+
export interface WebhookOptions {
|
|
582
|
+
/**
|
|
583
|
+
* URL retried immediately when the primary URL fails. After repeated consecutive failures
|
|
584
|
+
* the platform sends only here until the primary recovers.
|
|
585
|
+
*/
|
|
586
|
+
fallbackUrl?: string;
|
|
587
|
+
}
|
|
588
|
+
/**
|
|
589
|
+
* Credentials for the storage service a recording is delivered to.
|
|
590
|
+
*
|
|
591
|
+
* @remarks
|
|
592
|
+
* **This is a long-lived secret travelling inside a call flow.** The v2 schema takes the
|
|
593
|
+
* credential as one required colon-delimited string on the `startRecording` command, so it is
|
|
594
|
+
* present in the `POST /calls` body, in any webhook response or `PATCH` that starts a
|
|
595
|
+
* recording, and in every copy of those a log or an error message makes. There is no
|
|
596
|
+
* presigned-URL form and no STS session-token slot — the third component is the region, not a
|
|
597
|
+
* token — so the value cannot be made short-lived and must be treated as being exactly as
|
|
598
|
+
* sensitive as the IAM key it contains.
|
|
599
|
+
*
|
|
600
|
+
* Take it structured, as here, rather than concatenating secrets at the call site, and log
|
|
601
|
+
* v2 bodies only through `redactCredentials`. The client scrubs it out of API error text on
|
|
602
|
+
* its own, which is the one path that would otherwise carry it into a stack trace.
|
|
603
|
+
*
|
|
604
|
+
* @example
|
|
605
|
+
* ```typescript
|
|
606
|
+
* { accessKeyId: 'AKIA...', secretAccessKey: process.env.RECORDING_SECRET!, region: 'eu-central-1' }
|
|
607
|
+
* // → 'AKIA...:<secret>:eu-central-1'
|
|
608
|
+
* ```
|
|
609
|
+
*/
|
|
610
|
+
export interface RecordingCredentials {
|
|
611
|
+
/** Access key id */
|
|
612
|
+
accessKeyId: string;
|
|
613
|
+
/** Secret access key. The sensitive half. */
|
|
614
|
+
secretAccessKey: string;
|
|
615
|
+
/** Storage region, e.g. `eu-central-1` */
|
|
616
|
+
region: string;
|
|
617
|
+
}
|
|
618
|
+
/** Everything a `startRecording` command can carry */
|
|
619
|
+
export interface StartRecordingOptions {
|
|
620
|
+
/** Destination URL, e.g. `s3://voice-recordings-prod/calls` */
|
|
621
|
+
destinationUrl: string;
|
|
622
|
+
/**
|
|
623
|
+
* Credentials for the destination. Prefer the structured form; the raw colon-delimited
|
|
624
|
+
* string is there for credential formats this library does not model.
|
|
625
|
+
*/
|
|
626
|
+
credentials: RecordingCredentials | string;
|
|
627
|
+
/**
|
|
628
|
+
* Storage service. Defaults to `AWS`, and is always emitted — the schema lists
|
|
629
|
+
* `destination` as required, whatever its documented default.
|
|
630
|
+
*/
|
|
631
|
+
destination?: RecordingDestination;
|
|
632
|
+
/**
|
|
633
|
+
* Identifier for this recording (1-32 chars, no whitespace). Without it the recording can
|
|
634
|
+
* only be stopped by the call disconnecting, never by {@link CommandBuilder.stopRecording}.
|
|
635
|
+
*/
|
|
636
|
+
recordingName?: string;
|
|
637
|
+
/** Audio format. The platform defaults to `MP3`; omitted from the body when unset. */
|
|
638
|
+
format?: RecordingFormat;
|
|
639
|
+
/** Streams captured. The platform defaults to `COMBINED`; omitted from the body when unset. */
|
|
640
|
+
recordingType?: RecordingType;
|
|
641
|
+
/**
|
|
642
|
+
* Transcribe the recording to text. Setting this, or {@link transcriptionLocale}, emits
|
|
643
|
+
* `transcriptionOptions`; a locale on its own implies `isEnabled: true`.
|
|
644
|
+
*/
|
|
645
|
+
transcribe?: boolean;
|
|
646
|
+
/** BCP-47 language tag for transcription. The platform defaults to `en-US`. */
|
|
647
|
+
transcriptionLocale?: string;
|
|
648
|
+
/**
|
|
649
|
+
* Runs when the recording stops. Note this fires on *stop*, not on delivery — the file may
|
|
650
|
+
* still be in flight to the destination.
|
|
651
|
+
*
|
|
652
|
+
* Unlike a `dial` or an `amd`, naming neither this nor {@link onFailure} does **not** hand the
|
|
653
|
+
* outcome to the service webhook — see {@link RecordingEvents}. Nothing is emitted
|
|
654
|
+
* and nothing is notified.
|
|
655
|
+
*/
|
|
656
|
+
onFinish?: Flow;
|
|
657
|
+
/**
|
|
658
|
+
* Runs when the recording could not be started. The only way to hear about a failed recording:
|
|
659
|
+
* there is no service-webhook fallback for this command.
|
|
660
|
+
*/
|
|
661
|
+
onFailure?: Flow;
|
|
662
|
+
}
|
|
663
|
+
/** Anything that can stand in for a menu prompt: a builder, a callback, or plain text. */
|
|
664
|
+
export type PromptFlow = string | PromptBuilder | ((prompt: PromptBuilder) => PromptBuilder | void);
|
|
665
|
+
/** Collects the messages a menu plays, and whether a keypress may cut them short. */
|
|
666
|
+
export declare class PromptBuilder {
|
|
667
|
+
private readonly messages;
|
|
668
|
+
private barge;
|
|
669
|
+
/**
|
|
670
|
+
* Speak text.
|
|
671
|
+
*
|
|
672
|
+
* @param text - Text to synthesise, or an SSML document when `format` is `SSML`
|
|
673
|
+
* @param options - Voice and format overrides
|
|
674
|
+
*/
|
|
675
|
+
say(text: string, options?: SayOptions): this;
|
|
676
|
+
/**
|
|
677
|
+
* Play an audio file.
|
|
678
|
+
*
|
|
679
|
+
* @param url - Publicly reachable URL of the audio file
|
|
680
|
+
*/
|
|
681
|
+
play(url: string): this;
|
|
682
|
+
/**
|
|
683
|
+
* Let input interrupt the prompt instead of waiting for it to finish. Emits
|
|
684
|
+
* `allowBargeIn`, which the platform defaults to `true`.
|
|
685
|
+
*
|
|
686
|
+
* @param enabled - Pass `false` to state the opposite explicitly
|
|
687
|
+
*/
|
|
688
|
+
bargeIn(enabled?: boolean): this;
|
|
689
|
+
/** Emit the prompt. @throws If nothing was queued to play */
|
|
690
|
+
build(): MenuPrompt;
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* One named menu: a prompt, the input rules, and what each input does.
|
|
694
|
+
*
|
|
695
|
+
* A menu that defines neither `match()` nor `onFail()` falls through to the service webhook
|
|
696
|
+
* with the collected input, arriving as `call.menu`.
|
|
697
|
+
*/
|
|
698
|
+
export declare class MenuItemBuilder {
|
|
699
|
+
private readonly item;
|
|
700
|
+
private readonly matchOrder;
|
|
701
|
+
private readonly matches;
|
|
702
|
+
/**
|
|
703
|
+
* Prompt played when the menu is entered.
|
|
704
|
+
*
|
|
705
|
+
* @param prompt - Plain text, a {@link PromptBuilder}, or a callback receiving one
|
|
706
|
+
*/
|
|
707
|
+
prompt(prompt: PromptFlow): this;
|
|
708
|
+
/**
|
|
709
|
+
* Prompt played on each retry. Falls back to `prompt` when unset.
|
|
710
|
+
*
|
|
711
|
+
* @param prompt - Plain text, a {@link PromptBuilder}, or a callback receiving one
|
|
712
|
+
*/
|
|
713
|
+
repeatPrompt(prompt: PromptFlow): this;
|
|
714
|
+
/**
|
|
715
|
+
* How long to wait for input before repeating.
|
|
716
|
+
*
|
|
717
|
+
* @param seconds - Seconds of silence that count as no input
|
|
718
|
+
*/
|
|
719
|
+
inputTimeout(seconds: number): this;
|
|
720
|
+
/**
|
|
721
|
+
* How many times the prompt repeats before `onFail` runs.
|
|
722
|
+
*
|
|
723
|
+
* @param times - Repeat count
|
|
724
|
+
*/
|
|
725
|
+
repeatCount(times: number): this;
|
|
726
|
+
/**
|
|
727
|
+
* Fewest input characters collected before the menu evaluates them. Emits
|
|
728
|
+
* `minimumInputLength`. 1-100, default 1.
|
|
729
|
+
*
|
|
730
|
+
* @param count - Minimum input length
|
|
731
|
+
*/
|
|
732
|
+
minLength(count: number): this;
|
|
733
|
+
/**
|
|
734
|
+
* Input character count that triggers evaluation. Emits `maximumInputLength`. 1-100,
|
|
735
|
+
* default 1.
|
|
736
|
+
*
|
|
737
|
+
* @param count - Maximum input length
|
|
738
|
+
*/
|
|
739
|
+
maxLength(count: number): this;
|
|
740
|
+
/**
|
|
741
|
+
* Character sequence that ends input and triggers evaluation immediately, e.g. `#`.
|
|
742
|
+
*
|
|
743
|
+
* The pair to {@link maxLength}: with a range of accepted lengths, this is how a shorter
|
|
744
|
+
* entry is submitted without waiting out `inputTimeout`. The sequence itself is part of
|
|
745
|
+
* the input the `matches` keys see.
|
|
746
|
+
*
|
|
747
|
+
* @param sequence - Digits, `*` and `#` only, up to 10 characters
|
|
748
|
+
*/
|
|
749
|
+
terminatedBy(sequence: string): this;
|
|
750
|
+
/**
|
|
751
|
+
* What one input does.
|
|
752
|
+
*
|
|
753
|
+
* Keys may be literal digits or regular expressions, and the platform evaluates them in
|
|
754
|
+
* definition order with first match winning — so the order these are written in is part of
|
|
755
|
+
* the behaviour, not decoration. {@link build} refuses to emit a menu whose keys JSON
|
|
756
|
+
* cannot carry in that order; see the error it throws.
|
|
757
|
+
*
|
|
758
|
+
* @param pattern - Digits, or a regular expression source
|
|
759
|
+
* @param flow - Commands to run on a match
|
|
760
|
+
*/
|
|
761
|
+
match(pattern: string, flow: Flow): this;
|
|
762
|
+
/**
|
|
763
|
+
* Commands to run once the caller is out of attempts.
|
|
764
|
+
*
|
|
765
|
+
* @param flow - Commands to run
|
|
766
|
+
*/
|
|
767
|
+
onFail(flow: Flow): this;
|
|
768
|
+
/**
|
|
769
|
+
* Emit the menu.
|
|
770
|
+
*
|
|
771
|
+
* @throws If the `matches` keys cannot be serialised in the order they were written
|
|
772
|
+
*/
|
|
773
|
+
build(): MenuItem;
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* Ordered `svamlCommands` list.
|
|
777
|
+
*
|
|
778
|
+
* Commands come out in the order they were written. Consecutive `say` and `play` calls
|
|
779
|
+
* collect into one `messages` command — `messages` is non-blocking in v2, so two separate
|
|
780
|
+
* commands would play over each other instead of in sequence.
|
|
781
|
+
*
|
|
782
|
+
* A `hangup()` written directly after messages rides those messages' `onFinish`. That is how
|
|
783
|
+
* "say this, then hang up" is expressed against a non-blocking command: a standalone `hangup`
|
|
784
|
+
* queued next would fire while the audio was still playing. Written anywhere else it is a
|
|
785
|
+
* plain `hangup` command in exactly that position, so `hangup().say('x')` emits hangup then
|
|
786
|
+
* say — literally what it reads, and, as written, never reached on a live call.
|
|
787
|
+
*/
|
|
788
|
+
export declare class CommandBuilder {
|
|
789
|
+
private readonly list;
|
|
790
|
+
private readonly pending;
|
|
791
|
+
/**
|
|
792
|
+
* Speak text on the call.
|
|
793
|
+
*
|
|
794
|
+
* @param text - Text to synthesise, or an SSML document when `format` is `SSML`
|
|
795
|
+
* @param options - Voice and format overrides
|
|
796
|
+
*/
|
|
797
|
+
say(text: string, options?: SayOptions): this;
|
|
798
|
+
/**
|
|
799
|
+
* Play an audio file on the call.
|
|
800
|
+
*
|
|
801
|
+
* @param url - Publicly reachable URL of the audio file
|
|
802
|
+
*/
|
|
803
|
+
play(url: string): this;
|
|
804
|
+
/**
|
|
805
|
+
* End the call at this point in the sequence.
|
|
806
|
+
*
|
|
807
|
+
* Messages queued before it still play in full — and end the call whether they finish or
|
|
808
|
+
* fail, since a failed playback would otherwise leave the call with nothing to do.
|
|
809
|
+
* Anything queued after it is emitted after it, and on a live call is never reached.
|
|
810
|
+
*
|
|
811
|
+
* @param callName - Leg to end. Ends the current leg when omitted.
|
|
812
|
+
*/
|
|
813
|
+
hangup(callName?: string): this;
|
|
814
|
+
/** Explicitly answer an inbound leg. */
|
|
815
|
+
answer(): this;
|
|
816
|
+
/**
|
|
817
|
+
* Add the current leg to a named bridge, creating the bridge on first reference.
|
|
818
|
+
*
|
|
819
|
+
* @param bridgeName - Bridge name (1-32 chars, no whitespace)
|
|
820
|
+
*/
|
|
821
|
+
bridgeCall(bridgeName: string): this;
|
|
822
|
+
/**
|
|
823
|
+
* Dial another leg. Non-blocking — two dials in one list ring two legs in parallel.
|
|
824
|
+
*
|
|
825
|
+
* @param to - Who to call
|
|
826
|
+
* @param options - Dial settings, named events and leg topology
|
|
827
|
+
*/
|
|
828
|
+
dial(to: Destination, options?: DialOptions): this;
|
|
829
|
+
/**
|
|
830
|
+
* Collect DTMF input against a named menu. Blocking.
|
|
831
|
+
*
|
|
832
|
+
* Consecutive `menu()` calls extend one `menu` command, so a multi-level IVR is written as
|
|
833
|
+
* a run of them and `gotoMenu` jumps between the names. The first one names `startMenu`.
|
|
834
|
+
* Anything written between two menus (a `say`, a `dial`) breaks the run, and the next
|
|
835
|
+
* `menu()` starts a second command — the list stays in the order it was written.
|
|
836
|
+
*
|
|
837
|
+
* @param name - Menu name, referenced by {@link gotoMenu} and reported on `call.menu`
|
|
838
|
+
* @param define - Callback receiving the {@link MenuItemBuilder} for this menu
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```typescript
|
|
842
|
+
* commands().menu('main', (m) =>
|
|
843
|
+
* m
|
|
844
|
+
* .prompt((p) => p.say('Press 1 for sales or 2 for support').bargeIn())
|
|
845
|
+
* .match('1', (c) => c.dial(sales))
|
|
846
|
+
* .match('2', (c) => c.dial(support))
|
|
847
|
+
* .onFail((c) => c.say('Sorry, goodbye').hangup())
|
|
848
|
+
* );
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
menu(name: string, define: (menu: MenuItemBuilder) => MenuItemBuilder | void): this;
|
|
852
|
+
/**
|
|
853
|
+
* Jump to another menu in the enclosing `menu` command. Legal only inside menu execution.
|
|
854
|
+
*
|
|
855
|
+
* @param menuName - Menu to enter
|
|
856
|
+
*/
|
|
857
|
+
gotoMenu(menuName: string): this;
|
|
858
|
+
/**
|
|
859
|
+
* Wait before running the next command. Blocking.
|
|
860
|
+
*
|
|
861
|
+
* The call stays connected and audio is unaffected — this delays the *script*, not the
|
|
862
|
+
* media. So it is the way to let a non-blocking command get somewhere before the next one
|
|
863
|
+
* runs: a beat after `amd` reports a beep, before the message that leaves the voicemail.
|
|
864
|
+
*
|
|
865
|
+
* @param durationMilliseconds - How long to wait, in milliseconds. Minimum 1.
|
|
866
|
+
* @throws If the duration is below the schema's minimum of 1
|
|
867
|
+
*/
|
|
868
|
+
pause(durationMilliseconds: number): this;
|
|
869
|
+
/**
|
|
870
|
+
* Stop a named `messages` sequence. Non-blocking.
|
|
871
|
+
*
|
|
872
|
+
* Targets a sequence by the `messagesName` it was started under, so it is only reachable
|
|
873
|
+
* from a later command list — a `PATCH` on a live call, or a `dial` event — never from the
|
|
874
|
+
* same list that queued the messages.
|
|
875
|
+
*
|
|
876
|
+
* @param messagesName - Sequence to stop (1-32 chars, no whitespace)
|
|
877
|
+
* @param flags - `ONLY_PLAYING` cancels the current message and lets the queue continue.
|
|
878
|
+
* Omitted, the platform applies `ALL_FROM_NOW_ON` and the whole queue goes.
|
|
879
|
+
*/
|
|
880
|
+
stopMessages(messagesName: string, flags?: StopMessagesFlags): this;
|
|
881
|
+
/**
|
|
882
|
+
* Run answering machine detection on the call. Non-blocking.
|
|
883
|
+
*
|
|
884
|
+
* Detection runs in parallel with the rest of the list; the verdict arrives on one of the
|
|
885
|
+
* four events, or — with no events named — as a `call.amd.*` webhook.
|
|
886
|
+
*
|
|
887
|
+
* These four are the AMD *result* outcomes, so none of them gets a hangup default the way a
|
|
888
|
+
* `dial`'s never-connected outcomes do. They do follow `dial`'s all-or-nothing rule: naming
|
|
889
|
+
* any one of them detaches the service webhook from all four, so this emits a **complete**
|
|
890
|
+
* block once any is named, with the rest as empty lists. Confirmed in `calling-ng` — see
|
|
891
|
+
* {@link AmdEventOptions}.
|
|
892
|
+
*
|
|
893
|
+
* @param events - Commands to run per detection outcome. Omit entirely for webhook mode.
|
|
894
|
+
*
|
|
895
|
+
* @example
|
|
896
|
+
* ```typescript
|
|
897
|
+
* commands()
|
|
898
|
+
* .amd({
|
|
899
|
+
* onHuman: (c) => c.say('Hi, do you have a moment?'),
|
|
900
|
+
* onMachine: (c) => c.say('Sorry we missed you.').hangup(),
|
|
901
|
+
* onBeep: (c) => c.pause(500).say('Sorry we missed you.').hangup(),
|
|
902
|
+
* onUnknown: (c) => c.say('Hi, do you have a moment?'),
|
|
903
|
+
* })
|
|
904
|
+
* .say('Connecting you now.');
|
|
905
|
+
*
|
|
906
|
+
* // Naming none of them leaves all four to the service webhook as `call.amd.*`.
|
|
907
|
+
* commands().amd();
|
|
908
|
+
* ```
|
|
909
|
+
*/
|
|
910
|
+
amd(events?: AmdEventOptions): this;
|
|
911
|
+
/**
|
|
912
|
+
* Ask the application what to do next. **Blocking** — the call waits for the response.
|
|
913
|
+
*
|
|
914
|
+
* The event is delivered as `call.webhook.<webhookName>`, so `webhookName: 'escalate'`
|
|
915
|
+
* arrives as `'call.webhook.escalate'`. `Client.onCall` routes those by name to a handler
|
|
916
|
+
* registered under `webhooks`, and to `manage` when no name matches.
|
|
917
|
+
*
|
|
918
|
+
* @param webhookName - Name for this event (1-64 chars, no whitespace)
|
|
919
|
+
* @param url - URL to call. The platform allows it 5 seconds to answer.
|
|
920
|
+
* @param options - Fallback URL
|
|
921
|
+
*
|
|
922
|
+
* @example
|
|
923
|
+
* ```typescript
|
|
924
|
+
* commands().say('One moment.').webhook('escalate', 'https://acme.com/voice');
|
|
925
|
+
*
|
|
926
|
+
* export const handler = voice.onCall({
|
|
927
|
+
* webhooks: { escalate: () => commands().dial('+15550001111') },
|
|
928
|
+
* });
|
|
929
|
+
* ```
|
|
930
|
+
*/
|
|
931
|
+
webhook(webhookName: string, url: string, options?: WebhookOptions): this;
|
|
932
|
+
/**
|
|
933
|
+
* Start recording the call. Non-blocking.
|
|
934
|
+
*
|
|
935
|
+
* **The credential is a long-lived storage secret carried inside the command body** — the
|
|
936
|
+
* schema requires it and offers no short-lived alternative. See {@link RecordingCredentials}
|
|
937
|
+
* before logging anything a `startRecording` is part of.
|
|
938
|
+
*
|
|
939
|
+
* @param options - Destination, credentials, encoding, transcription and outcome events
|
|
940
|
+
* @throws If a structured credential component contains a colon
|
|
941
|
+
*
|
|
942
|
+
* @example
|
|
943
|
+
* ```typescript
|
|
944
|
+
* commands().startRecording({
|
|
945
|
+
* recordingName: 'support',
|
|
946
|
+
* destinationUrl: 's3://voice-recordings-prod/calls',
|
|
947
|
+
* credentials: {
|
|
948
|
+
* accessKeyId: process.env.RECORDING_KEY_ID!,
|
|
949
|
+
* secretAccessKey: process.env.RECORDING_SECRET!,
|
|
950
|
+
* region: 'eu-central-1',
|
|
951
|
+
* },
|
|
952
|
+
* transcribe: true,
|
|
953
|
+
* });
|
|
954
|
+
* ```
|
|
955
|
+
*/
|
|
956
|
+
startRecording(options: StartRecordingOptions): this;
|
|
957
|
+
/**
|
|
958
|
+
* Stop a named recording. Non-blocking.
|
|
959
|
+
*
|
|
960
|
+
* A recording started without a `recordingName` cannot be targeted at all — it ends when
|
|
961
|
+
* the call disconnects and not before.
|
|
962
|
+
*
|
|
963
|
+
* @param recordingName - Recording to stop (1-32 chars, no whitespace)
|
|
964
|
+
*/
|
|
965
|
+
stopRecording(recordingName: string): this;
|
|
966
|
+
/**
|
|
967
|
+
* Append a hand-built command — the escape hatch for anything not modelled here.
|
|
968
|
+
*
|
|
969
|
+
* @param commands - Commands to append, in order
|
|
970
|
+
*/
|
|
971
|
+
add(...commands: Command[]): this;
|
|
972
|
+
/**
|
|
973
|
+
* Emit the command list.
|
|
974
|
+
*
|
|
975
|
+
* Repeatable and non-consuming: the builder is a description of a flow, not a one-shot
|
|
976
|
+
* handle, so the same one can be sent twice or nested in two places.
|
|
977
|
+
*/
|
|
978
|
+
build(): Command[];
|
|
979
|
+
private push;
|
|
980
|
+
private flush;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Start a command list.
|
|
984
|
+
*
|
|
985
|
+
* @example
|
|
986
|
+
* ```typescript
|
|
987
|
+
* const flow = commands().say('One moment, connecting you').bridgeCall('support');
|
|
988
|
+
* ```
|
|
989
|
+
*/
|
|
990
|
+
export declare function commands(): CommandBuilder;
|
|
991
|
+
/**
|
|
992
|
+
* Emit-target-agnostic description of a call flow.
|
|
993
|
+
*
|
|
994
|
+
* Build one of these with the client's planning methods, then hand it to
|
|
995
|
+
* {@link toCallRequest} or {@link toWebhookResponse}.
|
|
996
|
+
*/
|
|
997
|
+
export interface Plan {
|
|
998
|
+
/** Ordered command list. Must contain at least one command. */
|
|
999
|
+
commands: Command[];
|
|
1000
|
+
/**
|
|
1001
|
+
* Name for the inbound leg. Webhook responses only — the API ignores it
|
|
1002
|
+
* everywhere except a response to `call.incoming`, and `POST /calls` rejects it.
|
|
1003
|
+
*/
|
|
1004
|
+
callName?: string;
|
|
1005
|
+
/**
|
|
1006
|
+
* Commands to run when the call hangs up. Webhook responses only; on a
|
|
1007
|
+
* call-create body the equivalent lives on the `dial` command's `events`.
|
|
1008
|
+
*/
|
|
1009
|
+
onHangup?: Command[];
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Emit a plan as a `POST /v2/projects/{projectId}/calls` body.
|
|
1013
|
+
*
|
|
1014
|
+
* Drops `callName` and `onHangup`: the `callRequest` schema forbids them and the
|
|
1015
|
+
* API rejects unknown keys with a 400.
|
|
1016
|
+
*
|
|
1017
|
+
* @param plan - Call flow to serialise
|
|
1018
|
+
* @throws If the plan has no commands
|
|
1019
|
+
*
|
|
1020
|
+
* @example
|
|
1021
|
+
* ```typescript
|
|
1022
|
+
* const body = toCallRequest({ commands: [{ command: 'hangup' }] });
|
|
1023
|
+
* // { commands: [{ command: 'hangup' }] }
|
|
1024
|
+
* ```
|
|
1025
|
+
*/
|
|
1026
|
+
export declare function toCallRequest(plan: Plan): CallRequest;
|
|
1027
|
+
/**
|
|
1028
|
+
* Emit a plan as a webhook-response body.
|
|
1029
|
+
*
|
|
1030
|
+
* The response is an object wrapping a `commands` array, not a bare array.
|
|
1031
|
+
*
|
|
1032
|
+
* @param plan - Call flow to serialise
|
|
1033
|
+
* @throws If the plan has no commands
|
|
1034
|
+
*
|
|
1035
|
+
* @example
|
|
1036
|
+
* ```typescript
|
|
1037
|
+
* const body = toWebhookResponse({
|
|
1038
|
+
* commands: [{ command: 'answer' }],
|
|
1039
|
+
* callName: 'incoming',
|
|
1040
|
+
* onHangup: [{ command: 'hangup' }],
|
|
1041
|
+
* });
|
|
1042
|
+
* // { commands: [...], callName: 'incoming', events: { onHangup: [...] } }
|
|
1043
|
+
* ```
|
|
1044
|
+
*/
|
|
1045
|
+
export declare function toWebhookResponse(plan: Plan): WebhookResponse;
|
|
1046
|
+
/**
|
|
1047
|
+
* The bridge every call this package builds joins unless told otherwise.
|
|
1048
|
+
*
|
|
1049
|
+
* Lives here rather than in `client.ts` because both the transfer builder and the client
|
|
1050
|
+
* need it, and the client is the one that imports — the other direction would be a cycle.
|
|
1051
|
+
*/
|
|
1052
|
+
export declare const DEFAULT_BRIDGE_NAME = "bridge";
|
|
1053
|
+
/** Name given to the leg a transfer dials, when the caller does not name it. */
|
|
1054
|
+
export declare const DEFAULT_TRANSFER_LEG = "transfer";
|
|
1055
|
+
/** Options for {@link buildTransferCommands} and {@link Client.transfer}. */
|
|
1056
|
+
export interface TransferOptions {
|
|
1057
|
+
/**
|
|
1058
|
+
* Bridge the live legs are already joined in. Defaults to {@link DEFAULT_BRIDGE_NAME}.
|
|
1059
|
+
*
|
|
1060
|
+
* Bridges are **session-scoped**, so this default is safe rather than merely convenient:
|
|
1061
|
+
* `bridgeCall` joins the current call to a bridge "in the same session", and the session
|
|
1062
|
+
* is pinned by the patch target. Two unrelated calls both defaulting to `bridge` are in
|
|
1063
|
+
* two different sessions and therefore two different bridges — there is no way for the
|
|
1064
|
+
* default to connect strangers.
|
|
1065
|
+
*
|
|
1066
|
+
* Pass it explicitly for a call whose bridge was named — `bridgeName` on `bridge()`,
|
|
1067
|
+
* `callWithStream()` or `callWithRelay()` — or for a call this package did not place.
|
|
1068
|
+
* Getting it wrong is quiet: the new leg lands in a freshly created, empty bridge and
|
|
1069
|
+
* hears silence, since the platform creates a bridge on demand rather than failing.
|
|
1070
|
+
*/
|
|
1071
|
+
bridgeName?: string;
|
|
1072
|
+
/** Caller identity presented to the party being dialled */
|
|
1073
|
+
from?: Origin;
|
|
1074
|
+
/** Seconds to wait for an answer. Defaults to 30; the platform maximum is 60. */
|
|
1075
|
+
timeout?: number;
|
|
1076
|
+
/**
|
|
1077
|
+
* Name for the new leg. Defaults to {@link DEFAULT_TRANSFER_LEG}.
|
|
1078
|
+
*
|
|
1079
|
+
* Must be unique among the session's live legs. Name it when something downstream reads
|
|
1080
|
+
* leg names off the webhook payload and has to tell this leg apart from the rest.
|
|
1081
|
+
*/
|
|
1082
|
+
callName?: string;
|
|
1083
|
+
/**
|
|
1084
|
+
* Leg to end when the dialled party never answers — busy, rejected, timed out, failed —
|
|
1085
|
+
* or hangs up after the handover.
|
|
1086
|
+
*
|
|
1087
|
+
* The one thing this operation cannot infer, and the one that matters most. See
|
|
1088
|
+
* {@link buildTransferCommands} for what happens when it is left unset.
|
|
1089
|
+
*/
|
|
1090
|
+
endLeg?: string;
|
|
1091
|
+
}
|
|
1092
|
+
/**
|
|
1093
|
+
* Commands that dial a party into a live call's existing bridge.
|
|
1094
|
+
*
|
|
1095
|
+
* The new leg joins the bridge the call is already using, so everything already on it stays
|
|
1096
|
+
* attached. There is deliberately no leading `bridgeCall`: that would *move* the addressed
|
|
1097
|
+
* leg into a new bridge and drop whoever it is currently talking to. The bridge already
|
|
1098
|
+
* exists — the new leg just joins it.
|
|
1099
|
+
*
|
|
1100
|
+
* Every outcome that is not an answer ends {@link TransferOptions.endLeg}, and so does the
|
|
1101
|
+
* dialled party hanging up afterwards. That is the whole reason this is a helper rather than
|
|
1102
|
+
* four inline lines. Somebody has just been told they are being put through; without it a
|
|
1103
|
+
* busy or unanswered number leaves them on a live, billed call with nobody on the other side
|
|
1104
|
+
* of the bridge and no command left to run — silence until they hang up themselves. Which
|
|
1105
|
+
* leg to end is caller-specific — for an agent it is the media leg, whose own `onHangup`
|
|
1106
|
+
* cascades and ends the call — so it is an option rather than a guess.
|
|
1107
|
+
*
|
|
1108
|
+
* Leaving it unset does not hand the outcome back to the service webhook: naming `onAnswer`
|
|
1109
|
+
* has already detached the webhook from all six outcomes, so the four failures fall to a bare
|
|
1110
|
+
* hangup of the leg that never connected and `onHangup` is not emitted at all. That is the
|
|
1111
|
+
* stranding case above. Set it unless you have arranged for something else to end the call.
|
|
1112
|
+
*
|
|
1113
|
+
* `onHangup` is the one an earlier version of this omitted, which left a complete-looking
|
|
1114
|
+
* events block that was not one: naming any outcome detaches the service webhook from *all*
|
|
1115
|
+
* of them, so the unnamed ones reached nothing at all.
|
|
1116
|
+
*
|
|
1117
|
+
* @param to - Party to dial: an E.164 number, a `sip:` URI, or an endpoint object
|
|
1118
|
+
* @param options - Bridge, caller id, dial timeout, leg names
|
|
1119
|
+
*
|
|
1120
|
+
* @example
|
|
1121
|
+
* ```typescript
|
|
1122
|
+
* const commands = buildTransferCommands('+15550001111', { endLeg: 'origin' });
|
|
1123
|
+
* await client.patch({ sessionId, callName: 'origin' }, commands);
|
|
1124
|
+
* ```
|
|
1125
|
+
*/
|
|
1126
|
+
export declare function buildTransferCommands(to: Destination, options?: TransferOptions): Command[];
|
|
1127
|
+
/** Construction options for {@link Client} */
|
|
1128
|
+
export interface Options {
|
|
1129
|
+
/** Sinch project id. Defaults to `PROJECT_ID`, then `context.config.projectId`. */
|
|
1130
|
+
projectId?: string;
|
|
1131
|
+
/** Access Key ID (Basic auth username). Defaults to `PROJECT_ID_API_KEY`. */
|
|
1132
|
+
keyId?: string;
|
|
1133
|
+
/** Access Key Secret (Basic auth password). Defaults to `PROJECT_ID_API_SECRET`. */
|
|
1134
|
+
keySecret?: string;
|
|
1135
|
+
/** API host. Defaults to `https://voice.api.sinch.com`; set a regional host to skip the redirect. */
|
|
1136
|
+
host?: string;
|
|
1137
|
+
/** Public base URL of this function, used to resolve relative stream paths. Defaults to `context.host`. */
|
|
1138
|
+
publicUrl?: string;
|
|
1139
|
+
/** Injected fetch, for tests. Defaults to `globalThis.fetch`. */
|
|
1140
|
+
fetch?: typeof globalThis.fetch;
|
|
1141
|
+
}
|
|
1142
|
+
/** Options shared by the call-creating helpers */
|
|
1143
|
+
export interface CallOptions {
|
|
1144
|
+
/** Caller identity presented to the callee */
|
|
1145
|
+
from?: Origin;
|
|
1146
|
+
/** Seconds to wait for an answer. Maximum 60. */
|
|
1147
|
+
timeout?: number;
|
|
1148
|
+
/** Maximum call duration in seconds. Maximum 14400. */
|
|
1149
|
+
maxDuration?: number;
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Options for {@link Client.call}.
|
|
1153
|
+
*
|
|
1154
|
+
* Naming **any** event switches the platform out of service-webhook mode for every event —
|
|
1155
|
+
* see `completeEvents`. Naming none leaves the service webhook in charge, which is the mode
|
|
1156
|
+
* `callBehavior: WEBHOOK` on the service configures and the only mode inbound calls have.
|
|
1157
|
+
* Inline events are an optimisation on top of it, not an alternative to it.
|
|
1158
|
+
*/
|
|
1159
|
+
export interface PlaceCallOptions extends CallOptions, DialEvents {
|
|
1160
|
+
/** Name for the dialled leg. Defaults to `origin`. */
|
|
1161
|
+
callName?: string;
|
|
1162
|
+
}
|
|
1163
|
+
/** Options for {@link Client.callWithStream} */
|
|
1164
|
+
export interface StreamCallOptions extends CallOptions {
|
|
1165
|
+
/** Headers delivered on the WebSocket upgrade and in the `connect` message */
|
|
1166
|
+
headers?: Headers$1;
|
|
1167
|
+
/** Audio sampling rate. Defaults to {@link DEFAULT_SAMPLE_RATE}. */
|
|
1168
|
+
sampleRate?: SampleRate;
|
|
1169
|
+
/** Bridge name joining the two legs. Defaults to `bridge`. */
|
|
1170
|
+
bridgeName?: string;
|
|
1171
|
+
}
|
|
1172
|
+
/** Options for {@link Client.callWithRelay} */
|
|
1173
|
+
export interface RelayCallOptions extends CallOptions {
|
|
1174
|
+
/** Platform TTS voice, e.g. `Emma`. Required on the wire; defaults to `DEFAULT_VOICE`. */
|
|
1175
|
+
ttsVoice?: string;
|
|
1176
|
+
/**
|
|
1177
|
+
* BCP-47 language tag for speech-to-text, e.g. `en-US`. Required on the wire; defaults to
|
|
1178
|
+
* {@link DEFAULT_STT_LANGUAGE}.
|
|
1179
|
+
*/
|
|
1180
|
+
sttLanguage?: string;
|
|
1181
|
+
/** Let the caller talk over the platform's TTS. The platform defaults this to `true`. */
|
|
1182
|
+
enableInterruptions?: boolean;
|
|
1183
|
+
/** Headers delivered on the WebSocket upgrade and in the `connect` message */
|
|
1184
|
+
headers?: Headers$1;
|
|
1185
|
+
/** Bridge name joining the two legs. Defaults to `bridge`. */
|
|
1186
|
+
bridgeName?: string;
|
|
1187
|
+
}
|
|
1188
|
+
/** Options for {@link Client.bridge} */
|
|
1189
|
+
export interface BridgeOptions extends CallOptions {
|
|
1190
|
+
/** Bridge name joining the two legs. Defaults to `bridge`. */
|
|
1191
|
+
bridgeName?: string;
|
|
1192
|
+
}
|
|
1193
|
+
/** What a webhook handler may return. Returning nothing responds with `204 No Content`. */
|
|
1194
|
+
export type HandlerResult = Plan | Command[] | CommandBuilder | void | undefined;
|
|
1195
|
+
/** A single webhook handler */
|
|
1196
|
+
export type WebhookHandler = (event: WebhookRequest) => HandlerResult | Promise<HandlerResult>;
|
|
1197
|
+
/**
|
|
1198
|
+
* Handlers keyed by call lifecycle stage.
|
|
1199
|
+
*
|
|
1200
|
+
* These are the v1 callback names carried over. The v2 event they map to is
|
|
1201
|
+
* listed in {@link EVENT_MAP}.
|
|
1202
|
+
*/
|
|
1203
|
+
export interface CallHandlers {
|
|
1204
|
+
/** `call.incoming` — an inbound call arrived (the v1 ICE callback) */
|
|
1205
|
+
incoming?: WebhookHandler;
|
|
1206
|
+
/** `call.answered` — an outbound call was answered (the v1 ACE callback) */
|
|
1207
|
+
answered?: WebhookHandler;
|
|
1208
|
+
/** `call.menu` and `call.webhook.*` — a mid-call decision point (the v1 PIE callback) */
|
|
1209
|
+
manage?: WebhookHandler;
|
|
1210
|
+
/** `call.hangup` and `call.failed` — the call ended (the v1 DICE callback) */
|
|
1211
|
+
completed?: WebhookHandler;
|
|
1212
|
+
/**
|
|
1213
|
+
* Handlers for `webhook` commands, keyed by the `webhookName` they were raised under.
|
|
1214
|
+
*
|
|
1215
|
+
* A `webhook` command names its own event: `webhook('escalate', url)` is delivered as
|
|
1216
|
+
* `call.webhook.escalate`. Registering the handler under the same name is what closes that
|
|
1217
|
+
* loop — without it every `webhook` command in a function funnels into the single `manage`
|
|
1218
|
+
* handler, which then has to re-parse the event string to tell them apart.
|
|
1219
|
+
*
|
|
1220
|
+
* Checked before `manage`, which still claims any `call.webhook.*` name not listed here.
|
|
1221
|
+
*/
|
|
1222
|
+
webhooks?: Record<string, WebhookHandler>;
|
|
1223
|
+
/** Any event none of the above claims */
|
|
1224
|
+
fallback?: WebhookHandler;
|
|
1225
|
+
}
|
|
1226
|
+
/**
|
|
1227
|
+
* A lifecycle handler slot — every key of {@link CallHandlers} except `webhooks`, which is a
|
|
1228
|
+
* map of handlers rather than one.
|
|
1229
|
+
*/
|
|
1230
|
+
export type HandlerKey = Exclude<keyof CallHandlers, "webhooks">;
|
|
1231
|
+
/**
|
|
1232
|
+
* Resolve a v2 event name to a handler key.
|
|
1233
|
+
*
|
|
1234
|
+
* Tolerates a leading `webhook.` (used in some early drafts) and routes every
|
|
1235
|
+
* dynamic `call.webhook.<name>` event from the `webhook` command to `manage`.
|
|
1236
|
+
*
|
|
1237
|
+
* @param event - Event name from the webhook payload
|
|
1238
|
+
* @returns The matching handler key, or `undefined` if the event is unmapped
|
|
1239
|
+
*/
|
|
1240
|
+
export declare function resolveHandlerKey(event: string): HandlerKey | undefined;
|
|
1241
|
+
/**
|
|
1242
|
+
* Recover the `webhookName` a `webhook` command was written with.
|
|
1243
|
+
*
|
|
1244
|
+
* The inverse of the naming rule in {@link CommandBuilder.webhook}: `webhook('my.custom.event',
|
|
1245
|
+
* url)` raises `call.webhook.my.custom.event`, and this turns that back into
|
|
1246
|
+
* `my.custom.event`. Names may contain dots, so everything after the prefix is the name.
|
|
1247
|
+
*
|
|
1248
|
+
* @param event - Event name from the webhook payload
|
|
1249
|
+
* @returns The webhook name, or `undefined` for any other event
|
|
1250
|
+
*/
|
|
1251
|
+
export declare function resolveWebhookName(event: string): string | undefined;
|
|
1252
|
+
/**
|
|
1253
|
+
* Client for the Sinch Voice API v2.
|
|
1254
|
+
*
|
|
1255
|
+
* The upper half of this package: it builds command lists, applies the leg-aware defaults and
|
|
1256
|
+
* dispatches webhooks. It sends nothing itself — the {@link CallTransport} does that, and by
|
|
1257
|
+
* default that is `HttpTransport`, which authenticates with HTTP Basic using the project
|
|
1258
|
+
* Access Key pair (`PROJECT_ID_API_KEY` / `PROJECT_ID_API_SECRET`) — not the v1
|
|
1259
|
+
* application key.
|
|
1260
|
+
*/
|
|
1261
|
+
export declare class Client {
|
|
1262
|
+
private readonly publicUrl;
|
|
1263
|
+
/**
|
|
1264
|
+
* The lower layer, reached only through the interface this half of the module owns.
|
|
1265
|
+
*
|
|
1266
|
+
* This field and the `new HttpTransport` below are the whole coupling between the
|
|
1267
|
+
* command builder and the network. When `@sinch/voice@2` ships, an adapter over the
|
|
1268
|
+
* SDK replaces that one expression and nothing else in this file moves.
|
|
1269
|
+
*/
|
|
1270
|
+
private readonly transport;
|
|
1271
|
+
/**
|
|
1272
|
+
* @param context - Function context, used for env and for the public host
|
|
1273
|
+
* @param options - Explicit overrides for anything the context cannot supply
|
|
1274
|
+
*/
|
|
1275
|
+
constructor(context?: ClientContext, options?: Options);
|
|
1276
|
+
/**
|
|
1277
|
+
* Place an outbound call.
|
|
1278
|
+
*
|
|
1279
|
+
* Name the events you want handled inline and they are sent as a **complete** block, with
|
|
1280
|
+
* busy, rejected, timed-out and failed defaulting to hangup. Name none and no `events` key
|
|
1281
|
+
* is sent at all, which is what hands the call to the service webhook.
|
|
1282
|
+
*
|
|
1283
|
+
* There is no half-way house, and that is the platform's rule rather than this client's:
|
|
1284
|
+
* `events` present means the service webhook is attached to *none* of the six lists, so a
|
|
1285
|
+
* lone `onAnswer` would silently stop busy and hangup from being handled by anything.
|
|
1286
|
+
*
|
|
1287
|
+
* @param to - Who to call
|
|
1288
|
+
* @param options - Dial settings and named events
|
|
1289
|
+
* @throws If the API rejects the request
|
|
1290
|
+
*
|
|
1291
|
+
* @example
|
|
1292
|
+
* ```typescript
|
|
1293
|
+
* // Inline: say a line and hang up, failures end the call
|
|
1294
|
+
* await voice.call('+15559876543', {
|
|
1295
|
+
* from: '+15551234567',
|
|
1296
|
+
* onAnswer: (c) => c.say('Your appointment is confirmed.').hangup(),
|
|
1297
|
+
* });
|
|
1298
|
+
*
|
|
1299
|
+
* // A flow built once and reused
|
|
1300
|
+
* const greeting = commands().say('One moment').bridgeCall('support');
|
|
1301
|
+
* await voice.call('+15559876543', { onAnswer: greeting });
|
|
1302
|
+
*
|
|
1303
|
+
* // Service-webhook mode: no events named, so `call.answered` fires
|
|
1304
|
+
* await voice.call('+15559876543', { from: '+15551234567' });
|
|
1305
|
+
* ```
|
|
1306
|
+
*/
|
|
1307
|
+
call(to: Destination, options?: PlaceCallOptions): Promise<CallResponse>;
|
|
1308
|
+
/**
|
|
1309
|
+
* Build the {@link call} flow without sending it.
|
|
1310
|
+
*
|
|
1311
|
+
* @param to - Who to call
|
|
1312
|
+
* @param options - Dial settings and named events
|
|
1313
|
+
*/
|
|
1314
|
+
planCall(to: Destination, options?: PlaceCallOptions): Plan;
|
|
1315
|
+
/**
|
|
1316
|
+
* Call a destination and put a WebSocket audio stream on the same call.
|
|
1317
|
+
*
|
|
1318
|
+
* Dials the destination as leg `origin`; on answer that leg joins a bridge and a
|
|
1319
|
+
* second leg is dialled to the STREAM endpoint, which joins the same bridge.
|
|
1320
|
+
* Either leg hanging up ends the other.
|
|
1321
|
+
*
|
|
1322
|
+
* `streamOptions` is always sent in full — the platform defaults to 44100 Hz
|
|
1323
|
+
* when the object is omitted and to 8000 Hz when it is partially supplied.
|
|
1324
|
+
*
|
|
1325
|
+
* Both endpoints are positional, mirroring {@link bridge}: this dials two things and
|
|
1326
|
+
* bridges them, and neither of them has a sensible default. In particular there is no
|
|
1327
|
+
* honest default path for the audio leg — the runtime neither serves nor owns one — so
|
|
1328
|
+
* the socket URL is as required as the number.
|
|
1329
|
+
*
|
|
1330
|
+
* @param to - Who to call
|
|
1331
|
+
* @param stream - WebSocket endpoint for the audio leg. Either a full `ws://`/`wss://`
|
|
1332
|
+
* URL or an absolute path, resolved against this function's public URL.
|
|
1333
|
+
* @param options - Headers, sample rate, bridge name and dial settings
|
|
1334
|
+
* @throws If the stream path cannot be resolved, or if the API rejects the request
|
|
1335
|
+
*
|
|
1336
|
+
* @example
|
|
1337
|
+
* ```typescript
|
|
1338
|
+
* // Relative path, resolved against the function's public host
|
|
1339
|
+
* await voice.callWithStream('+15559876543', '/media', {
|
|
1340
|
+
* from: '+15551234567',
|
|
1341
|
+
* headers: { 'x-contact-id': 'abc123' },
|
|
1342
|
+
* });
|
|
1343
|
+
*
|
|
1344
|
+
* // Full URL, 8 kHz to match a PSTN-only path
|
|
1345
|
+
* await voice.callWithStream('+15559876543', 'wss://example.com/audio', {
|
|
1346
|
+
* from: '+15551234567',
|
|
1347
|
+
* sampleRate: 8000,
|
|
1348
|
+
* });
|
|
1349
|
+
* ```
|
|
1350
|
+
*/
|
|
1351
|
+
callWithStream(to: Destination, stream: string, options?: StreamCallOptions): Promise<CallResponse>;
|
|
1352
|
+
/**
|
|
1353
|
+
* Build the {@link callWithStream} flow without sending it.
|
|
1354
|
+
*
|
|
1355
|
+
* @param to - Who to call
|
|
1356
|
+
* @param stream - WebSocket endpoint for the audio leg, as a URL or an absolute path
|
|
1357
|
+
* @param options - Headers, sample rate, bridge name and dial settings
|
|
1358
|
+
* @throws If the stream path cannot be resolved
|
|
1359
|
+
*/
|
|
1360
|
+
planStreamCall(to: Destination, stream: string, options?: StreamCallOptions): Plan;
|
|
1361
|
+
/**
|
|
1362
|
+
* Call a destination and put the Voice Relay service on the same call.
|
|
1363
|
+
*
|
|
1364
|
+
* Same topology as {@link callWithStream} — dial the human, bridge a second leg — but the
|
|
1365
|
+
* second leg is a VOICE_RELAY endpoint rather than a raw audio socket: Sinch runs STT and
|
|
1366
|
+
* TTS, and the application exchanges text. The trade is that the application never owns
|
|
1367
|
+
* the TTS stream, which rules the relay out for anything that needs its own voice or
|
|
1368
|
+
* needs to inject filler speech while an LLM thinks.
|
|
1369
|
+
*
|
|
1370
|
+
* The relay socket is positional and required: the `voiceRelay` schema (spec line 2946)
|
|
1371
|
+
* requires `endpoint`, so there is no relay leg without one.
|
|
1372
|
+
*
|
|
1373
|
+
* @param to - Who to call
|
|
1374
|
+
* @param relay - WebSocket endpoint the relay connects to. Either a full `ws://`/`wss://`
|
|
1375
|
+
* URL or an absolute path, resolved against this function's public URL.
|
|
1376
|
+
* @param options - Voice, transcription language, barge-in, bridge name and dial settings
|
|
1377
|
+
* @throws If the API rejects the request
|
|
1378
|
+
*/
|
|
1379
|
+
callWithRelay(to: Destination, relay: string, options?: RelayCallOptions): Promise<CallResponse>;
|
|
1380
|
+
/**
|
|
1381
|
+
* Build the {@link callWithRelay} flow without sending it.
|
|
1382
|
+
*
|
|
1383
|
+
* @param to - Who to call
|
|
1384
|
+
* @param relay - WebSocket endpoint the relay connects to, as a URL or an absolute path
|
|
1385
|
+
* @param options - Voice, transcription language, barge-in, bridge name and dial settings
|
|
1386
|
+
*/
|
|
1387
|
+
planRelayCall(to: Destination, relay: string, options?: RelayCallOptions): Plan;
|
|
1388
|
+
/**
|
|
1389
|
+
* Call two destinations and bridge them together.
|
|
1390
|
+
*
|
|
1391
|
+
* @param a - First party, dialled as leg `origin`
|
|
1392
|
+
* @param b - Second party, dialled once `a` answers
|
|
1393
|
+
* @param options - Dial settings and bridge name
|
|
1394
|
+
*
|
|
1395
|
+
* @example
|
|
1396
|
+
* ```typescript
|
|
1397
|
+
* await voice.bridge('+15551110000', '+15552220000', { from: '+15551234567' });
|
|
1398
|
+
* ```
|
|
1399
|
+
*/
|
|
1400
|
+
bridge(a: Destination, b: Destination, options?: BridgeOptions): Promise<CallResponse>;
|
|
1401
|
+
/**
|
|
1402
|
+
* Build the {@link bridge} flow without sending it.
|
|
1403
|
+
*
|
|
1404
|
+
* @param a - First party, dialled as leg `origin`
|
|
1405
|
+
* @param b - Second party, dialled once `a` answers
|
|
1406
|
+
* @param options - Dial settings and bridge name
|
|
1407
|
+
*/
|
|
1408
|
+
planBridge(a: Destination, b: Destination, options?: BridgeOptions): Plan;
|
|
1409
|
+
/**
|
|
1410
|
+
* End one or more legs of a live call.
|
|
1411
|
+
*
|
|
1412
|
+
* @param target - The live call, addressed by `callId` or by `sessionId` + `callName`
|
|
1413
|
+
* @param callNames - Legs to end. Ends the addressed leg when omitted.
|
|
1414
|
+
*
|
|
1415
|
+
* @example
|
|
1416
|
+
* ```typescript
|
|
1417
|
+
* await voice.hangup({ sessionId }, 'origin', 'stream');
|
|
1418
|
+
* ```
|
|
1419
|
+
*/
|
|
1420
|
+
hangup(target: PatchTarget, ...callNames: string[]): Promise<void>;
|
|
1421
|
+
/**
|
|
1422
|
+
* Build the {@link hangup} command list without sending it.
|
|
1423
|
+
*
|
|
1424
|
+
* @param callNames - Legs to end. Ends the addressed leg when omitted.
|
|
1425
|
+
*/
|
|
1426
|
+
planHangup(...callNames: string[]): Command[];
|
|
1427
|
+
/**
|
|
1428
|
+
* Run commands against a live call — the escalation path.
|
|
1429
|
+
*
|
|
1430
|
+
* @param target - The live call, addressed by `callId` or by `sessionId` + `callName`
|
|
1431
|
+
* @param flow - Commands to execute in the context of the addressed leg, in any
|
|
1432
|
+
* {@link Flow} spelling
|
|
1433
|
+
* @throws If the API rejects the request
|
|
1434
|
+
*
|
|
1435
|
+
* @example
|
|
1436
|
+
* ```typescript
|
|
1437
|
+
* // Pull a human agent into an in-progress streamed call
|
|
1438
|
+
* await voice.patch({ sessionId, callName: 'origin' }, (c) =>
|
|
1439
|
+
* c.bridgeCall('escalation').dial('+15550001111', {
|
|
1440
|
+
* callName: 'agent',
|
|
1441
|
+
* onAnswer: (a) => a.bridgeCall('escalation'),
|
|
1442
|
+
* endOnFailure: 'origin',
|
|
1443
|
+
* })
|
|
1444
|
+
* );
|
|
1445
|
+
* ```
|
|
1446
|
+
*/
|
|
1447
|
+
patch(target: PatchTarget, flow: Flow): Promise<void>;
|
|
1448
|
+
/**
|
|
1449
|
+
* Dial a party into a live call's bridge — the transfer v1 has no equivalent of.
|
|
1450
|
+
*
|
|
1451
|
+
* The named sugar over {@link patch}: it sends exactly
|
|
1452
|
+
* `patch(target, buildTransferCommands(to, options))`, and the value is entirely in what
|
|
1453
|
+
* that builder puts around the dial. See {@link buildTransferCommands} for why every
|
|
1454
|
+
* non-answer outcome has to end another leg.
|
|
1455
|
+
*
|
|
1456
|
+
* ### Why both a target and a bridge name
|
|
1457
|
+
*
|
|
1458
|
+
* They address different things and neither is redundant. {@link PatchTarget} pins the
|
|
1459
|
+
* **session** — by `callId`, or by `sessionId` plus the leg the commands run in the context
|
|
1460
|
+
* of. `bridgeName` then resolves **within** that session, because `bridgeCall` joins the
|
|
1461
|
+
* current call to a bridge "in the same session". That scoping is also what makes the
|
|
1462
|
+
* default safe: two unrelated calls both using `bridge` are in two different sessions, so
|
|
1463
|
+
* they cannot meet.
|
|
1464
|
+
*
|
|
1465
|
+
* The one genuinely ambiguous case is inside a single session: reuse a name for what you
|
|
1466
|
+
* meant as two bridges and you get one bridge, because joining a name that already exists
|
|
1467
|
+
* is documented to join it rather than create a second.
|
|
1468
|
+
*
|
|
1469
|
+
* @param target - The live call, addressed by `callId` or by `sessionId` + `callName`
|
|
1470
|
+
* @param to - Party to dial: an E.164 number, a `sip:` URI, or an endpoint object
|
|
1471
|
+
* @param options - Bridge, caller id, dial timeout, leg names
|
|
1472
|
+
* @throws If the API rejects the request
|
|
1473
|
+
*
|
|
1474
|
+
* @example
|
|
1475
|
+
* ```typescript
|
|
1476
|
+
* // A call placed by this client with default options: the bridge is already known
|
|
1477
|
+
* await voice.transfer({ sessionId, callName: 'origin' }, '+15550001111', {
|
|
1478
|
+
* endLeg: 'origin',
|
|
1479
|
+
* });
|
|
1480
|
+
*
|
|
1481
|
+
* // A call whose bridge was named, or one this package did not place
|
|
1482
|
+
* await voice.transfer({ callId }, 'sip:agent@pbx.example.com', {
|
|
1483
|
+
* bridgeName: 'agent',
|
|
1484
|
+
* endLeg: 'stream',
|
|
1485
|
+
* });
|
|
1486
|
+
* ```
|
|
1487
|
+
*/
|
|
1488
|
+
transfer(target: PatchTarget, to: Destination, options?: TransferOptions): Promise<void>;
|
|
1489
|
+
/**
|
|
1490
|
+
* Post a call-create body verbatim — the escape hatch for anything this client
|
|
1491
|
+
* does not model.
|
|
1492
|
+
*
|
|
1493
|
+
* The body type is deliberately permissive rather than the `callRequest` shape: the wire
|
|
1494
|
+
* command types are internal to this module, so anything hand-built here is unchecked by
|
|
1495
|
+
* design. Use {@link toCallRequest} on a plan when you want the shape validated.
|
|
1496
|
+
*
|
|
1497
|
+
* @param body - A `callRequest` body, or any object the API accepts
|
|
1498
|
+
* @throws If the API rejects the request
|
|
1499
|
+
*/
|
|
1500
|
+
raw(body: Record<string, unknown> | object): Promise<CallResponse>;
|
|
1501
|
+
/**
|
|
1502
|
+
* Build a webhook dispatcher over the v2 call lifecycle.
|
|
1503
|
+
*
|
|
1504
|
+
* Handlers may return a plan, a command builder, a bare command array, or nothing.
|
|
1505
|
+
* Nothing means "no commands" and yields `undefined`, which a handler should
|
|
1506
|
+
* turn into a `204`.
|
|
1507
|
+
*
|
|
1508
|
+
* @param handlers - Handlers keyed by lifecycle stage
|
|
1509
|
+
* @returns A function that maps a webhook payload to a response body
|
|
1510
|
+
*
|
|
1511
|
+
* @example
|
|
1512
|
+
* ```typescript
|
|
1513
|
+
* export const handleVoiceWebhook = voice.onCall({
|
|
1514
|
+
* incoming: () => commands().answer().say('Thanks for calling').hangup(),
|
|
1515
|
+
* completed: (event) => {
|
|
1516
|
+
* console.log('call ended', event.call.callId);
|
|
1517
|
+
* },
|
|
1518
|
+
* });
|
|
1519
|
+
* ```
|
|
1520
|
+
*/
|
|
1521
|
+
onCall(handlers: CallHandlers): (event: WebhookRequest) => Promise<WebhookResponse | undefined>;
|
|
1522
|
+
/**
|
|
1523
|
+
* The bridged shape: dial one leg, and on answer join a bridge and dial the second into it.
|
|
1524
|
+
*
|
|
1525
|
+
* The leg-aware defaults live here because this is where the topology is known. The second
|
|
1526
|
+
* leg names the first in both `endOnHangup` and `endOnFailure` — every way it can fail ends
|
|
1527
|
+
* the first one too, or `callWithStream` strands the human on a bridge with nothing on the
|
|
1528
|
+
* other side, and a stream-first plan leaves an answered WebSocket leg (with its billed
|
|
1529
|
+
* STT/TTS/LLM sockets) running to the platform's 14400-second ceiling talking to nobody.
|
|
1530
|
+
*
|
|
1531
|
+
* The first leg names the second in `endOnHangup` only. Its failure events fire *before*
|
|
1532
|
+
* the second leg has been dialled, so naming it there would target a leg that does not
|
|
1533
|
+
* exist; a bare hangup is the leg-aware answer for the first leg of a call.
|
|
1534
|
+
*/
|
|
1535
|
+
private planBridged;
|
|
1536
|
+
private resolveStreamEndpoint;
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Create a Voice API v2 client.
|
|
1540
|
+
*
|
|
1541
|
+
* @param context - Function context, used for env and for the public host
|
|
1542
|
+
* @param options - Explicit overrides for anything the context cannot supply
|
|
1543
|
+
*
|
|
1544
|
+
* @example
|
|
1545
|
+
* ```typescript
|
|
1546
|
+
* const voice = createClient(context);
|
|
1547
|
+
* const voiceEu = createClient(context, { host: 'https://eu1.voice.api.sinch.com' });
|
|
1548
|
+
* ```
|
|
1549
|
+
*/
|
|
1550
|
+
export declare function createClient(context?: ClientContext, options?: Options): Client;
|
|
1551
|
+
/** Global Voice API host. Geo-redirects to the nearest region. */
|
|
1552
|
+
export declare const DEFAULT_HOST = "https://voice.api.sinch.com";
|
|
1553
|
+
/**
|
|
1554
|
+
* Voice API v2 credential redaction.
|
|
1555
|
+
*
|
|
1556
|
+
* `startRecording.recordingOptions.credentials` is a **required** colon-delimited string
|
|
1557
|
+
* carrying a long-lived storage secret — `accessKeyId:secretAccessKey:eu-central-1` for AWS.
|
|
1558
|
+
* The v2 schema offers no presigned-URL alternative and no STS session-token slot (the third
|
|
1559
|
+
* component is the region, not a token), so the secret rides inside the SVAML command body
|
|
1560
|
+
* itself: in `POST /calls` requests, in webhook responses, in `PATCH` bodies, and in anything
|
|
1561
|
+
* that stringifies one of those.
|
|
1562
|
+
*
|
|
1563
|
+
* That makes every log line and every exception message a potential disclosure. This module
|
|
1564
|
+
* is the mitigation, and it mirrors `redactCallHeaders` in `@sinch/agents`: replace the value
|
|
1565
|
+
* with a placeholder on the way out, never suppress the field, so a redacted body still reads
|
|
1566
|
+
* as the body it came from.
|
|
1567
|
+
*/
|
|
1568
|
+
/** What a redacted secret is replaced with. */
|
|
1569
|
+
export declare const REDACTED = "[redacted]";
|
|
1570
|
+
/**
|
|
1571
|
+
* Deep-copy a command list, plan or request body with every recording credential replaced.
|
|
1572
|
+
*
|
|
1573
|
+
* Use this — never the original — whenever a v2 body is logged, printed or serialised into an
|
|
1574
|
+
* error. The copy is structurally identical apart from the credential strings, so it stays
|
|
1575
|
+
* useful for debugging the shape of a request.
|
|
1576
|
+
*
|
|
1577
|
+
* Any string-valued `credentials` key is redacted, wherever it sits. That is deliberately
|
|
1578
|
+
* broader than `recordingOptions.credentials`: bodies also reach here through `raw()`, which
|
|
1579
|
+
* accepts hand-built objects this module does not model, and over-redacting a log line costs
|
|
1580
|
+
* nothing while under-redacting one costs a storage key.
|
|
1581
|
+
*
|
|
1582
|
+
* @param body - Anything JSON-shaped: a command array, a plan, a request body
|
|
1583
|
+
* @returns A copy with credentials replaced by {@link REDACTED}
|
|
1584
|
+
*
|
|
1585
|
+
* @example
|
|
1586
|
+
* ```typescript
|
|
1587
|
+
* console.log(JSON.stringify(redactCredentials(plan.commands)));
|
|
1588
|
+
* // ... "credentials":"[redacted]" ...
|
|
1589
|
+
* ```
|
|
1590
|
+
*/
|
|
1591
|
+
export declare function redactCredentials<T>(body: T): T;
|
|
1592
|
+
|
|
1593
|
+
export {
|
|
1594
|
+
Headers$1 as Headers,
|
|
1595
|
+
};
|
|
1596
|
+
|
|
1597
|
+
export {};
|