Node.js 使用多语音库在Dialogflow for VUI中配置重复意图
我正在尝试将我的VUI配置为在Dialogflow出现提示时在Dialogflow中重复一句话。小背景故事,我正在帮助开发一个老年人社交机器人,所以重复一句话是一个非常需要的功能。我刚刚开始这个项目,之前负责这个项目的开发人员已经不在了,也无法联系到,而且,我在Node.js方面没有任何经验 我期待着使用这个。到目前为止,我已经完成了以下步骤:Node.js 使用多语音库在Dialogflow for VUI中配置重复意图,node.js,dialogflow-es,actions-on-google,dialogflow-es-fulfillment,packages.json,Node.js,Dialogflow Es,Actions On Google,Dialogflow Es Fulfillment,Packages.json,我正在尝试将我的VUI配置为在Dialogflow出现提示时在Dialogflow中重复一句话。小背景故事,我正在帮助开发一个老年人社交机器人,所以重复一句话是一个非常需要的功能。我刚刚开始这个项目,之前负责这个项目的开发人员已经不在了,也无法联系到,而且,我在Node.js方面没有任何经验 我期待着使用这个。到目前为止,我已经完成了以下步骤: 创建了一个名为“重复”的意图 为意图添加了培训短语 增加了“多声道.重复”作为动作 为此目的启用了webhook调用 在Node.js中添加了“inte
"name": "dialogflowFirebaseFulfillment",
"description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
"version": "0.0.1",
"private": true,
"license": "Apache Version 2.0",
"author": "Google Inc.",
"engines": {
"node": "8"
},
"scripts": {
"start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
"deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
},
"dependencies": {
"actions-on-google": "^2.2.0",
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"dialogflow": "^0.6.0",
"dialogflow-fulfillment": "^0.5.0"
}
}
那么,如何安装库呢?在Read.me文件中说“您可以使用npm安装——保存multivocal”来安装它。但是我应该在哪里安装它呢?我是否将其放在index.js或packages.js中的某个位置
此外,在本文中,它还显示了index.js代码:
const Color = require('./color.js');
Color.init();
const Multivocal = require('multivocal');
exports.webhook = Multivocal.processFirebaseWebhook;
我应该把它添加到index.js的末尾吗?还是应该将其包装在函数中?很抱歉,我在这方面没有经验,但我希望我能解释清楚。使用Dialogflow内联编辑器使用multivocal的一些答案: 如何将其包含在
package.json
文件中?
使用npm
的指导是,如果您在本地编写履行,而不是使用编辑器
您需要在依赖项
部分中添加此行:
"multivocal": "^0.14.0"
Dialogflow/Firebase云函数将负责导入库。您不需要“google上的操作”、“dialogflow”或“dialogflow实现”库,因此该部分可以如下所示:
"dependencies": {
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"multivocal": "^0.14.0"
}
// Import the library on the first line, so you can call methods on it to setup your configuration
const Multivocal = require('multivocal');
// Your configuration and code go here
// Setup the webhook as the final line
exports.dialogflowFirebaseFulfillment = Multivocal.processFirebaseWebhook;
const enRepeat = [
"Sorry about that, let me try again.",
"I said:"
];
const config = {
Local: {
en: {
Response: {
"Action.multivocal.repeat": enRepeat
}
}
}
}
如何编写index.js?
这个简单的示例假设您可以将配置和代码放在一个单独的文件中(“示例中的color.js”)。由于无法使用内联编辑器执行此操作,因此代码的通用样板文件如下所示:
"dependencies": {
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"multivocal": "^0.14.0"
}
// Import the library on the first line, so you can call methods on it to setup your configuration
const Multivocal = require('multivocal');
// Your configuration and code go here
// Setup the webhook as the final line
exports.dialogflowFirebaseFulfillment = Multivocal.processFirebaseWebhook;
const enRepeat = [
"Sorry about that, let me try again.",
"I said:"
];
const config = {
Local: {
en: {
Response: {
"Action.multivocal.repeat": enRepeat
}
}
}
}
意图处理程序的注册和功能在哪里?
与dialogflow实现库不同,multivocal不使用显式intentMap。它本身维护一个,所以要注册一个意图处理函数,您可以使用
Multivocal.addIntentHandler( intentName, handlerFunction );
但请记住,处理函数也有一些不同
什么?它们有何不同?
Multivocal通过配置而不是代码处理很多事情。因此,对于dialogflow fulfillment或googlelibrary上的操作,没有直接对应的agent.add()
函数调用
相反,您的意图处理函数应该执行任何逻辑、数据库调用或任何操作,以获取响应中使用的值并将其保存在环境中。每个处理程序都应该返回一个包含环境的承诺
您还应该为您的意图设置配置,其中最常见的是设置可能的“响应”模板。最简单的响应模板只包括文本以及从环境中插入值的位置。提示用户下一步可以做什么也是最佳实践,因此我们可以设置一个默认使用的“后缀”模板,或者一个用于特定意图、操作或输出的模板
因此,如果您有一个名为“color.favorite”的意图,并且在环境中有一个名为“color”的值(您的处理程序可能从数据库中加载了该值),则此响应的英文配置可能如下所示。它还包括一个默认后缀,用于提示用户下一步可以做什么
const config = {
Local: {
en: {
Response: {
"Intent.color.favorite": [
"{{color}} is one of my favorite colors as well.",
"Oh yes, {{color}} can be quite striking.",
"I can certainly understand why you like {{color}}."
]
},
Suffix: {
Default: [
"What other color do you like?"
"Tell me another color."
]
}
}
}
}
您可以将此配置注册到
new Multivocal.Config.Simple( config );
您可以(并且应该)注册多个配置,尽管您可以将它们组合到一个对象中。因此,上面的Response
部分可以按名称包含每个意图的响应部分
好的,但如何处理“重复”意图?
您只需在Dialogflow UI中提供一个意图,将其“Action”设置为“multivocal.repeat”,并启用webhook。因此,类似这样的方法会起作用:
Multivocal已经基于此注册了处理程序和配置
如果要更改可能的响应,可以为“multivocal.repeat”操作添加配置。可能看起来像这样:
"dependencies": {
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"multivocal": "^0.14.0"
}
// Import the library on the first line, so you can call methods on it to setup your configuration
const Multivocal = require('multivocal');
// Your configuration and code go here
// Setup the webhook as the final line
exports.dialogflowFirebaseFulfillment = Multivocal.processFirebaseWebhook;
const enRepeat = [
"Sorry about that, let me try again.",
"I said:"
];
const config = {
Local: {
en: {
Response: {
"Action.multivocal.repeat": enRepeat
}
}
}
}
然后将此配置与您编写的其他配置组合,或者如上所述加载它
需要强调的是,您无需为此编写任何代码,只需一些可选配置。使用Dialogflow内联编辑器使用multivocal的一些答案: 如何将其包含在
package.json
文件中?
使用npm
的指导是,如果您在本地编写履行,而不是使用编辑器
您需要在依赖项
部分中添加此行:
"multivocal": "^0.14.0"
Dialogflow/Firebase云函数将负责导入库。您不需要“google上的操作”、“dialogflow”或“dialogflow实现”库,因此该部分可以如下所示:
"dependencies": {
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"multivocal": "^0.14.0"
}
// Import the library on the first line, so you can call methods on it to setup your configuration
const Multivocal = require('multivocal');
// Your configuration and code go here
// Setup the webhook as the final line
exports.dialogflowFirebaseFulfillment = Multivocal.processFirebaseWebhook;
const enRepeat = [
"Sorry about that, let me try again.",
"I said:"
];
const config = {
Local: {
en: {
Response: {
"Action.multivocal.repeat": enRepeat
}
}
}
}
如何编写index.js?
这个简单的示例假设您可以将配置和代码放在一个单独的文件中(“示例中的color.js”)。由于无法使用内联编辑器执行此操作,因此代码的通用样板文件如下所示:
"dependencies": {
"firebase-admin": "^5.13.1",
"firebase-functions": "^2.0.2",
"multivocal": "^0.14.0"
}
// Import the library on the first line, so you can call methods on it to setup your configuration
const Multivocal = require('multivocal');
// Your configuration and code go here
// Setup the webhook as the final line
exports.dialogflowFirebaseFulfillment = Multivocal.processFirebaseWebhook;
const enRepeat = [
"Sorry about that, let me try again.",
"I said:"
];
const config = {
Local: {
en: {
Response: {
"Action.multivocal.repeat": enRepeat
}
}
}
}
意图处理程序的注册和功能在哪里?
与dialogflow实现库不同,multivocal没有