Calling the Dialogflow agent using Python API

In this example, we'll be creating a simple Python-based API that calls to the agent we created in the Dialogflow console to invoke Dummy Intent, as shown:

  1. Firstly, we must import the Dialogflow module to the project. To do so, use the following code:
import dialogflow
  1. To get the project ID into the script, we can fetch it from the runtime environment variables. To do so, use the following code:
import osproject_id = os.getenv("DIALOGFLOW_PROJECT_ID")
  1. We will also declare a unique session ID to store the records of the conversations made in any single session with the user:
session_id="any_random_unique_string"
  1. We'll now create a handy function that will allow us to repeatedly perform a ...

Get Hands-On Python Deep Learning for the Web now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.