java - 如何使用 dialogflow.v2beta1 创建默认响应

标签 java kotlin dialogflow-es

我有以下 (kotlin) 代码:

import com.google.cloud.dialogflow.v2beta1.*

val project = "my-super-agent"

val trainingPhraseBuilder = Intent.TrainingPhrase.Part.newBuilder()
trainingPhraseBuilder.text = "Tell me about the product."
val trainingPhrasePart = trainingPhraseBuilder.build()
println(trainingPhrasePart)

var i = with(Intent.newBuilder()) {
    displayName = "My First Built Intent"
    addTrainingPhrases(Intent.TrainingPhrase.newBuilder().addAllParts(listOf(trainingPhrasePart)))
    val message =
        with(addMessagesBuilder()) {
            basicCardBuilder.setFormattedText("It is amazing. Truly it is.")
            build()
        }
    build()
}

当然还有

IntentsClient.create().use({ intentsClient ->

    val intrequest = CreateIntentRequest.newBuilder()
        .setParent("projects/$project/agent")
        .setIntent(i)
        .build()

    val response1 = intentsClient.createIntent(intrequest)

})

但对于我来说,我无法弄清楚如何在本节中创建一个琐碎的条目:enter image description here

基本卡片出现在 Google 助理部分(显然)。

为了创建默认的简单默认响应,我缺少什么?如果您在想“哦,这很容易 - 它是....”那么是的,您是对的 - 很简单,我只是找不到它。

FWIW。我的一些(不工作)尝试看起来像:

var sr = Intent.Message.SimpleResponse.newBuilder()
sr.setDisplayText("Pleeeeaaaassssseeee")
val simpleReponseMessage = sr.build()

addMessagesBuilder()
.simpleResponsesBuilder
.addSimpleResponses(simpleReponseMessage)
.build()

最佳答案

虽然我自己没有做过,但我指的是 REST API 并找到了 Intent有一个 Message可以是集合响应的类型。

消息应该有一个名为 SimpleResponses 的字段,它是 SimpleResponse 的数组对象。

这应该会更新控制台。看起来它们出现在 Google 助理 中,因为 Message 类型有一个 Platform 类型的可选字段.我不确定默认值是什么,但 PLATFORM_UNSPECIFIED 会将其放在正确的部分吗?

实现看起来类似于(使用 dialogflow 包):

const intentsClient = new dialogflow.IntentsClient();
const parent = intentsClient.projectAgentPath(projectId);
const dfIntent = {
  // Put other values in here
  // ...
  messages: [{
    platform: 'PLATFORM_UNSPECIFIED',
    text: [ 'Default message' ]
  }]
}
// Or execute updateIntent if it already exists
const creationResponse = await intentsClient.createIntent({
  parent,
  languageCode: 'en',
  intent: dfIntent
})

我还没有测试片段的行为,但这应该会添加一个通用的文本响应。

关于java - 如何使用 dialogflow.v2beta1 创建默认响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56147720/

相关文章:

java - 键盘滑出/配置更改后 Android 循环速度更快

java - Kotlin:扩展动态给定的父类(super class)型

android - 无法解决 anko 库版本 0.9.1

dialogflow-es - 对话流中的可选输入上下文

javascript - 使用 Actions on Google 库集成时不显示轮播

java - 如果Java仅是按值传递,我可以在形式参数中强制使用final修饰符吗?

java - 抽象方法到底如何在不被覆盖的情况下返回所需类型?

Spring Boot jar 由于缺少 ServletWebServerFactory bean 而无法启动 Web 服务器

actions-on-google - 是否可以向 google home 应用程序发送丰富的响应?

java - 尝试使用正则表达式查找出现的数字后跟逗号