我正在制定一项使用成就的行动。我正在使用内联编辑器。我将硬编码的值移到FireStore中,因此数据存储在函数本身中。 FireStore请求没有按预期进行:尽管实现调用没有失败,但是它没有找到应有的信息。我正在尝试使用老式的console.log
类型日志记录,以找出问题所在。但是那些日志消息不会在任何地方显示。
我查看了该功能的Firebase日志,但它仅包含基本事件:执行开始,完成和警告。
我还通过将操作附加到已计划付款的项目来升级该操作,并启用了Stackdriver日志记录。这也没有显示我的自定义日志记录,仅显示样板消息。
然后,我尝试在此之后将自定义Stackdriver登录添加到内联实现功能中:https://firebase.google.com/docs/functions/writing-and-viewing-logs但是我收到一个错误,因为在该内联函数的nodejs环境中无法访问@google-cloud/logging
。所以我有点卡住了。我不敢相信没有简单的方法可以简单地登录,但是多次Google搜索并没有产生我可以采取的任何措施。
从Dialogflow的嵌入式编辑器中调用console.log()
应该的内容出现在Firebase日志记录的云功能中。
为了测试,我使用了默认代码,并在定义的两个Intent Handlers中添加了对console.log()
的调用。
/ See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
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));
function welcome(agent) {
console.log('welcome');
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
console.log('fallback');
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});
我确保启用了内联编辑器,进行了部署,然后单击页面底部的链接:
我进行测试时,Firebase控制台会按预期在日志记录部分显示它。
相同的日志记录也在Cloud Console中。请注意,您必须将Resources字段从Global
切换到Cloud Function
。
关于为什么您可能看不到它,老实说,我不确定。需要仔细检查的一些事情很容易忽略: