@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.
- package/dist/applications/buildService.js +10 -10
- package/dist/applications/{createApplication.d.ts → createCreateApplication.d.ts} +2 -2
- package/dist/applications/{createApplication.js → createCreateApplication.js} +14 -7
- package/dist/applications/{getApplication.d.ts → createDeleteApplication.d.ts} +2 -2
- package/dist/applications/{deleteApplication.js → createDeleteApplication.js} +4 -4
- package/dist/applications/{updateApplication.d.ts → createGetApplication.d.ts} +2 -2
- package/dist/applications/{getApplication.js → createGetApplication.js} +4 -4
- package/dist/applications/createGetFnUtil.d.ts +2 -0
- package/dist/applications/{listApplications.d.ts → createListApplications.d.ts} +2 -2
- package/dist/applications/{listApplications.js → createListApplications.js} +5 -6
- package/dist/applications/{deleteApplication.d.ts → createUpdateApplication.d.ts} +2 -2
- package/dist/applications/{updateApplication.js → createUpdateApplication.js} +7 -7
- package/dist/applications/utils/applicationWithEncodedStruct.js +2 -0
- package/dist/applications/utils/convertToApplicationData.d.ts +2 -2
- package/dist/applications/validation/assistantWithoutApiKeySchema.d.ts +671 -0
- package/dist/applications/validation/assistantWithoutApiKeySchema.js +35 -0
- package/dist/applications/validation/createValidationSchema.d.ts +1107 -0
- package/dist/applications/validation/createValidationSchema.js +67 -0
- package/dist/applications/validation/speechValidators.d.ts +29 -0
- package/dist/applications/{utils/getApplicationValidationSchema.js → validation/speechValidators.js} +3 -28
- package/dist/applications/{utils → validation}/validOrThrow.js +3 -2
- package/dist/calls/buildService.js +2 -2
- package/dist/calls/createCall.js +1 -2
- package/dist/calls/{makeTrackCall.d.ts → createTrackCall.d.ts} +2 -2
- package/dist/calls/{makeTrackCall.js → createTrackCall.js} +4 -4
- package/dist/calls/getCall.js +1 -2
- package/dist/calls/listCalls.js +1 -2
- package/dist/core/httpBridge.js +1 -1
- package/dist/core/runServices.js +2 -3
- package/dist/core/seed.js +11 -1
- package/dist/core/services.js +1 -1
- package/dist/envs.d.ts +1 -0
- package/dist/envs.js +3 -2
- package/dist/secrets/createGetFnUtil.js +12 -10
- package/dist/secrets/createSecret.js +1 -2
- package/dist/secrets/listSecrets.js +1 -2
- package/dist/secrets/updateSecret.js +1 -2
- package/dist/utils/createCheckNumberPreconditions.d.ts +6 -0
- package/dist/utils/{makeCheckNumberPreconditions.js → createCheckNumberPreconditions.js} +4 -4
- package/dist/utils/createHandleDialEventsWithNats.d.ts +5 -0
- package/dist/utils/{makeHandleDialEventsWithNats.js → createHandleDialEventsWithNats.js} +10 -8
- package/dist/utils/createHandleDialEventsWithVoiceClient.d.ts +5 -0
- package/dist/utils/{makeHandleDialEventsWithVoiceClient.js → createHandleDialEventsWithVoiceClient.js} +13 -11
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +3 -3
- package/dist/voice/VoiceClientImpl.js +13 -7
- package/dist/voice/VoiceDispatcher.js +16 -17
- package/dist/voice/connectToAri.js +3 -3
- package/dist/voice/{makeCreateVoiceClient.d.ts → createCreateVoiceClient.d.ts} +2 -2
- package/dist/voice/createCreateVoiceClient.js +76 -0
- package/dist/voice/handlers/createAnswerHandler.d.ts +5 -0
- package/dist/voice/handlers/{Answer.js → createAnswerHandler.js} +2 -2
- package/dist/voice/handlers/createHangupHandler.d.ts +5 -0
- package/dist/voice/handlers/{Hangup.js → createHangupHandler.js} +2 -2
- package/dist/voice/handlers/createMuteHandler.d.ts +4 -0
- package/dist/voice/handlers/{Mute.js → createMuteHandler.js} +2 -2
- package/dist/voice/handlers/createPlayDtmfHandler.d.ts +4 -0
- package/dist/voice/handlers/{PlayDtmf.js → createPlayDtmfHandler.js} +2 -2
- package/dist/voice/handlers/createPlayHandler.d.ts +4 -0
- package/dist/voice/handlers/{Play.js → createPlayHandler.js} +2 -2
- package/dist/voice/handlers/createPlaybackControlHandler.d.ts +4 -0
- package/dist/voice/handlers/{PlaybackControl.js → createPlaybackControlHandler.js} +2 -2
- package/dist/voice/handlers/createRecordHandler.d.ts +4 -0
- package/dist/voice/handlers/{Record.js → createRecordHandler.js} +2 -2
- package/dist/voice/handlers/createSayHandler.d.ts +4 -0
- package/dist/voice/handlers/{Say.js → createSayHandler.js} +2 -2
- package/dist/voice/handlers/createStreamGatherHandler.d.ts +3 -0
- package/dist/voice/handlers/{StreamGather.js → createStreamGatherHandler.js} +2 -2
- package/dist/voice/handlers/{StreamGather.d.ts → createStreamHandler.d.ts} +2 -2
- package/dist/voice/handlers/{Stream.js → createStreamHandler.js} +2 -2
- package/dist/voice/handlers/createUnmuteHandler.d.ts +4 -0
- package/dist/voice/handlers/{Unmute.js → createUnmuteHandler.js} +2 -2
- package/dist/voice/handlers/dial/createDialHandler.d.ts +5 -0
- package/dist/voice/handlers/dial/createDialHandler.js +78 -0
- package/dist/voice/handlers/dial/index.d.ts +1 -0
- package/dist/voice/handlers/dial/index.js +35 -0
- package/dist/voice/handlers/gather/createGatherHandler.d.ts +3 -0
- package/dist/voice/handlers/gather/{Gather.js → createGatherHandler.js} +2 -2
- package/dist/voice/handlers/index.d.ts +13 -12
- package/dist/voice/handlers/index.js +13 -12
- package/dist/voice/integrations/createCreateContainer.d.ts +4 -0
- package/dist/voice/integrations/{makeCreateContainer.js → createCreateContainer.js} +28 -26
- package/dist/voice/integrations/getSttConfig.js +20 -2
- package/dist/voice/integrations/getTtsConfig.js +2 -2
- package/dist/voice/integrations/index.d.ts +1 -1
- package/dist/voice/integrations/index.js +1 -1
- package/dist/voice/stt/types.d.ts +1 -1
- package/dist/voice/utils/createGetChannelVar.d.ts +4 -0
- package/dist/voice/utils/{makeGetChannelVar.js → createGetChannelVar.js} +14 -12
- package/dist/voice/utils/createGetChannelVarWithoutThrow.d.ts +4 -0
- package/dist/voice/utils/{makeGetChannelVarWithoutThrow.js → createGetChannelVarWithoutThrow.js} +14 -12
- package/dist/voice/utils/index.d.ts +2 -2
- package/dist/voice/utils/index.js +2 -2
- package/package.json +9 -9
- package/dist/applications/utils/getApplicationValidationSchema.d.ts +0 -64
- package/dist/utils/makeCheckNumberPreconditions.d.ts +0 -6
- package/dist/utils/makeHandleDialEventsWithNats.d.ts +0 -5
- package/dist/utils/makeHandleDialEventsWithVoiceClient.d.ts +0 -5
- package/dist/voice/handlers/Answer.d.ts +0 -5
- package/dist/voice/handlers/Hangup.d.ts +0 -5
- package/dist/voice/handlers/Mute.d.ts +0 -4
- package/dist/voice/handlers/Play.d.ts +0 -4
- package/dist/voice/handlers/PlayDtmf.d.ts +0 -4
- package/dist/voice/handlers/PlaybackControl.d.ts +0 -4
- package/dist/voice/handlers/Record.d.ts +0 -4
- package/dist/voice/handlers/Say.d.ts +0 -4
- package/dist/voice/handlers/Stream.d.ts +0 -3
- package/dist/voice/handlers/Unmute.d.ts +0 -4
- package/dist/voice/handlers/dial/Dial.d.ts +0 -5
- package/dist/voice/handlers/dial/Dial.js +0 -76
- package/dist/voice/handlers/gather/Gather.d.ts +0 -3
- package/dist/voice/integrations/findIntegrationsCredentials.d.ts +0 -3
- package/dist/voice/integrations/findIntegrationsCredentials.js +0 -7
- package/dist/voice/integrations/makeCreateContainer.d.ts +0 -4
- package/dist/voice/makeCreateVoiceClient.js +0 -74
- package/dist/voice/utils/makeGetChannelVar.d.ts +0 -4
- package/dist/voice/utils/makeGetChannelVarWithoutThrow.d.ts +0 -4
- /package/dist/applications/{utils → validation}/prepareForValidation.d.ts +0 -0
- /package/dist/applications/{utils → validation}/prepareForValidation.js +0 -0
- /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
|
|
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,
|
|
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.
|
|
74
|
-
vc.on(common_1.StreamContent.HANGUP_REQUEST, (0, handlers_1.
|
|
75
|
-
vc.on(common_1.StreamContent.MUTE_REQUEST, (0, handlers_1.
|
|
76
|
-
vc.on(common_1.StreamContent.UNMUTE_REQUEST, (0, handlers_1.
|
|
77
|
-
vc.on(common_1.StreamContent.PLAY_REQUEST, (0, handlers_1.
|
|
78
|
-
vc.on(common_1.StreamContent.PLAY_DTMF_REQUEST, (0, handlers_1.
|
|
79
|
-
vc.on(common_1.StreamContent.SAY_REQUEST, (0, handlers_1.
|
|
80
|
-
vc.on(common_1.StreamContent.GATHER_REQUEST, (0, handlers_1.
|
|
81
|
-
vc.on(common_1.StreamContent.DIAL_REQUEST, (0, handlers_1.
|
|
82
|
-
vc.on(common_1.StreamContent.PLAYBACK_CONTROL_REQUEST, (0, handlers_1.
|
|
83
|
-
vc.on(common_1.StreamContent.START_STREAM_GATHER_REQUEST, (0, handlers_1.
|
|
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,
|
|
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.
|
|
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,
|
|
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
|
|
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.
|
|
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,
|
|
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
|
|
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 {
|
|
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.
|
|
12
|
+
exports.createAnswerHandler = createAnswerHandler;
|
|
13
13
|
const withErrorHandling_1 = require("./utils/withErrorHandling");
|
|
14
|
-
function
|
|
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.
|
|
12
|
+
exports.createHangupHandler = createHangupHandler;
|
|
13
13
|
const withErrorHandling_1 = require("./utils/withErrorHandling");
|
|
14
|
-
function
|
|
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
|
|
@@ -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.
|
|
12
|
+
exports.createMuteHandler = createMuteHandler;
|
|
13
13
|
const withErrorHandling_1 = require("./utils/withErrorHandling");
|
|
14
|
-
function
|
|
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({
|
|
@@ -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.
|
|
12
|
+
exports.createPlayDtmfHandler = createPlayDtmfHandler;
|
|
13
13
|
const withErrorHandling_1 = require("./utils/withErrorHandling");
|
|
14
|
-
function
|
|
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({
|
|
@@ -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.
|
|
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
|
|
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.
|
|
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
|
|
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;
|
|
@@ -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.
|
|
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
|
|
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);
|
|
@@ -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.
|
|
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
|
|
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);
|
|
@@ -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.
|
|
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
|
|
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
|
|
3
|
-
export {
|
|
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.
|
|
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
|
|
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);
|
|
@@ -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.
|
|
12
|
+
exports.createUnmuteHandler = createUnmuteHandler;
|
|
13
13
|
const withErrorHandling_1 = require("./utils/withErrorHandling");
|
|
14
|
-
function
|
|
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);
|
|
@@ -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.
|
|
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
|
|
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 "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./
|
|
12
|
-
export * from "./
|
|
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";
|