我对请求有疑问。我从api和Webhook成功获取数据,但无法显示完整的完整文本。我正在发送api请求并获得响应。但是我不明白为什么我不能作为对用户的回应来展示。 Firebase和请求中没有错误。有人可以帮忙吗?
这是运行此代码时的屏幕截图。
'use strict';
const http = require('http');
const functions = require('firebase-functions')
const {dialogflow} = require('actions-on-google');
const app = dialogflow({debug: true});
const host = 'https://www.boredapi.com/api/activity?participants=1';
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((req, res) => {
// Call the weather API
callBored().then((output) => {
res.json({ 'fulfillmentText': output }); // Return the results of the weather API to Dialogflow
}).catch(() => {
res.json({ 'fulfillmentText': `NOOOOOOO FAİLED` });
});
});
function callBored () {
return new Promise((resolve, reject) => {
// Create the path for the HTTP request to get the weather
// Make the HTTP request to get the weather
https.get(host, (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
// After all the data has been received parse the JSON for desired data
// Create response
let output =JSON.parse(data).activity;
// Resolve the promise with the output text
console.log(output);
resolve(output);
});
res.on('error', (error) => {
console.log(`Error calling the weather API: ${error}`)
reject();
});
});
});
}