【发布时间】:2018-11-06 09:35:12
【问题描述】:
我正在尝试遵循对话流教程。我在调用 api 的 webhook 代码中设置了一个 node.js webhook,它是从 Dialogflow 调用的。但是,我的 node.js webhook 说“错误:getaddrinfo ENOTFOUND”。当我在可视代码中运行它但在通过 DialogFlow 调用时无法在 nodejs webhook 中找到 api 时,这工作正常。从 Dialogflow 调用它的事实似乎使它无法正常工作。
我在这方面花了很多时间,并且预先发现 DialogFlow 不能与 https 一起使用,因为它是一个自签名证书,因此我放置了一个 azure 函数,所以 webhook 调用 azure 函数然后调用 azure函数调用我需要的api。 抱歉发了这么长的帖子……
这里是 node.js 代码:
'use strict';
const http = require('http');
var request = require('request');
const apiUrl ="https://myapi";
exports.saledurationWebhook = (req, res) => {
// Get the city and date from the request
// let city = req.body.queryResult.parameters['geo-city']; // city is a required param
let city = "sdjk";
// Call the weather API
callSalesDurationApi(city).then((output) => {
res.json({ 'fulfillmentText': output }); // Return the results of the weather API to Dialogflow
})
.catch((err) => {
console.log(err);
//res.json({ 'fulfillmentText': `I don't know the sales duration is but I hope it's quick!` });
res.json({ 'fulfillmentText': err.message});
})
;
};
function callSalesDurationApi(city) {
return new Promise((resolve, reject) => {
console.log('API Request: ' + apiUrl);
var myJSONObject = {
"Inputs": "stuff"
};
request({
url: apiUrl,
method: "POST",
json: true, // <--Very important!!!
body: myJSONObject
}, function (error, response, body) {
console.log("successfully called api");
let output = "Current conditions in the " + body;
console.log(output);
console.log(body);
resolve(output);
});
});
}
有谁知道为什么会发生这种情况?或者我可以采取哪些进一步的步骤来调查它?我已经查看了 webhook 和 azure 函数的日志。
非常感谢您的任何帮助,我已经为此浪费了几天时间。如果这是一个重复的问题,那么我很抱歉,我试图寻找关于这个问题的现有答案。
谢谢劳拉
【问题讨论】:
标签: node.js webhooks dialogflow-es