Scenario: Capture email and phone via Webhooks, validate them individually by filtering using Regular Expressions (Regex) as match patterns, store the valid entries in a Data Store and respond to invalid entries via Responsive Webhooks.
Note: I have used Chatfuel to illustrate the use case of this tutorial but you can use any app that supports Webhooks or replace the Webhook module with any other app supported by Integromat. Also, it is assumed that you are familiar with Chatfuel, Webhooks, Regular Expressions and Data Stores. If you’re not, please refer to the following articles:
Chatfuel and Webhooks: How to connect Chatfuel to Airtable
Regular Expressions: Connect Email, Text Parser and Google Sheets
Data Stores: Typeform + Integromat Data Stores
Level of difficulty: Medium
Implementation Time: Approximately 30 Minutes
----
To get someone to submit their email address or phone number via sales funnels, surveys or forms is not easy. When a prospect does not see enough value or are not interested in what you have to offer, he or she might drop out. Fair enough. No big deal. You can always try again. But there’s a third scenario which is also highly counter-productive. Fake emails and phone numbers. Nobody likes to sift through and delete emails like testing@123.com or phone numbers like 98765432. It’s a thorough waste of time and not a task for sentient beings.
While most apps have inbuilt validation, many are not thorough and leave enough room for an unwanted entry to slip through. Chatfuel’s email validation accepts a@b as a valid email and that is a problem, especially if you’re using a CRM like InfusionSoft to create a new contact with that email address. InfusionSoft’s validation is more thorough and it returns an error on receiving a wrongly formatted email, which can result in your scenario being paused. In such cases, you’ll receive an email from Integromat as below:
To avoid such errors altogether and ensure that you capture data in a valid format, you can set up filters before passing that data to the next module. Using Regular Expressions as Match Patterns, you can effectively validate email addresses and phone numbers. Do not confuse validation with verification though. This tutorial is to only validate the format of the input and not verify if an email or phone exists or matches previous records.
A simple distinction as in the image below can be found here.
In this tutorial, we will validate an email address followed by a phone number, and if both are valid, we update a record in a Data Store. (Read more about Integromat Data Stores here). You can follow the same process to create a row in a Google Sheet or an Airtable Base. If either the email or the phone is invalid, a Webhook Response is set up to prompt the user to retry. The scenario looks like the one below:
Add the Webhook module, select an existing webhook or create a new one, and copy the URL to paste it in the JSON plugin in Chatfuel. If you are new to this, please refer to Step 1 in this tutorial. I have named this module ‘Validation Webhook’.
Now go to Chatfuel to set up the requisite blocks and plugins. To capture data, you can either use the User Input plugin or the newly added User Email and User Phone plugins, whichever you prefer. While you can use this scenario with your existing flow of blocks, I’m going to show the one that I consider neat and easy to comprehend.
We will create the following five blocks (feel free to use your own nomenclature for blocks and attributes):
The setup for all five blocks are shown below:
OR
attribute -> email_validation -> is -> not set
attribute -> email_validation -> is -> false
Note: If you’d like to, you may redirect back to the ‘email_capture’ block instead of ‘email_invalid’ and return a message such as “email is invalid, please try again” from the webhook response directly.
Clone the ‘email_capture’ block and rename it as above. And add the following text block after the Setup user attribute plugin:
This allows you to show the invalid email that a user had typed in and give an option to skip this step. The rest of the block remains as is.
{{first name}}, {{last name}}, {{email}} and {{phone}}
Note: The above attributes are assigned the value ‘true’ via the webhook response when both email and phone are valid (explained later). This scenario will work even if only phone_validation is true.
Clone the ‘phone_capture’ block and rename it as above. And add the following text block after the Setup user attribute plugin:
The rest of the block remains the same as before.
Just add a text block as shown below:
This is the block you will send the user to if both email and phone are valid.
Router is an incredible module that lets you filter data when setting up multiple Actions to a Trigger. It can be found under ‘Flow Control’.
In this scenario, we will use a Router for the following actions:
email -> Does not match pattern -> ([\w.-]+@[\w.-]+)
The response is sent if the value of the attribute email does not match the format of the Regular Expression.
You can test the above on https://regex101.com/ by pasting the regex,([\w.-]+@[\w.-]+) under REGULAR EXPRESSION and typing in an email address under TEST STRING. Make sure you choose Javascript as the FLAVOR.
phone -> Does not match pattern -> ^[+]?\(?(\d{1,3})\)?[\s-]?\(?(\d{3})\)?[\s-]?\d{3}[\s-]?\d{3,4}
The response is sent if the value of the attribute phone does not match the format of the Regex above.
phone -> Matches pattern -> ^[+]?\(?(\d{1,3})\)?[\s-]?\(?(\d{3})\)?[\s-]?\d{3}[\s-]?\d{3,4}
AND
email -> Matches pattern (case insensitive) -> ([\w.-]+@[\w.-]+)
At this point you must save your scenario and rename the modules to keep the setup clean and toggle the Scheduling switch to ON.
If you have followed the tutorial correctly, your Chatfuel bot is all set to validate emails and phone numbers and store them in a Data store. If both are valid, you should see a new row as below:
Wow! If you’ve got this far, I hope you’ve learned a thing or two. Do leave a comment if you have queries or are stuck somewhere.
Happy Automating!