首页 > 解决方案 > DialogFlow 发送 API 请求但未接收数据

问题描述

所以我正在按照这个Youtube 视频开发一个聊天机器人。每当我在本地主机上运行烧瓶(我通过 ngrok 连接到 Dialogflow)时,我都可以看到正在发出的请求,但是我的 python 代码无法将任何数据发回。通过 Postman 对其进行了测试,一切似乎都运行良好。如果有人想看一下,这是我的代码。为了解决这个问题,我什至导入了他的 DialogFlow 代理,但仍然无法正常工作。如果有人可以帮助我,我将不胜感激。

这是我正在努力解决的部分代码:

if intent == 'covid_searchcountry':
    cust_country = parameters.get("geo-country")
    if(cust_country=="United States"):
        cust_country = "USA"

    fulfillmentText, deaths_data, testsdone_data = makeAPIRequest(cust_country)
    webhookresponse = "***Covid Report*** \n\n" + " New cases :" + str(fulfillmentText.get('new')) + \
                      "\n" + " Active cases : " + str(
        fulfillmentText.get('active')) + "\n" + " Critical cases : " + str(fulfillmentText.get('critical')) + \
                      "\n" + " Recovered cases : " + str(
        fulfillmentText.get('recovered')) + "\n" + " Total cases : " + str(fulfillmentText.get('total')) + \
                      "\n" + " Total Deaths : " + str(deaths_data.get('total')) + "\n" + " New Deaths : " + str(
        deaths_data.get('new')) + \
                      "\n" + " Total Test Done : " + str(deaths_data.get('total')) + "\n\n*******END********* \n "
    print(webhookresponse)
    log.saveConversations(sessionID, cust_country, webhookresponse, intent, db)
    log.saveCases( "country", fulfillmentText, db)

    return {

        "fulfillmentMessages": [
            {
                "text": {
                    "text": [
                        webhookresponse
                    ]

                }
            },
            {
                "text": {
                    "text": [
                        "Do you want me to send the detailed report to your e-mail address? Type.. \n 1. Sure \n 2. Not now "
                        # "We have sent the detailed report of {} Covid-19 to your given mail address.Do you have any other Query?".format(cust_country)
                    ]

                }
            }
        ]
    }

由于某种原因,该程序无法将 webhook 响应返回给 Dialogflow,我不知道为什么。是 Postman 展示的内容。我可以在这里看到所有数据。是我在使用 ngrok 时在命令提示符上看到的内容。

标签: pythondialogflow-es-fulfillment

解决方案


推荐阅读