这是我在内联编辑器中的实现代码: 注意:请求正以200 OK代码到达我的api服务器,但说在dialogflow平台中超过了截止日期。希望您能尽快找到解决方案。
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');`
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
let number = request.body.queryResult.parameters['number'];
var url = 'https://7400546e4d1e.ngrok.io/api/reclamations'+'/'+ number ;
getDescription(url).then(response => {
var bot_response = "description:"+response.data.description ;
agent.add(bot_response);
console.log(bot_response);
response.json({ 'fulfillmentText': bot_response });
}).catch (error => {
console.log("Something is wrong !! ");
console.log(error);
agent.add(bot_response);
});
function getDescription(url) {
const axios = require('axios');
return axios.get(url,{timeout:10000});
}
});
答案 0 :(得分:1)
尝试将函数getDescription定义为异步函数(即async function getDescription(url){...}
)。
这是因为当您调用getDescription(url).then(response => {...})
时,.then()暗示它是异步的。