Force Dialogflow to get user’s name before continuing the conversation

I got this question recently:

I am trying to make a Chatbot that can request an information no matter where the user initiate the conversation.
An example:
User says: Hi, what you can do?
Chatbot says: Hi, I can do a lot of things, what is your name?
User says: I am Nicolas.
Chatbot says: Nice to meet you Nicolas.
User says: Can you help me to find a cheap flight to Brazil?
Chatbot says: Of course Nicolas, let’s take a look.

But I want that the chatbot request his name no matter where the user start the conversation:

Other Example:
User says: Can you help me to find a cheap flight to Brazil?
Chatbot: Of course, but can you tell your name before it?
User says: My name is Nicolas.
Chatbot: Ok Nicolas, let’s take a look.

Can I do something like this in Dialogflow or just by code?

What the user wants to do is to

a) acknowledge the already known information (e.g. find a cheap flight to Brazil) and

b) still force the user to provide a certain piece of information before moving on (their name)

Flowchart

This is a good time to pull out your XMind and build out a little flowchart.

Here is what I came up with:

If this flowchart has a slightly different look and feel from the previous ones on my site, it is because I upgraded from XMind 7.5 to XMind 8.0.

Also, you can read this article to understand the conventions I am using in this flowchart.

Logic

Here is the basic idea:

1 We need to know two things – the user’s name and the task they want to accomplish. In this case it seems like the reader wants to only accomplish a single task, but a given chatbot may have multiple functions. (e.g. you might later add a task to get flight status)

2 List the different ways the user might start the conversation

3 For each such input, note if they are specifying a task that the bot can do

4 If they are, then create an output context which indicates that you have already received the task and need to know the name

5 If they simply say “what can you do?” or “Hi”, then first ask them for their name, and create an output context which indicates that you need to receive both task and user’s name

6 Once both inputs have been collected, the flowchart should usually converge to get the next input from the user

Intents

Here are the intents inside the Dialogflow console

First, here is the intent where user asks what the bot can do. The bot asks for the user’s name first.

User provides their name, but task is still not known.

User provides task. Notice how we pull the name of the user from the context (in the response).

User starts by specifying the task. Bot asks for their name first.

User provides their name. Since the task is already known, the bot simply moves on to the next step.

What should the next step be? That is decided by the bot creator.

Output

Here are two sample conversations showing the two different flows:

>