@fonoster/ctl 0.7.42 → 0.7.43

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 (2) hide show
  1. package/README.md +8 -410
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -1,419 +1,17 @@
1
- voice
1
+ ctl
2
2
  =================
3
3
 
4
- [![Voice](https://img.shields.io/badge/voice-api-brightgreen.svg)](https://fonoster.com)
5
- [![Version](https://img.shields.io/npm/v/@fonoster/voice.svg)](https://npmjs.org/package/@fonoster/voice)
6
- [![Downloads/week](https://img.shields.io/npm/dw/@fonoster/voice.svg)](https://npmjs.org/package/@fonoster/voice)
7
- [![License](https://img.shields.io/npm/l/@fonoster/voice.svg)](https://github.com/fonoster/fonoster/blob/main/package.json)
8
-
9
- The Voice module is a library for creating voice applications using the Fonoster API. It provides a simple way to create voice applications that can interact with the calling party using DTMF or speech recognition combined with simple verbs.
10
-
11
- * [Installation](#installation)
12
- * [Example](#example)
13
- * [Voice Response](#VoiceResponse)
4
+ [![command-line tool](https://img.shields.io/badge/ctl-oclif-brightgreen.svg)](https://fonoster.com)
5
+ [![Version](https://img.shields.io/npm/v/@fonoster/ctl.svg)](https://npmjs.org/package/@fonoster/voice)
6
+ [![Downloads/week](https://img.shields.io/npm/dw/@fonoster/ctl.svg)](https://npmjs.org/package/@fonoster/voice)
7
+ [![License](https://img.shields.io/npm/l/@fonoster/ctl.svg)](https://github.com/fonoster/fonoster/blob/main/package.json)
14
8
 
15
9
  ## Installation
16
10
 
17
11
  ```sh-session
18
- $ npm install --save @fonoster/voice
19
- ```
20
-
21
- ## Example
22
-
23
- A Voice Application is a server that controls a call's flow. A Voice Application can use any combination of the following verbs:
24
-
25
- - `Answer` - Accepts an incoming call
26
- - `Dial` - Passes the call to an Agent or a Number at the PSTN
27
- - `Hangup` - Closes the call
28
- - `Play` - Takes a URL or file and streams the sound back to the calling party
29
- - `Say` - Takes a text, synthesizes the text into audio, and streams back the result
30
- - `Gather` - Waits for DTMF or speech events and returns back the result
31
- - `SGather` - Returns a stream for future DTMF and speech results
32
- - `Stream` - Starts a stream to read and write audio into the call
33
- - `Record` - It records the voice of the calling party and saves the audio on the Storage sub-system
34
- - `Mute` - It tells the channel to stop sending media, effectively muting the channel
35
- - `Unmute` - It tells the channel to allow media flow
36
-
37
- Voice Application Example:
38
-
39
- ```typescript
40
- const VoiceServer = require("@fonoster/voice").default;
41
- const {
42
- GatherSource,
43
- VoiceRequest,
44
- VoiceResponse
45
- } = require("@fonoster/voice");
46
-
47
- new VoiceServer().listen(async (req: VoiceRequest, voice: VoiceResponse) => {
48
- const { ingressNumber, sessionRef, appRef } = req;
49
-
50
- await voice.answer();
51
-
52
- await voice.say("Hi there! What's your name?");
53
-
54
- const { speech: name } = await res.gather({
55
- source: GatherSource.SPEECH
56
- });
57
-
58
- await voice.say("Nice to meet you " + name + "!");
59
-
60
- await voice.say("Please enter your 4 digit pin.");
61
-
62
- const { digits } = await voice.gather({
63
- maxDigits: 4,
64
- finishOnKey: "#"
65
- });
66
-
67
- await voice.say("Your pin is " + digits);
68
-
69
- await voice.hangup();
70
- });
71
-
72
- // Your app will live at tcp://127.0.0.1:50061
73
- // and you can easily publish it to the Internet with:
74
- // ngrok tcp 50061
75
- ```
76
-
77
- <a name="VoiceResponse"></a>
78
-
79
- ## VoiceResponse ⇐ <code>Verb</code>
80
- Use the VoiceResponse object, to construct advance Interactive
81
- Voice Response (IVR) applications.
82
-
83
- **Kind**: global class
84
- **Extends**: <code>Verb</code>
85
- **See**: module:core:APIClient
86
-
87
- * [VoiceResponse](#VoiceResponse) ⇐ <code>Verb</code>
88
- * [new VoiceResponse(request, voice)](#new_VoiceResponse_new)
89
- * [.answer()](#VoiceResponse+answer)
90
- * [.hangup()](#VoiceResponse+hangup)
91
- * [.play(url, options)](#VoiceResponse+play)
92
- * [.playDtmf(digits)](#VoiceResponse+playDtmf)
93
- * [.playbackControl(playbackRef, action)](#VoiceResponse+playbackControl)
94
- * [.gather(options)](#VoiceResponse+gather)
95
- * [.say(text, options)](#VoiceResponse+say)
96
- * [.record(options)](#VoiceResponse+record) ⇒ <code>RecordResponse</code>
97
- * [.dial(destination, options)](#VoiceResponse+dial) ⇒ <code>Promise.&lt;DialStatusStream&gt;</code>
98
- * [.stream(options)](#VoiceResponse+stream) ⇒ <code>Promise.&lt;Stream&gt;</code>
99
- * [.sgather(options)](#VoiceResponse+sgather) ⇒ <code>Promise.&lt;StreamGatherStream&gt;</code>
100
- * [.mute(options)](#VoiceResponse+mute)
101
- * [.unmute(options)](#VoiceResponse+unmute)
102
- * [.on(event, listener)](#VoiceResponse+on)
103
-
104
- <a name="new_VoiceResponse_new"></a>
105
-
106
- ### new VoiceResponse(request, voice)
107
- Constructs a new VoiceResponse object.
108
-
109
-
110
- | Param | Type | Description |
111
- | --- | --- | --- |
112
- | request | <code>VoiceRequest</code> | Options to indicate the objects endpoint |
113
- | voice | <code>VoiceSessionStream</code> | The voice session stream |
114
-
115
- **Example**
116
- ```js
117
- import { VoiceServer } from "@fonoster/voice";
118
-
119
- async function handler (request, response) {
120
- await response.answer();
121
- await response.play("https://soundsserver:9000/sounds/hello-world.wav");
122
- }
123
-
124
- new VoiceServer().listen(handler, { port: 3000 })
125
- ```
126
- <a name="VoiceResponse+answer"></a>
127
-
128
- ### voiceResponse.answer()
129
- Answer the call. Before running any other verb you
130
- must run the anwer command.
131
-
132
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
133
- **Example**
134
- ```js
135
- async function handler (request, response) {
136
- await response.answer();
137
- }
138
- ```
139
- <a name="VoiceResponse+hangup"></a>
140
-
141
- ### voiceResponse.hangup()
142
- Hangup the call.
143
-
144
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
145
- **Example**
146
- ```js
147
- async function handler (request, response) {
148
- await response.hangup();
149
- }
150
- ```
151
- <a name="VoiceResponse+play"></a>
152
-
153
- ### voiceResponse.play(url, options)
154
- Play an audio in the call.
155
-
156
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
157
- **See**: Playback
158
-
159
- | Param | Type | Description |
160
- | --- | --- | --- |
161
- | url | <code>string</code> | The URL of the media to play |
162
- | options | <code>PlayOptions</code> | Options to control the playback |
163
- | options.playbackRef | <code>string</code> | Playback identifier to use in Playback operations |
164
-
165
- **Example**
166
- ```js
167
- async function handler (request, response) {
168
- await response.answer();
169
- await response.play("https://soundsserver:9000/sounds/hello-world.wav");
170
- }
171
- ```
172
- <a name="VoiceResponse+playDtmf"></a>
173
-
174
- ### voiceResponse.playDtmf(digits)
175
- Play a series of DTMF digits in a call.
176
-
177
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
178
-
179
- | Param | Type | Description |
180
- | --- | --- | --- |
181
- | digits | <code>string</code> | The DTMF digits to play (0-9, #, or *) |
182
-
183
- **Example**
184
- ```js
185
- async function handler (request, response) {
186
- await response.answer();
187
- await response.playDtmf("1234");
188
- }
189
- ```
190
- <a name="VoiceResponse+playbackControl"></a>
191
-
192
- ### voiceResponse.playbackControl(playbackRef, action)
193
- Control the playback of the currently playing media.
194
-
195
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
196
- **See**: play
197
-
198
- | Param | Type | Description |
199
- | --- | --- | --- |
200
- | playbackRef | <code>string</code> | The playback identifier |
201
- | action | <code>PlaybackControlAction</code> | The action to perform (STOP, RESTART, PAUSE, UNPAUSE, FORWARD) |
202
-
203
- **Example**
204
- ```js
205
- async function handler (request, response) {
206
- await response.answer();
207
- await response.play("https://s3.fonoster.io/uuid/hello-world.wav", { playbackRef: "playback-01" });
208
-
209
- // Pause the media
210
- await response.playbackControl("playback-01", PlaybackControlAction.PAUSE);
211
- }
212
- ```
213
- <a name="VoiceResponse+gather"></a>
214
-
215
- ### voiceResponse.gather(options)
216
- Waits for data entry from the user's keypad or from a speech provider.
217
-
218
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
219
- **Note**: When including `SPEECH` the default timeout is 10000 (10s).
220
-
221
- | Param | Type | Description |
222
- | --- | --- | --- |
223
- | options | <code>GatherOptions</code> | Options to select the maximum number of digits, final character, and timeout |
224
- | options.maxDigits | <code>number</code> | Maximum number of digits to collect. Defaults to 1 |
225
- | options.timeout | <code>number</code> | Milliseconds to wait before timeout. Defaults to 4000. Use zero for no timeout. |
226
- | options.finishOnKey | <code>string</code> | Optional last character to wait for. Defaults to '#'. It will not be included in the returned digits |
227
- | options.source | <code>GatherSource</code> | Where to listen as input source. This option accepts `DTMF` and `SPEECH`. A speech provider must be configure when including the `SPEECH` source. You might inclue both with `SPEECH_AND_DTMF`. Defaults to `SPEECH_AND_DTMF` |
228
-
229
- **Example**
230
- ```js
231
- async function handler (request, response) {
232
- await response.answer();
233
- const speech = await response.gather({ source: GatherSource.SPEECH, numDigits: 3 });
234
- console.log("speech: " + speech);
235
- await response.hangup();
236
- }
237
- ```
238
- <a name="VoiceResponse+say"></a>
239
-
240
- ### voiceResponse.say(text, options)
241
- Send a text for a TTS engine to convert to speech.
242
-
243
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
244
- **See**: Say
245
-
246
- | Param | Type | Description |
247
- | --- | --- | --- |
248
- | text | <code>string</code> | The text to convert to speech |
249
- | options | <code>SayOptions</code> | Options to control the TTS engine |
250
- | options.playbackRef | <code>string</code> | Playback identifier to use in Playback operations |
251
- | options.ttsOptions | <code>TTSOptions</code> | Options to control the TTS engine (specific to the TTS engine) |
252
-
253
- **Example**
254
- ```js
255
- async function handler (request, response) {
256
- await response.answer();
257
- const playbackRef = await response.say("Hello World");
258
-
259
- // Like the play verb, you can control the playback
260
- await response.playbackControl(playbackRef, PlaybackControlAction.STOP);
261
- }
262
- ```
263
- <a name="VoiceResponse+record"></a>
264
-
265
- ### voiceResponse.record(options) ⇒ <code>RecordResponse</code>
266
- Record the audio of the call.
267
-
268
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
269
- **Returns**: <code>RecordResponse</code> - The record response
270
-
271
- | Param | Type | Description |
272
- | --- | --- | --- |
273
- | options | <code>RecordOptions</code> | Options to control the record operation |
274
- | options.maxDuration | <code>number</code> | The maximum duration of the recording in seconds. Default is 60 |
275
- | options.maxSilence | <code>number</code> | The maximum duration of silence in seconds. Default is 5 |
276
- | options.beep | <code>boolean</code> | Play a beep before recording. Default is true |
277
- | options.finishOnKey | <code>string</code> | Stop recording when a DTMF digit is received. Default is '#' |
278
-
279
- **Example**
280
- ```js
281
- async function handler (request, response) {
282
- await response.answer();
283
- const record = await response.record();
284
- console.log("Recording: %s", record.name);
285
- }
286
- ```
287
- <a name="VoiceResponse+dial"></a>
288
-
289
- ### voiceResponse.dial(destination, options) ⇒ <code>Promise.&lt;DialStatusStream&gt;</code>
290
- Dials a destination and returns a stream of status.
291
-
292
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
293
- **Returns**: <code>Promise.&lt;DialStatusStream&gt;</code> - The dial status stream
294
-
295
- | Param | Type | Description |
296
- | --- | --- | --- |
297
- | destination | <code>string</code> | The destination to dial |
298
- | options | <code>DialOptions</code> | Options to control the dial operation |
299
- | options.timeout | <code>number</code> | The timeout in seconds. Default is 60 |
300
- | options.recordDirection | <code>RecordDirection</code> | The direction to record the call (IN, OUT, BOTH). Default is BOTH |
301
-
302
- <a name="VoiceResponse+stream"></a>
303
-
304
- ### voiceResponse.stream(options) ⇒ <code>Promise.&lt;Stream&gt;</code>
305
- Starts a bidirectional audio stream between the call and the application.
306
-
307
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
308
- **Returns**: <code>Promise.&lt;Stream&gt;</code> - The stream object
309
-
310
- | Param | Type | Description |
311
- | --- | --- | --- |
312
- | options | <code>StreamOptions</code> | Options to control the stream operation |
313
- | options.direction | <code>StreamDirection</code> | The direction to stream the audio (IN, OUT, BOTH). Default is BOTH |
314
- | options.format | <code>StreamAudioFormat</code> | The audio format to stream (WAV). Default is WAV |
315
-
316
- **Example**
317
- ```js
318
- async function handler (request, response) {
319
- await response.answer();
320
-
321
- const stream = await response.stream({
322
- direction: StreamDirection.BOTH
323
- });
324
-
325
- stream.onPayload((payload) => {
326
- // Use the payload
327
- });
328
-
329
- // Or write to the stream
330
- // stream.write({ type: StreamMessageType.AUDIO_OUT, payload: "\x00\x01\x02" });
331
- }
12
+ $ npm install --save @fonoster/ctl@next
332
13
  ```
333
- <a name="VoiceResponse+sgather"></a>
334
-
335
- ### voiceResponse.sgather(options) ⇒ <code>Promise.&lt;StreamGatherStream&gt;</code>
336
- Starts a server-side stream gather operation which sends transcription data to the voice server.
337
-
338
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
339
- **Returns**: <code>Promise.&lt;StreamGatherStream&gt;</code> - The stream gather object
340
- **See**: Gather
341
-
342
- | Param | Type | Description |
343
- | --- | --- | --- |
344
- | options | <code>StreamGatherOptions</code> | Options to control the stream gather operation |
345
- | options.source | <code>StreamGatherSource</code> | The source to gather data from (DTMF, SPEECH, SPEECH_AND_DTMF). Default is SPEECH |
346
-
347
- **Example**
348
- ```js
349
- async function handler (request, response) {
350
- await response.answer();
351
- const sGather = await response.streamGather({ source: StreamGatherSource.SPEECH });
352
- sGather.onPayload((payload) => {
353
- console.log("Payload: %s", payload);
354
- });
355
- }
356
- ```
357
- <a name="VoiceResponse+mute"></a>
358
-
359
- ### voiceResponse.mute(options)
360
- Mutes a call.
361
-
362
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
363
- **See**: unmute
364
-
365
- | Param | Type | Description |
366
- | --- | --- | --- |
367
- | options | <code>MuteOptions</code> | Options to control the mute operation |
368
- | options.direction | <code>MuteDirection</code> | The direction to mute the channel (IN, OUT, BOTH). Default is BOTH |
369
14
 
370
- **Example**
371
- ```js
372
- async function handler (request, response) {
373
- await response.answer();
374
- await response.mute(); // Will mute both directions
375
- }
376
- ```
377
- <a name="VoiceResponse+unmute"></a>
378
-
379
- ### voiceResponse.unmute(options)
380
- Unmutes a call.
381
-
382
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
383
- **See**: mute
384
-
385
- | Param | Type | Description |
386
- | --- | --- | --- |
387
- | options | <code>MuteOptions</code> | Options to control the unmute operation |
388
- | options.direction | <code>MuteDirection</code> | The direction to unmute the call (IN, OUT, BOTH). Default is BOTH |
389
-
390
- **Example**
391
- ```js
392
- async function handler (request, response) {
393
- await response.answer();
394
- await response.unmute(); // Will unmute both directions
395
- }
396
- ```
397
- <a name="VoiceResponse+on"></a>
398
-
399
- ### voiceResponse.on(event, listener)
400
- Register a listener for the given event.
401
-
402
- **Kind**: instance method of [<code>VoiceResponse</code>](#VoiceResponse)
403
-
404
- | Param | Type | Description |
405
- | --- | --- | --- |
406
- | event | <code>StreamEvent</code> | The event to listen for |
407
- | listener | <code>function</code> | The callback function |
408
-
409
- **Example**
410
- ```js
411
- async function handler (request, response) {
412
- ...
413
-
414
- response.on(StreamEvent.END, () => {
415
- console.log("Call ended");
416
- });
417
- }
418
- ```
15
+ ## Usage
419
16
 
17
+ Check the docs [here](https://github.com/fonoster/fonoster/blob/main/docs/early-access/link-twilio-number.md) for more information.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/ctl",
3
- "version": "0.7.42",
3
+ "version": "0.7.43",
4
4
  "description": "Fonoster Control Tool",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -30,7 +30,7 @@
30
30
  "bugs": {
31
31
  "url": "https://github.com/fonoster/fonoster/issues"
32
32
  },
33
- "gitHead": "50867fa36ff09aedbbf44529d50c73c967defc78",
33
+ "gitHead": "b78418a8b177646715e56524c84200895646fb5e",
34
34
  "bin": {
35
35
  "fonoster": "./bin/run.js"
36
36
  },
@@ -42,7 +42,7 @@
42
42
  "helpClass": "./dist/help"
43
43
  },
44
44
  "dependencies": {
45
- "@fonoster/sdk": "^0.7.42",
45
+ "@fonoster/sdk": "^0.7.43",
46
46
  "@inquirer/prompts": "^7.1.0",
47
47
  "@oclif/core": "^4.0.34",
48
48
  "cliui": "^8.0.1",