简体   繁体   中英

How to store user inputs using fulfillments in dialogflow

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?

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}.`);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM