@fonoster/apiserver 0.8.24 → 0.8.26
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/createApplication.js +1 -2
- package/dist/applications/listApplications.js +1 -2
- package/dist/applications/updateApplication.js +2 -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/services.js +1 -1
- 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} +2 -2
- 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/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} +27 -25
- 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/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/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
|
@@ -29,7 +29,6 @@ exports.createApplication = createApplication;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const convertToApplicationData_1 = require("./utils/convertToApplicationData");
|
|
35
34
|
const validOrThrow_1 = require("./utils/validOrThrow");
|
|
@@ -38,7 +37,7 @@ function createApplication(prisma) {
|
|
|
38
37
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
39
38
|
const { request } = call;
|
|
40
39
|
const { type } = request;
|
|
41
|
-
const accessKeyId = (0,
|
|
40
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
42
41
|
logger.verbose("call to createApplication", {
|
|
43
42
|
accessKeyId,
|
|
44
43
|
type
|
|
@@ -29,7 +29,6 @@ exports.listApplications = listApplications;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const applicationWithEncodedStruct_1 = require("./utils/applicationWithEncodedStruct");
|
|
35
34
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
@@ -37,7 +36,7 @@ function listApplications(prisma) {
|
|
|
37
36
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
38
37
|
var _a;
|
|
39
38
|
const { pageSize, pageToken } = call.request;
|
|
40
|
-
const accessKeyId = (0,
|
|
39
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
41
40
|
logger.verbose("call to getApplication", {
|
|
42
41
|
accessKeyId,
|
|
43
42
|
pageSize,
|
|
@@ -29,18 +29,18 @@ exports.updateApplication = updateApplication;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
35
34
|
const convertToApplicationData_1 = require("./utils/convertToApplicationData");
|
|
36
35
|
const validOrThrow_1 = require("./utils/validOrThrow");
|
|
36
|
+
const identity_1 = require("@fonoster/identity");
|
|
37
37
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
38
38
|
function updateApplication(prisma) {
|
|
39
39
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
|
|
40
40
|
const fn = (call) => __awaiter(this, void 0, void 0, function* () {
|
|
41
41
|
const { request } = call;
|
|
42
42
|
const { type, ref: applicationRef } = request;
|
|
43
|
-
const accessKeyId = (0,
|
|
43
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
44
44
|
(0, validOrThrow_1.validOrThrow)(request);
|
|
45
45
|
logger.verbose("call to updateApplication", {
|
|
46
46
|
accessKeyId,
|
|
@@ -33,7 +33,7 @@ const createCall_1 = require("./createCall");
|
|
|
33
33
|
const createCallPublisher_1 = require("./createCallPublisher");
|
|
34
34
|
const getCall_1 = require("./getCall");
|
|
35
35
|
const listCalls_1 = require("./listCalls");
|
|
36
|
-
const
|
|
36
|
+
const createTrackCall_1 = require("./createTrackCall");
|
|
37
37
|
const db_1 = require("../core/db");
|
|
38
38
|
const envs_1 = require("../envs");
|
|
39
39
|
function buildService(influxdb) {
|
|
@@ -51,7 +51,7 @@ function buildService(influxdb) {
|
|
|
51
51
|
createCall: (0, createCall_1.createCall)(db_1.prisma, callPublisher),
|
|
52
52
|
listCalls: (0, listCalls_1.listCalls)(influxdb),
|
|
53
53
|
getCall: (0, getCall_1.getCall)(influxdb),
|
|
54
|
-
trackCall: (0,
|
|
54
|
+
trackCall: (0, createTrackCall_1.createTrackCall)(nc)
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
57
|
});
|
package/dist/calls/createCall.js
CHANGED
|
@@ -29,7 +29,6 @@ exports.createCall = createCall;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const uuid_1 = require("uuid");
|
|
35
34
|
const notFoundError_1 = require("../core/notFoundError");
|
|
@@ -40,7 +39,7 @@ function createCall(prisma, publisher) {
|
|
|
40
39
|
const { from, to, appRef, timeout } = request;
|
|
41
40
|
const ref = (0, uuid_1.v4)();
|
|
42
41
|
logger.verbose("call to createCall", Object.assign(Object.assign({}, request), { ref }));
|
|
43
|
-
const accessKeyId = (0,
|
|
42
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
44
43
|
const app = yield prisma.application.findUnique({
|
|
45
44
|
where: { ref: appRef, accessKeyId }
|
|
46
45
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NatsConnection } from "nats";
|
|
2
|
-
declare function
|
|
2
|
+
declare function createTrackCall(nc: NatsConnection): (call: {
|
|
3
3
|
request: unknown;
|
|
4
4
|
}, callback: (error?: import("@fonoster/common").GrpcErrorMessage, response?: unknown) => void) => Promise<void>;
|
|
5
|
-
export {
|
|
5
|
+
export { createTrackCall };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createTrackCall = createTrackCall;
|
|
4
4
|
/*
|
|
5
5
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
6
6
|
* http://github.com/fonoster/fonoster
|
|
@@ -28,7 +28,7 @@ const FINAL_STATUSES = [
|
|
|
28
28
|
common_1.DialStatus.NOANSWER
|
|
29
29
|
];
|
|
30
30
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
31
|
-
function
|
|
31
|
+
function createTrackCall(nc) {
|
|
32
32
|
const trackingCallsMap = new Map();
|
|
33
33
|
const subscription = nc.subscribe(envs_1.CALLS_TRACK_CALL_SUBJECT);
|
|
34
34
|
subscription.callback = (err, msg) => {
|
|
@@ -53,11 +53,11 @@ function makeTrackCall(nc) {
|
|
|
53
53
|
stream.write({ ref, status });
|
|
54
54
|
}
|
|
55
55
|
};
|
|
56
|
-
const
|
|
56
|
+
const trackCall = (call) => {
|
|
57
57
|
const stream = call;
|
|
58
58
|
const { ref } = call.request;
|
|
59
59
|
logger.verbose("call to trackCall", { ref });
|
|
60
60
|
trackingCallsMap.set(ref, stream);
|
|
61
61
|
};
|
|
62
|
-
return (0, common_1.withErrorHandlingAndValidation)(
|
|
62
|
+
return (0, common_1.withErrorHandlingAndValidation)(trackCall, common_1.Validators.baseApiObjectSchema);
|
|
63
63
|
}
|
package/dist/calls/getCall.js
CHANGED
|
@@ -29,7 +29,6 @@ exports.getCall = getCall;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const createFetchSingleCall_1 = require("./createFetchSingleCall");
|
|
35
34
|
const notFoundError_1 = require("../core/notFoundError");
|
|
@@ -38,7 +37,7 @@ function getCall(influx) {
|
|
|
38
37
|
const fetchSingleCall = (0, createFetchSingleCall_1.createFetchSingleCall)(influx);
|
|
39
38
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
40
39
|
const { ref } = call.request;
|
|
41
|
-
const accessKeyId = (0,
|
|
40
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
42
41
|
logger.verbose("call to getCall", { accessKeyId, ref });
|
|
43
42
|
const response = yield fetchSingleCall(accessKeyId, ref);
|
|
44
43
|
if (!response) {
|
package/dist/calls/listCalls.js
CHANGED
|
@@ -29,7 +29,6 @@ exports.listCalls = listCalls;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const createFetchCalls_1 = require("./createFetchCalls");
|
|
35
34
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
@@ -37,7 +36,7 @@ function listCalls(influx) {
|
|
|
37
36
|
const fetchCalls = (0, createFetchCalls_1.createFetchCalls)(influx);
|
|
38
37
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
39
38
|
const { request } = call;
|
|
40
|
-
const accessKeyId = (0,
|
|
39
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
41
40
|
logger.verbose("call to listCalls", { request, accessKeyId });
|
|
42
41
|
const result = yield fetchCalls(accessKeyId, request);
|
|
43
42
|
callback(null, result);
|
package/dist/core/httpBridge.js
CHANGED
|
@@ -46,7 +46,7 @@ function httpBridge(params) {
|
|
|
46
46
|
});
|
|
47
47
|
app.get("/api/identity/accept-invite", (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
48
48
|
try {
|
|
49
|
-
yield (0, identity_1.
|
|
49
|
+
yield (0, identity_1.createUpdateMembershipStatus)(identityConfig_1.identityConfig)(req.query.token);
|
|
50
50
|
res.redirect(envs_1.APP_URL);
|
|
51
51
|
}
|
|
52
52
|
catch (error) {
|
package/dist/core/runServices.js
CHANGED
|
@@ -64,7 +64,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
64
64
|
* limitations under the License.
|
|
65
65
|
*/
|
|
66
66
|
const common_1 = require("@fonoster/common");
|
|
67
|
-
const identity_1 = require("@fonoster/identity");
|
|
68
67
|
const logger_1 = require("@fonoster/logger");
|
|
69
68
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
70
69
|
const grpc_health_check_1 = require("grpc-health-check");
|
|
@@ -77,8 +76,8 @@ const envs_1 = require("../envs");
|
|
|
77
76
|
const connectToAri_1 = require("../voice/connectToAri");
|
|
78
77
|
const authz_1 = require("@fonoster/authz");
|
|
79
78
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
80
|
-
const authorization = (0,
|
|
81
|
-
const checkMethodAuthorized = (0, authz_1.
|
|
79
|
+
const authorization = (0, common_1.createAuthInterceptor)(envs_1.IDENTITY_PUBLIC_KEY, allowList_1.allowList);
|
|
80
|
+
const checkMethodAuthorized = (0, authz_1.createCheckMethodAuthorized)(`${envs_1.AUTHZ_SERVICE_HOST}:${envs_1.AUTHZ_SERVICE_PORT}`, envs_1.AUTHZ_SERVICE_METHODS);
|
|
82
81
|
function runServices() {
|
|
83
82
|
return __awaiter(this, void 0, void 0, function* () {
|
|
84
83
|
const healthImpl = new grpc_health_check_1.HealthImplementation(common_1.statusMap);
|
package/dist/core/services.js
CHANGED
|
@@ -36,7 +36,7 @@ const agentsService = (0, sipnet_1.buildAgentsService)(routrConfig_1.routrConfig
|
|
|
36
36
|
const domainsService = (0, sipnet_1.buildDomainsService)(routrConfig_1.routrConfig);
|
|
37
37
|
const credentialsService = (0, sipnet_1.buildCredentialsService)(routrConfig_1.routrConfig);
|
|
38
38
|
const trunksService = (0, sipnet_1.buildTrunksService)(routrConfig_1.routrConfig);
|
|
39
|
-
const numbersService = (0, sipnet_1.buildNumbersService)(routrConfig_1.routrConfig, (0, utils_1.
|
|
39
|
+
const numbersService = (0, sipnet_1.buildNumbersService)(routrConfig_1.routrConfig, (0, utils_1.createCheckNumberPreconditions)(db_1.prisma));
|
|
40
40
|
const aclsService = (0, sipnet_1.buildAclsService)(routrConfig_1.routrConfig);
|
|
41
41
|
const services = Promise.all([
|
|
42
42
|
applicationsService,
|
|
@@ -31,15 +31,17 @@ exports.createGetFnUtil = createGetFnUtil;
|
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const notFoundError_1 = require("../core/notFoundError");
|
|
33
33
|
function createGetFnUtil(prisma) {
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
return function getFnUtil(ref) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const response = yield prisma.secret.findUnique({
|
|
37
|
+
where: { ref }
|
|
38
|
+
});
|
|
39
|
+
if (!response) {
|
|
40
|
+
throw (0, notFoundError_1.notFoundError)(`Resource not found: ${ref}`);
|
|
41
|
+
}
|
|
42
|
+
return (0, common_1.datesMapper)(Object.assign(Object.assign({}, response), { extended: {
|
|
43
|
+
accessKeyId: response.accessKeyId
|
|
44
|
+
} }));
|
|
37
45
|
});
|
|
38
|
-
|
|
39
|
-
throw (0, notFoundError_1.notFoundError)(`Resource not found: ${ref}`);
|
|
40
|
-
}
|
|
41
|
-
return (0, common_1.datesMapper)(Object.assign(Object.assign({}, response), { extended: {
|
|
42
|
-
accessKeyId: response.accessKeyId
|
|
43
|
-
} }));
|
|
44
|
-
});
|
|
46
|
+
};
|
|
45
47
|
}
|
|
@@ -29,13 +29,12 @@ exports.createSecret = createSecret;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
35
34
|
function createSecret(prisma) {
|
|
36
35
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
37
36
|
const { name, secret } = call.request;
|
|
38
|
-
const accessKeyId = (0,
|
|
37
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
39
38
|
logger.verbose("call to createSecret", {
|
|
40
39
|
accessKeyId
|
|
41
40
|
});
|
|
@@ -29,14 +29,13 @@ exports.listSecrets = listSecrets;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
35
34
|
function listSecrets(prisma) {
|
|
36
35
|
const fn = (call, callback) => __awaiter(this, void 0, void 0, function* () {
|
|
37
36
|
var _a;
|
|
38
37
|
const { pageSize, pageToken } = call.request;
|
|
39
|
-
const accessKeyId = (0,
|
|
38
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
40
39
|
logger.verbose("call to getSecret", {
|
|
41
40
|
accessKeyId,
|
|
42
41
|
pageSize,
|
|
@@ -29,7 +29,6 @@ exports.updateSecret = updateSecret;
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
|
-
const identity_1 = require("@fonoster/identity");
|
|
33
32
|
const logger_1 = require("@fonoster/logger");
|
|
34
33
|
const createGetFnUtil_1 = require("./createGetFnUtil");
|
|
35
34
|
const withErrorHandlingAndValidationAndAccess_1 = require("../utils/withErrorHandlingAndValidationAndAccess");
|
|
@@ -38,7 +37,7 @@ function updateSecret(prisma) {
|
|
|
38
37
|
const getFn = (0, createGetFnUtil_1.createGetFnUtil)(prisma);
|
|
39
38
|
const fn = (call) => __awaiter(this, void 0, void 0, function* () {
|
|
40
39
|
const { name, secret } = call.request;
|
|
41
|
-
const accessKeyId = (0,
|
|
40
|
+
const accessKeyId = (0, common_1.getAccessKeyIdFromCall)(call);
|
|
42
41
|
logger.verbose("call to updateSecret", {
|
|
43
42
|
accessKeyId
|
|
44
43
|
});
|
|
@@ -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.createCheckNumberPreconditions = createCheckNumberPreconditions;
|
|
13
13
|
/*
|
|
14
14
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
15
15
|
* http://github.com/fonoster/fonoster
|
|
@@ -30,7 +30,7 @@ exports.makeCheckNumberPreconditions = makeCheckNumberPreconditions;
|
|
|
30
30
|
*/
|
|
31
31
|
const common_1 = require("@fonoster/common");
|
|
32
32
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
33
|
-
function
|
|
33
|
+
function createCheckNumberPreconditions(prisma) {
|
|
34
34
|
return function checkNumberPreconditions(_a) {
|
|
35
35
|
return __awaiter(this, arguments, void 0, function* ({ appRef, accessKeyId }) {
|
|
36
36
|
if (!appRef) {
|
|
@@ -9,14 +9,16 @@ 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.createHandleDialEventsWithNats = createHandleDialEventsWithNats;
|
|
13
13
|
const mapDialStatus_1 = require("./mapDialStatus");
|
|
14
14
|
const envs_1 = require("../envs");
|
|
15
|
-
function
|
|
16
|
-
return (callRef, event)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
function createHandleDialEventsWithNats(nc) {
|
|
16
|
+
return function handleDialEventsWithNats(callRef, event) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const mappedStatus = (0, mapDialStatus_1.mapDialStatus)(event.dialstatus);
|
|
19
|
+
if (!mappedStatus)
|
|
20
|
+
return; // Ignore the event if status is not mapped
|
|
21
|
+
nc.publish(envs_1.CALLS_TRACK_CALL_SUBJECT, JSON.stringify({ ref: callRef, status: mappedStatus }));
|
|
22
|
+
});
|
|
23
|
+
};
|
|
22
24
|
}
|
|
@@ -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.createHandleDialEventsWithVoiceClient = createHandleDialEventsWithVoiceClient;
|
|
13
13
|
/*
|
|
14
14
|
* Copyright (C) 2024 by Fonoster Inc (https://fonoster.com)
|
|
15
15
|
* http://github.com/fonoster/fonoster
|
|
@@ -29,15 +29,17 @@ exports.makeHandleDialEventsWithVoiceClient = makeHandleDialEventsWithVoiceClien
|
|
|
29
29
|
* limitations under the License.
|
|
30
30
|
*/
|
|
31
31
|
const mapDialStatus_1 = require("./mapDialStatus");
|
|
32
|
-
function
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
function createHandleDialEventsWithVoiceClient(voiceClient) {
|
|
33
|
+
return function handleDialEventsWithVoiceClient(event) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
const mappedStatus = (0, mapDialStatus_1.mapDialStatus)(event.dialstatus);
|
|
36
|
+
if (!mappedStatus)
|
|
37
|
+
return; // Ignore the event if status is not mapped
|
|
38
|
+
voiceClient.sendResponse({
|
|
39
|
+
dialResponse: {
|
|
40
|
+
status: mappedStatus
|
|
41
|
+
}
|
|
42
|
+
});
|
|
41
43
|
});
|
|
42
|
-
}
|
|
44
|
+
};
|
|
43
45
|
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./
|
|
2
|
-
export * from "./
|
|
3
|
-
export * from "./
|
|
1
|
+
export * from "./createCheckNumberPreconditions";
|
|
2
|
+
export * from "./createHandleDialEventsWithNats";
|
|
3
|
+
export * from "./createHandleDialEventsWithVoiceClient";
|
package/dist/utils/index.js
CHANGED
|
@@ -32,6 +32,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
* See the License for the specific language governing permissions and
|
|
33
33
|
* limitations under the License.
|
|
34
34
|
*/
|
|
35
|
-
__exportStar(require("./
|
|
36
|
-
__exportStar(require("./
|
|
37
|
-
__exportStar(require("./
|
|
35
|
+
__exportStar(require("./createCheckNumberPreconditions"), exports);
|
|
36
|
+
__exportStar(require("./createHandleDialEventsWithNats"), exports);
|
|
37
|
+
__exportStar(require("./createHandleDialEventsWithVoiceClient"), exports);
|
|
@@ -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 };
|