@sinch/functions-runtime 0.5.16 → 0.5.17

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.
@@ -1,4 +1,10 @@
1
1
  // Generated by dts-bundle-generator v9.5.1
2
+ import { commands, createClient, Client, CommandBuilder } from '../index.js';
3
+ import type { Command, Flow, WebhookRequest, Call, HandlerResult, CallHandlers } from '../index.js';
4
+
5
+ export { commands, createClient, Client, CommandBuilder };
6
+ export type { Command, Flow, WebhookRequest, Call, HandlerResult, CallHandlers };
7
+
2
8
 
3
9
  interface ClientContext {
4
10
  /** Function configuration. Only `projectId` is read. */
@@ -338,7 +344,38 @@ interface StopRecordingCommand {
338
344
  /** Recording to stop, as named by `recordingName` on the `startRecording` command */
339
345
  recordingName: string;
340
346
  }
341
- type Command = DialCommand | MessagesCommand | BridgeCallCommand | HangupCommand | AnswerCommand | MenuCommand | GotoMenuCommand | PauseCommand | StopMessagesCommand | AmdCommand | WebhookCommand | StartRecordingCommand | StopRecordingCommand;
347
+ /** Direction of the call, relative to the Sinch calling platform (spec `callDirection`). */
348
+ export type CallDirection = "INBOUND" | "OUTBOUND";
349
+ /** How the call was initiated — PSTN, a SIP trunk, or the API (spec `originationType`). */
350
+ export type OriginationType = "PHONE" | "SIP" | "SERVER";
351
+ /**
352
+ * Kind of endpoint the call is connected to (spec `callType`).
353
+ *
354
+ * The same four values as the `to` union's discriminators, which is what makes this the
355
+ * cheap way to tell a media leg from a phone leg without reaching into `to`.
356
+ */
357
+ export type CallType = "PHONE" | "SIP" | "STREAM" | "VOICE_RELAY";
358
+ /**
359
+ * Outcome or state of the call (spec `callResult`).
360
+ *
361
+ * Mixes transitional states — `QUEUED`, `INITIATED`, `IN_PROGRESS` — with the final ones, so
362
+ * a value here is not on its own evidence that the call has ended.
363
+ */
364
+ export type CallResult = "QUEUED" | "INITIATED" | "IN_PROGRESS" | "COMPLETED" | "REJECTED" | "NO_ANSWER" | "CANCEL" | "BUSY" | "FAILED";
365
+ /**
366
+ * Why the call ended in the reported {@link CallResult} (spec `callReason`).
367
+ *
368
+ * `callResult` is what happened; this is the cause — who hung up, a routing failure, an
369
+ * invalid script.
370
+ */
371
+ export type CallReason = "OK" | "NOT_AVAILABLE" | "CALLER_HANGUP" | "CALLEE_HANGUP" | "MANAGER_HANGUP" | "DID_NOT_FOUND" | "INVALID_SCRIPT" | "UNKNOWN_PRODUCT" | "NO_MORE_ROUTES" | "ERROR";
372
+ /** A monetary amount with a currency (spec `money`). */
373
+ export interface Money {
374
+ /** ISO 4217 three-letter currency code, e.g. `USD` */
375
+ currencyCode: string;
376
+ /** Amount as a decimal string, up to 4 places — a string to keep the precision */
377
+ amount: string;
378
+ }
342
379
  interface CallRequest {
343
380
  /** Ordered command list. At least one command. */
344
381
  commands: Command[];
@@ -373,20 +410,6 @@ export type PatchTarget = {
373
410
  * `webhook.` prefix; `Client.onCall` tolerates both.
374
411
  */
375
412
  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
413
  /**
391
414
  * Body returned from a webhook endpoint.
392
415
  *
@@ -404,6 +427,27 @@ export interface WebhookResponse {
404
427
  onHangup?: Command[];
405
428
  };
406
429
  }
430
+ interface CallTransport {
431
+ /**
432
+ * Create a call.
433
+ *
434
+ * The body is deliberately permissive rather than `CallRequest`: {@link Client.raw} is an
435
+ * escape hatch for bodies this module does not model, and validation belongs to
436
+ * `toCallRequest`, not to the transport.
437
+ *
438
+ * @param body - A `callRequest` body, or any object the API accepts
439
+ * @throws If the API rejects the request
440
+ */
441
+ createCall(body: object): Promise<CallResponse>;
442
+ /**
443
+ * Run commands against a live call.
444
+ *
445
+ * @param target - The live call, addressed by `callId` or by `sessionId` + `callName`
446
+ * @param commands - Ordered command list to execute against the addressed leg
447
+ * @throws If the API rejects the request
448
+ */
449
+ patchCall(target: PatchTarget, commands: Command[]): Promise<void>;
450
+ }
407
451
  /** Sample rate used when none is given. Matches the agent SDK's `pcm_16000`, so no resampling. */
408
452
  export declare const DEFAULT_SAMPLE_RATE: SampleRate;
409
453
  /** TTS voice used when none is given. `voiceName` is required by the API. */
@@ -480,17 +524,6 @@ export declare function dialRelay(endpoint: string, options?: {
480
524
  enableInterruptions?: boolean;
481
525
  headers?: Headers$1;
482
526
  }): 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
527
  /** Options for a single TTS message */
495
528
  export interface SayOptions {
496
529
  /** Voice name. Defaults to {@link DEFAULT_VOICE}. */
@@ -772,222 +805,6 @@ export declare class MenuItemBuilder {
772
805
  */
773
806
  build(): MenuItem;
774
807
  }
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
808
  /**
992
809
  * Emit-target-agnostic description of a call flow.
993
810
  *
@@ -1190,39 +1007,8 @@ export interface BridgeOptions extends CallOptions {
1190
1007
  /** Bridge name joining the two legs. Defaults to `bridge`. */
1191
1008
  bridgeName?: string;
1192
1009
  }
1193
- /** What a webhook handler may return. Returning nothing responds with `204 No Content`. */
1194
- export type HandlerResult = Plan | Command[] | CommandBuilder | void | undefined;
1195
1010
  /** A single webhook handler */
1196
1011
  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
1012
  /**
1227
1013
  * A lifecycle handler slot — every key of {@link CallHandlers} except `webhooks`, which is a
1228
1014
  * map of handlers rather than one.
@@ -1249,305 +1035,6 @@ export declare function resolveHandlerKey(event: string): HandlerKey | undefined
1249
1035
  * @returns The webhook name, or `undefined` for any other event
1250
1036
  */
1251
1037
  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
1038
  /** Global Voice API host. Geo-redirects to the nearest region. */
1552
1039
  export declare const DEFAULT_HOST = "https://voice.api.sinch.com";
1553
1040
  /**