@fonoster/apiserver 0.8.25 → 0.8.27

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 (120) hide show
  1. package/dist/applications/buildService.js +10 -10
  2. package/dist/applications/{createApplication.d.ts → createCreateApplication.d.ts} +2 -2
  3. package/dist/applications/{createApplication.js → createCreateApplication.js} +14 -7
  4. package/dist/applications/{getApplication.d.ts → createDeleteApplication.d.ts} +2 -2
  5. package/dist/applications/{deleteApplication.js → createDeleteApplication.js} +4 -4
  6. package/dist/applications/{updateApplication.d.ts → createGetApplication.d.ts} +2 -2
  7. package/dist/applications/{getApplication.js → createGetApplication.js} +4 -4
  8. package/dist/applications/createGetFnUtil.d.ts +2 -0
  9. package/dist/applications/{listApplications.d.ts → createListApplications.d.ts} +2 -2
  10. package/dist/applications/{listApplications.js → createListApplications.js} +5 -6
  11. package/dist/applications/{deleteApplication.d.ts → createUpdateApplication.d.ts} +2 -2
  12. package/dist/applications/{updateApplication.js → createUpdateApplication.js} +7 -7
  13. package/dist/applications/utils/applicationWithEncodedStruct.js +2 -0
  14. package/dist/applications/utils/convertToApplicationData.d.ts +2 -2
  15. package/dist/applications/validation/assistantWithoutApiKeySchema.d.ts +671 -0
  16. package/dist/applications/validation/assistantWithoutApiKeySchema.js +35 -0
  17. package/dist/applications/validation/createValidationSchema.d.ts +1107 -0
  18. package/dist/applications/validation/createValidationSchema.js +67 -0
  19. package/dist/applications/validation/speechValidators.d.ts +29 -0
  20. package/dist/applications/{utils/getApplicationValidationSchema.js → validation/speechValidators.js} +3 -28
  21. package/dist/applications/{utils → validation}/validOrThrow.js +3 -2
  22. package/dist/calls/buildService.js +2 -2
  23. package/dist/calls/createCall.js +1 -2
  24. package/dist/calls/{makeTrackCall.d.ts → createTrackCall.d.ts} +2 -2
  25. package/dist/calls/{makeTrackCall.js → createTrackCall.js} +4 -4
  26. package/dist/calls/getCall.js +1 -2
  27. package/dist/calls/listCalls.js +1 -2
  28. package/dist/core/httpBridge.js +1 -1
  29. package/dist/core/runServices.js +2 -3
  30. package/dist/core/seed.js +11 -1
  31. package/dist/core/services.js +1 -1
  32. package/dist/envs.d.ts +1 -0
  33. package/dist/envs.js +3 -2
  34. package/dist/secrets/createGetFnUtil.js +12 -10
  35. package/dist/secrets/createSecret.js +1 -2
  36. package/dist/secrets/listSecrets.js +1 -2
  37. package/dist/secrets/updateSecret.js +1 -2
  38. package/dist/utils/createCheckNumberPreconditions.d.ts +6 -0
  39. package/dist/utils/{makeCheckNumberPreconditions.js → createCheckNumberPreconditions.js} +4 -4
  40. package/dist/utils/createHandleDialEventsWithNats.d.ts +5 -0
  41. package/dist/utils/{makeHandleDialEventsWithNats.js → createHandleDialEventsWithNats.js} +10 -8
  42. package/dist/utils/createHandleDialEventsWithVoiceClient.d.ts +5 -0
  43. package/dist/utils/{makeHandleDialEventsWithVoiceClient.js → createHandleDialEventsWithVoiceClient.js} +13 -11
  44. package/dist/utils/index.d.ts +3 -3
  45. package/dist/utils/index.js +3 -3
  46. package/dist/voice/VoiceClientImpl.js +13 -7
  47. package/dist/voice/VoiceDispatcher.js +16 -17
  48. package/dist/voice/connectToAri.js +3 -3
  49. package/dist/voice/{makeCreateVoiceClient.d.ts → createCreateVoiceClient.d.ts} +2 -2
  50. package/dist/voice/createCreateVoiceClient.js +76 -0
  51. package/dist/voice/handlers/createAnswerHandler.d.ts +5 -0
  52. package/dist/voice/handlers/{Answer.js → createAnswerHandler.js} +2 -2
  53. package/dist/voice/handlers/createHangupHandler.d.ts +5 -0
  54. package/dist/voice/handlers/{Hangup.js → createHangupHandler.js} +2 -2
  55. package/dist/voice/handlers/createMuteHandler.d.ts +4 -0
  56. package/dist/voice/handlers/{Mute.js → createMuteHandler.js} +2 -2
  57. package/dist/voice/handlers/createPlayDtmfHandler.d.ts +4 -0
  58. package/dist/voice/handlers/{PlayDtmf.js → createPlayDtmfHandler.js} +2 -2
  59. package/dist/voice/handlers/createPlayHandler.d.ts +4 -0
  60. package/dist/voice/handlers/{Play.js → createPlayHandler.js} +2 -2
  61. package/dist/voice/handlers/createPlaybackControlHandler.d.ts +4 -0
  62. package/dist/voice/handlers/{PlaybackControl.js → createPlaybackControlHandler.js} +2 -2
  63. package/dist/voice/handlers/createRecordHandler.d.ts +4 -0
  64. package/dist/voice/handlers/{Record.js → createRecordHandler.js} +2 -2
  65. package/dist/voice/handlers/createSayHandler.d.ts +4 -0
  66. package/dist/voice/handlers/{Say.js → createSayHandler.js} +2 -2
  67. package/dist/voice/handlers/createStreamGatherHandler.d.ts +3 -0
  68. package/dist/voice/handlers/{StreamGather.js → createStreamGatherHandler.js} +2 -2
  69. package/dist/voice/handlers/{StreamGather.d.ts → createStreamHandler.d.ts} +2 -2
  70. package/dist/voice/handlers/{Stream.js → createStreamHandler.js} +2 -2
  71. package/dist/voice/handlers/createUnmuteHandler.d.ts +4 -0
  72. package/dist/voice/handlers/{Unmute.js → createUnmuteHandler.js} +2 -2
  73. package/dist/voice/handlers/dial/createDialHandler.d.ts +5 -0
  74. package/dist/voice/handlers/dial/createDialHandler.js +78 -0
  75. package/dist/voice/handlers/dial/index.d.ts +1 -0
  76. package/dist/voice/handlers/dial/index.js +35 -0
  77. package/dist/voice/handlers/gather/createGatherHandler.d.ts +3 -0
  78. package/dist/voice/handlers/gather/{Gather.js → createGatherHandler.js} +2 -2
  79. package/dist/voice/handlers/index.d.ts +13 -12
  80. package/dist/voice/handlers/index.js +13 -12
  81. package/dist/voice/integrations/createCreateContainer.d.ts +4 -0
  82. package/dist/voice/integrations/{makeCreateContainer.js → createCreateContainer.js} +28 -26
  83. package/dist/voice/integrations/getSttConfig.js +20 -2
  84. package/dist/voice/integrations/getTtsConfig.js +2 -2
  85. package/dist/voice/integrations/index.d.ts +1 -1
  86. package/dist/voice/integrations/index.js +1 -1
  87. package/dist/voice/stt/types.d.ts +1 -1
  88. package/dist/voice/utils/createGetChannelVar.d.ts +4 -0
  89. package/dist/voice/utils/{makeGetChannelVar.js → createGetChannelVar.js} +14 -12
  90. package/dist/voice/utils/createGetChannelVarWithoutThrow.d.ts +4 -0
  91. package/dist/voice/utils/{makeGetChannelVarWithoutThrow.js → createGetChannelVarWithoutThrow.js} +14 -12
  92. package/dist/voice/utils/index.d.ts +2 -2
  93. package/dist/voice/utils/index.js +2 -2
  94. package/package.json +9 -9
  95. package/dist/applications/utils/getApplicationValidationSchema.d.ts +0 -64
  96. package/dist/utils/makeCheckNumberPreconditions.d.ts +0 -6
  97. package/dist/utils/makeHandleDialEventsWithNats.d.ts +0 -5
  98. package/dist/utils/makeHandleDialEventsWithVoiceClient.d.ts +0 -5
  99. package/dist/voice/handlers/Answer.d.ts +0 -5
  100. package/dist/voice/handlers/Hangup.d.ts +0 -5
  101. package/dist/voice/handlers/Mute.d.ts +0 -4
  102. package/dist/voice/handlers/Play.d.ts +0 -4
  103. package/dist/voice/handlers/PlayDtmf.d.ts +0 -4
  104. package/dist/voice/handlers/PlaybackControl.d.ts +0 -4
  105. package/dist/voice/handlers/Record.d.ts +0 -4
  106. package/dist/voice/handlers/Say.d.ts +0 -4
  107. package/dist/voice/handlers/Stream.d.ts +0 -3
  108. package/dist/voice/handlers/Unmute.d.ts +0 -4
  109. package/dist/voice/handlers/dial/Dial.d.ts +0 -5
  110. package/dist/voice/handlers/dial/Dial.js +0 -76
  111. package/dist/voice/handlers/gather/Gather.d.ts +0 -3
  112. package/dist/voice/integrations/findIntegrationsCredentials.d.ts +0 -3
  113. package/dist/voice/integrations/findIntegrationsCredentials.js +0 -7
  114. package/dist/voice/integrations/makeCreateContainer.d.ts +0 -4
  115. package/dist/voice/makeCreateVoiceClient.js +0 -74
  116. package/dist/voice/utils/makeGetChannelVar.d.ts +0 -4
  117. package/dist/voice/utils/makeGetChannelVarWithoutThrow.d.ts +0 -4
  118. /package/dist/applications/{utils → validation}/prepareForValidation.d.ts +0 -0
  119. /package/dist/applications/{utils → validation}/prepareForValidation.js +0 -0
  120. /package/dist/applications/{utils → validation}/validOrThrow.d.ts +0 -0
