@fonoster/voice 0.5.4 → 0.6.1-alpha.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 (109) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +3 -0
  3. package/dist/VoiceResponse.d.ts +218 -0
  4. package/dist/VoiceResponse.js +352 -0
  5. package/dist/VoiceServer.d.ts +6 -0
  6. package/dist/VoiceServer.js +109 -0
  7. package/dist/createSession.d.ts +4 -0
  8. package/dist/createSession.js +45 -0
  9. package/dist/defaultServerConfig.d.ts +3 -0
  10. package/dist/defaultServerConfig.js +10 -0
  11. package/dist/demo.d.ts +1 -0
  12. package/dist/demo.js +56 -0
  13. package/dist/index.d.ts +6 -6
  14. package/dist/index.js +42 -7
  15. package/dist/serviceDefinition.d.ts +2 -0
  16. package/dist/serviceDefinition.js +29 -0
  17. package/dist/types.d.ts +8 -20
  18. package/dist/verbs/Answer.d.ts +6 -0
  19. package/dist/{mute/mute.js → verbs/Answer.js} +8 -7
  20. package/dist/verbs/Dial.d.ts +16 -0
  21. package/dist/verbs/Dial.js +52 -0
  22. package/dist/verbs/Gather.d.ts +7 -0
  23. package/dist/verbs/Gather.js +39 -0
  24. package/dist/verbs/Hangup.d.ts +6 -0
  25. package/dist/{unmute/unmute.js → verbs/Hangup.js} +8 -7
  26. package/dist/verbs/Mute.d.ts +7 -0
  27. package/dist/verbs/Mute.js +36 -0
  28. package/dist/verbs/Play.d.ts +7 -0
  29. package/dist/verbs/Play.js +14 -0
  30. package/dist/verbs/PlayDtmf.d.ts +7 -0
  31. package/dist/verbs/PlayDtmf.js +13 -0
  32. package/dist/verbs/PlaybackControl.d.ts +7 -0
  33. package/dist/{dial/status_stream.js → verbs/PlaybackControl.js} +11 -17
  34. package/dist/verbs/Record.d.ts +7 -0
  35. package/dist/verbs/Record.js +20 -0
  36. package/dist/verbs/Say.d.ts +7 -0
  37. package/dist/verbs/Say.js +14 -0
  38. package/dist/verbs/Stream.d.ts +22 -0
  39. package/dist/verbs/Stream.js +76 -0
  40. package/dist/verbs/Unmute.d.ts +4 -0
  41. package/dist/verbs/Unmute.js +26 -0
  42. package/dist/verbs/Verb.d.ts +10 -0
  43. package/dist/verbs/Verb.js +70 -0
  44. package/dist/verbs/index.d.ts +14 -0
  45. package/dist/verbs/index.js +48 -0
  46. package/dist/verbs/validateRequest.d.ts +2 -0
  47. package/dist/verbs/validateRequest.js +12 -0
  48. package/package.json +22 -21
  49. package/dist/answer/answer.d.ts +0 -4
  50. package/dist/answer/answer.js +0 -55
  51. package/dist/asserts.d.ts +0 -4
  52. package/dist/asserts.js +0 -47
  53. package/dist/dial/dial.d.ts +0 -6
  54. package/dist/dial/dial.js +0 -77
  55. package/dist/dial/status_stream.d.ts +0 -9
  56. package/dist/dial/types.d.ts +0 -6
  57. package/dist/dial/types.js +0 -2
  58. package/dist/dtmf/asserts.d.ts +0 -2
  59. package/dist/dtmf/asserts.js +0 -9
  60. package/dist/dtmf/dtmf.d.ts +0 -5
  61. package/dist/dtmf/dtmf.js +0 -61
  62. package/dist/dtmf/types.d.ts +0 -3
  63. package/dist/dtmf/types.js +0 -2
  64. package/dist/gather/asserts.d.ts +0 -2
  65. package/dist/gather/asserts.js +0 -9
  66. package/dist/gather/gather.d.ts +0 -10
  67. package/dist/gather/gather.js +0 -50
  68. package/dist/gather/source_dtmf.d.ts +0 -3
  69. package/dist/gather/source_dtmf.js +0 -46
  70. package/dist/gather/source_speech.d.ts +0 -5
  71. package/dist/gather/source_speech.js +0 -65
  72. package/dist/gather/types.d.ts +0 -6
  73. package/dist/gather/types.js +0 -2
  74. package/dist/hangup/hangup.d.ts +0 -4
  75. package/dist/hangup/hangup.js +0 -57
  76. package/dist/mute/mute.d.ts +0 -6
  77. package/dist/mute/types.d.ts +0 -3
  78. package/dist/mute/types.js +0 -2
  79. package/dist/play/play.d.ts +0 -6
  80. package/dist/play/play.js +0 -57
  81. package/dist/play/types.d.ts +0 -5
  82. package/dist/play/types.js +0 -2
  83. package/dist/playback/playback.d.ts +0 -12
  84. package/dist/playback/playback.js +0 -67
  85. package/dist/record/record.d.ts +0 -6
  86. package/dist/record/record.js +0 -68
  87. package/dist/record/types.d.ts +0 -13
  88. package/dist/record/types.js +0 -2
  89. package/dist/say/types.d.ts +0 -5
  90. package/dist/say/types.js +0 -2
  91. package/dist/server.d.ts +0 -15
  92. package/dist/server.js +0 -90
  93. package/dist/sgather/gather.d.ts +0 -10
  94. package/dist/sgather/gather.js +0 -42
  95. package/dist/sgather/source_speech.d.ts +0 -7
  96. package/dist/sgather/source_speech.js +0 -42
  97. package/dist/sgather/stream_data.d.ts +0 -14
  98. package/dist/sgather/stream_data.js +0 -69
  99. package/dist/sgather/types.d.ts +0 -7
  100. package/dist/sgather/types.js +0 -2
  101. package/dist/unmute/types.d.ts +0 -3
  102. package/dist/unmute/types.js +0 -2
  103. package/dist/unmute/unmute.d.ts +0 -6
  104. package/dist/utils.d.ts +0 -12
  105. package/dist/utils.js +0 -57
  106. package/dist/verb.d.ts +0 -9
  107. package/dist/verb.js +0 -50
  108. package/dist/voice.d.ts +0 -284
  109. package/dist/voice.js +0 -367
