Search code examples
dialogflow-es

How do I create a Dialogflow custom entity that works like @sys.airport?


Since @sys.airport only exists for the default English locale, I want to create a custom entity that emulates it for other locales. From what I've read here, you can put subentity types into the value fields, say, the system entity @sys.geo-city:city and a custom entity @usr.iata-code:iata, and it will match either one or the other.

But I don't understand how you would tell Dialogflow which city and which IATA code go together, so that Dialogflow (ES) would know to send the complete object {"city":"Amsterdam", "iata": "AMS"} to the webhook after matching either "Amsterdam" or "AMS", as it does happen with @sys.airport.

Thanks for any input!


Solution

  • It will be difficult to create a custom entity that works just like @sys.airport. The @sys entities are special and can do somethings custom entities can't, for instance, pairing values together.

    As you pointed out, you can put multiple entities together in one single entity by using Composite Entities, but the only thing this does is allow you to recognize two values made up from other @sys or custom entities in a single entity. It doesn't give you the option to create pairs between the values of the entities.

    If you would want to create something like this, you would need some code that does a look up in a dictionary or list. So when "AMS" is matched, the code fills in the missing property "Amsterdam" or vice versa.