RegEx entity in Power Virtual Agents
Microsoft has introduced a new feature called RegEx entities in Power Virtual Agents. This blog shows how you can use RegEx entities to validate input of a user who interacts with a Power Virtual Agent.
Regular Expressions have always been a great way of validating field values. It is a sequence of characters which defines a search pattern. And now it is possible to use your own regular expressions in Power Virtual Agents: Regex (regular expression) entity support in Power Virtual Agents.
UK Postcode example
To explore this feature I am going to use a challenging example, UK Postcodes. There has been a lot of debate about this one, but for demo purposes I am using the expression below:
Before you start with the Power Automate flow and the Power Virtual Agent setup you need to make sure you request a 30-day trial API key at GetAddressIO. Obviously there are also other services out there. For me this was just the easiest one to setup for a demo.
The flow steps
2. Add three Initialize variable actions. Below is a table with the name, type and value for each of the variables.
|ApiKey||String||Your key from the trial|
3. Add a HTTP action. Use the GET method to interact with the Find Method of the Get Address IO API. Use the URI from below.
4. Add a Return value(s) to Power Virtual Agents action. Use the following expression.
In this expression I am retrieving the 10th item of the result set. It probably makes more sense to retrieve the first item. In that case replace  by the index reference .
The bot steps
1. Create a new blank topic.
2. Give it a name, in this case FindLocation. Add some trigger phrases. Via these you can interact with your topic. Save the topic.
3. Click Entities on the left menu. Click New Entity. Select Regular expression (Regex) option in the dialog.
4. Add a name, description and a pattern for your new RegEx entity. I used UK Postcode and the pattern below. Save the entity.
5. Go to the Authoring canvas of your topic. Add the first question, What is your postcode?. You now should be able to select your new RegEx UK Postcode entity from the list for this question.
6. Add another question, What is your house number? This time use the Number type for the question.
7. Add a Call an action. Connect it to your earlier created flow. Make sure you map the variables of the questions to the input fields of the flow.
8. Add a message action. Use the AddressFound variable in the body of the message to show the address which the bot has found to the user.
Testing the final result
Test the bot with some data. As you can see it will respond with Sorry, I didn’t understand if it isn’t a postcode which matches our Regular Expression.