我正在创建一个googledialogflow操作,如果我处理正常的事情,它可以正常工作。 但是我必须从URL中获取一些数据,并且一旦我有意通过使用async / await来获取数据,代码就会停止工作,并且我无法确定错误是什么。 自5天以来,我一直在为此苦苦挣扎。 这严重地使我发疯,因此我无法完成自己的动作。 我在控制台中遇到的唯一错误: 格式错误的响应 由于平台响应无效,无法将Dialogflow响应解析为AppResponse:在agentId:b71b73aa-854f-4979-a062-e7aedb906e04和intentId:80a4b104-26ba-4f9f-a717-4f65f7f1465d的平台响应中找不到RichResponse或SystemIntent。 WebhookStatus:代码:14消息:“ Webhook调用失败。错误:无法使用。” ..
下面的测试代码:
"use strict";
// Import the Dialogflow module and response creation dependencies
// from the Actions on Google client library.
const {
dialogflow,
BasicCard,
Permission,
Suggestions,
Carousel,
Image,
} = require("actions-on-google");
// Import the firebase-functions package for deployment.
const functions = require("firebase-functions");
// Instantiate the Dialogflow client.
const app = dialogflow({
debug: true
});
const axios = require("axios");
const URL = "https://example.com/example.json"; //example URL
let confirmedCases;
let activeCases;
let recoveredCases;
let deathCases;
async function testIt() {
try {
const response = await axios.get(URL);
const result = response.data;
let data = result["data"];
let confirmedCases = data[0];
let activeCases = data[1];
let recoveredCases = data[2];
let deathCases = data[3];
console.log(String(confirmedCases));
} catch (error) {
console.log(error);
}
}
testIt(); //works fine in terminal (by running node index.js)
app.catch((conv, error) => {
console.error(error);
conv.ask(`I encountered a glitch. Can you say that again? ${error}`);
});
// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', async (conv) => {
try {
const response = await axios.get(URL);
const result = response.data;
let data = result["data"];
let confirmedCases = data[0];
let activeCases = data[1];
let recoveredCases = data[2];
let deathCases = data[3];
//console.log(typeof(String(confirmedCases)));
conv.ask(String(confirmedCases));
} catch (error) {
console.log(error);
}
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);