0

I was playing a bit with google actions. I defined a custom entity. I would like to match that entity in my package.json:

xports.answerColleague = functions.https.onRequest((request, response) => {
  const app = new App({request, response});
  console.log('Request headers: ' + JSON.stringify(request.headers));
  console.log('Request body: ' + JSON.stringify(request.body));
  let profession = app.getArgument(PROFESSION_ARGUMENT);


// c. The function that generates the silly name
  function answerColleague (app) {

How can i use my custom entity here? Let's say i defined an Entity call Profession. I want to check if profession == Profession.DEVELOPER for example. Where DEVELOPER is one of the row i added in the Entity. How can i access those values to verify which one the user selected?

Thanks.

1 Answers1

1

While the variable profession will contain what the user said, the client library doesn't currently provide any functionality to access an enumeration of the possible values (e.g. Profession.DEVELOPER).

For entities that contain relatively short or static lists of items, I would recommend hard-coding an object in your webhook code that defines the possible values. As long as the items don't change often, this won't be too difficult to maintain. To avoid creating it by hand, you could build it by exporting your Dialogflow agent and then reading the list from the resulting JSON.

If you have a very long or dynamic list of items in your entity, you might want to access them by API and build a list dynamically. This extra engineering and maintenance would likely only be worth it if the items change frequently. You can see the /entities API documentation for information on how to grab an entity's rows via the API.

Daniel Situnayake
  • 2,874
  • 2
  • 30
  • 38