@fonoster/voice 0.27.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +32 -419
  2. package/dist/Session.d.ts +161 -0
  3. package/dist/Session.js +576 -0
  4. package/dist/VoiceServer.d.ts +70 -5
  5. package/dist/VoiceServer.js +149 -43
  6. package/dist/{verbs/Dial.d.ts → errors.d.ts} +9 -13
  7. package/dist/{verbs/Answer.js → errors.js} +18 -7
  8. package/dist/index.d.ts +4 -6
  9. package/dist/index.js +4 -15
  10. package/dist/signature.d.ts +31 -0
  11. package/dist/signature.js +93 -0
  12. package/dist/types.d.ts +88 -10
  13. package/dist/types.js +0 -21
  14. package/package.json +13 -19
  15. package/session.d.ts +1 -0
  16. package/session.js +2 -0
  17. package/dist/VoiceResponse.d.ts +0 -304
  18. package/dist/VoiceResponse.js +0 -461
  19. package/dist/createSession.d.ts +0 -22
  20. package/dist/createSession.js +0 -66
  21. package/dist/defaultServerConfig.d.ts +0 -21
  22. package/dist/defaultServerConfig.js +0 -10
  23. package/dist/demo.d.ts +0 -1
  24. package/dist/demo.js +0 -83
  25. package/dist/filters.d.ts +0 -44
  26. package/dist/filters.js +0 -17
  27. package/dist/serviceDefinition.d.ts +0 -2
  28. package/dist/serviceDefinition.js +0 -29
  29. package/dist/verbs/Answer.d.ts +0 -24
  30. package/dist/verbs/Dial.js +0 -60
  31. package/dist/verbs/Gather.d.ts +0 -25
  32. package/dist/verbs/Gather.js +0 -57
  33. package/dist/verbs/Hangup.d.ts +0 -24
  34. package/dist/verbs/Hangup.js +0 -29
  35. package/dist/verbs/Mute.d.ts +0 -25
  36. package/dist/verbs/Mute.js +0 -36
  37. package/dist/verbs/Play.d.ts +0 -25
  38. package/dist/verbs/Play.js +0 -33
  39. package/dist/verbs/PlayDtmf.d.ts +0 -25
  40. package/dist/verbs/PlayDtmf.js +0 -32
  41. package/dist/verbs/PlaybackControl.d.ts +0 -25
  42. package/dist/verbs/PlaybackControl.js +0 -35
  43. package/dist/verbs/Record.d.ts +0 -25
  44. package/dist/verbs/Record.js +0 -49
  45. package/dist/verbs/Say.d.ts +0 -25
  46. package/dist/verbs/Say.js +0 -33
  47. package/dist/verbs/SetAudioFilters.d.ts +0 -25
  48. package/dist/verbs/SetAudioFilters.js +0 -16
  49. package/dist/verbs/StopSay.d.ts +0 -25
  50. package/dist/verbs/StopSay.js +0 -11
  51. package/dist/verbs/Stream.d.ts +0 -39
  52. package/dist/verbs/Stream.js +0 -80
  53. package/dist/verbs/StreamGather.d.ts +0 -37
  54. package/dist/verbs/StreamGather.js +0 -66
  55. package/dist/verbs/Unmute.d.ts +0 -22
  56. package/dist/verbs/Unmute.js +0 -26
  57. package/dist/verbs/Verb.d.ts +0 -28
  58. package/dist/verbs/Verb.js +0 -103
  59. package/dist/verbs/getExpectedContent.d.ts +0 -2
  60. package/dist/verbs/getExpectedContent.js +0 -32
  61. package/dist/verbs/index.d.ts +0 -35
  62. package/dist/verbs/index.js +0 -51
  63. package/dist/verbs/validateRequest.d.ts +0 -20
  64. package/dist/verbs/validateRequest.js +0 -13
