Dialogflow fulfillment parameter not accessible

I'm currency trying out dialogflow fulfillment with NodeJS (dialogflow-fulfillment).

I am trying to access the parameters from dialogflow, but when I'm trying to access the currency-name parameter I get the following error: ReferenceError: name is not defined

But when I print the parameters I get: parameters: {"currency-name":["GBP","USD"],"number":500}

Currently using this code:

agent.add("parameters: " + JSON.stringify(agent.parameters.currency-name));
agent.add("parameters: " + JSON.stringify(agent.parameters));

Upvotes: 2

Views: 538

Answers (1)

Prisoner
Prisoner

Reputation: 50741

The problem is that agent.parameters.currency-name is treated as trying to access agent.parameters.currency and subtracting what is in name.

To reference a parameter name that includes characters besides letters and numbers, you need to use [] referencing and a string for the name. Something like this:

agent.parameters['currency-name']

You can also change the name of the parameter in Dialogflow to remove the hyphen.

Upvotes: 2

Related Questions