What is your goal?
Get an email and put in a database once my chatbot ask for it.
What is the problem & what have you tried?
Hi Everyone
I have an scenario that connects OpenAI agent to WhatsApp for business working as a chatbot. This scenario is capable to follow the conversation using the threadid from OpenAI agent but I need to ask in some point the email to the user through the conversation to store in a database to use it later.
The only way that comes to mi mind is validate every message that I get from the user using some kind off regular expression validator to identify the email.
¿Any better Idea?
See the image from my scenario layout attached.
Screenshots (scenario flow, module settings, errors)
1 Like
Hey there,
if you want this to happen independently of the conversation, add a third route on the router without a filter so it always executes. Follow it with a Match pattern module that uses a regex to check the incoming message for a valid email address. If the Match pattern finds anything → store it in a Data Store (or wherever).
Hi thanks for your suggestion!
I think is important to keep the email related to the conversation because this ChatGPT chatbot is working as a Virtual University assistant, in some point this chatbot will ask for the email to further contact by the sales department. Is important to keep related the email to the other info collected in the conversation (phone number, thread_id).
So, my next question, this regex validation should be right after every message arrives?
No, I meant so you don’t track when the assistant asked for the email and then check the response for a valid email.
You still do the check within the same conversation, its just parallel to the conversation, you check each incoming message if it has a valid email inside.
3 Likes
Ok… I will try this and i ‘ll go back to tell you the results. 
Thanks again, greetings from Mexico 
Just to add a practical tip for the regex approach - here is a simple email pattern you can use in the Match Pattern module:
[a-zA-Z0-9._%±]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}
This will catch most email formats from the user messages.
Another approach you could try is using the OpenAI module with function calling. You can define a function in the OpenAI agent that captures contact information. When the user provides their email, the agent will automatically call that function and return the email in a structured format. This way you dont need regex at all and the AI handles the extraction naturally as part of the conversation.
But for a quick solution, the third route with Match Pattern as suggested above works well. Just make sure to link the extracted email to the thread_id so you can associate it with the right conversation in your database.
1 Like
Works perfectly with an independent branch.
I’ve tested with a simple filter too and already created the regex using chatgpt 
For now is the better solution to catch an email to store in my database.
Thanks!