@@ -1,304 +0,0 @@
1
- /**
2
- * Copyright (C) 2025 by Fonoster Inc (https://fonoster.com)
3
- * http://github.com/fonoster/fonoster
4
- *
5
- * This file is part of Fonoster
6
- *
7
- * Licensed under the MIT License (the "License");
8
- * you may not use this file except in compliance with
9
- * the License. You may obtain a copy of the License at
10
- *
11
- * https://opensource.org/licenses/MIT
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- */
19
- import { AudioFilterConfig, DialOptions, GatherOptions, GatherResponse, MuteOptions, PlaybackControlAction, PlayOptions, PlayResponse, RecordOptions, RecordResponse, SayOptions, StreamEvent, StreamGatherOptions, StreamOptions, VerbResponse, VoiceRequest, VoiceSessionStreamServer } from "@fonoster/common";
20
- import { DialStatusStream, Stream, StreamGatherStream } from "./verbs";
21
- /**
22
- * @classdesc Use the VoiceResponse object, to construct advance Interactive
23
- * Voice Response (IVR) applications.
24
- *
25
- * @extends Verb
26
- * @example
27
- *
28
- * import { VoiceServer } from "@fonoster/voice";
29
- *
30
- * async function handler (request, response) {
31
- * await response.answer();
32
- * await response.play("https://soundsserver:9000/sounds/hello-world.wav");
33
- * }
34
- *
35
- * new VoiceServer().listen(handler, { port: 3000 })
36
- */
37
- declare class VoiceResponse {
38
- voice: VoiceSessionStreamServer;
39
- request: VoiceRequest;
40
- /**
41
- * Constructs a new VoiceResponse object.
42
- *
43
- * @param {VoiceRequest} request - Options to indicate the objects endpoint
44
- * @param {VoiceSessionStream} voice - The voice session stream
45
- * @see module:core:APIClient
46
- */
47
- constructor(request: VoiceRequest, voice: VoiceSessionStreamServer);
48
- /**
49
- * Answer the call. Before running any other verb you
50
- * must run the answer command.
51
- * @example
52
- *
53
- * async function handler (request, response) {
54
- * await response.answer();
55
- * }
56
- */
57
- answer(): Promise<VerbResponse>;
58
- /**
59
- * Hangup the call.
60
- * @example
61
- *
62
- * async function handler (request, response) {
63
- * await response.hangup();
64
- * }
65
- */
66
- hangup(): Promise<VerbResponse>;
67
- /**
68
- * Play an audio in the call.
69
- *
70
- * @param {string} url - The URL of the media to play
71
- * @param {PlayOptions} options - Options to control the playback
72
- * @param {string} options.playbackRef - Playback identifier to use in Playback operations
73
- * @see Playback
74
- * @example
75
- *
76
- * async function handler (request, response) {
77
- * await response.answer();
78
- * await response.play("https://soundsserver:9000/sounds/hello-world.wav");
79
- * }
80
- */
81
- play(url: string, options?: PlayOptions): Promise<PlayResponse>;
82
- /**
83
- * Play a series of DTMF digits in a call.
84
- *
85
- * @param {string} digits -The DTMF digits to play (0-9, #, or *)
86
- * @example
87
- *
88
- * async function handler (request, response) {
89
- * await response.answer();
90
- * await response.playDtmf("1234");
91
- * }
92
- */
93
- playDtmf(digits: string): Promise<void>;
94
- /**
95
- * Control the playback of the currently playing media.
96
- *
97
- * @param {string} playbackRef - The playback identifier
98
- * @param {PlaybackControlAction} action - The action to perform (STOP, RESTART, PAUSE, UNPAUSE, FORWARD)
99
- * @see play
100
- * @example
101
- *
102
- * async function handler (request, response) {
103
- * await response.answer();
104
- * await response.play("https://s3.fonoster.io/uuid/hello-world.wav", { playbackRef: "playback-01" });
105
- *
106
- * // Pause the media
107
- * await response.playbackControl("playback-01", PlaybackControlAction.PAUSE);
108
- * }
109
- */
110
- playbackControl(playbackRef: string, action: PlaybackControlAction): Promise<VerbResponse>;
111
- /**
112
- * Waits for data entry from the user's keypad or from a speech provider.
113
- *
114
- * @param {GatherOptions} options - Options to select the maximum number of digits, final character, and timeout
115
- * @param {number} options.maxDigits - Maximum number of digits to collect. Defaults to 1
116
- * @param {number} options.timeout - Milliseconds to wait before timeout. Defaults to 4000. Use zero for no timeout.
117
- * @param {string} options.finishOnKey - Optional last character to wait for. Defaults to '#'. It will not be included in the returned digits
118
- * @param {GatherSource} options.source - Where to listen as input source. This option accepts `DTMF` and `SPEECH`. A speech provider must be configure
119
- * when including the `SPEECH` source. You might include both with `SPEECH_AND_DTMF`. Defaults to `SPEECH_AND_DTMF`
120
- * @note When including `SPEECH` the default timeout is 10000 (10s).
121
- * @example
122
- *
123
- * async function handler (request, response) {
124
- * await response.answer();
125
- * const speech = await response.gather({ source: GatherSource.SPEECH, numDigits: 3 });
126
- * console.log("speech: " + speech);
127
- * await response.hangup();
128
- * }
129
- */
130
- gather(options?: GatherOptions): Promise<GatherResponse>;
131
- /**
132
- * Send a text for a TTS engine to convert to speech.
133
- *
134
- * @param {string} text - The text to convert to speech
135
- * @param {SayOptions} options - Options to control the TTS engine
136
- * @param {string} options.playbackRef - Playback identifier to use in Playback operations
137
- * @param {TTSOptions} options.ttsOptions - Options to control the TTS engine (specific to the TTS engine)
138
- * @see Say
139
- * @example
140
- *
141
- * async function handler (request, response) {
142
- * await response.answer();
143
- * const playbackRef = await response.say("Hello World");
144
- *
145
- * // Like the play verb, you can control the playback
146
- * await response.playbackControl(playbackRef, PlaybackControlAction.STOP);
147
- * }
148
- */
149
- say(text: string, options?: SayOptions): Promise<VerbResponse>;
150
- /**
151
- * Stop the current TTS operation.
152
- * @example
153
- *
154
- * async function handler (request, response) {
155
- * await response.answer();
156
- *
157
- * // Some async operation
158
- * setTimeout(() => {
159
- * // Will stop the current TTS operation
160
- * response.stopSay();
161
- * }, 10000);
162
- *
163
- * await response.say("Long text to say...");
164
- * }
165
- */
166
- stopSay(): Promise<VerbResponse>;
167
- /**
168
- * Record the audio of the call.
169
- *
170
- * @param {RecordOptions} options - Options to control the record operation
171
- * @param {number} options.maxDuration - The maximum duration of the recording in seconds. Default is 60
172
- * @param {number} options.maxSilence - The maximum duration of silence in seconds. Default is 5
173
- * @param {boolean} options.beep - Play a beep before recording. Default is true
174
- * @param {string} options.finishOnKey - Stop recording when a DTMF digit is received. Default is '#'
175
- * @return {RecordResponse} The record response
176
- * @example
177
- *
178
- * async function handler (request, response) {
179
- * await response.answer();
180
- * const record = await response.record();
181
- * console.log("Recording: %s", record.name);
182
- * }
183
- */
184
- record(options?: RecordOptions): Promise<RecordResponse>;
185
- /**
186
- * Dials a destination and returns a stream of status.
187
- *
188
- * @param {string} destination - The destination to dial
189
- * @param {DialOptions} options - Options to control the dial operation
190
- * @param {number} options.timeout - The timeout in seconds. Default is 60
191
- * @param {RecordDirection} options.recordDirection - The direction to record the call (IN, OUT, BOTH). Default is BOTH
192
- * @return {Promise<DialStatusStream>} The dial status stream
193
- */
194
- dial(destination: string, options?: DialOptions): Promise<DialStatusStream>;
195
- /**
196
- * Starts a bidirectional audio stream between the call and the application.
197
- *
198
- * @param {StreamOptions} options - Options to control the stream operation
199
- * @param {StreamDirection} options.direction - The direction to stream the audio (IN, OUT, BOTH). Default is BOTH
200
- * @param {StreamAudioFormat} options.format - The audio format to stream (WAV). Default is WAV
201
- * @return {Promise<Stream>} The stream object
202
- * @example
203
- *
204
- * async function handler (request, response) {
205
- * await response.answer();
206
- *
207
- * const stream = await response.stream({
208
- * direction: StreamDirection.BOTH
209
- * });
210
- *
211
- * stream.onPayload((payload) => {
212
- * // Use the payload
213
- * });
214
- *
215
- * // Or write to the stream
216
- * // stream.write({ type: StreamMessageType.AUDIO_OUT, payload: "\x00\x01\x02" });
217
- * }
218
- */
219
- stream(options?: StreamOptions): Promise<Stream>;
220
- /**
221
- * Starts a server-side stream gather operation which sends transcription data to the voice server.
222
- *
223
- * @param {StreamGatherOptions} options - Options to control the stream gather operation
224
- * @param {StreamGatherSource} options.source - The source to gather data from (DTMF, SPEECH, SPEECH_AND_DTMF). Default is SPEECH
225
- * @return {Promise<StreamGatherStream>} The stream gather object
226
- * @see Gather
227
- * @example
228
- *
229
- * async function handler (request, response) {
230
- * await response.answer();
231
- * const sGather = await response.sgather({ source: StreamGatherSource.SPEECH });
232
- * sGather.onPayload((payload) => {
233
- * console.log("Payload: %s", payload);
234
- * });
235
- * }
236
- */
237
- sgather(options: StreamGatherOptions): Promise<StreamGatherStream>;
238
- /**
239
- * Sets the audio filters for this session. Filters run in the Media Server,
240
- * on the caller's audio, before it reaches speech recognition and the
241
- * application's media stream. Call it before answering.
242
- *
243
- * Sending a new list replaces the previous one; an empty list removes all
244
- * filters. If a filter cannot be created — an unknown name, invalid options,
245
- * a missing SDK or license — the verb fails and the call continues with
246
- * unfiltered audio.
247
- *
248
- * @param {AudioFilterConfig[]} filters - The filters to run, in order
249
- * @return {Promise<void>}
250
- * @see aiCoustics
251
- * @example
252
- *
253
- * async function handler (request, response) {
254
- * await response.setAudioFilters([aiCoustics({ enhancementLevel: 0.8 })]);
255
- * await response.answer();
256
- * }
257
- */
258
- setAudioFilters(filters: AudioFilterConfig[]): Promise<void>;
259
- /**
260
- * Mutes a call.
261
- *
262
- * @param {MuteOptions} options - Options to control the mute operation
263
- * @param {MuteDirection} options.direction - The direction to mute the channel (IN, OUT, BOTH). Default is BOTH
264
- * @see unmute
265
- * @example
266
- *
267
- * async function handler (request, response) {
268
- * await response.answer();
269
- * await response.mute(); // Will mute both directions
270
- * }
271
- */
272
- mute(options?: MuteOptions): Promise<void>;
273
- /**
274
- * Unmute a call.
275
- *
276
- * @param {MuteOptions} options - Options to control the unmute operation
277
- * @param {MuteDirection} options.direction - The direction to unmute the call (IN, OUT, BOTH). Default is BOTH
278
- * @see mute
279
- * @example
280
- *
281
- * async function handler (request, response) {
282
- * await response.answer();
283
- * await response.unmute(); // Will unmute both directions
284
- * }
285
- */
286
- unmute(options?: MuteOptions): Promise<void>;
287
- /**
288
- * Register a listener for the given event.
289
- *
290
- * @param {StreamEvent} event - The event to listen for
291
- * @param {Function} listener - The callback function
292
- * @example
293
- *
294
- * async function handler (request, response) {
295
- * ...
296
- *
297
- * response.on(StreamEvent.END, () => {
298
- * console.log("Call ended");
299
- * });
300
- * }
301
- */
302
- on(event: StreamEvent, listener: (...args: unknown[]) => void): void;
303
- }
304
- export { VoiceResponse };