1

I'm now stuck on the problem of getting user input (what user says) in my index.js. For example, the user says: please tell me if {animals} can live between temperature {x} to {y}. I want to get exact value (in string) for what animals, x and y so that I can check if it is possible in my own server. I am wondering how to do that since the entities need to map to some exact key values if I annotate these three parameters to some entities category.

The methods for ApiAiApp is very limited: https://developers.google.com/actions/reference/nodejs/ApiAiApp

And from my perspective, none of the listed methods work in this case.

Please help!

2 Answers 2

2

Generally API.AI entities are for some set of known values, rather than listening for any value and validating in the webhook. First, I'd identify the kinds of entities you expect to validate against. For the temperatures (x and y), I'd use API.AI's system entities. Calling getArgument() for those parameters (as explained in the previous answer) should return the exact number value.

For the animals, I'd use API.AI's developer entities. You can upload them in the Entity console using JSON or CSV. You can enable API.AI's automated expansion to allow the user to speak animals which you don't support, and then getArgument() in webhook the webhook will return the new value recognized by API.AI. You can use this to validate and respond with an appropriate message. For each animal, you can also specify synonymous names and when any of these are spoken, and getArgument() will return the canonical entity value for that animal.

Extra tip, if you expect the user might speak more than one animal, make sure to check the Is List box in the parameter section of the API.AI intent.

Sign up to request clarification or add additional context in comments.

1 Comment

Just want to follow a question, what will be stored in the variable if it can't get the argument? In other words, in index.js we have const animal = assistant.getArgument('animal'); However, we didn't annotate it in the api.ai, how do we check that? The fact is, if we do assistant.ask((variable).toString()) it will only show something if it gets some value and will show NOT AVAILABLE if the argument can't get the value.
0

If "animals", "x", and "y" are defined as parameters in your Intent in API.AI, then you can use the getArgument() method defined in ApiAiApp.

So the following should work:

function tempCheck( app ){
  var animals = app.getArgument('animals');
  var x       = app.getArgument('x');
  var y       = app.getArgument('y');
  // Check the range and then use something like app.tell() to give a response.
}

1 Comment

Hi Prisoner, I tried this before as 'animals' 'x' and 'y' are exact parameters I defined in the intent by using the example annotation to associate them. The problem is, it only gets the mapping value I defined in the entity but not what user says. If it not matches the key value then getArgument() seems not working for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.