Pattern matched engagements
Engagements give your FAQ Bot maximum flexibility to trigger forms, actions or sequences of messages based on what is typed in chat, plus other context. Learn more about engagements.
One way to trigger an engagement is when a user types something into the chat with a defined pattern.
- an email address
- a reference number (based on a predictable pattern - eg 12 digits, 8 digits starting with 00, an 11 character string starting with three letters)
There are three steps to setting up a pattern matched engagement.
Step one: set up a context key
We use a context key to store the matched value.
To set a new context key, go to Configuration > Bot context. (Can't see Bot context on your menu? Contact us to enable).
The name of your context key should match any other uses of that context within the bot/portal. For example, if you are matching a reference number, the context key could be named Reference, corresponding to a form field also named Reference.
There are three options for the scope of the context key:
- Message - persists for that message only and then is 'forgotten' by the bot
- Conversation - persists for the conversation before being 'forgotten' by the bot. A conversation is a series of messages that may last up to a number of hours, but not over multiple days.
- User - is forever attached to that user - typically this would be used for a name, for example.
The sensitivity setting allows you to mask sensitive data collected
Data contained in the context key can be viewed and modified by the owner. This can be set to the user or the system.
Step two: define the pattern
The pattern is expressed as a regular expression (or regex).
If you're not familiar with regular expressions, you could try using ChatGPT to help you formulate it. Here is an example:
Prefer to build from scratch? Here's a reference guide that might be useful.
You can also try this site as you build and test - select .NET (C#) flavor of regex.
It's important to test your regular expression, to make sure that it captures different examples of the pattern you're looking for (and doesn't capture, for example, longer strings that contain the match but also extra info).
Once you have formulated your regex, you can also test it on some different examples here.
Feel free to get in touch if you need help formulating your regular expression.
Step three: set up your engagement
- Create a new engagement and select "Pattern matched"
- Enter your regular expression from step two in the Pattern field
- Enter your context key from step one in the Context key field
Set up the engagement action as you normally would for any engagement.
A pattern matched engagement does have an additional option of collecting context from the pattern match.
In this case there wouldn't be any visible action for the user, but the context recognised in the pattern (eg email address, reference number) is collected and stored (if allowed for in step 1).
Test it out
Once you have saved your engagement, you can test in your bot by typing some words/phrases including your pattern, and make sure everything works as you expect.