@fonoster/autopilot 0.5.4 → 0.7.0

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 (61) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +3 -0
  3. package/dist/Autopilot.d.ts +7 -0
  4. package/dist/Autopilot.js +58 -0
  5. package/dist/assistants/assistants.d.ts +4 -0
  6. package/dist/assistants/assistants.js +39 -0
  7. package/dist/assistants/examples.d.ts +10 -0
  8. package/dist/assistants/examples.js +96 -0
  9. package/dist/assistants/index.d.ts +2 -0
  10. package/dist/{file-retention → assistants}/index.js +7 -4
  11. package/dist/assistants/types.d.ts +13 -0
  12. package/dist/{events → assistants}/types.js +10 -12
  13. package/dist/demo.d.ts +1 -0
  14. package/dist/demo.js +57 -0
  15. package/dist/envs.d.ts +1 -4
  16. package/dist/envs.js +11 -8
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +4 -11
  19. package/dist/machine/index.d.ts +1 -0
  20. package/dist/machine/index.js +23 -0
  21. package/dist/machine/machine.d.ts +108 -0
  22. package/dist/machine/machine.js +111 -0
  23. package/dist/machine/types.d.ts +21 -0
  24. package/dist/machine/types.js +9 -0
  25. package/dist/types.d.ts +14 -41
  26. package/dist/types.js +0 -7
  27. package/package.json +29 -27
  28. package/dist/cerebro/cerebro.d.ts +0 -42
  29. package/dist/cerebro/cerebro.js +0 -266
  30. package/dist/cerebro/effects.d.ts +0 -11
  31. package/dist/cerebro/effects.js +0 -113
  32. package/dist/cerebro/helper.d.ts +0 -5
  33. package/dist/cerebro/helper.js +0 -43
  34. package/dist/cerebro/index.d.ts +0 -2
  35. package/dist/cerebro/index.js +0 -36
  36. package/dist/cerebro/types.d.ts +0 -40
  37. package/dist/cerebro/types.js +0 -9
  38. package/dist/events/emitter.d.ts +0 -7
  39. package/dist/events/emitter.js +0 -13
  40. package/dist/events/server.d.ts +0 -12
  41. package/dist/events/server.js +0 -67
  42. package/dist/events/types.d.ts +0 -20
  43. package/dist/file-retention/cron.d.ts +0 -2
  44. package/dist/file-retention/cron.js +0 -23
  45. package/dist/file-retention/index.d.ts +0 -1
  46. package/dist/file-retention/task.d.ts +0 -6
  47. package/dist/file-retention/task.js +0 -56
  48. package/dist/intents/df_utils.d.ts +0 -3
  49. package/dist/intents/df_utils.js +0 -39
  50. package/dist/intents/dialogflow_cx.d.ts +0 -43
  51. package/dist/intents/dialogflow_cx.js +0 -102
  52. package/dist/intents/dialogflow_es.d.ts +0 -15
  53. package/dist/intents/dialogflow_es.js +0 -166
  54. package/dist/intents/engines.d.ts +0 -3
  55. package/dist/intents/engines.js +0 -32
  56. package/dist/intents/types.d.ts +0 -25
  57. package/dist/intents/types.js +0 -2
  58. package/dist/pilot.d.ts +0 -3
  59. package/dist/pilot.js +0 -150
  60. package/dist/util.d.ts +0 -44
  61. package/dist/util.js +0 -105
