【发布时间】:2021-09-04 06:42:53
【问题描述】:
我正在尝试将 openweathermap API 与 Watson Assistant 一起使用,但我收到“Webhook 调用不成功。响应代码为 [404]。(日志中还有 1 个错误)。”
(我正在研究 Sabharwal 等人的书,我自己对过时的元素进行了即兴创作,例如 @sys-location。)
我创建了一个名为“https://us-south.functions.appdomain.cloud/api/v1/web/my-account-email%40dev/default/Weather-Connection”的云功能操作并选中启用为 Web行动。操作代码是从本书的 git 存储库中导入的:
let rp = require('request-promise')
function main(params) {
const options = {
uri: "http://api.openweathermap.org/data/2.5/weather?q=" + encodeURIComponent(params.object_of_interest)+ "&units=metric&APPID=19e8588cb3d7d0623e3a5a8ec529232f" ,
json: true
}
return rp(options)
.then(res => {
WeatherReport = "Current Temperature : " +res.main.temp+ ", Pressure : " + res.main.pressure + ", Humidity : " + res.main.humidity + ", temp min : " + res.main.temp_min + " , temp max : " + res.main.temp_max
return { WeatherReport
}
})
}
在助手选项中,webhook URI 设置为
https://us-south.functions.appdomain.cloud/api/v1/web/my-account-email%40dev/default/Weather-Connection.json.
“助手响应”JSON 是 “助手响应”JSON 是
{
"output": {
"text": {
"values": [],
"selection_policy": "sequential"
}
},
"actions": [
{
"name": "/my-account-email%40dev/default/Weather-Connection.json",
"type": "cloud_function",
"parameters": {
"object_of_interest": "$location"
},
"credentials": "$credentials",
"result_variable": "$response"
}
],
"context": {
"credentials": {
"api_key": "[my-openweathermap-api-key]"
},
"object_of_interest": "@object_of_interest"
}
}
为了调试,我包含了一个显示 $location 值的对话框节点,这没问题(例如“London”)。
“试用”窗格打印 {"cloud_functions_call_error":"The requested resource does not exist."} 当我单击错误图标时,我收到一个运行时错误弹出窗口,提示 Direct CloudFunctions call was not successful. Http response code is [404]. (and there is 1 more error in the log)。
我没有从运行 CLI 命令 ibmcloud fn activation list 得到任何输出(我不确定这是检查日志的正确方法)。
我已经通过使用参数{"object_of_interest": "London"} 调用Action 来测试Weather-Connection 功能,并且它可以工作。
所有东西都部署在同一个区域(us-south)和命名空间中。
我想不出还有什么可以尝试的。
【问题讨论】:
-
更正:现在我正在获取日志。状态返回为
application error -
“响应”:{“状态”:“应用程序错误”,“状态代码”:0,“成功”:假,“结果”:{“错误”:{“错误”:{“ cod": "400", "message": "错误查询" },
-
您可以检查激活,也可以使用 Cloud Functions 的浏览器 UI 调用:cloud.ibm.com/functions/dashboard
-
检查从 Watson Assistant 传递到函数的内容,接收的有效负载是否具有预期的格式。
-
谢谢@data_henrik。日志显示有一个参数“q=undefined”,它告诉我位置变量的值没有进入请求。我会继续挖掘。
标签: ibm-cloud watson-assistant ibm-cloud-functions