Home / DialogFlow ES / DialogFlow tutorial: Capturing non-English names from user input
DialogFlow ES

DialogFlow tutorial: Capturing non-English names from user input

Update Nov 2019 : This tutorial was written in Oct 2017. Dialogflow has since introduced system entity extensions, so you can use that instead. However, I have left this article as it is because the other stuff I talk about (overuse of @sys.any) is still valid.

In a recent coaching call, a client of mine had some difficulty capturing names using the @sys.given-name entity. In fact, the name which he tried and which failed, was mine 🙂

He replaced the name with @sys.any and was able to capture the name. So he got curious: why not just use @sys.any everywhere? It is not a good idea, and this article will describe why.

Capturing non-English names

First of all, I believe DialogFlow will soon become smart enough to capture a whole lot more names simply because they now have access to Google’s data and expertise in this area.

But at the moment, it is very challenging.

However, using the @sys.any wildcard entity comes with a set of challenges and you should learn about those challenges before using it willy nilly.

Putting only the @sys.any in your userSays

So when DialogFlow prompts for a name, most people are not going to say “My name is Aravind”. They will simply say, “Aravind”. You might think it is a good idea to just use @sys.any alone in the userSays. You will run into two possible issues:

Sometimes users will say a question back. “Do you mean my first name?” or “I don’t wish to give you that information” or some thing like that. Now since you used the @sys.any you wouldn’t really have any way to capture this information, and you might instead reply with “Hi $name. Nice to meet you”. As you can imagine, starting off a conversation with “Hi I don’t wish to give you that information. Nice to meet you” won’t make your chatbot look particularly smart.

There is a second challenge. Suppose you didn’t have an input context for the intent which captures the name, that means every intent which has no input context (i.e. probably most of your intents) is now a candidate for selection. When there are multiple candidates for selection, the @sys.any intent has to work extra hard to figure out whether it is the actual winner. And from experience, I can tell you that sometimes it fails.

Parsing the @sys.any on your webhook

So you might choose to get the full string in the @sys.any and see if it matches any names in your database in your webhook code. When you do this, you will run into a new set of challenges.

Incomplete name database

As you do this, you might simply not have the name even in your database (unless your database is really exhaustive).

Typos in names

You might have the name in your database, but the user might have made a typo. This means the name is not going to match.

Nearby and almost matches

You can, finally, try to handle typos by using some type of program which can do “nearby” and “almost” matches, such as the Levenshtein distance. First, it is not that straight-forward to implement these algorithms (especially if you customize the scoring rules to handle special cases).

But more importantly, by the time you reach this point, you are almost replicating the functionality that DialogFlow is doing for you. So here is a rule of thumb:

Don’t build a mini-DialogFlow in your code in the name of improving accuracy

So what is the alternative?

Suggested approach

Here is my suggested approach:

  1. For the intent which prompts for the user name, be sure to add an output context (this makes sure there is a context for the intent which gets the name, and reduces the selection candidate list)
  2. Create a name entity which can capture as many names as possible. Use the approach shown in the video below to extend the @sys.given-name entity. Let us call the entity @namelist.
  3. Create one intent which uses the @namelist entity
  4. Create a fallback intent with the same context, and simply respond with “I couldn’t get that name. Can I just call you Guest?” or some variant.
  5. Important: Later, analyze your Training/History tab and look for this particular fallback intent. Now copy the user’s name and add it to @namelist.

Obviously, if you are capturing the name so you can do a lookup, this isn’t going to work very well. Also, there are probably going to be some scenarios where calling the user by their name is extremely important.

For scenarios where you wish to use it just to address the user, this approach is probably the most reasonable tradeoff between accuracy, development time and smooth conversation flow.

<— End of article —>

This website contains affiliate links. See the disclosure page for more details. 
"The magic key I needed as a non-programmer"

The custom payload generator was the magic key I needed (as a non-programmer) to build a good demo with rich responses in DialogFlow Messenger. I've only used it for 30 minutes and am thrilled. I've spent hours trying to figure out some of the intricacies of DialogFlow on my own. Over and over, I kept coming back to Aravind's tutorials available on-line. I trust the other functionalities I learn to use in the app will save me additional time and heartburn.

- Kathleen R
Cofounder, gathrHealth
"Much clearer than the official documentation to be honest"

Thanks a lot for the advice (of buying and following your videos)! They helped a lot indeed. Everything is very clear when you explain, much clearer than the official documentation to be honest 🙂

Neuraz T
Review for Learn Dialogflow CX
"I will strongly recommend this course because even I can learn how to design chatbot (no programming background)"

I think Aravind really did a great job to introduce dialogflow to people like me, without programming background. He organizes his course in very clear manner since I have been a college professor for 20 years. It is very easy for me to recognize how great Aravind’s course is! Very use-friend and very easy to follow. He doesn’t have any strong accent when he gives the lectures. It is so easy for me to understand. Really appreciate it.

Yes, I will strongly recommend this course because even I can learn how to design chatbot (no programming background) after studying Avarind’s course, you definitely can!

Ann Cai
Review for Learn Dialogflow ES

Similar Posts

  • Hi Aravin! Thank you by the video. I Really like Mining Bussiness.

    I have a issue with your solution… When i put @sys.given.name:name inside another Entitie my bot return: “Hi [Object Object]”. And the parameter value is: “name { “name”: “John” }”. In this case seems like DIalogflow create a new .JSON like name, and i can’t acces this data in a normaly way with ${name}.

    Do you have some idea about why this is happening?

    • Can you paste a link to a screenshot of the entity definition, and another screenshot of how you are using the entity value inside your response?

    • First of all, make sure you check out the system entity extension feature. You don’t need this tutorial if you can already make use of the system entity extensions.

      In general, if you need to take a list of values in a text file and upload them to an entity, the simplest way would be to load them into Excel/Google Sheets, use a simple formula to convert it into the correct CSV format in a new computed column, and then paste everything from the computed column as CSV using the bulk upload feature.

    • Can you give an example when you need to do this differentiation? In the chatbots I have helped build, this hasn’t been an issue (since pronouns are very common, they are usually considered just regular words and not entities).