我有以下 (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)
})
基本卡片出现在 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/