我在哪里可以看到在我的Google Action履行功能中记录的console.log消息,或者如何简单地记录调试记录文本?

问题描述 投票:0回答:1

我正在制定一项使用成就的行动。我正在使用内联编辑器。我将硬编码的值移到FireStore中,因此数据存储在函数本身中。 FireStore请求没有按预期进行:尽管实现调用没有失败,但是它没有找到应有的信息。我正在尝试使用老式的console.log类型日志记录,以找出问题所在。但是那些日志消息不会在任何地方显示。

我查看了该功能的Firebase日志,但它仅包含基本事件:执行开始,完成和警告。

enter image description here

我还通过将操作附加到已计划付款的项目来升级该操作,并启用了Stackdriver日志记录。这也没有显示我的自定义日志记录,仅显示样板消息。

enter image description here

然后,我尝试在此之后将自定义Stackdriver登录添加到内联实现功能中:https://firebase.google.com/docs/functions/writing-and-viewing-logs但是我收到一个错误,因为在该内联函数的nodejs环境中无法访问@google-cloud/logging。所以我有点卡住了。我不敢相信没有简单的方法可以简单地登录,但是多次Google搜索并没有产生我可以采取的任何措施。

google-cloud-firestore google-cloud-functions actions-on-google stackdriver dialogflow-fulfillment
1个回答
0
投票

从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);
});

我确保启用了内联编辑器,进行了部署,然后单击页面底部的链接:

Dialogflow Fulfillment Console

我进行测试时,Firebase控制台会按预期在日志记录部分显示它。

Firebase Cloud Functions logging

相同的日志记录也在Cloud Console中。请注意,您必须将Resources字段从Global切换到Cloud Function

Google Cloud Console logging

关于为什么您可能看不到它,老实说,我不确定。需要仔细检查的一些事情很容易忽略:

  • 确认日志记录实际上在应调用的函数中。
  • 确保在添加日志后单击内联编辑器底部的“部署”按钮。
  • 确认已为要通过实现处理的Intent启用了“为此意图启用Webhook调用”。enter image description here确保您正在查看同一项目。
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.