@@ -1,15 +0,0 @@
1
- import * as dialogflow from "@google-cloud/dialogflow";
2
- import { IntentsEngine, Intent, DialogFlowESConfig } from "./types";
3
- export default class DialogFlow implements IntentsEngine {
4
- sessionClient: dialogflow.v2beta1.SessionsClient;
5
- sessionPath: string;
6
- config: DialogFlowESConfig;
7
- sessionId: string;
8
- projectId: string;
9
- constructor(config: DialogFlowESConfig);
10
- setProjectId(projectId: string): void;
11
- findIntentWithEvent(name: string, payload?: Record<string, unknown>): Promise<Intent>;
12
- findIntent(txt: string, payload?: Record<string, unknown>): Promise<Intent>;
13
- private detectItent;
14
- private getEffects;
15
- }
@@ -1,166 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- /* eslint-disable no-loops/no-loops */
27
- /* eslint-disable require-jsdoc */
28
- /*
29
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
30
- * http://github.com/fonoster/rox
31
- *
32
- * This file is part of Rox AI
33
- *
34
- * Licensed under the MIT License (the "License");
35
- * you may not use this file except in compliance with
36
- * the License. You may obtain a copy of the License at
37
- *
38
- * https://opensource.org/licenses/MIT
39
- *
40
- * Unless required by applicable law or agreed to in writing, software
41
- * distributed under the License is distributed on an "AS IS" BASIS,
42
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43
- * See the License for the specific language governing permissions and
44
- * limitations under the License.
45
- */
46
- const dialogflow = __importStar(require("@google-cloud/dialogflow"));
47
- const df_utils_1 = require("./df_utils");
48
- const pb_util_1 = require("pb-util");
49
- const logger_1 = require("@fonoster/logger");
50
- const uuid = require("uuid");
51
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
52
- class DialogFlow {
53
- sessionClient;
54
- sessionPath;
55
- config;
56
- sessionId;
57
- projectId;
58
- constructor(config) {
59
- this.sessionId = uuid.v4();
60
- this.config = config;
61
- this.projectId = config.projectId;
62
- // Create a new session
63
- this.sessionClient = new dialogflow.v2beta1.SessionsClient({
64
- credentials: config.credentials
65
- });
66
- logger.verbose("created new dialogflow/es session", {
67
- projectId: this.projectId,
68
- sessionId: this.sessionId
69
- });
70
- }
71
- setProjectId(projectId) {
72
- this.projectId = projectId;
73
- }
74
- async findIntentWithEvent(name, payload) {
75
- const request = {
76
- queryInput: {
77
- event: {
78
- name: name.toUpperCase(),
79
- languageCode: this.config.languageCode
80
- }
81
- }
82
- };
83
- return this.detectItent(request, payload);
84
- }
85
- async findIntent(txt, payload) {
86
- const request = {
87
- queryParams: {},
88
- queryInput: {
89
- text: {
90
- text: txt,
91
- languageCode: this.config.languageCode
92
- }
93
- }
94
- };
95
- return this.detectItent(request, payload);
96
- }
97
- async detectItent(request, payload) {
98
- const sessionPath = this.sessionClient.projectAgentSessionPath(this.projectId, this.sessionId);
99
- request.session = sessionPath;
100
- if (payload) {
101
- request.queryParams = {
102
- payload: pb_util_1.struct.encode(payload)
103
- };
104
- }
105
- const [response] = await this.sessionClient.detectIntent(request);
106
- logger.silly("got speech from api", { text: JSON.stringify(response) });
107
- if (!response.queryResult?.intent) {
108
- throw new Error("got unexpect null intent");
109
- }
110
- let effects = [];
111
- if (response.queryResult.fulfillmentMessages) {
112
- const messages = response.queryResult.fulfillmentMessages.filter((f) => f.platform === this.config.platform);
113
- effects = this.getEffects(messages);
114
- }
115
- else if (response.queryResult.fulfillmentText) {
116
- effects = [
117
- {
118
- type: "say",
119
- parameters: {
120
- response: response.queryResult.fulfillmentText
121
- }
122
- }
123
- ];
124
- }
125
- return {
126
- ref: response.queryResult.intent.displayName || "unknown",
127
- effects,
128
- confidence: response.queryResult.intentDetectionConfidence || 0
129
- };
130
- }
131
- getEffects(fulfillmentMessages) {
132
- const effects = [];
133
- for (const f of fulfillmentMessages) {
134
- if (f.payload) {
135
- effects.push((0, df_utils_1.transformPayloadToEffect)(f.payload));
136
- }
137
- else if (f.telephonySynthesizeSpeech) {
138
- effects.push({
139
- type: "say",
140
- parameters: {
141
- response: f.telephonySynthesizeSpeech.text ||
142
- f.telephonySynthesizeSpeech.ssml
143
- }
144
- });
145
- }
146
- else if (f.telephonyTransferCall) {
147
- effects.push({
148
- type: "transfer",
149
- parameters: {
150
- destination: f.telephonyTransferCall.phoneNumber
151
- }
152
- });
153
- }
154
- else if (f.text) {
155
- effects.push({
156
- type: "say",
157
- parameters: {
158
- response: f.text.text[0]
159
- }
160
- });
161
- }
162
- }
163
- return effects;
164
- }
165
- }
166
- exports.default = DialogFlow;
@@ -1,3 +0,0 @@
1
- import { App } from "@fonoster/apps";
2
- import { IntentsEngine } from "./types";
3
- export declare function getIntentsEngine(app: App): (credentials: Record<string, string>) => IntentsEngine;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getIntentsEngine = void 0;
7
- const dialogflow_cx_1 = __importDefault(require("./dialogflow_cx"));
8
- const dialogflow_es_1 = __importDefault(require("./dialogflow_es"));
9
- function getIntentsEngine(app) {
10
- return function getEngine(credentials) {
11
- const platform = app.intentsEngineConfig.emulateTelephonyPlatform
12
- ? "TELEPHONY"
13
- : "PLATFORM_UNSPECIFIED";
14
- if ("location" in app.intentsEngineConfig) {
15
- return new dialogflow_cx_1.default({
16
- credentials,
17
- projectId: app.intentsEngineConfig.projectId,
18
- agent: app.intentsEngineConfig.agent,
19
- location: app.intentsEngineConfig.location,
20
- platform,
21
- languageCode: "en-US"
22
- });
23
- }
24
- return new dialogflow_es_1.default({
25
- credentials,
26
- projectId: app.intentsEngineConfig.projectId,
27
- platform,
28
- languageCode: "en-US"
29
- });
30
- };
31
- }
32
- exports.getIntentsEngine = getIntentsEngine;
@@ -1,25 +0,0 @@
1
- import { Effect } from "../cerebro/types";
2
- export interface Intent {
3
- ref: string;
4
- effects: Effect[];
5
- confidence: number;
6
- }
7
- export interface IntentsEngine {
8
- setProjectId: (id: string) => void;
9
- findIntent: (text: string, payload?: Record<string, unknown>) => Promise<Intent>;
10
- findIntentWithEvent?: (name: string, payload?: Record<string, unknown>) => Promise<Intent>;
11
- }
12
- export interface DialogFlowESConfig {
13
- projectId: string;
14
- languageCode: string;
15
- platform: string;
16
- credentials: Record<string, string>;
17
- }
18
- export interface DialogFlowCXConfig {
19
- projectId: string;
20
- languageCode: string;
21
- location: string;
22
- agent: string;
23
- platform: string;
24
- credentials: Record<string, string>;
25
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/dist/pilot.d.ts DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import { ServerConfig } from "./types";
3
- export default function pilot(config: ServerConfig): void;
package/dist/pilot.js DELETED
@@ -1,150 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- /* eslint-disable require-jsdoc */
8
- /*
9
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
10
- * http://github.com/fonoster/rox
11
- *
12
- * This file is part of Rox AI
13
- *
14
- * Licensed under the MIT License (the "License");
15
- * you may not use this file except in compliance with
16
- * the License. You may obtain a copy of the License at
17
- *
18
- * https://opensource.org/licenses/MIT
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
- const types_1 = require("./events/types");
27
- const voice_1 = require("@fonoster/voice");
28
- const cerebro_1 = require("./cerebro");
29
- const server_1 = require("./events/server");
30
- const engines_1 = require("./intents/engines");
31
- const util_1 = require("./util");
32
- const googleasr_1 = __importDefault(require("@fonoster/googleasr"));
33
- const logger_1 = require("@fonoster/logger");
34
- const apps_1 = __importDefault(require("@fonoster/apps"));
35
- const secrets_1 = __importDefault(require("@fonoster/secrets"));
36
- const envs_1 = require("./envs");
37
- const logger = (0, logger_1.getLogger)({ service: "autopilot", filePath: __filename });
38
- function pilot(config) {
39
- logger.info("starting autopilot");
40
- const voiceServer = new voice_1.VoiceServer({
41
- port: config.port
42
- });
43
- if (config.eventsServerEnabled)
44
- server_1.eventsServer.start();
45
- logger.verbose("events server enabled = " + config.eventsServerEnabled);
46
- voiceServer.listen(async (voiceRequest, voiceResponse) => {
47
- logger.verbose(`new request [sessionId: ${voiceRequest.sessionId}]`, {
48
- voiceRequest
49
- });
50
- try {
51
- if (!voiceRequest.appRef)
52
- throw new Error("invalid voice request: missing appRef");
53
- // If set, we overwrite the configuration with the values obtain from the webhook
54
- const serviceCredentials = {
55
- accessKeyId: voiceRequest.accessKeyId,
56
- accessKeySecret: voiceRequest.sessionToken
57
- };
58
- const apps = new apps_1.default(serviceCredentials);
59
- const secrets = new secrets_1.default(serviceCredentials);
60
- const app = await apps.getApp(voiceRequest.appRef);
61
- logger.verbose("requested app", { app, ref: app.ref });
62
- const ieSecret = await secrets.getSecret(app.intentsEngineConfig.secretName);
63
- const intentsEngine = (0, engines_1.getIntentsEngine)(app)(JSON.parse(ieSecret.secret));
64
- intentsEngine?.setProjectId(app.intentsEngineConfig.projectId);
65
- const speechSecret = await secrets.getSecret(app.speechConfig.secretName);
66
- const speechCredentials = {
67
- private_key: JSON.parse(speechSecret.secret).private_key,
68
- client_email: JSON.parse(speechSecret.secret).client_email
69
- };
70
- const voiceConfig = (0, util_1.getVoiceConfig)({
71
- secretString: speechSecret.secret,
72
- app,
73
- config
74
- });
75
- logger.verbose("voice config", { voiceConfig });
76
- const ttsPlugin = (0, util_1.getTTSPlugin)({
77
- languageCode: voiceConfig.languageCode,
78
- vendor: voiceConfig.vendor,
79
- secretString: speechSecret.secret,
80
- path: config.fileRetentionPolicyDirectory
81
- });
82
- voiceResponse.use(ttsPlugin);
83
- voiceResponse.use(new googleasr_1.default({
84
- credentials: speechCredentials,
85
- languageCode: config.defaultLanguageCode
86
- }));
87
- await voiceResponse.answer();
88
- const eventsClient = app.enableEvents && config.eventsServerEnabled
89
- ? server_1.eventsServer.getConnection(voiceRequest.callerNumber)
90
- : null;
91
- (0, util_1.sendClientEvent)(eventsClient, {
92
- eventName: types_1.CLIENT_EVENTS.ANSWERED
93
- });
94
- if (app.initialDtmf) {
95
- await voiceResponse.dtmf({ dtmf: app.initialDtmf });
96
- }
97
- if (app.intentsEngineConfig.welcomeIntentId &&
98
- intentsEngine.findIntentWithEvent) {
99
- const response = await intentsEngine.findIntentWithEvent(
100
- // TODO: This should be renamed to welcomeEventId
101
- app.intentsEngineConfig.welcomeIntentId, {
102
- telephony: {
103
- caller_id: voiceRequest.callerNumber
104
- }
105
- });
106
- if (response.effects.length > 0) {
107
- // eslint-disable-next-line no-loops/no-loops
108
- for await (const effect of response.effects) {
109
- if (effect.type === "say") {
110
- await voiceResponse.say(effect.parameters["response"], voiceConfig);
111
- }
112
- }
113
- }
114
- else {
115
- logger.warn("no effects found for welcome event", {
116
- eventId: app.intentsEngineConfig.welcomeIntentId
117
- });
118
- }
119
- }
120
- const transfer = app.transferConfig;
121
- transfer.messageNoAnswer = transfer.messageBusy =
122
- transfer.messageBusy || envs_1.APISERVER_AUTOPILOT_MEDIA_BUSY_MESSAGE;
123
- transfer.messageNoAnswer =
124
- transfer.messageNoAnswer ||
125
- envs_1.APISERVER_AUTOPILOT_MEDIA_NOANSWER_MESSAGE;
126
- const cerebro = new cerebro_1.Cerebro({
127
- voiceRequest,
128
- voiceResponse,
129
- eventsClient,
130
- voiceConfig,
131
- intentsEngine,
132
- activationIntentId: app.activationIntentId,
133
- activationTimeout: app.activationTimeout,
134
- transfer: app.transferConfig,
135
- alternativeLanguageCode: app.speechConfig.languageCode
136
- });
137
- // Open for bussiness
138
- await cerebro.wake();
139
- }
140
- catch (e) {
141
- (0, logger_1.ulogger)({
142
- accessKeyId: voiceRequest.accessKeyId,
143
- eventType: logger_1.ULogType.APP,
144
- level: "error",
145
- message: e.message
146
- });
147
- }
148
- });
149
- }
150
- exports.default = pilot;
package/dist/util.d.ts DELETED
@@ -1,44 +0,0 @@
1
- import GoogleTTS from "@fonoster/googletts";
2
- import PollyTTS from "@fonoster/pollytts";
3
- import AzureTTS from "@fonoster/azuretts";
4
- import { EventsClient } from "./events/emitter";
5
- import { ClientEvent } from "./events/types";
6
- import { TTSVendor } from "./types";
7
- export declare const getEnvOrDefault: (envName: string, def: number) => number;
8
- export declare const getEnvOrBool: (envName: string) => boolean;
9
- export declare const removeEmpty: (obj: any) => {};
10
- export declare const sendClientEvent: (eventsClient: EventsClient | null, event: ClientEvent) => void;
11
- export declare const getTTSPlugin: (params: {
12
- languageCode: string;
13
- vendor: TTSVendor;
14
- path: string;
15
- secretString: string;
16
- }) => PollyTTS | AzureTTS | GoogleTTS;
17
- export declare const getVoiceConfig: (params: {
18
- secretString: string;
19
- app: {
20
- speechConfig: {
21
- voice: string;
22
- languageCode: string;
23
- };
24
- };
25
- config: {
26
- defaultLanguageCode: string;
27
- };
28
- }) => {
29
- voice: string;
30
- languageCode: string;
31
- region: string;
32
- vendor: TTSVendor;
33
- cachingFields: string[];
34
- playbackId: string;
35
- name?: undefined;
36
- } | {
37
- name: string;
38
- languageCode: string;
39
- cachingFields: string[];
40
- playbackId: string;
41
- vendor: TTSVendor;
42
- voice?: undefined;
43
- region?: undefined;
44
- };
package/dist/util.js DELETED
@@ -1,105 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getVoiceConfig = exports.getTTSPlugin = exports.sendClientEvent = exports.removeEmpty = exports.getEnvOrBool = exports.getEnvOrDefault = void 0;
7
- /*
8
- * Copyright (C) 2023 by Fonoster Inc (https://fonoster.com)
9
- * http://github.com/fonoster/rox
10
- *
11
- * This file is part of Rox AI
12
- *
13
- * Licensed under the MIT License (the "License")
14
- * you may not use this file except in compliance with
15
- * the License. You may obtain a copy of the License at
16
- *
17
- * https://opensource.org/licenses/MIT
18
- *
19
- * Unless required by applicable law or agreed to in writing, software
20
- * distributed under the License is distributed on an "AS IS" BASIS,
21
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
- * See the License for the specific language governing permissions and
23
- * limitations under the License.
24
- */
25
- const googletts_1 = __importDefault(require("@fonoster/googletts"));
26
- const pollytts_1 = __importDefault(require("@fonoster/pollytts"));
27
- const azuretts_1 = __importDefault(require("@fonoster/azuretts"));
28
- const types_1 = require("./types");
29
- const nanoid_1 = require("nanoid");
30
- const getEnvOrDefault = (envName, def) => process.env[envName] ? parseInt(process.env[envName] || "") : def;
31
- exports.getEnvOrDefault = getEnvOrDefault;
32
- const getEnvOrBool = (envName) => process.env[envName]
33
- ? (process.env[envName] || "false").toLowerCase() === "true"
34
- : false;
35
- exports.getEnvOrBool = getEnvOrBool;
36
- const removeEmpty = (obj) => {
37
- const newObj = {};
38
- Object.keys(obj).forEach((key) => {
39
- if (obj[key] === Object(obj[key]))
40
- newObj[key] = (0, exports.removeEmpty)(obj[key]);
41
- else if (obj[key] !== undefined)
42
- newObj[key] = obj[key];
43
- });
44
- return newObj;
45
- };
46
- exports.removeEmpty = removeEmpty;
47
- const sendClientEvent = (eventsClient, event) => {
48
- if (eventsClient) {
49
- eventsClient.send(event);
50
- }
51
- };
52
- exports.sendClientEvent = sendClientEvent;
53
- const getTTSPlugin = (params) => {
54
- const { path, languageCode, vendor, secretString } = params;
55
- if (vendor === types_1.TTSVendor.AMAZON) {
56
- const config = JSON.parse(secretString);
57
- return new pollytts_1.default({
58
- accessKeyId: config.tts?.credentials?.accessKeyId,
59
- secretAccessKey: config.tts?.credentials?.secretAccessKey,
60
- path
61
- });
62
- }
63
- if (vendor === types_1.TTSVendor.MICROSOFT) {
64
- const config = JSON.parse(secretString);
65
- return new azuretts_1.default({
66
- subscriptionKey: config.tts?.subscriptionKey,
67
- serviceRegion: config.tts?.serviceRegion,
68
- path
69
- });
70
- }
71
- // Default to Google
72
- const credentials = JSON.parse(secretString);
73
- return new googletts_1.default({
74
- credentials: {
75
- privateKey: credentials.private_key,
76
- clientEmail: credentials.client_email
77
- },
78
- languageCode,
79
- path
80
- });
81
- };
82
- exports.getTTSPlugin = getTTSPlugin;
83
- const getVoiceConfig = (params) => {
84
- const { secretString, app } = params;
85
- const speechSecret = JSON.parse(secretString);
86
- if ("tts" in speechSecret) {
87
- const ttsConfig = speechSecret.tts;
88
- return {
89
- voice: ttsConfig.voice,
90
- languageCode: ttsConfig.languageCode,
91
- region: ttsConfig.region,
92
- vendor: ttsConfig.vendor,
93
- cachingFields: ttsConfig.cachingFields,
94
- playbackId: (0, nanoid_1.nanoid)()
95
- };
96
- }
97
- return {
98
- name: app.speechConfig.voice,
99
- languageCode: app.speechConfig.languageCode || params.config.defaultLanguageCode,
100
- cachingFields: ["name"],
101
- playbackId: (0, nanoid_1.nanoid)(),
102
- vendor: types_1.TTSVendor.GOOGLE
103
- };
104
- };
105
- exports.getVoiceConfig = getVoiceConfig;