@fonoster/apiserver 0.7.16 → 0.7.22
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.
|
@@ -67,6 +67,7 @@ function createCreateCallSubscriber(config) {
|
|
|
67
67
|
"PJSIP_HEADER(add,X-Dod-Number)": from,
|
|
68
68
|
"PJSIP_HEADER(add,X-Access-Key-Id)": accessKeyId,
|
|
69
69
|
"PJSIP_HEADER(add,X-Is-Api-Originated-Type)": "true",
|
|
70
|
+
CALL_DIRECTION: "peer-to-pstn",
|
|
70
71
|
INGRESS_NUMBER: from,
|
|
71
72
|
APP_REF: appRef
|
|
72
73
|
}
|
|
@@ -14,12 +14,15 @@ const withErrorHandling_1 = require("./utils/withErrorHandling");
|
|
|
14
14
|
function hangupHandler(ari, voiceClient) {
|
|
15
15
|
return (0, withErrorHandling_1.withErrorHandling)((request) => __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
const { sessionRef } = request;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
// Give some time for the last sound to play
|
|
18
|
+
setTimeout(() => {
|
|
19
|
+
ari.channels.hangup({ channelId: sessionRef });
|
|
20
|
+
voiceClient.sendResponse({
|
|
21
|
+
hangupResponse: {
|
|
22
|
+
sessionRef
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
voiceClient.close();
|
|
26
|
+
}, 2000);
|
|
24
27
|
}));
|
|
25
28
|
}
|
|
@@ -34,22 +34,24 @@ const makeGetChannelVar_1 = require("./makeGetChannelVar");
|
|
|
34
34
|
const types_1 = require("./types");
|
|
35
35
|
const VoiceClientImpl_1 = require("./VoiceClientImpl");
|
|
36
36
|
const identityConfig_1 = require("../core/identityConfig");
|
|
37
|
+
const mapCallDirectionToEnum_1 = require("../events/mapCallDirectionToEnum");
|
|
37
38
|
const logger = (0, logger_1.getLogger)({ service: "apiserver", filePath: __filename });
|
|
38
39
|
const createToken = (0, identity_1.createCallAccessToken)(identityConfig_1.identityConfig);
|
|
39
40
|
// Note: By the time the call arrives here the owner of the app MUST be authenticated
|
|
40
41
|
function makeCreateVoiceClient(createContainer) {
|
|
41
42
|
return (params) => __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
var _a, _b, _c;
|
|
43
|
+
var _a, _b, _c, _d;
|
|
43
44
|
const { ari, event, channel } = params;
|
|
44
45
|
const { id: sessionRef, caller } = event.channel;
|
|
45
46
|
const { name: callerName, number: callerNumber } = caller;
|
|
46
47
|
const getChannelVar = (0, makeGetChannelVar_1.makeGetChannelVarWithoutThrow)(channel);
|
|
47
48
|
// Variables set by Asterisk's dialplan
|
|
48
|
-
const
|
|
49
|
-
const
|
|
49
|
+
const callDirection = (_a = (yield getChannelVar(types_1.ChannelVar.CALL_DIRECTION))) === null || _a === void 0 ? void 0 : _a.value;
|
|
50
|
+
const appRef = (_b = (yield getChannelVar(types_1.ChannelVar.APP_REF))) === null || _b === void 0 ? void 0 : _b.value;
|
|
51
|
+
const ingressNumber = ((_c = (yield getChannelVar(types_1.ChannelVar.INGRESS_NUMBER))) === null || _c === void 0 ? void 0 : _c.value) || "";
|
|
50
52
|
const { accessKeyId, endpoint, tts, stt } = yield createContainer(appRef);
|
|
51
53
|
const sessionToken = yield createToken({ accessKeyId, appRef });
|
|
52
|
-
const metadataStr = (
|
|
54
|
+
const metadataStr = (_d = (yield getChannelVar(types_1.ChannelVar.METADATA))) === null || _d === void 0 ? void 0 : _d.value;
|
|
53
55
|
const config = {
|
|
54
56
|
appRef,
|
|
55
57
|
sessionRef,
|
|
@@ -59,6 +61,7 @@ function makeCreateVoiceClient(createContainer) {
|
|
|
59
61
|
callerNumber,
|
|
60
62
|
ingressNumber,
|
|
61
63
|
sessionToken,
|
|
64
|
+
callDirection: (0, mapCallDirectionToEnum_1.mapCallDirectionToEnum)(callDirection),
|
|
62
65
|
metadata: metadataStr ? JSON.parse(metadataStr) : {}
|
|
63
66
|
};
|
|
64
67
|
logger.verbose("creating voice client with config: ", {
|
|
@@ -79,7 +79,8 @@ class ElevenLabs extends AbstractTextToSpeech_1.AbstractTextToSpeech {
|
|
|
79
79
|
if (this.fileExists(this.getFullPathToFile(filename))) {
|
|
80
80
|
return this.getFilenameWithoutExtension(filename);
|
|
81
81
|
}
|
|
82
|
-
const
|
|
82
|
+
const audioStream = yield this.client.generate({
|
|
83
|
+
stream: true,
|
|
83
84
|
voice,
|
|
84
85
|
text,
|
|
85
86
|
// TODO: This should be configurable
|
|
@@ -90,7 +91,7 @@ class ElevenLabs extends AbstractTextToSpeech_1.AbstractTextToSpeech {
|
|
|
90
91
|
encoding: "binary"
|
|
91
92
|
});
|
|
92
93
|
yield new Promise((resolve, reject) => {
|
|
93
|
-
|
|
94
|
+
audioStream.pipe(writable);
|
|
94
95
|
writable.on("finish", resolve);
|
|
95
96
|
writable.on("error", reject);
|
|
96
97
|
});
|
|
@@ -12,11 +12,11 @@ declare enum AriEvent {
|
|
|
12
12
|
DIAL = "Dial"
|
|
13
13
|
}
|
|
14
14
|
declare enum ChannelVar {
|
|
15
|
+
CALL_DIRECTION = "CALL_DIRECTION",
|
|
15
16
|
INGRESS_NUMBER = "INGRESS_NUMBER",
|
|
16
17
|
APP_REF = "APP_REF",
|
|
17
18
|
APP_ENDPOINT = "APP_ENDPOINT",
|
|
18
19
|
METADATA = "METADATA",
|
|
19
|
-
CURRENT_BRIDGE = "CURRENT_BRIDGE",
|
|
20
20
|
FROM_EXTERNAL_MEDIA = "FROM_EXTERNAL_MEDIA"
|
|
21
21
|
}
|
|
22
22
|
export { AriEvent, ChannelVar };
|
package/dist/voice/types/ari.js
CHANGED
|
@@ -35,10 +35,10 @@ var AriEvent;
|
|
|
35
35
|
})(AriEvent || (exports.AriEvent = AriEvent = {}));
|
|
36
36
|
var ChannelVar;
|
|
37
37
|
(function (ChannelVar) {
|
|
38
|
+
ChannelVar["CALL_DIRECTION"] = "CALL_DIRECTION";
|
|
38
39
|
ChannelVar["INGRESS_NUMBER"] = "INGRESS_NUMBER";
|
|
39
40
|
ChannelVar["APP_REF"] = "APP_REF";
|
|
40
41
|
ChannelVar["APP_ENDPOINT"] = "APP_ENDPOINT";
|
|
41
42
|
ChannelVar["METADATA"] = "METADATA";
|
|
42
|
-
ChannelVar["CURRENT_BRIDGE"] = "CURRENT_BRIDGE";
|
|
43
43
|
ChannelVar["FROM_EXTERNAL_MEDIA"] = "FROM_EXTERNAL_MEDIA";
|
|
44
44
|
})(ChannelVar || (exports.ChannelVar = ChannelVar = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/apiserver",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.22",
|
|
4
4
|
"description": "APIServer for Fonoster",
|
|
5
5
|
"author": "Pedro Sanders <psanders@fonoster.com>",
|
|
6
6
|
"homepage": "https://github.com/fonoster/fonoster#readme",
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@deepgram/sdk": "^3.5.1",
|
|
24
|
-
"@fonoster/common": "^0.7.
|
|
25
|
-
"@fonoster/identity": "^0.7.
|
|
26
|
-
"@fonoster/logger": "^0.7.
|
|
27
|
-
"@fonoster/sipnet": "^0.7.
|
|
28
|
-
"@fonoster/streams": "^0.7.
|
|
29
|
-
"@fonoster/types": "^0.7.
|
|
24
|
+
"@fonoster/common": "^0.7.22",
|
|
25
|
+
"@fonoster/identity": "^0.7.22",
|
|
26
|
+
"@fonoster/logger": "^0.7.22",
|
|
27
|
+
"@fonoster/sipnet": "^0.7.22",
|
|
28
|
+
"@fonoster/streams": "^0.7.22",
|
|
29
|
+
"@fonoster/types": "^0.7.22",
|
|
30
30
|
"@google-cloud/speech": "^6.6.0",
|
|
31
31
|
"@google-cloud/text-to-speech": "^5.3.0",
|
|
32
32
|
"@grpc/grpc-js": "~1.10.6",
|
|
@@ -72,5 +72,5 @@
|
|
|
72
72
|
"@types/uuid": "^9.0.8",
|
|
73
73
|
"@types/validator": "^13.12.0"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "3755f19ef8a8b7f584f6f27e3dc5c277d63f1a19"
|
|
76
76
|
}
|