Note: This is an advanced feature that requires some knowledge about regular expressions.
Pattern dialogues allow you to capture information from a user's message and store it in a bot's Context memory for later use.
For example, you could make a bot ask the user "What is your email?", then capture an email with a pattern followup and send it to a webhook, such as the one shown in Example: Chatlog webhook.
A pattern dialogue consists of:
- A key which identifies the captured information.
- One or more patterns.
The captured value will be stored in Context memory under the key provided. Make sure you don't accidentally re-use the same key in different dialogues so you accidentally overwrite your values.
Defining a pattern
If you define multiple patterns, the bot will try to match them in turn, top to bottom.
Enclose the pattern you want to capture in parentheses so that it forms a regex capturing group.
You can also have non-captured parts of the expression outside the parentheses, which will not be collected in context. For example, if your bot asks "What is your email?", you can have both My email is (.+) and (.+) as patterns. The most generic pattern comes last, which in this case is (.+), since the pattern My email is (.+) is more specific than (.+).
Now the user can reply with either "My email is firstname.lastname@example.org or with just "email@example.com", and only the email address will be captured and stored in context.
Read more about how to use context memory in the article on context.
Use with caution
A pattern dialogue is a naive approach to parsing natural text and could be destructive for your bot if too broad/generic patterns are used. To avoid this you should try to keep pattern dialogues out of the root scope of your bot by always defining them as follow ups to other dialogues, reducing risk of capturing unwanted user messages.
In the example above "What is your email?" is a follow dialogue to another dialogue, which in turn has a follow up with a pattern dialogue including the two patterns. By using followup dialogues you can be more confident that your patterns will not give unwanted matches, since you have narrowed down the possible user intents already.