Python Dialog flow api get dialog flow entities from intents

Here is the code:

import argparse
import uuid
import json
import dialogflow
import os
import google.protobuf  as pf   ##for parsing the params
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="poc-demo-6e2f30e03b3a.json"## google dialogflow authentication

# [START dialogflow_detect_intent_text]
def detect_intent_texts(project_id, session_id, text, language_code):
    """Returns the result of detect intent with texts as inputs.

    Using the same `session_id` between requests allows continuation
    of the conversation."""

    import dialogflow_v2 as dialogflow
    session_client = dialogflow.SessionsClient()

    session = session_client.session_path(project_id, session_id)
    print('Session path: {}\n'.format(session))

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

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

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

    print('=' * 20)
    print('Query text: {}'.format(response.query_result.query_text))
    print('Detected intent: {} (confidence: {})\n'.format(
        response.query_result.intent.display_name,
        response.query_result.intent_detection_confidence))
    params = pf.json_format.MessageToJson(response.query_result.parameters, including_default_value_fields=False)

    print('Fulfillment text: {}\n'.format(params))

# [END dialogflow_detect_intent_text]


if __name__ == '__main__':

    detect_intent_texts('poc-demo-77e74', "unique", 'booked revenue last week', 'en')

Comments