DialogFlow 发送 API 请求但未收到数据

时间:2021-06-27 07:48:46

标签: python dialogflow-es-fulfillment

所以我正在通过关注 this Youtube 视频开发聊天机器人。每当我在本地主机上运行 Flask(我通过 ngrok 连接到 Dialogflow)时,我都可以看到正在发出的请求,但我的 python 代码无法将任何数据发回。通过 Postman 对其进行了测试,一切似乎都正常。 Here's 我的代码,如果有人想看一看。为了找出问题所在,我什至导入了他的 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,我无法弄清楚原因。Here's Postman 显示的内容。我可以在这里看到所有数据。 Here's 我在使用 ngrok 时在命令提示符下看到的内容。

0 个答案:

没有答案