8

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: enter image description here

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()
Richard Green
  • 2,037
  • 2
  • 20
  • 38

2 Answers2

1

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.

Nick Felker
  • 11,536
  • 1
  • 21
  • 35
  • Sure - but I can't figure out how to use the API in order to make this happen.. Do you have the line of code? – Richard Green May 18 '19 at 13:09
  • I've updated the answer with a Node.js snippet of the code you'd generally need to implement. I think, based on reading the docs, that many response types are only used in the Google Assistant section, such as simpleResponses. The text field should be generic. – Nick Felker May 20 '19 at 14:12
  • Thanks Nick - but I need a java / kotlin solution as this needs to integrate with the rest of the platform, and that requires the `builder` and `SimpleResponse.newBuilder()` stuff... – Richard Green May 20 '19 at 15:13
  • If you understand the snippet above, you should be able to adjust the logic to fit your language of choice – Nick Felker May 20 '19 at 15:40
  • Seems like you can do `addMessagesBuilder().setPlatform(...).addText(...).build()` – Nick Felker May 20 '19 at 15:40
  • There is no `addText()` after `setPlatform()` – Richard Green May 21 '19 at 09:40
0
 addMessagesBuilder().setPlatform(Intent.Message.Platform.PLATFORM_UNSPECIFIED).setText(Intent.Message.Text.newBuilder().addText("ffs")).build()
Richard Green
  • 2,037
  • 2
  • 20
  • 38