@@ -0,0 +1,7 @@
1
+ import { PlaybackControlRequest } from "@fonoster/common";
2
+ import { z } from "zod";
3
+ import { Verb } from "./Verb";
4
+ declare class PlaybackControl extends Verb<PlaybackControlRequest> {
5
+ getValidationSchema(): z.Schema;
6
+ }
7
+ export { PlaybackControl };
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlaybackControl = void 0;
3
4
  /*
4
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
5
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
5
6
  * http://github.com/fonoster/fonoster
6
7
  *
7
8
  * This file is part of Fonoster
@@ -18,22 +19,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
19
  * See the License for the specific language governing permissions and
19
20
  * limitations under the License.
20
21
  */
21
- const stream_1 = require("stream");
22
- class StatusStream {
23
- stream;
24
- constructor() {
25
- this.stream = new stream_1.Stream();
26
- }
27
- close() {
28
- this.stream.removeAllListeners();
29
- }
30
- on(event, callback) {
31
- this.stream.on(event, (data) => {
32
- callback(data);
22
+ const common_1 = require("@fonoster/common");
23
+ const zod_1 = require("zod");
24
+ const Verb_1 = require("./Verb");
25
+ class PlaybackControl extends Verb_1.Verb {
26
+ getValidationSchema() {
27
+ return zod_1.z.object({
28
+ playbackRef: zod_1.z.string(),
29
+ action: zod_1.z.nativeEnum(common_1.PlaybackControlAction)
33
30
  });
34
31
  }
35
- emit(event, data) {
36
- this.stream.emit(event, data);
37
- }
38
32
  }
39
- exports.default = StatusStream;
33
+ exports.PlaybackControl = PlaybackControl;
@@ -0,0 +1,7 @@
1
+ import { RecordRequest } from "@fonoster/common";
2
+ import { z } from "zod";
3
+ import { Verb } from "./Verb";
4
+ declare class Record extends Verb<RecordRequest> {
5
+ getValidationSchema(): z.Schema;
6
+ }
7
+ export { Record };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Record = void 0;
4
+ const zod_1 = require("zod");
5
+ const Verb_1 = require("./Verb");
6
+ class Record extends Verb_1.Verb {
7
+ getValidationSchema() {
8
+ return zod_1.z.object({
9
+ maxDuration: zod_1.z.number().int().positive().optional(),
10
+ maxSilence: zod_1.z.number().int().positive().optional(),
11
+ beep: zod_1.z.boolean().optional(),
12
+ finishOnKey: zod_1.z
13
+ .string()
14
+ .regex(/^[0-9*#]+$/)
15
+ .length(1)
16
+ .optional()
17
+ });
18
+ }
19
+ }
20
+ exports.Record = Record;
@@ -0,0 +1,7 @@
1
+ import { SayRequest } from "@fonoster/common";
2
+ import { z } from "zod";
3
+ import { Verb } from "./Verb";
4
+ declare class Say extends Verb<SayRequest> {
5
+ getValidationSchema(): z.Schema;
6
+ }
7
+ export { Say };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Say = void 0;
4
+ const zod_1 = require("zod");
5
+ const Verb_1 = require("./Verb");
6
+ class Say extends Verb_1.Verb {
7
+ getValidationSchema() {
8
+ return zod_1.z.object({
9
+ text: zod_1.z.string().min(1),
10
+ playbackRef: zod_1.z.string().optional()
11
+ });
12
+ }
13
+ }
14
+ exports.Say = Say;
@@ -0,0 +1,22 @@
1
+ /// <reference types="node" />
2
+ import { Stream as StreamObj } from "stream";
3
+ import { StartStreamRequest, StopStreamRequest, StreamPayload } from "@fonoster/common";
4
+ import { z } from "zod";
5
+ import { Verb } from "./Verb";
6
+ declare class StartStream extends Verb<StartStreamRequest> {
7
+ getValidationSchema(): z.Schema;
8
+ }
9
+ declare class StopStream extends Verb<StopStreamRequest> {
10
+ getValidationSchema(): z.Schema;
11
+ }
12
+ declare class Stream {
13
+ stream: StreamObj;
14
+ constructor();
15
+ close(): void;
16
+ onPayload(callback: (payload: StreamPayload) => void): void;
17
+ write(payload: StreamPayload): void;
18
+ onPayloadIn(callback: (payload: StreamPayload) => void): void;
19
+ emit(event: "payloadIn" | "payloadOut", payload: StreamPayload): void;
20
+ cleanup(callback: () => void): void;
21
+ }
22
+ export { StartStream, StopStream, Stream };
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Stream = exports.StopStream = exports.StartStream = void 0;
4
+ /*
5
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/fonoster
7
+ *
8
+ * This file is part of Fonoster
9
+ *
10
+ * Licensed under the MIT License (the "License");
11
+ * you may not use this file except in compliance with
12
+ * the License. You may obtain a copy of the License at
13
+ *
14
+ * https://opensource.org/licenses/MIT
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const stream_1 = require("stream");
23
+ const common_1 = require("@fonoster/common");
24
+ const zod_1 = require("zod");
25
+ const Verb_1 = require("./Verb");
26
+ class StartStream extends Verb_1.Verb {
27
+ getValidationSchema() {
28
+ return zod_1.z.object({
29
+ direction: zod_1.z.nativeEnum(common_1.StreamDirection),
30
+ format: zod_1.z.nativeEnum(common_1.StreamAudioFormat),
31
+ enableVad: zod_1.z.boolean()
32
+ });
33
+ }
34
+ }
35
+ exports.StartStream = StartStream;
36
+ class StopStream extends Verb_1.Verb {
37
+ getValidationSchema() {
38
+ return zod_1.z.object({
39
+ streamRef: zod_1.z.string()
40
+ });
41
+ }
42
+ }
43
+ exports.StopStream = StopStream;
44
+ class Stream {
45
+ constructor() {
46
+ this.stream = new stream_1.Stream();
47
+ }
48
+ close() {
49
+ this.stream.removeAllListeners();
50
+ }
51
+ // Public API
52
+ onPayload(callback) {
53
+ this.stream.on("payloadOut", (payload) => {
54
+ callback(payload);
55
+ });
56
+ }
57
+ write(payload) {
58
+ this.stream.emit("payloadIn", payload);
59
+ }
60
+ // TODO: We should hide this method from the public API
61
+ // Private API
62
+ onPayloadIn(callback) {
63
+ this.stream.on("payloadIn", (payload) => {
64
+ callback(payload);
65
+ });
66
+ }
67
+ // Private API
68
+ emit(event, payload) {
69
+ this.stream.emit(event, payload);
70
+ }
71
+ // Private API
72
+ cleanup(callback) {
73
+ this.stream.on("close", callback);
74
+ }
75
+ }
76
+ exports.Stream = Stream;
@@ -0,0 +1,4 @@
1
+ import { Mute } from "./Mute";
2
+ declare class Unmute extends Mute {
3
+ }
4
+ export { Unmute };
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Unmute = void 0;
4
+ /*
5
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
6
+ * http://github.com/fonoster/fonoster
7
+ *
8
+ * This file is part of Fonoster
9
+ *
10
+ * Licensed under the MIT License (the "License");
11
+ * you may not use this file except in compliance with
12
+ * the License. You may obtain a copy of the License at
13
+ *
14
+ * https://opensource.org/licenses/MIT
15
+ *
16
+ * Unless required by applicable law or agreed to in writing, software
17
+ * distributed under the License is distributed on an "AS IS" BASIS,
18
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
+ * See the License for the specific language governing permissions and
20
+ * limitations under the License.
21
+ */
22
+ const Mute_1 = require("./Mute");
23
+ // Shares everything with Mute except the class name
24
+ class Unmute extends Mute_1.Mute {
25
+ }
26
+ exports.Unmute = Unmute;
@@ -0,0 +1,10 @@
1
+ import { VerbRequest, VoiceIn, VoiceRequest, VoiceSessionStreamServer } from "@fonoster/common";
2
+ import { z } from "zod";
3
+ declare abstract class Verb<T extends VerbRequest = VerbRequest> {
4
+ request: VoiceRequest;
5
+ voice: VoiceSessionStreamServer;
6
+ constructor(request: VoiceRequest, voice: VoiceSessionStreamServer);
7
+ run(params?: T): Promise<VoiceIn>;
8
+ abstract getValidationSchema(): z.Schema;
9
+ }
10
+ export { Verb };
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Verb = void 0;
13
+ /*
14
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
+ * http://github.com/fonoster/fonoster
16
+ *
17
+ * This file is part of Fonoster
18
+ *
19
+ * Licensed under the MIT License (the "License");
20
+ * you may not use this file except in compliance with
21
+ * the License. You may obtain a copy of the License at
22
+ *
23
+ * https://opensource.org/licenses/MIT
24
+ *
25
+ * Unless required by applicable law or agreed to in writing, software
26
+ * distributed under the License is distributed on an "AS IS" BASIS,
27
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
+ * See the License for the specific language governing permissions and
29
+ * limitations under the License.
30
+ */
31
+ const common_1 = require("@fonoster/common");
32
+ const logger_1 = require("@fonoster/logger");
33
+ const validateRequest_1 = require("./validateRequest");
34
+ const logger = (0, logger_1.getLogger)({ service: "voice", filePath: __filename });
35
+ class Verb {
36
+ constructor(request, voice) {
37
+ this.request = request;
38
+ this.voice = voice;
39
+ }
40
+ run(params) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const { sessionRef } = this.request;
43
+ const { voice } = this;
44
+ logger.verbose(`sending a request with the ${this.constructor.name} verb`, {
45
+ sessionRef
46
+ });
47
+ return new Promise((resolve, reject) => {
48
+ try {
49
+ const fullRequest = Object.assign(Object.assign({}, params), { sessionRef });
50
+ (0, validateRequest_1.validateRequest)(this.getValidationSchema(), fullRequest);
51
+ voice.write({
52
+ [`${(0, common_1.toCamelCase)(this.constructor.name)}Request`]: fullRequest
53
+ });
54
+ const dataListener = (result) => {
55
+ logger.verbose(`received ${this.constructor.name} response`, {
56
+ sessionRef
57
+ });
58
+ resolve(result);
59
+ voice.removeListener(common_1.StreamEvent.DATA, dataListener);
60
+ };
61
+ voice.on(common_1.StreamEvent.DATA, dataListener);
62
+ }
63
+ catch (e) {
64
+ reject(e);
65
+ }
66
+ });
67
+ });
68
+ }
69
+ }
70
+ exports.Verb = Verb;
@@ -0,0 +1,14 @@
1
+ export * from "./Answer";
2
+ export * from "./Gather";
3
+ export * from "./Hangup";
4
+ export * from "./Mute";
5
+ export * from "./Dial";
6
+ export * from "./Play";
7
+ export * from "./PlayDtmf";
8
+ export * from "./PlaybackControl";
9
+ export * from "./Record";
10
+ export * from "./Say";
11
+ export * from "./Stream";
12
+ export * from "./Unmute";
13
+ export * from "./validateRequest";
14
+ export * from "./Verb";
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ /*
18
+ * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
19
+ * http://github.com/fonoster/fonoster
20
+ *
21
+ * This file is part of Fonoster
22
+ *
23
+ * Licensed under the MIT License (the "License");
24
+ * you may not use this file except in compliance with
25
+ * the License. You may obtain a copy of the License at
26
+ *
27
+ * https://opensource.org/licenses/MIT
28
+ *
29
+ * Unless required by applicable law or agreed to in writing, software
30
+ * distributed under the License is distributed on an "AS IS" BASIS,
31
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
+ * See the License for the specific language governing permissions and
33
+ * limitations under the License.
34
+ */
35
+ __exportStar(require("./Answer"), exports);
36
+ __exportStar(require("./Gather"), exports);
37
+ __exportStar(require("./Hangup"), exports);
38
+ __exportStar(require("./Mute"), exports);
39
+ __exportStar(require("./Dial"), exports);
40
+ __exportStar(require("./Play"), exports);
41
+ __exportStar(require("./PlayDtmf"), exports);
42
+ __exportStar(require("./PlaybackControl"), exports);
43
+ __exportStar(require("./Record"), exports);
44
+ __exportStar(require("./Say"), exports);
45
+ __exportStar(require("./Stream"), exports);
46
+ __exportStar(require("./Unmute"), exports);
47
+ __exportStar(require("./validateRequest"), exports);
48
+ __exportStar(require("./Verb"), exports);
@@ -0,0 +1,2 @@
1
+ import { z } from "zod";
2
+ export declare function validateRequest<T>(schema: z.Schema<T>, data: unknown): T;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateRequest = void 0;
4
+ const zod_validation_error_1 = require("zod-validation-error");
5
+ function validateRequest(schema, data) {
6
+ const parsedData = schema.safeParse(data);
7
+ if (!parsedData.success) {
8
+ throw (0, zod_validation_error_1.fromError)(parsedData.error);
9
+ }
10
+ return parsedData.data;
11
+ }
12
+ exports.validateRequest = validateRequest;
package/package.json CHANGED
@@ -1,20 +1,35 @@
1
1
  {
2
2
  "name": "@fonoster/voice",
3
- "version": "0.5.4",
4
- "description": "Voice verbs",
3
+ "version": "0.6.1-alpha.0",
4
+ "description": "Voice Server for Fonoster",
5
5
  "author": "Pedro Sanders <psanders@fonoster.com>",
6
6
  "homepage": "https://github.com/fonoster/fonoster#readme",
7
7
  "license": "MIT",
8
8
  "main": "dist/index",
9
9
  "types": "dist/index",
10
- "scripts": {
11
- "prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
12
- "build": "tsc -b tsconfig.json"
13
- },
14
10
  "directories": {
15
11
  "src": "src",
16
12
  "test": "test"
17
13
  },
14
+ "scripts": {
15
+ "prebuild": "rimraf ./dist tsconfig.tsbuildinfo",
16
+ "build": "tsc -b tsconfig.json",
17
+ "clean": "rimraf ./dist node_modules tsconfig.tsbuildinfo"
18
+ },
19
+ "bin": {
20
+ "fonoster": "./dist/index.js"
21
+ },
22
+ "dependencies": {
23
+ "@fonoster/common": "^0.6.1-alpha.0",
24
+ "@fonoster/identity": "^0.6.1-alpha.0",
25
+ "@fonoster/logger": "^0.6.1-alpha.0",
26
+ "@grpc/grpc-js": "^1.10.6",
27
+ "deepmerge": "^4.3.1",
28
+ "grpc-health-check": "^2.0.2",
29
+ "pb-util": "^1.0.3",
30
+ "zod": "^3.23.8",
31
+ "zod-validation-error": "^3.3.0"
32
+ },
18
33
  "files": [
19
34
  "dist"
20
35
  ],
@@ -28,19 +43,5 @@
28
43
  "bugs": {
29
44
  "url": "https://github.com/fonoster/fonoster/issues"
30
45
  },
31
- "dependencies": {
32
- "@fonoster/common": "^0.5.4",
33
- "@fonoster/logger": "^0.5.4",
34
- "axios": "^1.6.2",
35
- "bson-objectid": "^2.0.2",
36
- "deepmerge": "^4.2.2",
37
- "express": "^4.17.1",
38
- "express-ws": "^4.0.0",
39
- "pubsub-js": "^1.9.3"
40
- },
41
- "gitHead": "a1dae664944ab191e925e49346e0916f8c8347a1",
42
- "devDependencies": {
43
- "@types/express": "^4.17.13",
44
- "@types/pubsub-js": "^1.8.2"
45
- }
46
+ "gitHead": "2cdd1508146747550fe048c35d9a010d04f6d3aa"
46
47
  }
@@ -1,4 +0,0 @@
1
- import { Verb } from "../verb";
2
- export default class AnswerVerb extends Verb {
3
- run(): Promise<void>;
4
- }
@@ -1,55 +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
- /*
7
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
8
- * http://github.com/fonoster/fonoster
9
- *
10
- * This file is part of Fonoster
11
- *
12
- * Licensed under the MIT License (the "License");
13
- * you may not use this file except in compliance with
14
- * the License. You may obtain a copy of the License at
15
- *
16
- * https://opensource.org/licenses/MIT
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
- const verb_1 = require("../verb");
25
- const logger_1 = require("@fonoster/logger");
26
- const utils_1 = require("../utils");
27
- const pubsub_js_1 = __importDefault(require("pubsub-js"));
28
- const logger = (0, logger_1.getLogger)({ service: "voice", filePath: __filename });
29
- class AnswerVerb extends verb_1.Verb {
30
- async run() {
31
- logger.verbose(`sending answer request [sessionId = ${this.request.sessionId}]`);
32
- return new Promise(async (resolve, reject) => {
33
- let token;
34
- try {
35
- token = pubsub_js_1.default.subscribe(`SessionOpen.${this.request.sessionId}`, (type, data) => {
36
- resolve();
37
- pubsub_js_1.default.unsubscribe(token);
38
- });
39
- await super.post("events/user/Answer", (0, utils_1.objectToQString)({
40
- // WARNING: Harcoded value
41
- application: "mediacontroller"
42
- }), {
43
- variables: {
44
- sessionId: this.request.sessionId
45
- }
46
- });
47
- }
48
- catch (e) {
49
- reject(e);
50
- pubsub_js_1.default.unsubscribe(token);
51
- }
52
- });
53
- }
54
- }
55
- exports.default = AnswerVerb;
package/dist/asserts.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare const assertsValueIsPositive: (name: string, value: any) => void;
2
- export declare const assertsValuesIsZeroOrGreater: (name: string, value: any) => void;
3
- export declare const assertsFinishOnKeyIsChar: (key: string) => void;
4
- export declare const assertPluginExist: (self: any, pluginName: any) => void;
package/dist/asserts.js DELETED
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertPluginExist = exports.assertsFinishOnKeyIsChar = exports.assertsValuesIsZeroOrGreater = exports.assertsValueIsPositive = void 0;
4
- /*
5
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
6
- * http://github.com/fonoster/fonoster
7
- *
8
- * This file is part of Fonoster
9
- *
10
- * Licensed under the MIT License (the "License");
11
- * you may not use this file except in compliance with
12
- * the License. You may obtain a copy of the License at
13
- *
14
- * https://opensource.org/licenses/MIT
15
- *
16
- * Unless required by applicable law or agreed to in writing, software
17
- * distributed under the License is distributed on an "AS IS" BASIS,
18
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
- * See the License for the specific language governing permissions and
20
- * limitations under the License.
21
- */
22
- const assertsValueIsPositive = (name, value) => {
23
- if (value !== undefined && value <= 0 && !isNaN(value)) {
24
- throw new Error(`the option '${name}' must be a number greater than zero`);
25
- }
26
- };
27
- exports.assertsValueIsPositive = assertsValueIsPositive;
28
- const assertsValuesIsZeroOrGreater = (name, value) => {
29
- if (value !== undefined && value < 0 && !isNaN(value)) {
30
- throw new Error(`the option '${name}' must be a number equal or greater than zero`);
31
- }
32
- };
33
- exports.assertsValuesIsZeroOrGreater = assertsValuesIsZeroOrGreater;
34
- const assertsFinishOnKeyIsChar = (key) => {
35
- const isKey = (key) => ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "#"].indexOf(key) !=
36
- -1;
37
- if (key && key.length > 1 && !isKey(key)) {
38
- throw new Error("the option 'finishOnKey' must be a single char [0-9], *, or #");
39
- }
40
- };
41
- exports.assertsFinishOnKeyIsChar = assertsFinishOnKeyIsChar;
42
- const assertPluginExist = (self, pluginName) => {
43
- if (!self.plugins[pluginName]) {
44
- throw Error("No available plugin for tts");
45
- }
46
- };
47
- exports.assertPluginExist = assertPluginExist;
@@ -1,6 +0,0 @@
1
- import { Verb } from "../verb";
2
- import { DialOptions } from "./types";
3
- import StatusStream from "./status_stream";
4
- export default class DialVerb extends Verb {
5
- run(destination: string, options?: DialOptions): Promise<StatusStream>;
6
- }
package/dist/dial/dial.js DELETED
@@ -1,77 +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
- /*
7
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
8
- * http://github.com/fonoster/fonoster
9
- *
10
- * This file is part of Fonoster
11
- *
12
- * Licensed under the MIT License (the "License");
13
- * you may not use this file except in compliance with
14
- * the License. You may obtain a copy of the License at
15
- *
16
- * https://opensource.org/licenses/MIT
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
- const logger_1 = require("@fonoster/logger");
25
- const utils_1 = require("../utils");
26
- const verb_1 = require("../verb");
27
- const pubsub_js_1 = __importDefault(require("pubsub-js"));
28
- const status_stream_1 = __importDefault(require("./status_stream"));
29
- const logger = (0, logger_1.getLogger)({ service: "voice", filePath: __filename });
30
- class DialVerb extends verb_1.Verb {
31
- async run(destination, options = {}) {
32
- const streamStatus = new status_stream_1.default();
33
- logger.verbose("dialing", {
34
- sessionId: this.request.sessionId,
35
- number: this.request.number
36
- });
37
- // We should reject if DialFailed
38
- return new Promise(async (resolve, reject) => {
39
- let dialFailedToken;
40
- let statusChangeToken;
41
- try {
42
- statusChangeToken = pubsub_js_1.default.subscribe(`DialStatusChanged.${this.request.sessionId}`, (type, d) => {
43
- if (d.data.status === "trying") {
44
- resolve(streamStatus);
45
- }
46
- else {
47
- streamStatus.emit(d.data.status, d.data);
48
- }
49
- });
50
- dialFailedToken = pubsub_js_1.default.subscribe(`DialFailed.${this.request.sessionId}`, (type, data) => {
51
- reject(data.error);
52
- pubsub_js_1.default.unsubscribe(dialFailedToken);
53
- pubsub_js_1.default.unsubscribe(statusChangeToken);
54
- });
55
- await super.post("events/user/Dial", (0, utils_1.objectToQString)({
56
- // WARNING: Harcoded value
57
- application: "mediacontroller"
58
- }), {
59
- variables: {
60
- accessKeyId: this.request.accessKeyId,
61
- sessionId: this.request.sessionId,
62
- // Could be a Number or an Agent
63
- destination,
64
- number: this.request.number,
65
- timeout: options.timeout || -1,
66
- record: options.record
67
- }
68
- });
69
- }
70
- catch (e) {
71
- reject(e);
72
- pubsub_js_1.default.unsubscribe(dialFailedToken);
73
- }
74
- });
75
- }
76
- }
77
- exports.default = DialVerb;