[Python] How to get dialogflow analytics data

Discussão em 'Python' iniciado por Stack, Setembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    So what I am trying is, I have a dialogflow cx phone-gateway setup and a react project and python backend. What I'm trying is when I load the frontend page, it calls the backend which gets the analytics data from dialogflow and gives it to react js which uses react flow library to render the flow and analytics data on these flows/pages.

    By Analytics data I mean: Which flows have been hit the most during a call, which flows have missed, which intents/questions were asked the most and where did the user end the call mostly etc.

    What I have tried is, call a webhook on each page and record the user journey in the db. Then when the page loads, I get the dialogflow cx flows and pages in python,


    def get_dialogflow_flows(parent):
    try:
    print("Flows and Intents called")
    os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = current_app.config['GOOGLE_APPLICATION_CREDENTIALS']

    flow_client = dialogflowcx.FlowsClient()
    page_client = dialogflowcx.PagesClient()

    start_time = time.time()

    flows = flow_client.list_flows(parent=parent)
    print("Flows Fetched --- %s seconds ---" % (time.time() - start_time))
    flow_data = []

    # start_time = time.time()
    for flow in flows:
    # Fetch pages for each flow using PagesClient
    pages = list(page_client.list_pages(parent=flow.name))
    flow_pages = []

    for page in pages:
    # Get full page details including transition routes
    page_details = page_client.get_page(name=page.name)
    transitions = []

    for route in page_details.transition_routes:
    transitions.append({
    'target_page': route.target_page,
    'target_flow': route.target_flow,
    'condition': route.condition
    })

    flow_pages.append({
    'page_name': page.display_name,
    'page_id': page.name,
    'transitions': transitions # Include transition routes
    })

    flow_data.append({
    'flow': flow.display_name,
    'flow_id': flow.name,
    'pages': flow_pages
    })

    # print("Second --- %s seconds ---" % (time.time() - start_time))
    return make_response(message="Data fetched successfully", success=True, data=flow_data, status=200)
    except Exception as e:
    current_app.logger.error(e)
    return make_response(message=str(e), success=False, data=None, status=500)



    using this data, I try to render the flow from dialogflow cx console in my react frontend using react flow library. But, doing this is not great because I have to manage webhooks call and database entries for each page/flow.

    So, is there a way I can do this better? I know there is analytics page in dialogflow cx console, is there any way I can get that data?

    Continue reading...

Compartilhe esta Página