1

I am using the following detect_intent function:

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = 'private_key.json'

DIALOGFLOW_PROJECT_ID = 'kuku-lulu'

DIALOGFLOW_LANGUAGE_CODE = 'en'

SESSION_ID = 'me'

def detect_intent(text):

    session_client = dialogflow.SessionsClient()

    session = session_client.session_path(DIALOGFLOW_PROJECT_ID, SESSION_ID)

    text_input = dialogflow.types.TextInput(text = text, language_code = DIALOGFLOW_LANGUAGE_CODE)

    query_input = dialogflow.types.QueryInput(text = text_input)

    try:

        response = session_client.detect_intent(session = session, query_input = query_input)

    except InvalidArgument:

        raise

    # print("Query text:", response.query_result.query_text)

    # print("Detected intent:", response.query_result.intent.display_name)

    # print("Detected intent confidence:", response.query_result.intent_detection_confidence)

    # print("Fulfillment text:", response.query_result.fulfillment_text)

    return {'sc': session_client, 'intent_name': response.query_result.intent.display_name}

How can I also detect the context from Dialogflow?

SteveS
  • 3,789
  • 5
  • 30
  • 64

1 Answers1

1

The response.query_result.output_context field should be an array of currently active contexts, each one being a Context object.

You can read this information and send it back as the input contexts for the next request.

Prisoner
  • 49,922
  • 7
  • 53
  • 105