问题描述
我正在尝试将 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”的 Cloud Functions Action 并选中启用为 Web行动。操作代码是从本书的 git repo 中导入的:
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":"请求的资源不存在。"} 当我单击错误图标时,我收到一个运行时错误弹出窗口,提示 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) 和命名空间中。
我想不出还有什么可以尝试的了。
解决方法
我刚刚破解了它。我试图使用文本 response is <? $webhook_result_1.response ?>
显示结果,而它应该是 response is <? $webhook_result_1 ?>
。