jsongoogle-cloud-platformdialogflow-esdialogflow-es-fulfillment

Link Custom Payload Buttons to Intents


I am Already using this custom payload to generate buttons but how can I link specific intent to the buttons like in the example below if user clicks yes follow up default intent yes response and so on.

Dialog Flow Screen Shot

{
  "richContent": [
    [
      {
        "text": "Yes",
        "link": "https://example.com",
        "type": "button",
        "icon": {
          "color": "#FF9800",
          "type": "chevron_right"
        },
        "event": {
          "languageCode": "en",
          "name": "DefaultWelcomeIntent.DefaultWelcomeIntent-yes",
          "parameters": {}
        }
      },
      {
        "event": {
          "parameters": {},
          "name": "DefaultWelcomeIntent.DefaultWelcomeIntent-no",
          "languageCode": "en"
        },
        "type": "button",
        "link": "https://example.com",
        "text": "No",
        "icon": {
          "type": "chevron_right",
          "color": "#FF9800"
        }
      }
    ]

  ]
}

Solution

  • You may use the Suggestion Chip Response Type approach in your custom payload in which you will be able to have your desired "Yes" and "No" button. Once you click on your desired button, it will return as a text response on the Dialogflow Messenger and you will be redirected to your follow-up intent that matches the text response based on the training phrases of the follow-up intent (eg. "Yes", "No", etc).

    You may try below sample custom payload and must be able to redirect you to either follow-up intent - yes or follow-up intent - no depending on the button you click.

    {
      "richContent": [
        [
          {
            "type": "chips",
            "options": [
              {
                "text": "Yes"
              },
              {
                "text": "No"
              }
            ]
          }
        ]
      ]
    }
    

    UPDATE: There is another approach for your use case that uses your current custom payload script. Please see below updated custom payload script.

    {
        "richContent": [
            [{
                    "event": {
                        "languageCode": "en",
                        "parameters": {},
                        "name": "click_yes"
                    },
                    "text": "Yes",
                    "link": "",
                    "icon": {
                        "type": "chevron_right",
                        "color": "#FF9800"
                    },
                    "type": "button"
                },
                {
                    "text": "No",
                    "event": {
                        "parameters": {},
                        "name": "click_no",
                        "languageCode": "en"
                    },
                    "link": "",
                    "icon": {
                        "color": "#FF9800",
                        "type": "chevron_right"
                    },
                    "type": "button"
                }
            ]
        ]
    }
    

    As you can see, I changed the value of the event name for both buttons. click_yes for button Yes and click_no for button No.

    Next step is to go to your Default Welcome Intent - yes and under Events, input click_yes. By doing this, the intent will be triggered by the click_yes event that is tied up to your Yes button. (Do the same step for Default Welcome Intent - no by using the event name click_no.)