Where can I see console.log messages logged in my Google Action fulfillment function or how can I simply log debug logging text?

Viewed 2267

I'm developing an action which uses fulfillment. I'm using the Inline Editor. I'm moving hard coded values into FireStore so data is stored inside the function itself. The FireStore request don't go as intended: although the fulfillment call doesn't fail it doesn't find the information it supposed to. I'm trying the good old console.log type logging to try to figure out what goes wrong. But those log messages don't show anywhere.

I looked at the Function's Firebase log, but it only contains basic events: execution started, finished, and a warning.

enter image description here

I also upgraded the action by attaching it to a payment planned project, and enabled Stackdriver logging. That also did not display my custom logging, only boilerplate messages.

enter image description here

Then I tried to add custom Stackdriver logging into the Inline fulfillment function following this: https://firebase.google.com/docs/functions/writing-and-viewing-logs But I get an error because the @google-cloud/logging is not accessible in the nodejs environment of that inline function. So I'm kinda stuck. I cannot believe there's no easy way to simply log, but multiple Google searches didn't yield anything usable I could act on.

2 Answers

Calling console.log() from the Inline Editor in Dialogflow should have the contents appear in the Cloud Functions for Firebase logging.

To test, I used the default code, and added a call to console.log() in the two Intent Handlers defined.

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

I made sure the Inline Editor was enabled, the deployment happened, and then clicked on the link at the bottom of the page:

Dialogflow Fulfillment Console

When I test it, the Firebase Console shows it in the logging section, as expected.

Firebase Cloud Functions logging

This same logging is also in the Cloud Console. Note that you have to switch the Resources field from Global to Cloud Function.

Google Cloud Console logging

As for why you might not be seeing it, I'm honestly not sure. Some things to double-check which are easy to overlook:

  • Confirm the logging is actually in the functions that should be called.
  • Make sure you have clicked the "Deploy" button at the bottom of the Inline Editor after you have added the logging.
  • Confirm that "Enable webhook call for this Intent" is turned on for all the Intents you want to handle with fulfillment. enter image description here
  • Make sure you're looking at the same project.
Related