@fonoster/autopilot 0.4.18 → 0.4.20
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/package.json +8 -8
- package/dist/voice.d.ts +0 -3
- package/dist/voice.js +0 -154
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fonoster/autopilot",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.20",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index",
|
|
6
6
|
"types": "dist/index",
|
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
"build": "tsc --build ./tsconfig.json"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@fonoster/apps": "^0.4.
|
|
16
|
-
"@fonoster/googleasr": "^0.4.
|
|
17
|
-
"@fonoster/googletts": "^0.4.
|
|
18
|
-
"@fonoster/logger": "^0.4.
|
|
19
|
-
"@fonoster/secrets": "^0.4.
|
|
20
|
-
"@fonoster/voice": "^0.4.
|
|
15
|
+
"@fonoster/apps": "^0.4.20",
|
|
16
|
+
"@fonoster/googleasr": "^0.4.20",
|
|
17
|
+
"@fonoster/googletts": "^0.4.20",
|
|
18
|
+
"@fonoster/logger": "^0.4.20",
|
|
19
|
+
"@fonoster/secrets": "^0.4.20",
|
|
20
|
+
"@fonoster/voice": "^0.4.20",
|
|
21
21
|
"@google-cloud/dialogflow": "^4.3.1",
|
|
22
22
|
"@google-cloud/dialogflow-cx": "^2.13.0",
|
|
23
23
|
"date-fns": "^2.29.3",
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"publishConfig": {
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "ed0b5cf9d2b5a0e01eb0ce163ff1fccbc86b8778"
|
|
41
41
|
}
|
package/dist/voice.d.ts
DELETED
package/dist/voice.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
-
}) : function(o, v) {
|
|
17
|
-
o["default"] = v;
|
|
18
|
-
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
20
|
-
if (mod && mod.__esModule) return mod;
|
|
21
|
-
var result = {};
|
|
22
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
23
|
-
__setModuleDefault(result, mod);
|
|
24
|
-
return result;
|
|
25
|
-
};
|
|
26
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
27
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
28
|
-
};
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.voice = void 0;
|
|
31
|
-
/* eslint-disable require-jsdoc */
|
|
32
|
-
/*
|
|
33
|
-
* Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
|
|
34
|
-
* http://github.com/fonoster/rox
|
|
35
|
-
*
|
|
36
|
-
* This file is part of Rox AI
|
|
37
|
-
*
|
|
38
|
-
* Licensed under the MIT License (the "License");
|
|
39
|
-
* you may not use this file except in compliance with
|
|
40
|
-
* the License. You may obtain a copy of the License at
|
|
41
|
-
*
|
|
42
|
-
* https://opensource.org/licenses/MIT
|
|
43
|
-
*
|
|
44
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
45
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
46
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
47
|
-
* See the License for the specific language governing permissions and
|
|
48
|
-
* limitations under the License.
|
|
49
|
-
*/
|
|
50
|
-
const types_1 = require("./events/types");
|
|
51
|
-
const voice_1 = require("@fonoster/voice");
|
|
52
|
-
const cerebro_1 = require("./cerebro");
|
|
53
|
-
const server_1 = require("./events/server");
|
|
54
|
-
const nanoid_1 = require("nanoid");
|
|
55
|
-
const engines_1 = require("./intents/engines");
|
|
56
|
-
const util_1 = require("./util");
|
|
57
|
-
const logger_1 = __importStar(require("@fonoster/logger"));
|
|
58
|
-
const apps_1 = __importDefault(require("@fonoster/apps"));
|
|
59
|
-
const secrets_1 = __importDefault(require("@fonoster/secrets"));
|
|
60
|
-
const googletts_1 = __importDefault(require("@fonoster/googletts"));
|
|
61
|
-
const googleasr_1 = __importDefault(require("@fonoster/googleasr"));
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
63
|
-
const { version } = require("../../lerna.json");
|
|
64
|
-
function voice(config) {
|
|
65
|
-
logger_1.default.info(`autopilot v${version}`);
|
|
66
|
-
const voiceServer = new voice_1.VoiceServer({});
|
|
67
|
-
if (config.eventsServerEnabled)
|
|
68
|
-
server_1.eventsServer.start();
|
|
69
|
-
logger_1.default.verbose("events server enabled = " + config.eventsServerEnabled);
|
|
70
|
-
voiceServer.listen(async (voiceRequest, voiceResponse) => {
|
|
71
|
-
logger_1.default.verbose(`new request [sessionId: ${voiceRequest.sessionId}]`, {
|
|
72
|
-
voiceRequest
|
|
73
|
-
});
|
|
74
|
-
try {
|
|
75
|
-
if (!voiceRequest.appRef)
|
|
76
|
-
throw new Error("invalid voice request: missing appRef");
|
|
77
|
-
// If set, we overwrite the configuration with the values obtain from the webhook
|
|
78
|
-
const serviceCredentials = {
|
|
79
|
-
accessKeyId: voiceRequest.accessKeyId,
|
|
80
|
-
accessKeySecret: voiceRequest.sessionToken
|
|
81
|
-
};
|
|
82
|
-
const apps = new apps_1.default(serviceCredentials);
|
|
83
|
-
const secrets = new secrets_1.default(serviceCredentials);
|
|
84
|
-
const app = await apps.getApp(voiceRequest.appRef);
|
|
85
|
-
logger_1.default.verbose(`requested app [ref: ${app.ref}]`, { app });
|
|
86
|
-
const ieSecret = await secrets.getSecret(app.intentsEngineConfig.secretName);
|
|
87
|
-
const intentsEngine = (0, engines_1.getIntentsEngine)(app)(JSON.parse(ieSecret.secret));
|
|
88
|
-
intentsEngine?.setProjectId(app.intentsEngineConfig.projectId);
|
|
89
|
-
const voiceConfig = {
|
|
90
|
-
name: app.speechConfig.voice,
|
|
91
|
-
playbackId: (0, nanoid_1.nanoid)()
|
|
92
|
-
};
|
|
93
|
-
const speechSecret = await secrets.getSecret(app.speechConfig.secretName);
|
|
94
|
-
const speechCredentials = {
|
|
95
|
-
private_key: JSON.parse(speechSecret.secret).private_key,
|
|
96
|
-
client_email: JSON.parse(speechSecret.secret).client_email
|
|
97
|
-
};
|
|
98
|
-
voiceResponse.use(new googletts_1.default({
|
|
99
|
-
credentials: speechCredentials,
|
|
100
|
-
languageCode: config.defaultLanguageCode,
|
|
101
|
-
path: config.fileRetentionPolicyDirectory
|
|
102
|
-
}));
|
|
103
|
-
voiceResponse.use(new googleasr_1.default({
|
|
104
|
-
credentials: speechCredentials,
|
|
105
|
-
languageCode: config.defaultLanguageCode
|
|
106
|
-
}));
|
|
107
|
-
await voiceResponse.answer();
|
|
108
|
-
const eventsClient = app.enableEvents && config.eventsServerEnabled
|
|
109
|
-
? server_1.eventsServer.getConnection(voiceRequest.callerNumber)
|
|
110
|
-
: null;
|
|
111
|
-
(0, util_1.sendClientEvent)(eventsClient, {
|
|
112
|
-
eventName: types_1.CLIENT_EVENTS.ANSWERED
|
|
113
|
-
});
|
|
114
|
-
if (app.initialDtmf)
|
|
115
|
-
await voiceResponse.dtmf({ dtmf: app.initialDtmf });
|
|
116
|
-
if (app.intentsEngineConfig.welcomeIntentId &&
|
|
117
|
-
intentsEngine.findIntentWithEvent) {
|
|
118
|
-
const response = await intentsEngine.findIntentWithEvent(app.intentsEngineConfig.welcomeIntentId, {
|
|
119
|
-
telephony: {
|
|
120
|
-
caller_id: voiceRequest.callerNumber
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
if (response.effects.length > 0) {
|
|
124
|
-
await voiceResponse.say(response.effects[0].parameters["response"], voiceConfig);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
logger_1.default.warn(`no effects found for welcome intent: trigger '${app.intentsEngineConfig.welcomeIntentId}'`);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
const cerebro = new cerebro_1.Cerebro({
|
|
131
|
-
voiceRequest,
|
|
132
|
-
voiceResponse,
|
|
133
|
-
eventsClient,
|
|
134
|
-
voiceConfig,
|
|
135
|
-
intentsEngine,
|
|
136
|
-
activationIntentId: app.activationIntentId,
|
|
137
|
-
activationTimeout: app.activationTimeout,
|
|
138
|
-
transfer: app.transferConfig,
|
|
139
|
-
alternativeLanguageCode: app.speechConfig.languageCode
|
|
140
|
-
});
|
|
141
|
-
// Open for bussiness
|
|
142
|
-
await cerebro.wake();
|
|
143
|
-
}
|
|
144
|
-
catch (e) {
|
|
145
|
-
(0, logger_1.ulogger)({
|
|
146
|
-
accessKeyId: voiceRequest.accessKeyId,
|
|
147
|
-
eventType: logger_1.ULogType.APP,
|
|
148
|
-
level: "error",
|
|
149
|
-
message: e.message
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
}
|
|
154
|
-
exports.voice = voice;
|