[当我运行firebase serve --only functions
时
这是我的代码:
exports.helloWorld = 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));
function findWidget(agent) {
agent.add(`You are now being handled by the productivity intent`);
const url = "https://reqres.in/api/users?page=2";
return request.get(url)
.then(jsonBody => {
var body = JSON.parse(jsonBody);
agent.add(body.data[0].first_name)
return Promise.resolve(agent);
})
.catch(err => {
console.error('Problem making network call', err);
agent.add('Unable to get result');
return Promise.resolve(agent);
});
};
let intentMap = new Map();
intentMap.set('Default Welcome Intent', findWidget);
agent.handleRequest(intentMap);
});
请帮助我解决此问题,我不知道这有什么问题。
更新:错误图片:https://i.stack.imgur.com/1YDP2.png屏幕截图浏览器:https://i.stack.imgur.com/uPV9w.png
尽管我们说Dialogflow fulfillment代码旨在作为Webhook运行,但这并不一定意味着您将能够在Web浏览器中对其进行访问。
在这种情况下,需要实现Dialogflow Webhook
Dialogflow fulfillment library旨在接受格式化的请求并帮助您创建格式化的响应。
但是,就您而言,您是使用网络浏览器访问它的。可能使用了HTTP GET命令,但没有发送JSON正文。错误消息告诉您请求看起来不像来自Dialogflow,因此无法处理。