0

I'm trying to make an app for Google Home that takes a users weight and says it back to them. Below is the index.js code for the intent responsible for doing this,

const functions = require('firebase-functions');
const {dialogflow} = require('actions-on-google');

const app = dialogflow({
    debug: true,
});

app.intent('vitals-weight', (conv) => {
    const weight = conv.parameters['weight'];
    const weight_name = conv.parameters['weight-name'];
    conv.ask('I have recorded that your weight is, ${weight} and ${weight-name}.');

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

'weight' and 'weight-name' are the entities in the intent that store the weight and the weight unit respectively. Is this the correct approach when trying to handle user data?

  • Did you try this? Did you get any errors? StackOverflow works best if you come to us with concrete questions related to the code you're working with. Responding if something is "correct" can be arbitrary. – Prisoner Jan 04 '19 at 20:55
  • I updated the code with square brackets instead of round for the declaration of weight and weight_name and the app does not crash at this intent anymore, but it is not displaying the stored values for weight and weight name. So my question is how do I get Google Home to relay the value stored in weight and weight_name? – user10687878 Jan 04 '19 at 21:08
  • Well, what *is* it doing? Any errors in the logs? – Prisoner Jan 04 '19 at 21:58
  • No there are no errors, it just returns "I have recorded that your weight is, ${weight} and ${weight-name}." (literally with the dollar signs, curly brackets and all).. – user10687878 Jan 04 '19 at 22:46

1 Answers1

0

You have several errors in your code as it exists right now.

First is what I assume is a paste error. There is no closing bracket or parenthesis for the function. Since you say the function is being called, I assume this is actually in your code.

Your call to conv.ask() has a few logic errors.

The first is that you're using single quotation marks (or apostrophes), but are trying to do expression evaluation inside it (the ${} part). Expression evaluation is only done using backtick quotes `.

Additionally, you have an expression ${weight-name}, which I think you're trying to use to access the weight-name parameter (with a hyphen). But you've assigned the value of that parameter to a variable named weight_name (with an underscore). It is a good thing you did, too, since ${weight-name} is evaluated as "weight minus name", rather than as a variable with a hyphen in it, which isn't allowed. You probably want ${weight_name} there.

So that line should look something more like

conv.ask(`I have recorded that your weight is, ${weight} and ${weight_name}.`);
Prisoner
  • 49,922
  • 7
  • 53
  • 105