如何使用 dialogflow.v2beta1 创建默认响应
How to create a default response using dialogflow.v2beta1
我有以下 (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 助手部分(很明显)。
我缺少什么来创建默认的简单默认响应?如果您认为 "oh that's easy - it's ...." 那么是的,您是对的 - 很简单,我只是找不到它。
FWIW。我的一些(不工作)尝试看起来像:
var sr = Intent.Message.SimpleResponse.newBuilder()
sr.setDisplayText("Pleeeeaaaassssseeee")
val simpleReponseMessage = sr.build()
addMessagesBuilder()
.simpleResponsesBuilder
.addSimpleResponses(simpleReponseMessage)
.build()
虽然我自己没有做过,但我指的是RESTAPI,发现Intent has a Message类型可以是一个集合响应。
该消息应该有一个名为 SimpleResponses, which is an array of SimpleResponse 个对象的字段。
这应该会更新控制台。看起来它们出现在 Google Assistant 中,因为 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
})
我还没有测试代码段的行为,但这应该会添加一个通用的文本响应。
addMessagesBuilder().setPlatform(Intent.Message.Platform.PLATFORM_UNSPECIFIED).setText(Intent.Message.Text.newBuilder().addText("ffs")).build()
我有以下 (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 助手部分(很明显)。
我缺少什么来创建默认的简单默认响应?如果您认为 "oh that's easy - it's ...." 那么是的,您是对的 - 很简单,我只是找不到它。
FWIW。我的一些(不工作)尝试看起来像:
var sr = Intent.Message.SimpleResponse.newBuilder()
sr.setDisplayText("Pleeeeaaaassssseeee")
val simpleReponseMessage = sr.build()
addMessagesBuilder()
.simpleResponsesBuilder
.addSimpleResponses(simpleReponseMessage)
.build()
虽然我自己没有做过,但我指的是RESTAPI,发现Intent has a Message类型可以是一个集合响应。
该消息应该有一个名为 SimpleResponses, which is an array of SimpleResponse 个对象的字段。
这应该会更新控制台。看起来它们出现在 Google Assistant 中,因为 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
})
我还没有测试代码段的行为,但这应该会添加一个通用的文本响应。
addMessagesBuilder().setPlatform(Intent.Message.Platform.PLATFORM_UNSPECIFIED).setText(Intent.Message.Text.newBuilder().addText("ffs")).build()