首页 > 解决方案 > 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 函数和名称节点服务器的检索是正确的,因为它们在调试中记录了正确的输出。

诊断信息: 在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

标签: javascriptnode.jsgoogle-cloud-platformdialogflow-es

解决方案


我联系了 Dialogflow 的某个人,这是他们的回复。

感谢您提供所有信息。我在您的代码中观察到您使用的是 http 请求而不是 https。该服务必须使用 HTTPS,并且 URL 必须是可公开访问的,才能正常运行。Dialogflow 不支持自签名 SSL 证书。有关 SSL 设置的信息,请参阅: https ://developers.google.com/web/fundamentals/security/encrypt-in-transit/enable-https


推荐阅读