@fonoster/voice 0.4.8 → 0.4.10

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.
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  */
21
21
  const stream_1 = require("stream");
22
22
  class StatusStream {
23
+ stream;
23
24
  constructor() {
24
25
  this.stream = new stream_1.Stream();
25
26
  }
@@ -14,6 +14,7 @@ const defaultOptions = {
14
14
  source: "dtmf"
15
15
  };
16
16
  class GatherVerb extends verb_1.Verb {
17
+ speechProvider;
17
18
  constructor(request, speechProvider) {
18
19
  super(request);
19
20
  this.speechProvider = speechProvider;
@@ -25,6 +25,7 @@ exports.PlaybackControl = void 0;
25
25
  const verb_1 = require("../verb");
26
26
  const logger_1 = __importDefault(require("@fonoster/logger"));
27
27
  class PlaybackControl extends verb_1.Verb {
28
+ playbackId;
28
29
  constructor(request, playbackId) {
29
30
  super(request);
30
31
  this.playbackId = playbackId;
package/dist/server.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { ServerConfig } from "./types";
2
2
  import { Plugin } from "@fonoster/common";
3
- import { VoiceTracer } from "./tracer";
4
3
  export default class VoiceServer {
5
4
  config: ServerConfig;
6
5
  plugins: {};
7
- voiceTracer: VoiceTracer;
8
6
  constructor(config?: ServerConfig);
9
7
  /**
10
8
  * Add tts or asr plugin.
package/dist/server.js CHANGED
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = require("path");
7
- const tracer_1 = require("./tracer");
8
7
  const utils_1 = require("./utils");
9
8
  const voice_1 = __importDefault(require("./voice"));
10
9
  const logger_1 = __importDefault(require("@fonoster/logger"));
@@ -19,10 +18,11 @@ const defaultServerConfig = {
19
18
  base: "/",
20
19
  port: 3000,
21
20
  bind: "0.0.0.0",
22
- pathToFiles: os_1.default.tmpdir(),
23
- otlSpanExporters: []
21
+ pathToFiles: os_1.default.tmpdir()
24
22
  };
25
23
  class VoiceServer {
24
+ config;
25
+ plugins;
26
26
  constructor(config = defaultServerConfig) {
27
27
  this.config = merge(defaultServerConfig, config);
28
28
  this.init();
@@ -45,9 +45,7 @@ class VoiceServer {
45
45
  res.send("pong");
46
46
  });
47
47
  app.post(path_1.posix.join(this.config.base), async (req, res) => {
48
- this.voiceTracer = new tracer_1.VoiceTracer(this.config.otlSpanExporters);
49
- this.voiceTracer.init();
50
- const response = new voice_1.default(req.body, this.voiceTracer);
48
+ const response = new voice_1.default(req.body);
51
49
  response.plugins = this.plugins;
52
50
  handler(req.body, response);
53
51
  res.end();
@@ -13,6 +13,7 @@ const defaultOptions = {
13
13
  source: "speech,dtmf"
14
14
  };
15
15
  class SGatherVerb extends verb_1.Verb {
16
+ speechProvider;
16
17
  constructor(request, speechProvider) {
17
18
  super(request);
18
19
  this.speechProvider = speechProvider;
@@ -24,6 +24,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
24
24
  const stream_1 = require("stream");
25
25
  const pubsub_js_1 = __importDefault(require("pubsub-js"));
26
26
  class StreamData {
27
+ stream;
28
+ dtmfSubscribeToken;
29
+ speechSubscribeToken;
27
30
  constructor() {
28
31
  this.stream = new stream_1.Stream();
29
32
  }
package/dist/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { MeterProvider } from "@opentelemetry/sdk-metrics-base";
2
1
  export interface VoiceRequest {
3
2
  accessKeyId: string;
4
3
  sessionToken: string;
@@ -15,8 +14,6 @@ export interface ServerConfig {
15
14
  port?: number;
16
15
  base?: string;
17
16
  pathToFiles?: string;
18
- otlSpanExporters?: Array<any>;
19
- meterProvider?: MeterProvider;
20
17
  }
21
18
  export interface VoiceEventData {
22
19
  type: string;
package/dist/verb.js CHANGED
@@ -4,33 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Verb = void 0;
7
- /*
8
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
- * http://github.com/fonoster/fonoster
10
- *
11
- * This file is part of Fonoster
12
- *
13
- * Licensed under the MIT License (the "License");
14
- * you may not use this file except in compliance with
15
- * the License. You may obtain a copy of the License at
16
- *
17
- * https://opensource.org/licenses/MIT
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS,
21
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- * See the License for the specific language governing permissions and
23
- * limitations under the License.
24
- */
25
7
  const axios_1 = __importDefault(require("axios"));
26
8
  const logger_1 = __importDefault(require("@fonoster/logger"));
27
- const auth = process.env.NODE_ENV != "production"
28
- ? {
29
- username: "admin",
30
- password: "changeit"
31
- }
32
- : null;
33
9
  class Verb {
10
+ request;
34
11
  constructor(request) {
35
12
  this.request = request;
36
13
  }
@@ -46,7 +23,6 @@ class Verb {
46
23
  return await (0, axios_1.default)({
47
24
  method: "post",
48
25
  url,
49
- auth,
50
26
  headers: {
51
27
  "X-Session-Token": this.request.sessionToken,
52
28
  "Content-Type": "application/json"
@@ -60,7 +36,6 @@ class Verb {
60
36
  return await (0, axios_1.default)({
61
37
  method: "delete",
62
38
  url,
63
- auth,
64
39
  headers: {
65
40
  "X-Session-Token": this.request.sessionToken
66
41
  }
package/dist/voice.d.ts CHANGED
@@ -1,17 +1,16 @@
1
- import { GatherOptions } from "./gather/gather";
2
- import { MuteOptions } from "./mute/mute";
3
- import { PlayOptions } from "./play/play";
4
- import { RecordOptions, RecordResult } from "./record/record";
5
1
  import { PlaybackControl } from "./playback/playback";
6
2
  import { SayOptions } from "./say/types";
7
3
  import { VoiceRequest } from "./types";
8
4
  import { Plugin } from "@fonoster/common";
9
- import { SGatherOptions } from "./sgather/gather";
5
+ import { DialOptions } from "./dial/types";
10
6
  import { SGatherStream } from "./sgather/types";
11
7
  import { DtmfOptions } from "./dtmf/types";
12
- import { DialOptions } from "./dial/types";
8
+ import { SGatherOptions } from "./sgather/gather";
13
9
  import StreamStatus from "./dial/status_stream";
14
- import { VoiceTracer } from "./tracer";
10
+ import { GatherOptions } from "./gather/gather";
11
+ import { MuteOptions } from "./mute/mute";
12
+ import { PlayOptions } from "./play/play";
13
+ import { RecordOptions, RecordResult } from "./record/record";
15
14
  /**
16
15
  * @classdesc Use the VoiceResponse object, to construct advance Interactive
17
16
  * Voice Response (IVR) applications.
@@ -32,14 +31,13 @@ import { VoiceTracer } from "./tracer";
32
31
  export default class VoiceResponse {
33
32
  request: VoiceRequest;
34
33
  plugins: {};
35
- voiceTracer: VoiceTracer;
36
34
  /**
37
35
  * Constructs a new VoiceResponse object.
38
36
  *
39
37
  * @param {VoiceRequest} request - Options to indicate the objects endpoint
40
38
  * @see module:core:APIClient
41
39
  */
42
- constructor(request: VoiceRequest, voiceTracer: VoiceTracer);
40
+ constructor(request: VoiceRequest);
43
41
  /**
44
42
  * Adds a tts or asr plugin. Only one type of plugin can be attached.
45
43
  *
@@ -68,7 +66,7 @@ export default class VoiceResponse {
68
66
  play(media: string, options?: PlayOptions): Promise<void>;
69
67
  /**
70
68
  * Converts a text into a sound and sends sound to media server. To use this verb, you must
71
- * first setup a TTS plugin such as MaryTTS, GoogleTTS, or AWS PollyTTS
69
+ * first setup a TTS plugin such as GoogleTTS, or AWS PollyTTS
72
70
  *
73
71
  * @param {string} text - Converts a text into a sound and sends sound to media server
74
72
  * @param {SayOptions} options - Optional parameters to alter the command's normal
package/dist/voice.js CHANGED
@@ -21,21 +21,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
21
21
  * See the License for the specific language governing permissions and
22
22
  * limitations under the License.
23
23
  */
24
- const answer_1 = __importDefault(require("./answer/answer"));
25
- const hangup_1 = __importDefault(require("./hangup/hangup"));
26
- const unmute_1 = __importDefault(require("./unmute/unmute"));
27
- const gather_1 = __importDefault(require("./gather/gather"));
28
- const mute_1 = __importDefault(require("./mute/mute"));
29
- const play_1 = __importDefault(require("./play/play"));
30
- const record_1 = __importDefault(require("./record/record"));
31
24
  const playback_1 = require("./playback/playback");
32
25
  const asserts_1 = require("./asserts");
33
- const pubsub_js_1 = __importDefault(require("pubsub-js"));
34
26
  const verb_1 = require("./verb");
35
27
  const utils_1 = require("./utils");
36
- const gather_2 = __importDefault(require("./sgather/gather"));
28
+ const gather_1 = __importDefault(require("./sgather/gather"));
37
29
  const dtmf_1 = __importDefault(require("./dtmf/dtmf"));
38
30
  const dial_1 = __importDefault(require("./dial/dial"));
31
+ const pubsub_js_1 = __importDefault(require("pubsub-js"));
32
+ const answer_1 = __importDefault(require("./answer/answer"));
33
+ const hangup_1 = __importDefault(require("./hangup/hangup"));
34
+ const unmute_1 = __importDefault(require("./unmute/unmute"));
35
+ const gather_2 = __importDefault(require("./gather/gather"));
36
+ const mute_1 = __importDefault(require("./mute/mute"));
37
+ const play_1 = __importDefault(require("./play/play"));
38
+ const record_1 = __importDefault(require("./record/record"));
39
39
  /**
40
40
  * @classdesc Use the VoiceResponse object, to construct advance Interactive
41
41
  * Voice Response (IVR) applications.
@@ -54,15 +54,16 @@ const dial_1 = __importDefault(require("./dial/dial"));
54
54
  * voiceServer.listen(handler, { port: 3000 })
55
55
  */
56
56
  class VoiceResponse {
57
+ request;
58
+ plugins;
57
59
  /**
58
60
  * Constructs a new VoiceResponse object.
59
61
  *
60
62
  * @param {VoiceRequest} request - Options to indicate the objects endpoint
61
63
  * @see module:core:APIClient
62
64
  */
63
- constructor(request, voiceTracer) {
65
+ constructor(request) {
64
66
  this.request = request;
65
- this.voiceTracer = voiceTracer;
66
67
  this.plugins = {};
67
68
  }
68
69
  /**
@@ -93,13 +94,11 @@ class VoiceResponse {
93
94
  * }
94
95
  */
95
96
  async play(media, options = {}) {
96
- const span = this.voiceTracer.createSpan("play");
97
97
  await new play_1.default(this.request).run(media, options);
98
- span.end();
99
98
  }
100
99
  /**
101
100
  * Converts a text into a sound and sends sound to media server. To use this verb, you must
102
- * first setup a TTS plugin such as MaryTTS, GoogleTTS, or AWS PollyTTS
101
+ * first setup a TTS plugin such as GoogleTTS, or AWS PollyTTS
103
102
  *
104
103
  * @param {string} text - Converts a text into a sound and sends sound to media server
105
104
  * @param {SayOptions} options - Optional parameters to alter the command's normal
@@ -121,17 +120,9 @@ class VoiceResponse {
121
120
  (0, asserts_1.assertPluginExist)(this, "tts");
122
121
  const tts = this.plugins["tts"];
123
122
  // It should return the filename and the generated file location
124
- const main = this.voiceTracer.createSpan("play");
125
- const span = this.voiceTracer.createSpan("synthesize");
126
123
  const result = await tts.synthesize(text, options);
127
- span.setAttribute("text", text);
128
- span.setAttribute("options", JSON.stringify(options));
129
- span.end();
130
124
  const media = `sound:${this.request.selfEndpoint}/tts/${result.filename}`;
131
125
  await new play_1.default(this.request).run(media, options);
132
- main.setAttribute("media", media);
133
- main.setAttribute("options", JSON.stringify(options));
134
- main.end();
135
126
  }
136
127
  /**
137
128
  * Waits for data entry from the user's keypad or from a speech provider.
@@ -158,10 +149,7 @@ class VoiceResponse {
158
149
  (0, asserts_1.assertPluginExist)(this, "asr");
159
150
  asr = this.plugins["asr"];
160
151
  }
161
- const span = this.voiceTracer.createSpan("gather");
162
- const result = await new gather_1.default(this.request, asr).run(options);
163
- span.setAttribute("options", JSON.stringify(options));
164
- span.end();
152
+ const result = await new gather_2.default(this.request, asr).run(options);
165
153
  return result;
166
154
  }
167
155
  /**
@@ -196,7 +184,7 @@ class VoiceResponse {
196
184
  (0, asserts_1.assertPluginExist)(this, "asr");
197
185
  asr = this.plugins["asr"];
198
186
  }
199
- return await new gather_2.default(this.request, asr).run(options);
187
+ return await new gather_1.default(this.request, asr).run(options);
200
188
  }
201
189
  /**
202
190
  * Sends dtmf tones to the current session.
@@ -212,11 +200,7 @@ class VoiceResponse {
212
200
  * }
213
201
  */
214
202
  async dtmf(options) {
215
- const span = this.voiceTracer.createSpan("dtmf");
216
- const result = await new dtmf_1.default(this.request).run(options);
217
- span.setAttribute("options", JSON.stringify(options));
218
- span.end();
219
- return result;
203
+ return await new dtmf_1.default(this.request).run(options);
220
204
  }
221
205
  /**
222
206
  * Forwards the call to an Agent or the PSTN.
@@ -238,12 +222,7 @@ class VoiceResponse {
238
222
  * }
239
223
  */
240
224
  async dial(destination, options) {
241
- const span = this.voiceTracer.createSpan("dial");
242
- const result = await new dial_1.default(this.request).run(destination, options);
243
- span.setAttribute("destination", destination);
244
- span.setAttribute("options", JSON.stringify(options));
245
- span.end();
246
- return result;
225
+ return await new dial_1.default(this.request).run(destination, options);
247
226
  }
248
227
  /**
249
228
  * Returns a PlaybackControl control object.
@@ -267,11 +246,7 @@ class VoiceResponse {
267
246
  * }
268
247
  */
269
248
  playback(playbackId) {
270
- const span = this.voiceTracer.createSpan("playback");
271
- const result = new playback_1.PlaybackControl(this.request, playbackId);
272
- span.setAttribute("playbackId", playbackId);
273
- span.end();
274
- return result;
249
+ return new playback_1.PlaybackControl(this.request, playbackId);
275
250
  }
276
251
  /**
277
252
  * Listens event publication.
@@ -312,11 +287,7 @@ class VoiceResponse {
312
287
  * }
313
288
  */
314
289
  async mute(options) {
315
- const span = this.voiceTracer.createSpan("mute");
316
- const result = new mute_1.default(this.request).run(options);
317
- span.setAttribute("options", JSON.stringify(options));
318
- span.end();
319
- await result;
290
+ return new mute_1.default(this.request).run(options);
320
291
  }
321
292
  /**
322
293
  * Unmutes a channel.
@@ -332,11 +303,7 @@ class VoiceResponse {
332
303
  * }
333
304
  */
334
305
  async unmute(options) {
335
- const span = this.voiceTracer.createSpan("unmute");
336
- const result = new unmute_1.default(this.request).run(options);
337
- span.setAttribute("options", JSON.stringify(options));
338
- span.end();
339
- await result;
306
+ return new unmute_1.default(this.request).run(options);
340
307
  }
341
308
  /**
342
309
  * Answer the communication channel. Before running any other verb you
@@ -350,10 +317,7 @@ class VoiceResponse {
350
317
  * }
351
318
  */
352
319
  async answer() {
353
- const span = this.voiceTracer.createSpan("answer");
354
- const result = new answer_1.default(this.request).run();
355
- span.end();
356
- await result;
320
+ return new answer_1.default(this.request).run();
357
321
  }
358
322
  /**
359
323
  * Terminates the communication channel.
@@ -366,12 +330,7 @@ class VoiceResponse {
366
330
  * }
367
331
  */
368
332
  async hangup() {
369
- const span = this.voiceTracer.createSpan("hangup");
370
- const result = new hangup_1.default(this.request).run();
371
- span.end();
372
- // Need to close or the span will be lost
373
- this.voiceTracer.close();
374
- await result;
333
+ return new hangup_1.default(this.request).run();
375
334
  }
376
335
  /**
377
336
  * Records the current channel and uploads the file to the storage subsystem.
@@ -392,24 +351,17 @@ class VoiceResponse {
392
351
  * }
393
352
  */
394
353
  async record(options) {
395
- const span = this.voiceTracer.createSpan("record");
396
- const result = await new record_1.default(this.request).run(options);
397
- span.end();
398
- return result;
354
+ return await new record_1.default(this.request).run(options);
399
355
  }
400
356
  // Requests media from Media server
401
357
  async openMediaPipe() {
402
- const span = this.voiceTracer.createSpan("openMediaPipe");
403
358
  const genericVerb = new verb_1.Verb(this.request);
404
359
  await (0, utils_1.startMediaTransfer)(genericVerb, this.request.sessionId);
405
- span.end();
406
360
  }
407
361
  // Requests media stop from Media server
408
362
  async closeMediaPipe() {
409
- const span = this.voiceTracer.createSpan("stopMediaTransfer");
410
363
  const genericVerb = new verb_1.Verb(this.request);
411
364
  await (0, utils_1.stopMediaTransfer)(genericVerb, this.request.sessionId);
412
- span.end();
413
365
  }
414
366
  }
415
367
  exports.default = VoiceResponse;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fonoster/voice",
3
- "version": "0.4.8",
3
+ "version": "0.4.10",
4
4
  "description": "Voice verbs",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
@@ -29,25 +29,16 @@
29
29
  "url": "https://github.com/fonoster/fonoster/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@fonoster/common": "^0.4.8",
33
- "@fonoster/logger": "^0.4.7",
34
- "@opentelemetry/api": "^1.0.4",
35
- "@opentelemetry/instrumentation": "^0.27.0",
36
- "@opentelemetry/instrumentation-express": "^0.27.0",
37
- "@opentelemetry/instrumentation-http": "^0.27.0",
38
- "@opentelemetry/resources": "^1.0.4",
39
- "@opentelemetry/sdk-metrics-base": "0.27.0",
40
- "@opentelemetry/sdk-trace-base": "^1.0.4",
41
- "@opentelemetry/sdk-trace-node": "^1.0.4",
42
- "@opentelemetry/semantic-conventions": "^1.0.4",
32
+ "@fonoster/common": "^0.4.10",
33
+ "@fonoster/logger": "^0.4.10",
34
+ "axios": "^1.6.2",
43
35
  "bson-objectid": "^2.0.2",
44
36
  "deepmerge": "^4.2.2",
45
37
  "express": "^4.17.1",
46
38
  "express-ws": "^4.0.0",
47
- "pubsub-js": "^1.9.3",
48
- "sync": "^0.2.5"
39
+ "pubsub-js": "^1.9.3"
49
40
  },
50
- "gitHead": "e594d9c289ce814090b8133d3efb03561cfa7598",
41
+ "gitHead": "5803a7dc72afe7bf454896ae4c60c7565d27eb49",
51
42
  "devDependencies": {
52
43
  "@types/express": "^4.17.13",
53
44
  "@types/pubsub-js": "^1.8.2"
package/dist/tracer.d.ts DELETED
@@ -1,10 +0,0 @@
1
- import { Context, Span, Tracer } from "@opentelemetry/api";
2
- export declare class VoiceTracer {
3
- callTracer: Tracer;
4
- parentSpan: Span;
5
- ctx: Context;
6
- constructor(otlSpanExporters: Array<any>);
7
- init(): void;
8
- close(): void;
9
- createSpan(name: string): Span;
10
- }
package/dist/tracer.js DELETED
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.VoiceTracer = void 0;
7
- /*
8
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
- * http://github.com/fonoster/fonoster
10
- *
11
- * This file is part of Fonoster
12
- *
13
- * Licensed under the MIT License (the "License");
14
- * you may not use this file except in compliance with
15
- * the License. You may obtain a copy of the License at
16
- *
17
- * https://opensource.org/licenses/MIT
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS,
21
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- * See the License for the specific language governing permissions and
23
- * limitations under the License.
24
- */
25
- const api_1 = __importDefault(require("@opentelemetry/api"));
26
- const resources_1 = require("@opentelemetry/resources");
27
- const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
28
- const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
29
- const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
30
- class VoiceTracer {
31
- constructor(otlSpanExporters) {
32
- // Configure span processor to send spans to the exporter
33
- const provider = new NodeTracerProvider({
34
- resource: new resources_1.Resource({
35
- [semantic_conventions_1.SemanticResourceAttributes.SERVICE_NAME]: "voice-service"
36
- })
37
- });
38
- for (const exp of otlSpanExporters) {
39
- const exporter = new exp.exporter(exp.config);
40
- provider.addSpanProcessor(new sdk_trace_base_1.BatchSpanProcessor(exporter));
41
- }
42
- provider.register();
43
- this.callTracer = api_1.default.trace.getTracer("call_tracer");
44
- }
45
- init() {
46
- this.parentSpan = this.callTracer.startSpan("call");
47
- this.ctx = api_1.default.trace.setSpan(api_1.default.context.active(), this.parentSpan);
48
- }
49
- close() {
50
- this.parentSpan.end();
51
- }
52
- createSpan(name) {
53
- return this.callTracer.startSpan(name, undefined, this.ctx);
54
- }
55
- }
56
- exports.VoiceTracer = VoiceTracer;