@@ -31,10 +31,9 @@ exports.VoiceDispatcher = void 0;
31
31
  const common_1 = require("@fonoster/common");
32
32
  const logger_1 = require("@fonoster/logger");
33
33
  const handlers_1 = require("./handlers");
34
- const Stream_1 = require("./handlers/Stream");
35
34
  const types_1 = require("./types");
36
35
  const utils_1 = require("../utils");
37
- const makeGetChannelVarWithoutThrow_1 = require("./utils/makeGetChannelVarWithoutThrow");
36
+ const utils_2 = require("./utils");
38
37
  const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
39
38
  class VoiceDispatcher {
40
39
  constructor(ari, nc, createVoiceClient) {
@@ -55,7 +54,7 @@ class VoiceDispatcher {
55
54
  return __awaiter(this, void 0, void 0, function* () {
56
55
  var _a;
57
56
  const { ari, voiceClients, createVoiceClient, isHandledElsewhere } = this;
58
- const getChannelVar = (0, makeGetChannelVarWithoutThrow_1.makeGetChannelVarWithoutThrow)(channel);
57
+ const getChannelVar = (0, utils_2.createGetChannelVarWithoutThrow)(channel);
59
58
  const appRef = (_a = (yield getChannelVar(types_1.ChannelVar.APP_REF))) === null || _a === void 0 ? void 0 : _a.value;
60
59
  // This check feels strange but is necessary as ARI calls this event twice
61
60
  if (!appRef) {
@@ -70,21 +69,21 @@ class VoiceDispatcher {
70
69
  // Connect to voice server
71
70
  vc.connect();
72
71
  voiceClients.set(channel.id, vc);
73
- vc.on(common_1.StreamContent.ANSWER_REQUEST, (0, handlers_1.answerHandler)(ari, vc).bind(this));
74
- vc.on(common_1.StreamContent.HANGUP_REQUEST, (0, handlers_1.hangupHandler)(ari, vc).bind(this));
75
- vc.on(common_1.StreamContent.MUTE_REQUEST, (0, handlers_1.muteHandler)(ari, vc).bind(this));
76
- vc.on(common_1.StreamContent.UNMUTE_REQUEST, (0, handlers_1.unmuteHandler)(ari, vc).bind(this));
77
- vc.on(common_1.StreamContent.PLAY_REQUEST, (0, handlers_1.playHandler)(ari, vc).bind(this));
78
- vc.on(common_1.StreamContent.PLAY_DTMF_REQUEST, (0, handlers_1.playDtmfHandler)(ari, vc).bind(this));
79
- vc.on(common_1.StreamContent.SAY_REQUEST, (0, handlers_1.sayHandler)(ari, vc).bind(this));
80
- vc.on(common_1.StreamContent.GATHER_REQUEST, (0, handlers_1.gatherHandler)(vc).bind(this));
81
- vc.on(common_1.StreamContent.DIAL_REQUEST, (0, handlers_1.dialHandler)(ari, vc).bind(this));
82
- vc.on(common_1.StreamContent.PLAYBACK_CONTROL_REQUEST, (0, handlers_1.playbackControlHandler)(ari, vc).bind(this));
83
- vc.on(common_1.StreamContent.START_STREAM_GATHER_REQUEST, (0, handlers_1.streamGatherHandler)(vc).bind(this));
72
+ vc.on(common_1.StreamContent.ANSWER_REQUEST, (0, handlers_1.createAnswerHandler)(ari, vc).bind(this));
73
+ vc.on(common_1.StreamContent.HANGUP_REQUEST, (0, handlers_1.createHangupHandler)(ari, vc).bind(this));
74
+ vc.on(common_1.StreamContent.MUTE_REQUEST, (0, handlers_1.createMuteHandler)(ari, vc).bind(this));
75
+ vc.on(common_1.StreamContent.UNMUTE_REQUEST, (0, handlers_1.createUnmuteHandler)(ari, vc).bind(this));
76
+ vc.on(common_1.StreamContent.PLAY_REQUEST, (0, handlers_1.createPlayHandler)(ari, vc).bind(this));
77
+ vc.on(common_1.StreamContent.PLAY_DTMF_REQUEST, (0, handlers_1.createPlayDtmfHandler)(ari, vc).bind(this));
78
+ vc.on(common_1.StreamContent.SAY_REQUEST, (0, handlers_1.createSayHandler)(ari, vc).bind(this));
79
+ vc.on(common_1.StreamContent.GATHER_REQUEST, (0, handlers_1.createGatherHandler)(vc).bind(this));
80
+ vc.on(common_1.StreamContent.DIAL_REQUEST, (0, handlers_1.createDialHandler)(ari, vc).bind(this));
81
+ vc.on(common_1.StreamContent.PLAYBACK_CONTROL_REQUEST, (0, handlers_1.createPlaybackControlHandler)(ari, vc).bind(this));
82
+ vc.on(common_1.StreamContent.START_STREAM_GATHER_REQUEST, (0, handlers_1.createStreamGatherHandler)(vc).bind(this));
84
83
  vc.on(common_1.StreamContent.STOP_STREAM_GATHER_REQUEST, () => {
85
84
  vc.stopStreamGather();
86
85
  });
87
- vc.on(common_1.StreamContent.START_STREAM_REQUEST, (0, Stream_1.streamHandler)(vc).bind(this));
86
+ vc.on(common_1.StreamContent.START_STREAM_REQUEST, (0, handlers_1.createStreamHandler)(vc).bind(this));
88
87
  }
89
88
  catch (err) {
90
89
  logger.error("error handling stasis start", { error: err.message });
@@ -101,13 +100,13 @@ class VoiceDispatcher {
101
100
  }
102
101
  handleDial(event, channel) {
103
102
  return __awaiter(this, void 0, void 0, function* () {
104
- (0, utils_1.makeHandleDialEventsWithNats)(this.nc)(channel.id, event);
103
+ (0, utils_1.createHandleDialEventsWithNats)(this.nc)(channel.id, event);
105
104
  });
106
105
  }
107
106
  isHandledElsewhere(channel) {
108
107
  return __awaiter(this, void 0, void 0, function* () {
109
108
  var _a;
110
- return (((_a = (yield (0, makeGetChannelVarWithoutThrow_1.makeGetChannelVarWithoutThrow)(channel)(types_1.ChannelVar.FROM_EXTERNAL_MEDIA))) === null || _a === void 0 ? void 0 : _a.value) === "true");
109
+ return (((_a = (yield (0, utils_2.createGetChannelVarWithoutThrow)(channel)(types_1.ChannelVar.FROM_EXTERNAL_MEDIA))) === null || _a === void 0 ? void 0 : _a.value) === "true");
111
110
  });
112
111
  }
113
112
  }
@@ -36,7 +36,7 @@ const ari_client_1 = __importDefault(require("ari-client"));
36
36
  const nats_1 = require("nats");
37
37
  const wait_port_1 = __importDefault(require("wait-port"));
38
38
  const integrations_1 = require("./integrations");
39
- const makeCreateVoiceClient_1 = require("./makeCreateVoiceClient");
39
+ const createCreateVoiceClient_1 = require("./createCreateVoiceClient");
40
40
  const types_1 = require("./types");
41
41
  const VoiceDispatcher_1 = require("./VoiceDispatcher");
42
42
  const db_1 = require("../core/db");
@@ -62,9 +62,9 @@ function connectToAri(filesServer) {
62
62
  attemptReconnection(filesServer);
63
63
  });
64
64
  logger.info("asterisk is ready");
65
- const createContainer = (0, integrations_1.makeCreateContainer)(db_1.prisma, envs_1.INTEGRATIONS_FILE);
65
+ const createContainer = (0, integrations_1.createCreateContainer)(db_1.prisma, envs_1.INTEGRATIONS_FILE);
66
66
  const nats = yield (0, nats_1.connect)({ servers: envs_1.NATS_URL, maxReconnectAttempts: -1 });
67
- const dispatcher = new VoiceDispatcher_1.VoiceDispatcher(ari, nats, (0, makeCreateVoiceClient_1.makeCreateVoiceClient)(createContainer, filesServer));
67
+ const dispatcher = new VoiceDispatcher_1.VoiceDispatcher(ari, nats, (0, createCreateVoiceClient_1.createCreateVoiceClient)(createContainer, filesServer));
68
68
  dispatcher.start();
69
69
  }
70
70
  else {
@@ -1,9 +1,9 @@
1
1
  import { Channel, Client, StasisStart } from "ari-client";
2
2
  import { CreateContainer } from "./integrations/types";
3
3
  import { VoiceClient } from "./types";
4
- declare function makeCreateVoiceClient(createContainer: CreateContainer, filesServer: any): (params: {
4
+ declare function createCreateVoiceClient(createContainer: CreateContainer, filesServer: any): (params: {
5
5
  ari: Client;
6
6
  event: StasisStart;
7
7
  channel: Channel;
8
8
  }) => Promise<VoiceClient>;
9
- export { makeCreateVoiceClient };
9
+ export { createCreateVoiceClient };
@@ -0,0 +1,76 @@
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.createCreateVoiceClient = createCreateVoiceClient;
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 identity_1 = require("@fonoster/identity");
32
+ const logger_1 = require("@fonoster/logger");
33
+ const types_1 = require("./types");
34
+ const createGetChannelVarWithoutThrow_1 = require("./utils/createGetChannelVarWithoutThrow");
35
+ const VoiceClientImpl_1 = require("./VoiceClientImpl");
36
+ const identityConfig_1 = require("../core/identityConfig");
37
+ const mapCallDirectionToEnum_1 = require("../events/mapCallDirectionToEnum");
38
+ const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
39
+ const generateCallAccessToken = (0, identity_1.createGenerateCallAccessToken)(identityConfig_1.identityConfig);
40
+ // Note: By the time the call arrives here the owner of the app MUST be authenticated
41
+ function createCreateVoiceClient(createContainer, filesServer) {
42
+ return function createVoiceClient(params) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ var _a, _b, _c, _d;
45
+ const { ari, event, channel } = params;
46
+ const { id: sessionRef, caller } = event.channel;
47
+ const { name: callerName, number: callerNumber } = caller;
48
+ const getChannelVar = (0, createGetChannelVarWithoutThrow_1.createGetChannelVarWithoutThrow)(channel);
49
+ // Variables set by Asterisk's dialplan
50
+ const callDirection = (_a = (yield getChannelVar(types_1.ChannelVar.CALL_DIRECTION))) === null || _a === void 0 ? void 0 : _a.value;
51
+ const appRef = (_b = (yield getChannelVar(types_1.ChannelVar.APP_REF))) === null || _b === void 0 ? void 0 : _b.value;
52
+ const ingressNumber = ((_c = (yield getChannelVar(types_1.ChannelVar.INGRESS_NUMBER))) === null || _c === void 0 ? void 0 : _c.value) || "";
53
+ const { accessKeyId, endpoint, tts, stt } = yield createContainer(appRef);
54
+ const sessionToken = yield generateCallAccessToken({ accessKeyId, appRef });
55
+ const metadataStr = (_d = (yield getChannelVar(types_1.ChannelVar.METADATA))) === null || _d === void 0 ? void 0 : _d.value;
56
+ const config = {
57
+ appRef,
58
+ sessionRef,
59
+ accessKeyId,
60
+ endpoint,
61
+ callerName,
62
+ callerNumber,
63
+ ingressNumber,
64
+ sessionToken,
65
+ callDirection: (0, mapCallDirectionToEnum_1.mapCallDirectionToEnum)(callDirection),
66
+ metadata: metadataStr ? JSON.parse(metadataStr) : {}
67
+ };
68
+ logger.verbose("creating voice client with config: ", {
69
+ appRef,
70
+ callerNumber,
71
+ ingressNumber
72
+ });
73
+ return new VoiceClientImpl_1.VoiceClientImpl({ ari, config, tts, stt }, filesServer);
74
+ });
75
+ };
76
+ }
@@ -0,0 +1,5 @@
1
+ import { VerbRequest } from "@fonoster/common";
2
+ import { Client } from "ari-client";
3
+ import { VoiceClient } from "../types";
4
+ declare function createAnswerHandler(ari: Client, voiceClient: VoiceClient): (request: VerbRequest) => Promise<void>;
5
+ export { createAnswerHandler };
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.answerHandler = answerHandler;
12
+ exports.createAnswerHandler = createAnswerHandler;
13
13
  const withErrorHandling_1 = require("./utils/withErrorHandling");
14
- function answerHandler(ari, voiceClient) {
14
+ function createAnswerHandler(ari, voiceClient) {
15
15
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
16
16
  const { sessionRef } = request;
17
17
  yield ari.channels.answer({ channelId: sessionRef });
@@ -0,0 +1,5 @@
1
+ import { VerbRequest } from "@fonoster/common";
2
+ import { Client } from "ari-client";
3
+ import { VoiceClient } from "../types";
4
+ declare function createHangupHandler(ari: Client, voiceClient: VoiceClient): (request: VerbRequest) => Promise<void>;
5
+ export { createHangupHandler };
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.hangupHandler = hangupHandler;
12
+ exports.createHangupHandler = createHangupHandler;
13
13
  const withErrorHandling_1 = require("./utils/withErrorHandling");
14
- function hangupHandler(ari, voiceClient) {
14
+ function createHangupHandler(ari, voiceClient) {
15
15
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
16
16
  const { sessionRef } = request;
17
17
  // Give some time for the last sound to play
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function createMuteHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { createMuteHandler };
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.muteHandler = muteHandler;
12
+ exports.createMuteHandler = createMuteHandler;
13
13
  const withErrorHandling_1 = require("./utils/withErrorHandling");
14
- function muteHandler(ari, voiceClient) {
14
+ function createMuteHandler(ari, voiceClient) {
15
15
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
16
16
  const { sessionRef, direction } = request;
17
17
  yield ari.channels.mute({
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function createPlayDtmfHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { createPlayDtmfHandler };
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.playDtmfHandler = playDtmfHandler;
12
+ exports.createPlayDtmfHandler = createPlayDtmfHandler;
13
13
  const withErrorHandling_1 = require("./utils/withErrorHandling");
14
- function playDtmfHandler(ari, voiceClient) {
14
+ function createPlayDtmfHandler(ari, voiceClient) {
15
15
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
16
16
  const { sessionRef, digits } = request;
17
17
  yield ari.channels.sendDTMF({
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function createPlayHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { createPlayHandler };
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.playHandler = playHandler;
12
+ exports.createPlayHandler = createPlayHandler;
13
13
  const nanoid_1 = require("nanoid");
14
14
  const awaitForPlaybackFinished_1 = require("./utils/awaitForPlaybackFinished");
15
15
  const withErrorHandling_1 = require("./utils/withErrorHandling");
16
- function playHandler(ari, voiceClient) {
16
+ function createPlayHandler(ari, voiceClient) {
17
17
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
18
18
  const { sessionRef } = request;
19
19
  const playbackRef = request.playbackRef || (0, nanoid_1.nanoid)(10);
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function createPlaybackControlHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { createPlaybackControlHandler };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.playbackControlHandler = playbackControlHandler;
12
+ exports.createPlaybackControlHandler = createPlaybackControlHandler;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -38,7 +38,7 @@ const requestSchema = zod_1.z.object({
38
38
  message: "Invalid playback control action."
39
39
  })
40
40
  });
41
- function playbackControlHandler(ari, voiceClient) {
41
+ function createPlaybackControlHandler(ari, voiceClient) {
42
42
  return (0, withErrorHandling_1.withErrorHandling)((playbackControlReq) => __awaiter(this, void 0, void 0, function* () {
43
43
  requestSchema.parse(playbackControlReq);
44
44
  const { sessionRef, playbackRef: playbackId, action } = playbackControlReq;
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function createRecordHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { createRecordHandler };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.recordHandler = recordHandler;
12
+ exports.createRecordHandler = createRecordHandler;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -32,7 +32,7 @@ const common_1 = require("@fonoster/common");
32
32
  const nanoid_1 = require("nanoid");
33
33
  const awaitForRecordingFinished_1 = require("./utils/awaitForRecordingFinished");
34
34
  const withErrorHandling_1 = require("./utils/withErrorHandling");
35
- function recordHandler(ari, voiceClient) {
35
+ function createRecordHandler(ari, voiceClient) {
36
36
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
37
37
  const { sessionRef, maxDuration, maxSilence, beep, finishOnKey } = request;
38
38
  const name = (0, nanoid_1.nanoid)(10);
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function createSayHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { createSayHandler };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.sayHandler = sayHandler;
12
+ exports.createSayHandler = createSayHandler;
13
13
  const nanoid_1 = require("nanoid");
14
14
  const pb_util_1 = require("pb-util");
15
15
  const zod_1 = require("zod");
@@ -23,7 +23,7 @@ const sayRequestSchema = zod_1.z.object({
23
23
  options: zod_1.z.record(zod_1.z.unknown()).optional()
24
24
  });
25
25
  const getMediaUrl = (filename) => `sound:http://${envs_1.APISERVER_HOST}:${envs_1.HTTP_BRIDGE_PORT}/api/sounds/${filename}.sln16`;
26
- function sayHandler(ari, voiceClient) {
26
+ function createSayHandler(ari, voiceClient) {
27
27
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
28
28
  const { sessionRef: channelId } = request;
29
29
  sayRequestSchema.parse(request);
@@ -0,0 +1,3 @@
1
+ import { VoiceClient } from "../types";
2
+ declare function createStreamGatherHandler(voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
3
+ export { createStreamGatherHandler };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.streamGatherHandler = streamGatherHandler;
12
+ exports.createStreamGatherHandler = createStreamGatherHandler;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -36,7 +36,7 @@ const gatherRequestSchema = zod_1.z.object({
36
36
  message: "Invalid stream gather source."
37
37
  }))
38
38
  });
39
- function streamGatherHandler(voiceClient) {
39
+ function createStreamGatherHandler(voiceClient) {
40
40
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
41
41
  const { sessionRef, source } = request;
42
42
  gatherRequestSchema.parse(request);
@@ -1,3 +1,3 @@
1
1
  import { VoiceClient } from "../types";
2
- declare function streamGatherHandler(voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
3
- export { streamGatherHandler };
2
+ declare function createStreamHandler(voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
3
+ export { createStreamHandler };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.streamHandler = streamHandler;
12
+ exports.createStreamHandler = createStreamHandler;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -39,7 +39,7 @@ const streamRequestSchema = zod_1.z.object({
39
39
  .nativeEnum(common_1.StreamAudioFormat, { message: "Invalid stream audio format" })
40
40
  .optional()
41
41
  });
42
- function streamHandler(voiceClient) {
42
+ function createStreamHandler(voiceClient) {
43
43
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
44
44
  const { sessionRef, direction, format } = request;
45
45
  streamRequestSchema.parse(request);
@@ -0,0 +1,4 @@
1
+ import { Client } from "ari-client";
2
+ import { VoiceClient } from "../types";
3
+ declare function createUnmuteHandler(ari: Client, voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
4
+ export { createUnmuteHandler };
@@ -9,9 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.unmuteHandler = unmuteHandler;
12
+ exports.createUnmuteHandler = createUnmuteHandler;
13
13
  const withErrorHandling_1 = require("./utils/withErrorHandling");
14
- function unmuteHandler(ari, voiceClient) {
14
+ function createUnmuteHandler(ari, voiceClient) {
15
15
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
16
16
  const { sessionRef, direction } = request;
17
17
  yield ari.channels.unmute({
@@ -0,0 +1,5 @@
1
+ import { DialRequest } from "@fonoster/common";
2
+ import { Client } from "ari-client";
3
+ import { VoiceClient } from "../../types";
4
+ declare function createDialHandler(ari: Client, voiceClient: VoiceClient): (request: DialRequest) => Promise<void>;
5
+ export { createDialHandler };
@@ -0,0 +1,78 @@
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.createDialHandler = createDialHandler;
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 uuid_1 = require("uuid");
33
+ const handleChannelLeftBridge_1 = require("./handleChannelLeftBridge");
34
+ const handleStasisEnd_1 = require("./handleStasisEnd");
35
+ const handleStasisStart_1 = require("./handleStasisStart");
36
+ const envs_1 = require("../../../envs");
37
+ const utils_1 = require("../../../utils");
38
+ const types_1 = require("../../types");
39
+ const createGetChannelVar_1 = require("../../utils/createGetChannelVar");
40
+ // TODO: Needs request validation
41
+ function createDialHandler(ari, voiceClient) {
42
+ return function dial(request) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const { sessionRef: channelId, destination, timeout } = request;
45
+ const bridge = yield ari.bridges.create({
46
+ type: "mixing"
47
+ });
48
+ // eslint-disable-next-line new-cap
49
+ const dialed = ari.Channel();
50
+ yield bridge.addChannel({ channel: channelId });
51
+ const callerChannel = yield ari.channels.get({ channelId });
52
+ const getChannelVar = (0, createGetChannelVar_1.createGetChannelVar)(callerChannel);
53
+ const ingressNumber = (yield getChannelVar(types_1.ChannelVar.INGRESS_NUMBER))
54
+ .value;
55
+ const ref = (0, uuid_1.v4)();
56
+ yield dialed.originate({
57
+ app: common_1.STASIS_APP_NAME,
58
+ endpoint: `PJSIP/${envs_1.ASTERISK_TRUNK}/sip:${destination}@${envs_1.ASTERISK_SYSTEM_DOMAIN}`,
59
+ timeout,
60
+ variables: {
61
+ "PJSIP_HEADER(add,X-Call-Ref)": ref,
62
+ "PJSIP_HEADER(add,X-Dod-Number)": ingressNumber,
63
+ "PJSIP_HEADER(add,X-Is-Api-Originated-Type)": "true"
64
+ }
65
+ });
66
+ yield ari.channels.ring({ channelId });
67
+ dialed.once(types_1.AriEvent.STASIS_START, (0, handleStasisStart_1.handleStasisStart)({ ari, request, bridge, dialed }));
68
+ dialed.once(types_1.AriEvent.CHANNEL_LEFT_BRIDGE, (0, handleChannelLeftBridge_1.handleChannelLeftBridge)({ bridge, dialed }));
69
+ dialed.once(types_1.AriEvent.STASIS_END, (0, handleStasisEnd_1.handleStasisEnd)(request));
70
+ dialed.on(types_1.AriEvent.DIAL, (0, utils_1.createHandleDialEventsWithVoiceClient)(voiceClient));
71
+ voiceClient.sendResponse({
72
+ dialResponse: {
73
+ status: common_1.DialStatus.TRYING
74
+ }
75
+ });
76
+ });
77
+ };
78
+ }
@@ -0,0 +1 @@
1
+ export * from "./createDialHandler";
@@ -0,0 +1,35 @@
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("./createDialHandler"), exports);
@@ -0,0 +1,3 @@
1
+ import { VoiceClient } from "../../types";
2
+ declare function createGatherHandler(voiceClient: VoiceClient): (request: import("@fonoster/common").VerbRequest) => Promise<void>;
3
+ export { createGatherHandler };
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.gatherHandler = gatherHandler;
12
+ exports.createGatherHandler = createGatherHandler;
13
13
  /*
14
14
  * Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
15
15
  * http://github.com/fonoster/fonoster
@@ -52,7 +52,7 @@ const gatherRequestSchema = zod_1.z.object({
52
52
  .max(1, { message: common_1.MUST_BE_A_SINGLE_CHARACTER })
53
53
  .optional()
54
54
  });
55
- function gatherHandler(voiceClient) {
55
+ function createGatherHandler(voiceClient) {
56
56
  return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
57
57
  const { sessionRef, source, timeout, finishOnKey, maxDigits } = request;
58
58
  gatherRequestSchema.parse(request);
@@ -1,12 +1,13 @@
1
- export * from "./Answer";
2
- export * from "./Hangup";
3
- export * from "./Mute";
4
- export * from "./Play";
5
- export * from "./PlayDtmf";
6
- export * from "./PlaybackControl";
7
- export * from "./Record";
8
- export * from "./Say";
9
- export * from "./StreamGather";
10
- export * from "./Unmute";
11
- export * from "./dial/Dial";
12
- export * from "./gather/Gather";
1
+ export * from "./createAnswerHandler";
2
+ export * from "./createHangupHandler";
3
+ export * from "./createMuteHandler";
4
+ export * from "./createStreamHandler";
5
+ export * from "./createPlayHandler";
6
+ export * from "./createPlayDtmfHandler";
7
+ export * from "./createPlaybackControlHandler";
8
+ export * from "./createRecordHandler";
9
+ export * from "./createSayHandler";
10
+ export * from "./createStreamGatherHandler";
11
+ export * from "./createUnmuteHandler";
12
+ export * from "./dial/createDialHandler";
13
+ export * from "./gather/createGatherHandler";