Search code examples
pythonflaskdialogflow-esactions-on-google

Fulfillment Webhook in Python for Dialogflow


I want to develop a webhook in Python using Flask. All documentation and tutorials I found online are for Node.js.

How can I include suggestion chips and action cards for some intents, using Python in a webhook?


Solution

  • If you take a look at the Responses doc for Actions on Google, you can see the JSON responses that you can use rather than Node.js.

    A response with a suggestion chip has this format:

    {
      "payload": {
        "google": {
          "expectUserResponse": true,
          "richResponse": {
            "items": [
              {
                "simpleResponse": {
                  "textToSpeech": "These are suggestion chips."
                }
              },
              {
                "simpleResponse": {
                  "textToSpeech": "Which type of response would you like to see next?"
                }
              }
            ],
            "suggestions": [
              {
                "title": "Suggestion 1"
              },
              {
                "title": "Suggestion 2"
              },
              {
                "title": "Suggestion 3"
              }
            ],
            "linkOutSuggestion": {
              "destinationName": "Suggestion Link",
              "url": "https://assistant.google.com/"
            }
          }
        }
      }
    }
    

    Alternatively you can find a pre-existing library from a third-party developer to provide fulfillment, such as flask-dialogflow.