I have the following (kotlin) code:
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()
}
and then of course
IntentsClient.create().use({ intentsClient ->
val intrequest = CreateIntentRequest.newBuilder()
.setParent("projects/$project/agent")
.setIntent(i)
.build()
val response1 = intentsClient.createIntent(intrequest)
})
but for the life of me I can't figure out how to create a trivial entry in this section:
The basic cards appear in the Google Assistant section (obviously).
What am I missing in order to create default simple default responses? If you are thinking "oh that's easy - it's ...." then yes you are correct - it is simple I just can't find it.
FWIW. Some of my (not working) attempts look like:
var sr = Intent.Message.SimpleResponse.newBuilder()
sr.setDisplayText("Pleeeeaaaassssseeee")
val simpleReponseMessage = sr.build()
addMessagesBuilder()
.simpleResponsesBuilder
.addSimpleResponses(simpleReponseMessage)
.build()
While I haven't done it myself, I am referring to the REST API and found the Intent has a Message type which can be a collection responses.
The message should have a field called SimpleResponses, which is an array of SimpleResponse objects.
This should update the console. It looks like they appear in Google Assistant because the Message type has an optional field of type Platform. I'm not sure what the default value is, but would PLATFORM_UNSPECIFIED
place it in the right section?
The implementation would look similar to (using the dialogflow package):
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
})
I haven't tested the behavior of the snippet, but this should add a generic text response.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With