【发布时间】:2019-05-02 06:57:20
【问题描述】:
我已经购买了云功能的火焰计划。我正在使用对话流部署我的 webhook 仍然遇到同样的错误:
错误:getaddrinfo ENOTFOUND jsonplaceholder.typicode.com/ jsonplaceholder.typicode.com/:8080
在 errnoException (dns.js:28:10)
在 GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
'use strict';
var https = require ('https');
const functions = require('firebase-functions');
const DialogFlowApp = require('actions-on-google').DialogFlowApp;
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request,
response) => {
let action = request.body.queryResult.action;
var chat = "here is a sample response: trump sucks";
response.setHeader('Content-Type','application/json');
if (action!= 'input.getStockPrice'){
console.log('Inside input function');
response.send(buildChatResponse("I'm sorry, I don't know this"));
return;
}
getStockPrice (response);
});
function getStockPrice (CloudFnResponse) {
var pathString = "users/2";
var request = https.get({
host: "jsonplaceholder.typicode.com/",
path: pathString,
}, function (response) {
var json = "";
response.on('data', function(chunk) {
console.log("received JSON response: " + chunk);
json += chunk;
});
response.on('end', function(){
var jsonData = JSON.parse(json);
console.log("1");
var stockPrice = jsonData.name
console.log ("the stock price received is:" + stockPrice);
CloudFnResponse.send(buildChatResponse(stockPrice ));
});
});
}
function buildChatResponse(chat) {
return JSON.stringify({"fulfillmentText": chat});
}
【问题讨论】:
标签: firebase google-cloud-functions dialogflow-es