Google Assistant advanced responses with API.AI

2019-07-13 11:55发布

问题:

I already have a webhook, and I am using it to change the assistant answers. But I can't figure out how to send a suggestions card or a link, as you can send them from API.AI web GUI (From the add content button).

Should I send them as a JSON object under the data name.

API.AI webhook documentation

回答1:

The general form for the JSON body of a response to a API.AI fulfillment webhook call that will include a Action on Google rich response for a simple response and a card is below. If you want to use lists or carousel the documentation is here:

{
  "speech": "This is a API.AI default speech response",
  "displayText": "This is a API.AI default display text response",
  "data": {
    "google": {
      "expectUserResponse": true,
      "isSsml": false,
      "noInputPrompts": [],
      "richResponse": {
        "items": [
          {
            "simpleResponse": {
              "textToSpeech": "This is a simple speech response for Actions on Google.",
              "displayText": "This is a simple display text response for Action on Google."
            }
          },
          {
            "basicCard": {
              "title": "Title: this is a title",
              "subtitle": "This is a subtitle",
              "formattedText": "This is a basic card.  Text in a basic card can include \"quotes\" and most other unicode characters including emoji