node.js - 错误:node.js webhook 中用于对话框流的 getaddrinfo ENOTFOUND
问题描述
我正在尝试遵循对话流教程。我在调用 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 函数的日志。
任何帮助都会非常感激,我已经在这上面浪费了好几天。如果这是一个重复的问题,那么我很抱歉,我试图寻找关于这个问题的现有答案。
谢谢劳拉
解决方案
我发现这个问题已经回答了:https ://stackoverflow.com/a/46692487/7654050
这是因为我还没有为这个项目设置帐单。我以为它是在我的工作帐户上设置的。
推荐阅读
- json - 当您不知道键名时如何在 jq csv 中提取键和值
- php - 在 Laravel Eloquent 中计算关系数据时出错
- python - Dataframe PANDAS Python 格式数据
- javascript - 比较 2 个数组及其对象
- visual-studio-code - VS Code - 无法写入用户设置
- mobile - 2sxc: Accordion App - 打开/关闭桌面/移动视图的部分状态
- php - 如何检查 WooCommerce 产品是否来自自定义产品类型?
- flutter - 如何在 pubspec 文件中添加english_words 时解决依赖错误
- python - Matplotlib 图未使用 ipywidgets 滑块更新
- python - 在 macOS Big Sur 上将 Python 3.7 升级到 3.9