In this guide, we will walk you through the process of capturing and reusing user input within a conversation, using the example of a 5-digit zip code. By using a Regular Expression (regex) entity, we’ll show you how to capture the zip code entered by the user, store it in a Conversation Variable, and then reuse it throughout your interactions. This method allows for dynamic and personalized responses based on user input, improving the overall conversational experience. Let’s get started!
Step 1: Create a Regular Expression Entity (Regex)
- Create a new 'expression' entity: This entity will recognize specific patterns in user input. In this case, you'll use it to capture numbers.
- Define the regex pattern: For example, if you want to capture 5-digit numbers, use a regex pattern that matches this format.Example:
- Regex for capturing 5-digit numbers:
\d{5}(-\d{4})?
- This will match any sequence of exactly five digits.
Step 2: Link the Entity to a Conversation Variable
- Create a Conversation Variable: This variable will store the value captured by the regex entity.
- Link the Regular Expression entity to the Conversation Variable: This ensures that when the user provides input, the regex entity extracts the number and saves it in the variable.
Step 3: Create an Article to Capture the Input
- Create a new article: This article will be used to capture and respond to the user input.
- Add a question that will trigger the regex: 12345
- Add the Conversation Variable to the Answer: In the response, include the conversation variable to dynamically repeat the captured number back to the user. Example:
- "You entered the number: {{conversation.variable}}"
Step 4: Use the Conversation Variable in Other Articles or Dialogs
- Reusing the Variable: You can now use the Conversation Variable wherever you need to repeat the captured value across multiple articles, dialog nodes, or event answers. Example:
Additional Considerations
Handling Special Characters: If the number input includes characters like dashes or spaces (e.g., 123-456 or 123 456), the system may strip out these symbols, possibly resulting in an unintentional input format (e.g., 123456). Test your regex pattern to ensure it captures the number correctly in these cases.