0

I have created an intent in Dialogflow web interface. It auto detected a parameter called given-name, which lists it as $given-name in the web interface. I am trying to address $given-name in the fulfillment inline editor provided by the web interface, but I am not having any success.

I've tried changing the parameter name to camel case, and also alternatively to using an underscore to replace the hyphen but neither seemed to work.

Here is the code snippet from the dialogflow fulfillment inline editor:

'use strict';

// Import the Dialogflow module from the Actions on Google client library.
const {dialogflow} = require('actions-on-google');

// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');

// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});

// Can't address given-name, intentionally used an underscore 
app.intent('run demo', (conv, {given_name}) => {
conv.close('Hi ' + given_name +'! This is the demo you asked me to run!');
});

// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);

I want to know the correct way to address the given name parameter in the code section app.intent('run demo', (conv ...);

Lsakurifaisu
  • 133
  • 1
  • 12
  • Think I found the online documentation: https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html#intent . If someone could confirm that this the correct page that would be greatly appreciated. – Lsakurifaisu Jan 02 '19 at 13:34

1 Answers1

2

Solution

One solution I found is this piece of code:

app.intent('run demo', (conv, params) => {
    conv.close('Hi ' + params['given-name'] +'! This is the demo you asked me to run!');
});

Explanation

The (conv, params) => {...} of app.intent('run demo',... is actually a callback function which is anonymous (aka anonymous callback function). The conv and params are arguments/parameters passed into the callback function. The definition of the function appears to be on this page of the API: Callable. It stats the the parameters/arguments that can be passed in could be conv, params, argument, status.

Final thoughts

The API documentation for actions on google helped: actions on google api reference link

Lsakurifaisu
  • 133
  • 1
  • 12
  • This was a tricky one. I found some code that destructured the param and gave it a name like `{'unit-weight': unitWeight}` but actually the best docs I found was by running it in the test simulator and looking in the debug tabs. It's there that I found out what I needed was `params['unit-weight'].amount`. – rtpHarry Apr 16 '20 at 19:17