@fonoster/apiserver 0.5.5 → 0.6.1

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 (224) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +3 -0
  3. package/dist/applications/buildService.d.ts +29 -0
  4. package/dist/applications/buildService.js +43 -0
  5. package/dist/applications/createApplication.d.ts +6 -0
  6. package/dist/applications/createApplication.js +56 -0
  7. package/dist/applications/createGetFnUtil.d.ts +33 -0
  8. package/dist/applications/createGetFnUtil.js +31 -0
  9. package/dist/applications/deleteApplication.d.ts +6 -0
  10. package/dist/applications/deleteApplication.js +25 -0
  11. package/dist/applications/getApplication.d.ts +6 -0
  12. package/dist/applications/getApplication.js +46 -0
  13. package/dist/applications/hostOrHostPortSchema.d.ts +3 -0
  14. package/dist/applications/hostOrHostPortSchema.js +34 -0
  15. package/dist/applications/index.d.ts +1 -0
  16. package/dist/applications/index.js +23 -0
  17. package/dist/applications/listApplications.d.ts +6 -0
  18. package/dist/applications/listApplications.js +68 -0
  19. package/dist/applications/types.d.ts +27 -0
  20. package/dist/applications/types.js +2 -0
  21. package/dist/applications/updateApplication.d.ts +8 -0
  22. package/dist/applications/updateApplication.js +56 -0
  23. package/dist/applications/utils/applicationWithEncodedStruct.d.ts +3 -0
  24. package/dist/applications/utils/applicationWithEncodedStruct.js +22 -0
  25. package/dist/applications/utils/convertToApplicationData.d.ts +4 -0
  26. package/dist/applications/utils/convertToApplicationData.js +37 -0
  27. package/dist/applications/utils/getApplicationValidationSchema.d.ts +64 -0
  28. package/dist/applications/utils/getApplicationValidationSchema.js +63 -0
  29. package/dist/applications/utils/prepareForValidation.d.ts +3 -0
  30. package/dist/applications/utils/prepareForValidation.js +35 -0
  31. package/dist/applications/utils/validOrThrow.d.ts +3 -0
  32. package/dist/applications/utils/validOrThrow.js +14 -0
  33. package/dist/calls/ListCallsRequestSchema.d.ts +28 -0
  34. package/dist/calls/ListCallsRequestSchema.js +58 -0
  35. package/dist/calls/buildService.d.ts +26 -0
  36. package/dist/calls/buildService.js +57 -0
  37. package/dist/calls/createCall.d.ts +6 -0
  38. package/dist/calls/createCall.js +63 -0
  39. package/dist/calls/createCallPublisher.d.ts +7 -0
  40. package/dist/calls/createCallPublisher.js +46 -0
  41. package/dist/calls/createFetchCalls.d.ts +3 -0
  42. package/dist/calls/createFetchCalls.js +86 -0
  43. package/dist/calls/createFetchSingleCall.d.ts +3 -0
  44. package/dist/calls/createFetchSingleCall.js +47 -0
  45. package/dist/calls/createTrackCallSubscriber.d.ts +5 -0
  46. package/dist/calls/createTrackCallSubscriber.js +52 -0
  47. package/dist/calls/getCall.d.ts +6 -0
  48. package/dist/calls/getCall.js +59 -0
  49. package/dist/calls/index.d.ts +1 -0
  50. package/dist/calls/index.js +23 -0
  51. package/dist/calls/influxdb.d.ts +2 -0
  52. package/dist/calls/influxdb.js +29 -0
  53. package/dist/calls/listCalls.d.ts +6 -0
  54. package/dist/calls/listCalls.js +51 -0
  55. package/dist/calls/runCallManager.d.ts +8 -0
  56. package/dist/calls/runCallManager.js +81 -0
  57. package/dist/calls/trackCall.d.ts +14 -0
  58. package/dist/calls/trackCall.js +63 -0
  59. package/dist/calls/types.d.ts +96 -0
  60. package/dist/calls/types.js +42 -0
  61. package/dist/core/allowList.d.ts +2 -0
  62. package/dist/core/allowList.js +31 -0
  63. package/dist/core/db.d.ts +13 -0
  64. package/dist/core/db.js +29 -0
  65. package/dist/core/filesServer.d.ts +5 -0
  66. package/dist/{ari_proxy.js → core/filesServer.js} +23 -20
  67. package/dist/core/identityConfig.d.ts +21 -0
  68. package/dist/core/identityConfig.js +43 -0
  69. package/dist/core/loadServices.d.ts +8 -0
  70. package/dist/core/loadServices.js +43 -0
  71. package/dist/core/notFoundError.d.ts +6 -0
  72. package/dist/core/notFoundError.js +27 -0
  73. package/dist/core/removeSwaggerNotice.d.ts +2 -0
  74. package/dist/core/removeSwaggerNotice.js +34 -0
  75. package/dist/core/routrConfig.d.ts +5 -0
  76. package/dist/core/routrConfig.js +27 -0
  77. package/dist/core/runServices.d.ts +2 -0
  78. package/dist/core/runServices.js +97 -0
  79. package/dist/core/seed.js +76 -0
  80. package/dist/core/services.d.ts +432 -0
  81. package/dist/core/services.js +53 -0
  82. package/dist/core/upsertDefaultPeer.d.ts +3 -0
  83. package/dist/core/upsertDefaultPeer.js +88 -0
  84. package/dist/envs.d.ts +46 -6
  85. package/dist/envs.js +94 -8
  86. package/dist/events/createInfluxDbPub.d.ts +13 -0
  87. package/dist/events/createInfluxDbPub.js +53 -0
  88. package/dist/events/nats.d.ts +10 -0
  89. package/dist/events/nats.js +84 -0
  90. package/dist/events/types.d.ts +8 -0
  91. package/dist/events/types.js +20 -0
  92. package/dist/index.js +53 -122
  93. package/dist/secrets/buildService.d.ts +31 -0
  94. package/dist/secrets/buildService.js +43 -0
  95. package/dist/secrets/createGetFnUtil.d.ts +16 -0
  96. package/dist/secrets/createGetFnUtil.js +45 -0
  97. package/dist/secrets/createSecret.d.ts +7 -0
  98. package/dist/secrets/createSecret.js +56 -0
  99. package/dist/secrets/deleteSecret.d.ts +8 -0
  100. package/dist/secrets/deleteSecret.js +43 -0
  101. package/dist/secrets/getSecret.d.ts +6 -0
  102. package/dist/secrets/getSecret.js +42 -0
  103. package/dist/secrets/index.d.ts +1 -0
  104. package/dist/secrets/index.js +23 -0
  105. package/dist/secrets/listSecrets.d.ts +7 -0
  106. package/dist/secrets/listSecrets.js +61 -0
  107. package/dist/secrets/types.d.ts +32 -0
  108. package/dist/secrets/types.js +2 -0
  109. package/dist/secrets/updateSecret.d.ts +8 -0
  110. package/dist/secrets/updateSecret.js +52 -0
  111. package/dist/utils/index.d.ts +1 -0
  112. package/dist/utils/index.js +35 -0
  113. package/dist/utils/makeCheckNumberPreconditions.d.ts +6 -0
  114. package/dist/utils/makeCheckNumberPreconditions.js +48 -0
  115. package/dist/voice/ChannelVarNotFoundError.d.ts +5 -0
  116. package/dist/voice/ChannelVarNotFoundError.js +10 -0
  117. package/dist/voice/MethodNotImplementedError.d.ts +4 -0
  118. package/dist/voice/MethodNotImplementedError.js +27 -0
  119. package/dist/voice/VoiceClientImpl.d.ts +41 -0
  120. package/dist/voice/VoiceClientImpl.js +192 -0
  121. package/dist/voice/VoiceDispatcher.d.ts +17 -0
  122. package/dist/voice/VoiceDispatcher.js +99 -0
  123. package/dist/voice/VoiceServiceClientConst.d.ts +3 -0
  124. package/dist/voice/VoiceServiceClientConst.js +53 -0
  125. package/dist/voice/connectToAri.d.ts +2 -0
  126. package/dist/voice/connectToAri.js +79 -0
  127. package/dist/voice/createExternalMediaConfig.d.ts +9 -0
  128. package/dist/voice/createExternalMediaConfig.js +34 -0
  129. package/dist/voice/handlers/Answer.d.ts +5 -0
  130. package/dist/voice/handlers/Answer.js +24 -0
  131. package/dist/voice/handlers/Hangup.d.ts +5 -0
  132. package/dist/voice/handlers/Hangup.js +25 -0
  133. package/dist/voice/handlers/Mute.d.ts +4 -0
  134. package/dist/voice/handlers/Mute.js +27 -0
  135. package/dist/voice/handlers/Play.d.ts +4 -0
  136. package/dist/voice/handlers/Play.js +33 -0
  137. package/dist/voice/handlers/PlayDtmf.d.ts +4 -0
  138. package/dist/voice/handlers/PlayDtmf.js +27 -0
  139. package/dist/voice/handlers/PlaybackControl.d.ts +4 -0
  140. package/dist/voice/handlers/PlaybackControl.js +27 -0
  141. package/dist/voice/handlers/Record.d.ts +4 -0
  142. package/dist/voice/handlers/Record.js +58 -0
  143. package/dist/voice/handlers/Say.d.ts +4 -0
  144. package/dist/voice/handlers/Say.js +45 -0
  145. package/dist/voice/handlers/StasisEnd.d.ts +4 -0
  146. package/dist/voice/handlers/StasisEnd.js +27 -0
  147. package/dist/voice/handlers/Unmute.d.ts +4 -0
  148. package/dist/voice/handlers/Unmute.js +27 -0
  149. package/dist/voice/handlers/awaitForPlaybackFinished.d.ts +3 -0
  150. package/dist/voice/handlers/awaitForPlaybackFinished.js +25 -0
  151. package/dist/voice/handlers/awaitForRecordingFinished.d.ts +5 -0
  152. package/dist/voice/handlers/awaitForRecordingFinished.js +53 -0
  153. package/dist/voice/handlers/dial/Dial.d.ts +5 -0
  154. package/dist/voice/handlers/dial/Dial.js +71 -0
  155. package/dist/voice/handlers/dial/handleChannelLeftBridge.d.ts +6 -0
  156. package/dist/voice/handlers/dial/handleChannelLeftBridge.js +29 -0
  157. package/dist/voice/handlers/dial/handleDialEvents.d.ts +5 -0
  158. package/dist/voice/handlers/dial/handleDialEvents.js +54 -0
  159. package/dist/voice/handlers/dial/handleStasisEnd.d.ts +3 -0
  160. package/dist/voice/handlers/dial/handleStasisEnd.js +19 -0
  161. package/dist/voice/handlers/dial/handleStasisStart.d.ts +9 -0
  162. package/dist/voice/handlers/dial/handleStasisStart.js +53 -0
  163. package/dist/voice/handlers/dial/recordChannel.d.ts +4 -0
  164. package/dist/voice/handlers/dial/recordChannel.js +45 -0
  165. package/dist/voice/handlers/gather/Gather.d.ts +3 -0
  166. package/dist/voice/handlers/gather/Gather.js +72 -0
  167. package/dist/voice/handlers/gather/getTimeoutPromise.d.ts +8 -0
  168. package/dist/voice/handlers/gather/getTimeoutPromise.js +18 -0
  169. package/dist/voice/handlers/withErrorHandling.d.ts +4 -0
  170. package/dist/voice/handlers/withErrorHandling.js +35 -0
  171. package/dist/voice/integrations/ApplicationNotFoundError.d.ts +4 -0
  172. package/dist/voice/integrations/ApplicationNotFoundError.js +28 -0
  173. package/dist/voice/integrations/findIntegrationsCredentials.d.ts +3 -0
  174. package/dist/voice/integrations/findIntegrationsCredentials.js +6 -0
  175. package/dist/voice/integrations/getSttConfig.d.ts +7 -0
  176. package/dist/voice/integrations/getSttConfig.js +9 -0
  177. package/dist/voice/integrations/getTtsConfig.d.ts +7 -0
  178. package/dist/voice/integrations/getTtsConfig.js +10 -0
  179. package/dist/voice/integrations/index.d.ts +1 -0
  180. package/dist/voice/integrations/index.js +35 -0
  181. package/dist/voice/integrations/makeCreateContainer.d.ts +4 -0
  182. package/dist/voice/integrations/makeCreateContainer.js +88 -0
  183. package/dist/voice/integrations/types.d.ts +15 -0
  184. package/dist/voice/integrations/types.js +2 -0
  185. package/dist/voice/makeCreateVoiceClient.d.ts +9 -0
  186. package/dist/voice/makeCreateVoiceClient.js +77 -0
  187. package/dist/voice/makeGetChannelVar.d.ts +4 -0
  188. package/dist/voice/makeGetChannelVar.js +25 -0
  189. package/dist/voice/stt/AbstractSpeechToText.d.ts +14 -0
  190. package/dist/voice/stt/AbstractSpeechToText.js +19 -0
  191. package/dist/voice/stt/Google.d.ts +19 -0
  192. package/dist/voice/stt/Google.js +99 -0
  193. package/dist/voice/stt/SpeechToTextFactory.d.ts +9 -0
  194. package/dist/voice/stt/SpeechToTextFactory.js +41 -0
  195. package/dist/voice/stt/types.d.ts +25 -0
  196. package/dist/voice/stt/types.js +2 -0
  197. package/dist/voice/transcribeOnConnection.d.ts +4 -0
  198. package/dist/voice/transcribeOnConnection.js +26 -0
  199. package/dist/voice/tts/AbstractTextToSpeech.d.ts +18 -0
  200. package/dist/voice/tts/AbstractTextToSpeech.js +82 -0
  201. package/dist/voice/tts/Azure.d.ts +30 -0
  202. package/dist/voice/tts/Azure.js +128 -0
  203. package/dist/voice/tts/Google.d.ts +25 -0
  204. package/dist/voice/tts/Google.js +116 -0
  205. package/dist/voice/tts/TextToSpeechFactory.d.ts +9 -0
  206. package/dist/voice/tts/TextToSpeechFactory.js +43 -0
  207. package/dist/voice/tts/computeFilename.d.ts +7 -0
  208. package/dist/voice/tts/computeFilename.js +38 -0
  209. package/dist/voice/tts/flattenObject.d.ts +2 -0
  210. package/dist/voice/tts/flattenObject.js +38 -0
  211. package/dist/voice/tts/isSsml.d.ts +2 -0
  212. package/dist/voice/tts/isSsml.js +25 -0
  213. package/dist/voice/tts/types.d.ts +7 -0
  214. package/dist/voice/tts/types.js +2 -0
  215. package/dist/voice/types/ari.d.ts +21 -0
  216. package/dist/voice/types/ari.js +43 -0
  217. package/dist/voice/types/index.d.ts +2 -0
  218. package/dist/voice/types/index.js +36 -0
  219. package/dist/voice/types/voice.d.ts +33 -0
  220. package/dist/voice/types/voice.js +2 -0
  221. package/package.json +46 -36
  222. package/dist/upsert_peer.d.ts +0 -1
  223. package/dist/upsert_peer.js +0 -63
  224. /package/dist/{ari_proxy.d.ts → core/seed.d.ts} +0 -0
@@ -0,0 +1,27 @@
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.playDtmfHandler = playDtmfHandler;
13
+ const withErrorHandling_1 = require("./withErrorHandling");
14
+ function playDtmfHandler(ari, voiceClient) {
15
+ return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
16
+ const { sessionRef, digits } = request;
17
+ yield ari.channels.sendDTMF({
18
+ channelId: sessionRef,
19
+ dtmf: digits
20
+ });
21
+ voiceClient.sendResponse({
22
+ playDtmfResponse: {
23
+ sessionRef
24
+ }
25
+ });
26
+ }));
27
+ }
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function playbackControlHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { playbackControlHandler };
@@ -0,0 +1,27 @@
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.playbackControlHandler = playbackControlHandler;
13
+ const withErrorHandling_1 = require("./withErrorHandling");
14
+ function playbackControlHandler(ari, voiceClient) {
15
+ return (0, withErrorHandling_1.withErrorHandling)((playbackControlReq) => __awaiter(this, void 0, void 0, function* () {
16
+ const { sessionRef, playbackRef, action } = playbackControlReq;
17
+ yield ari.playbacks.control({
18
+ playbackId: playbackRef,
19
+ operation: action
20
+ });
21
+ voiceClient.sendResponse({
22
+ playbackControlResponse: {
23
+ sessionRef
24
+ }
25
+ });
26
+ }));
27
+ }
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function recordHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { recordHandler };
@@ -0,0 +1,58 @@
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.recordHandler = recordHandler;
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 nanoid_1 = require("nanoid");
33
+ const awaitForRecordingFinished_1 = require("./awaitForRecordingFinished");
34
+ const withErrorHandling_1 = require("./withErrorHandling");
35
+ function recordHandler(ari, voiceClient) {
36
+ return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
37
+ const { sessionRef, maxDuration, maxSilence, beep, finishOnKey } = request;
38
+ const name = (0, nanoid_1.nanoid)(10);
39
+ yield ari.channels.record({
40
+ channelId: sessionRef,
41
+ format: common_1.RecordFormat.WAV,
42
+ name,
43
+ beep,
44
+ maxDurationSeconds: maxDuration,
45
+ maxSilenceSeconds: maxSilence,
46
+ terminateOn: finishOnKey
47
+ });
48
+ const { duration } = yield (0, awaitForRecordingFinished_1.awaitForRecordingFinished)(ari, name);
49
+ voiceClient.sendResponse({
50
+ recordResponse: {
51
+ sessionRef,
52
+ name,
53
+ format: common_1.RecordFormat.WAV,
54
+ duration
55
+ }
56
+ });
57
+ }));
58
+ }
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function sayHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { sayHandler };
@@ -0,0 +1,45 @@
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.sayHandler = sayHandler;
13
+ const nanoid_1 = require("nanoid");
14
+ const pb_util_1 = require("pb-util");
15
+ const zod_1 = require("zod");
16
+ const awaitForPlaybackFinished_1 = require("./awaitForPlaybackFinished");
17
+ const withErrorHandling_1 = require("./withErrorHandling");
18
+ const envs_1 = require("../../envs");
19
+ const sayRequestSchema = zod_1.z.object({
20
+ text: zod_1.z.string(),
21
+ sessionRef: zod_1.z.string(),
22
+ playbackRef: zod_1.z.string().optional().nullable(),
23
+ options: zod_1.z.record(zod_1.z.unknown()).optional().nullable()
24
+ });
25
+ const getMediaUrl = (filename) => `sound:http://${envs_1.APISERVER_HOST}:${envs_1.FILES_SERVER_PORT}/sounds/${filename}.sln16`;
26
+ function sayHandler(ari, voiceClient) {
27
+ return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
28
+ const { sessionRef } = request;
29
+ // Error handled by withErrorHandling
30
+ sayRequestSchema.parse(request);
31
+ const playbackRef = request.playbackRef || (0, nanoid_1.nanoid)(10);
32
+ const filename = yield voiceClient.synthesize(request.text, request.options ? pb_util_1.struct.decode(request.options) : {});
33
+ yield ari.channels.play({
34
+ channelId: sessionRef,
35
+ media: getMediaUrl(filename),
36
+ playbackId: playbackRef
37
+ });
38
+ yield (0, awaitForPlaybackFinished_1.awaitForPlaybackFinished)(ari, playbackRef);
39
+ voiceClient.sendResponse({
40
+ sayResponse: {
41
+ playbackRef
42
+ }
43
+ });
44
+ }));
45
+ }
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function muteHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { muteHandler };
@@ -0,0 +1,27 @@
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.muteHandler = muteHandler;
13
+ const withErrorHandling_1 = require("./withErrorHandling");
14
+ function muteHandler(ari, voiceClient) {
15
+ return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
16
+ const { sessionRef, direction } = request;
17
+ yield ari.channels.mute({
18
+ channelId: sessionRef,
19
+ direction
20
+ });
21
+ voiceClient.sendResponse({
22
+ muteResponse: {
23
+ sessionRef
24
+ }
25
+ });
26
+ }));
27
+ }
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function unmuteHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { unmuteHandler };
@@ -0,0 +1,27 @@
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.unmuteHandler = unmuteHandler;
13
+ const withErrorHandling_1 = require("./withErrorHandling");
14
+ function unmuteHandler(ari, voiceClient) {
15
+ return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
16
+ const { sessionRef, direction } = request;
17
+ yield ari.channels.unmute({
18
+ channelId: sessionRef,
19
+ direction
20
+ });
21
+ voiceClient.sendResponse({
22
+ muteResponse: {
23
+ sessionRef
24
+ }
25
+ });
26
+ }));
27
+ }
@@ -0,0 +1,3 @@
1
+ import { Client } from "ari-client";
2
+ declare const awaitForPlaybackFinished: (ari: Client, playbackRef: string) => Promise<void>;
3
+ export { awaitForPlaybackFinished };
@@ -0,0 +1,25 @@
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.awaitForPlaybackFinished = void 0;
13
+ const types_1 = require("../types");
14
+ const awaitForPlaybackFinished = (ari, playbackRef) => __awaiter(void 0, void 0, void 0, function* () {
15
+ return new Promise((resolve) => {
16
+ const listener = (_, playback) => {
17
+ if (playbackRef === playback.id) {
18
+ ari.removeListener(types_1.AriEvent.PLAYBACK_FINISHED, listener);
19
+ resolve();
20
+ }
21
+ };
22
+ ari.on(types_1.AriEvent.PLAYBACK_FINISHED, listener);
23
+ });
24
+ });
25
+ exports.awaitForPlaybackFinished = awaitForPlaybackFinished;
@@ -0,0 +1,5 @@
1
+ import { Client } from "ari-client";
2
+ declare function awaitForRecordingFinished(ari: Client, name: string): Promise<{
3
+ duration: number;
4
+ }>;
5
+ export { awaitForRecordingFinished };
@@ -0,0 +1,53 @@
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.awaitForRecordingFinished = awaitForRecordingFinished;
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 grpc_js_1 = require("@grpc/grpc-js");
33
+ const types_1 = require("../types");
34
+ function awaitForRecordingFinished(ari, name) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ return new Promise((resolve, reject) => {
37
+ const listener = (event) => {
38
+ if ("cause" in event.recording) {
39
+ ari.removeListener(types_1.AriEvent.RECORDING_FINISHED, listener);
40
+ ari.removeListener(types_1.AriEvent.RECORDING_FAILED, listener);
41
+ reject(new common_1.GrpcError(grpc_js_1.status.INTERNAL, "Recording failed"));
42
+ }
43
+ else if (name === event.recording.name) {
44
+ ari.removeListener(types_1.AriEvent.RECORDING_FINISHED, listener);
45
+ ari.removeListener(types_1.AriEvent.RECORDING_FAILED, listener);
46
+ resolve({ duration: event.recording.duration });
47
+ }
48
+ };
49
+ ari.on(types_1.AriEvent.RECORDING_FINISHED, listener);
50
+ ari.on(types_1.AriEvent.RECORDING_FAILED, listener);
51
+ });
52
+ });
53
+ }
@@ -0,0 +1,5 @@
1
+ import { DialRequest } from "@fonoster/common";
2
+ import { Client } from "ari-client";
3
+ import { VoiceClient } from "../../types";
4
+ declare function dialHandler(ari: Client, voiceClient: VoiceClient): (request: DialRequest) => Promise<void>;
5
+ export { dialHandler };
@@ -0,0 +1,71 @@
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.dialHandler = dialHandler;
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 handleChannelLeftBridge_1 = require("./handleChannelLeftBridge");
33
+ const handleDialEvents_1 = require("./handleDialEvents");
34
+ const handleStasisEnd_1 = require("./handleStasisEnd");
35
+ const handleStasisStart_1 = require("./handleStasisStart");
36
+ const envs_1 = require("../../../envs");
37
+ const makeGetChannelVar_1 = require("../../makeGetChannelVar");
38
+ const types_1 = require("../../types");
39
+ // TODO: Needs request validation
40
+ function dialHandler(ari, voiceClient) {
41
+ return (request) => __awaiter(this, void 0, void 0, function* () {
42
+ const { sessionRef, destination, timeout } = request;
43
+ const bridge = yield ari.bridges.create({
44
+ type: "mixing"
45
+ });
46
+ // eslint-disable-next-line new-cap
47
+ const dialed = ari.Channel();
48
+ yield bridge.addChannel({ channel: sessionRef });
49
+ const callerChannel = yield ari.channels.get({ channelId: sessionRef });
50
+ const getChannelVar = (0, makeGetChannelVar_1.makeGetChannelVar)(callerChannel);
51
+ const ingressNumber = (yield getChannelVar(types_1.ChannelVar.INGRESS_NUMBER))
52
+ .value;
53
+ yield dialed.originate({
54
+ app: common_1.STASIS_APP_NAME,
55
+ endpoint: `PJSIP/${envs_1.ASTERISK_TRUNK}/sip:${destination}@${envs_1.ASTERISK_SYSTEM_DOMAIN}`,
56
+ timeout,
57
+ variables: {
58
+ "PJSIP_HEADER(add,X-DOD-Number)": ingressNumber
59
+ }
60
+ });
61
+ dialed.on(types_1.AriEvent.STASIS_START, (0, handleStasisStart_1.handleStasisStart)({ ari, request, bridge, dialed }));
62
+ dialed.on(types_1.AriEvent.CHANNEL_LEFT_BRIDGE, (0, handleChannelLeftBridge_1.handleChannelLeftBridge)({ bridge, dialed }));
63
+ dialed.on(types_1.AriEvent.STASIS_END, (0, handleStasisEnd_1.handleStasisEnd)(request));
64
+ dialed.on(types_1.AriEvent.DIAL, (0, handleDialEvents_1.handleDialEvents)(voiceClient));
65
+ voiceClient.sendResponse({
66
+ dialResponse: {
67
+ status: common_1.DialStatus.TRYING
68
+ }
69
+ });
70
+ });
71
+ }
@@ -0,0 +1,6 @@
1
+ import { Bridge, Channel } from "ari-client";
2
+ declare function handleChannelLeftBridge(params: {
3
+ bridge: Bridge;
4
+ dialed: Channel;
5
+ }): () => Promise<void>;
6
+ export { handleChannelLeftBridge };
@@ -0,0 +1,29 @@
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.handleChannelLeftBridge = handleChannelLeftBridge;
13
+ function handleChannelLeftBridge(params) {
14
+ const { dialed, bridge } = params;
15
+ return () => __awaiter(this, void 0, void 0, function* () {
16
+ try {
17
+ dialed.hangup();
18
+ }
19
+ catch (e) {
20
+ /** We can only try */
21
+ }
22
+ try {
23
+ yield bridge.destroy();
24
+ }
25
+ catch (e) {
26
+ /* Ignore because the bridge might not exist anymore */
27
+ }
28
+ });
29
+ }
@@ -0,0 +1,5 @@
1
+ import { VoiceClient } from "../../types";
2
+ declare function handleDialEvents(voiceClient: VoiceClient): (event: {
3
+ dialstatus: string;
4
+ }) => Promise<void>;
5
+ export { handleDialEvents };
@@ -0,0 +1,54 @@
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.handleDialEvents = handleDialEvents;
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 FailedStatus = ["CHANUNAVAIL", "CONGESTION"];
33
+ function handleDialEvents(voiceClient) {
34
+ return (event) => __awaiter(this, void 0, void 0, function* () {
35
+ const status = event.dialstatus.toUpperCase();
36
+ const dialStatusArray = Object.keys(common_1.DialStatus).map((key) => common_1.DialStatus[key]);
37
+ let mappedStatus;
38
+ if (FailedStatus.includes(status)) {
39
+ mappedStatus = common_1.DialStatus.FAILED;
40
+ }
41
+ else if (dialStatusArray.includes(status)) {
42
+ mappedStatus = common_1.DialStatus[status];
43
+ }
44
+ else {
45
+ // If the status is not in the DialStatus enum, we ignore the event
46
+ return;
47
+ }
48
+ voiceClient.sendResponse({
49
+ dialResponse: {
50
+ status: mappedStatus
51
+ }
52
+ });
53
+ });
54
+ }
@@ -0,0 +1,3 @@
1
+ import { DialRequest } from "@fonoster/common";
2
+ declare function handleStasisEnd(request: DialRequest): () => Promise<void>;
3
+ export { handleStasisEnd };
@@ -0,0 +1,19 @@
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.handleStasisEnd = handleStasisEnd;
13
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
14
+ function handleStasisEnd(request) {
15
+ return () => __awaiter(this, void 0, void 0, function* () {
16
+ // Fixme: Should upload the recording to the storage service
17
+ // no-op
18
+ });
19
+ }
@@ -0,0 +1,9 @@
1
+ import { DialRequest } from "@fonoster/common";
2
+ import { Bridge, Channel, Client } from "ari-client";
3
+ declare function handleStasisStart(params: {
4
+ ari: Client;
5
+ request: DialRequest;
6
+ bridge: Bridge;
7
+ dialed: Channel;
8
+ }): (_: undefined, channel: Channel) => Promise<void>;
9
+ export { handleStasisStart };
@@ -0,0 +1,53 @@
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.handleStasisStart = handleStasisStart;
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 recordChannel_1 = require("./recordChannel");
33
+ function handleStasisStart(params) {
34
+ const { ari, request, dialed, bridge } = params;
35
+ const { recordDirection } = request;
36
+ return (_, channel) => __awaiter(this, void 0, void 0, function* () {
37
+ try {
38
+ yield bridge.addChannel({ channel: dialed.id });
39
+ if (recordDirection === common_1.DialRecordDirection.IN ||
40
+ recordDirection === common_1.DialRecordDirection.BOTH) {
41
+ (0, recordChannel_1.recordChannel)(ari, common_1.DialRecordDirection.IN, channel.id);
42
+ }
43
+ if (recordDirection === common_1.DialRecordDirection.OUT ||
44
+ recordDirection === common_1.DialRecordDirection.BOTH) {
45
+ (0, recordChannel_1.recordChannel)(ari, common_1.DialRecordDirection.OUT, dialed.id);
46
+ }
47
+ }
48
+ catch (e) {
49
+ // It is possible that the originating side was already closed
50
+ yield dialed.hangup();
51
+ }
52
+ });
53
+ }
@@ -0,0 +1,4 @@
1
+ import { DialRecordDirection } from "@fonoster/common";
2
+ import { Client } from "ari-client";
3
+ declare function recordChannel(ari: Client, direction: DialRecordDirection.IN | DialRecordDirection.OUT, sessionRef: string): Promise<import("ari-client").LiveRecording>;
4
+ export { recordChannel };