python - 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 时在命令提示符上看到的内容。
解决方案
推荐阅读
- c# - 如何在 Acumatica 销售订单中根据客户的税区显示价值
- kubernetes - GKE 在超过 5 个时杀死 pod
- python - Plotly:如何在 Barpolar 图上添加 Scatterpolar?
- asp.net - 无法使用 .Net Framework 库在 IIS 10 .Net Core 应用程序上加载文件或程序集“Microsoft.AspNet.SessionState.SessionStateModule”
- java - 授予 Elasticsearch 访问 Java 的适当权限
- visual-studio - Git fetch 在 Visual Studio 中未检索到任何结果
- f# - F#中如何处理类似于Typescript的非结构化数据
- sql - 如何在数据透视表中使用汇总/多维数据集(汇总行)
- sql-server - 如何使用 SQL Server 获取 Join 中的所有值?
- python - 过滤掉 NOT isin 中的字典