javascript - Dialogflow Webhook(Webhook 调用失败。错误:500 内部服务器错误)
问题描述
我已按照本教程的代码 ( https://dialogflow.com/docs/getting-started/basic-fulfillment-conversation ) 将 API 的结果返回到对话流。但是我的 webhook 一直失败。有人可以帮我弄清楚为什么吗?
这是我的代码:
'use strict';
const http = require('http');
exports.Hadoop = (req, res) => {
// Get name node server from the request
let nameNodeServer = req.body.queryResult.parameters['nameNodeServer']; // nameNodeServer is a required param
// Call the Hadoop API
getNameNodeInfo(nameNodeServer).then(function(output) {
res.json({ 'fulfillmentText': output }); // Return the results to Dialogflow
}).catch(() => {
res.json({ 'fulfillmentText': 'getNameNodeInfo() Error'- });
});
};
function getNameNodeInfo (nameNodeServer) {
return new Promise((resolve, reject) => {
// Create url for the HTTP request to get the name node info
let url = 'http://' + nameNodeServer + '[rest of url]';
// Make the HTTP request to get the name node info
http.get(url, (res) => {
let body = ''; // var to store the response chunks
res.on('data', (chunk) => {body += chunk; });
res.on('end', () => {
// After all the data has been received, parse the JSON for desired data
let response = JSON.parse(body);
let beans = response['beans'][0];
// Create response
let output = `Percent Used: ${beans['PercentUsed']}`;
// Resolve the promise with the output text
console.log(output);
resolve(output);
});
res.on('error', (error) => {
console.log(`Error calling the Hadoop API: ${error}`);
reject();
});
});
});
}
我相信 getNameNodeInfo 函数和名称节点服务器的检索是正确的,因为它们在调试中记录了正确的输出。
解决方案
我联系了 Dialogflow 的某个人,这是他们的回复。
感谢您提供所有信息。我在您的代码中观察到您使用的是 http 请求而不是 https。该服务必须使用 HTTPS,并且 URL 必须是可公开访问的,才能正常运行。Dialogflow 不支持自签名 SSL 证书。有关 SSL 设置的信息,请参阅: https ://developers.google.com/web/fundamentals/security/encrypt-in-transit/enable-https
推荐阅读
- javascript - 每个 ejs 渲染调用的“默认”参数?
- swift - 在 UIStackView 中以编程方式堆叠视图
- javascript - 手动修复 NPM 中的漏洞
- ios - 从以前的文本字段切换后,iOS 13 仅偶尔会建议使用强密码
- python - 熊猫组合不适用于数据框中的某些行
- ngrx - createAction ngrx 方法论
- pandas - 制作自定义移位函数以滞后于缺少观察的数据框
- node.js - 如何区分 Node.JS 中的两个 POST 请求?
- curl - httpie 是否有与 curl 的 --path-as-is 选项等效的选项
- python - (Python) 根据现有列的值创建新列