How to recognize entities with regular expressions on Dialogflow and Actions Builder

Alessio Pomaro
2 min readSep 8, 2020

In this mini post, in a simple example, we will understand how to make a conversational agent recognize the product code entered by the user within Dialogflow. The principle is the same on Actions Builder and Dialogflow CX.

The following are two examples of code format to recognize:

  • C16Z-1D12–0Y73 (3 blocks formed by 4 alphanumeric characters);
  • SDC-P1-V2–4560 (4 blocks consisting of a variable number of alphanumeric characters)

So I create the “codice-prodotto” entity, and I select “Regexp entity” as the type of recognition.

To describe the formats, I used the following rules.

The regular expressions associated with the entity on Dialogflow
The regular expressions associated with the entity on Dialogflow

To fine-tune regular expressions, also thanks to a series of interesting utilities, I recommend the following tool: Regular Expressions 101 (https://regex101.com/).

An example of a regular expression test
An example of a regular expression test

The image below shows how the entity is recognized in intent training phrases, and how the value is extracted correctly.

The recognition of the entity in the intent training sentences
The recognition of the entity in the intent training sentences

As you can see, I have set the parameter of the product code as “required” and I have set the message to request the code from the user, in case he has not specified it in the conversation.

In the image below, we see an example of a flow in which a chatbot asks the user for the product code, and recognizes it.

An example where a chatbot asks and recognizes the product code
An example where a chatbot asks and recognizes the product code

Clearly the agent asks for the code to offer a service to the user, for example to give him the availability, the price, or other. Then, using the parameter inside the webhook, we can get all the information we want.

--

--

Alessio Pomaro

Head of AI @ Search On Media Group, Docente, Speaker, Autore