使用多语言库为VUI在Dialogflow中配置重复意图

问题描述 投票:1回答:1

我正在尝试将我的VUI配置为在提示时在Dialogflow中重复一个句子。小故事,我正在帮助开发老年人社交机器人,因此重复句子是非常需要的功能。我刚刚开始这个项目,以前负责此工作的开发人员已经离开并且无法联系到我,而且我也没有Node.js的经验。

我正在为此使用multivocal。这些是我到目前为止已完成的步骤:

  1. 创建了一个名为“重复”的意图。
  2. 添加了意图的训练短语
  3. 添加了“ multivocal.repeat”作为动作
  4. 为此目的启用了webhook调用
  5. 在Node.js中添加了'intentMap.set('Repeat',repeat);'到我现有的intentMap
// Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('Game_Rock_Paper_Scissors - Result', game_stone_paper_scissors);
  intentMap.set('Game_Rock_Paper_Scissors - Result - yes', game_stone_paper_scissors_again);
  intentMap.set('Conversation tree', conversation_tree);
  intentMap.set('Question date', question_date);
  intentMap.set('Question time', question_time);
  intentMap.set('Music', music);
  intentMap.set('Repeat', repeat);

[接下来,在“实现”选项卡下,我想在内联编辑器的“ index.js”选项卡中输入该函数,并确保在“ package.json”中多声道库已安装且可用。到目前为止,我的package.json

中有一些东西
  "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 install --save multivocal安装它。”但是我要在哪里安装呢?是否将其放在index.js或packages.js中?

此外,在此example中,它显示的index.js代码为:

const Color = require('./color.js');
Color.init();

const Multivocal = require('multivocal');
exports.webhook = Multivocal.processFirebaseWebhook;

是否应该将其添加到index.js的末尾?还是应该将其包装在函数中?抱歉,我们对此没有经验,但是我希望我能清楚地解释。

node.js dialogflow actions-on-google dialogflow-fulfillment packages.json
1个回答
2
投票

使用Dialogflow内联编辑器使用多声的一些答案:

我如何将其包含在package.json文件中?

npm的使用说明是您在本地编写实现而不是使用编辑器。

您需要在dependencies部分中添加此行:

    "multivocal": "^0.14.0"

和Dialogflow / Firebase Cloud Functions将负责导入库。您将不需要“ Google动作”,“ dialogflow”或“ dialogflow-fulfillment”库,因此该部分的内容如下所示:

  "dependencies": {
    "firebase-admin": "^5.13.1",
    "firebase-functions": "^2.0.2",
    "multivocal": "^0.14.0"
  }

我该如何编写index.js?

简单的示例假定您可以将配置和代码放在单独的文件中(示例中为“ color.js”)。由于您无法使用内联编辑器执行此操作,因此代码的一般样板将如下所示:

// 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;

Intent Handler的注册和功能在哪里?

与对话流实现库不同,多声不使用显式的intentMap。它自己维护一个,因此要注册一个Intent Handler函数,您可以使用

Multivocal.addIntentHandler( intentName, handlerFunction );

[BUT请记住,处理程序功能也有所不同。

什么?它们有何不同?

Multivocal有很多事情是通过配置而不是代码来处理的。因此,与实现对话流或Google动作库中的agent.add()函数调用没有直接对应的内容。

相反,您的Intent Handler函数应该执行任何逻辑,数据库调用或任何其他操作,以获取将在响应中使用的值并将其保存在环境中。每个处理程序都应返回一个包含环境的Promise。

您还应该为Intent设置配置-其中最常见的是设置可能的“响应”模板。最简单的响应模板仅包括文本,以及在环境中插入值的位置。最好的做法是提示用户下一步该做什么,因此我们可以设置一个“后缀”模板以默认使用,也可以设置一个模板用于特定的Intent,Action或Outouts。

因此,如果您有一个名为“ color.favorite”的Intent,并且在环境中具有一个名为“ 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部分可以按名称包含每个Intent的响应部分。

好,但是如何处理“重复”意图?

您要做的[[需要要做的就是提供一个Intent,该Intent在Dialogflow UI中将其“操作”设置为“ multivocal.repeat”,并启用了Webhook。所以这样的事情会起作用:

Intent illustrating where to configure the Action value

Multivocal已经基于此注册了处理程序和配置。

如果要更改可能的响应,则可以为“ multivocal.repeat”操作添加配置。可能看起来像这样:

const enRepeat = [ "Sorry about that, let me try again.", "I said:" ]; const config = { Local: { en: { Response: { "Action.multivocal.repeat": enRepeat } } } }

然后将该配置与您编写的其他配置结合使用,或如上所述进行加载。

要强调-您不需要为此编写任何代码,只需一些可选配置。

© www.soinside.com 2019 - 2024. All rights reserved.