2
votes

Got the error

MalformedResponse Failed to parse Dialogflow response into AppResponse because of empty speech response

had read Failed to parse Dialogflow response into AppResponse because of empty speech response for Ssml response but still did not get the point.

I'm quite a newbie.

Tried to follow the code provided in "Query Data Scalably for Actions on Google using Cloud Firestore", but got the error.

//Copyright 2018 Google LLC.SPDX-License-Identifier: Apache-2.0

'use strict';

const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const app = dialogflow({debug: true});

admin.initializeApp();

const db = admin.firestore();
const collectionRef = db.collection('restaurants');

app.intent('ask_recipe_intent', (conv, {name}) => {
  const term = name.toLowerCase();
  const termRef = collectionRef.doc(`${term}`);

  return termRef.get()
    .then((snapshot) => {
      const {city, name} = snapshot.data();
      conv.ask(`Here you go, ${name}, ${city}. ` +
            `What else do you want to know?`);

    }).catch((e) => {
      console.log('error:', e);
      conv.close('Sorry, try again and tell me another food.');
    });
});


exports.actionsOracle = functions.https.onRequest(app);

I'm trying to understand what

`${term}`

is and how this is used in Firebase? I don't have any document named "term".

1
What is (${term}) ? I don't have any document in Firebase collection called "term", how this is used in Firebase Document?MubieSam Lin
Please don't add code in comments - it makes it more difficult to understand what your question is. Go ahead and edit the question if you are trying to clarify what you're asking.Prisoner
@Prisoner My question is, where should I look into the error message as title? I'm guessing ${term} should be the problem since I copied the code but don't really understand what this mean.MubieSam Lin

1 Answers

0
votes

You have a few unrelated questions here.

The line

collectionRef.doc(`${term}`);

is overly complex. You can safely rewrite it as

collectionRef.doc(term);

since the backtick-quote doesn't do anything in this case. Backtick quotes in recent versions of JavaScript do expression expansion inside the ${} part. So evaluating the expression

`${term}`

just evaluates to whatever term is. So the result of that function is to create a reference to a document in Firestore named by term, which is just the lowercase version of the name parameter from your Dialogflow Intent.

Which leads us to the error you're getting. That typically happens if you fail to send a reply. Failing to send a reply can happen for a number of reasons, the two most common being

  • You didn't call conv.ask() or conv.close()
  • You are doing an asynchronous operation (such as calling a database) without returning a Promise

However, in your case, it looks like you're doing both.

It seems possible that your function is generating an error before it reaches the database call. The most likely possibility in this case might be the line

const term = name.toLowerCase();

which could be causing an error if name isn't defined, meaning it wasn't a parameter in the Dialogflow Intent.

You may wish to consult the following two articles which also look into debugging Actions on Google Intent fulfillments: