Use Case Guide: Insurance Quote
Intro and Overview
WhatsApp is making it easier than ever for your customers to understand the options available to them, offering a convenient and immediate solution for getting a quote. Creating an experience within a WhatsApp Flow is a quick and easy way for your customers to interact with your offering, without having to exchange multiple messages back and forth. WhatsApp Flows enables your users to get a quote within the chat thread - providing an experience that is quick and easy for users to complete. In this guide, we will walk through the entire process to build a Flow for a ‘Get Insurance Quote’ use case. The templates here can be adapted to suit your use case. Flows we will build will demonstrate how you can:- Collect relevant information to help build a personalised quote
- Allow your users to customise their preferred excess amount
- Request appropriate personal information of the people who the insurance will cover
- Allow your users to select the payment frequency
- Review available insurance plans based on the selections and present a description for each
- Publish, Send, and Monitor your Flow
Getting Started
To follow this guide, ensure you have:- Completed prerequisites for building Flows.
- A Glitch account
Flows JSON Template
See the Flows reference documentation for JSON schema details. APPLICANTS Preview Flow
Tell us who you’d like to cover?
Who would you like to cover?- Just myself
- Myself & another person
- My family
- Just my children (under 18)
Additional applicant
Additional applicant Number of people you want to add to this policy Continue Managed by the business. Learn more Learn moreCreate new flow from a template
- In the Flows section of WhatsApp Manager click on the Create Flow button in the top right corner.
-
In the Create page, fill in the details for the pre-approved loan Flow:
- Name - Type Insurance Quote, or choose another name you like.
- Categories - Select Lead generation.
- Template - Choose Provide Insurance Quote. You can further customize the template to suit your use case.
- Click Create to create Flow.
Configure Demo Backend on Glitch
WhatsApp Flows lets you connect to an external endpoint. This endpoint can provide dynamic data for your Flow and control routing. It also receives user-submitted responses from the Flow. For testing purposes, this template uses Glitch to host the endpoint. Using Glitch is entirely optional, and not required to use Flows. You can clone the endpoint code from GitHub and run it in any environment you prefer.1. Remix (fork) Glitch endpoint
Access the endpoint code in Glitch and remix it to get your unique domain. To remix it, click Remix at the top of the page. A unique domain will appear as a placeholder in the input element on the right side of the Glitch page.2. Setup encryption key
Private key helps decrypt the messages received. The passphrase will be used to verify the private key. Along with the private key, you also need its corresponding public key, which you’ll upload later. Never use the private keys for your production accounts here. Create a temporary private key for testing on Glitch, and then replace it with your production key in your own infrastructure.-
Generate the public-private key pair by running the command below in the Glitch terminal. Replace
YOUR_PASSPHRASEwith your designated passphrase. Access the Glitch terminal by clicking the TERMINAL tab at the bottom of the page a run following command:node src/keyGenerator.js YOUR_PASSPHRASE - Copy the passphrase and private key and paste them to the .env file. Click on the file labeled .env on the left sidebar, then click on ✏️ Plain text on top. Do not edit it directly from the UI, as it will break your key formatting.
- After you set the environment variables, copy the public key that you generated and upload the public key via the Graph API.
3. Set endpoint URI
Once you set up encryption keys, you can proceed with setting Endpoint URI for your flow.- At the top right of the Glitch page, click on Share and copy the Live Site URL from the displayed modal.
- Head to the Flow Builder and in the Flow Builder click on the three dot menu in top right corner of the screen. Select Setup under the Endpoint section.
- A popup will appear, allowing you to configure the endpoint URI, business phone number, and app on Meta for Developers. Save the Live Site URL copied from the Glitch into the first step of modal.
4. Set App Secret (optional)
App secret is used in signature verification. It helps you check whether a request is coming via WhatsApp and, therefore, is safe to process. You’ll add it to the .env file. To access your app secret, select your App from the dashboard in the Meta for Developers. In the left navigation pane under App settings, choose Basic. Click Show under App secret and copy the secret. Then, return to Glitch, open the .env file, and create a variable named APP_SECRET with the value of the secret you copied. Now you have completed all the required steps to be able to test flow with the provided endpoint. See also- Detailed code walk through for demo backend
- Implementing endpoint for Flows for full details on how to build production endpoint
Testing and Debugging
Debug flow using the interactive preview
After you complete the configurations, toggle the interactive preview in the WhatsApp Builder UI to test the Flow.- Trigger the interactive preview by clicking on settings menu in the Preview section of the Flow Builder and enabling Interactive mode toggle.
- In the modal that appears, select the phone number, enter any string as Flow token and choose the Request data option under Request data on the first screen. This sends a request to the endpoint to retrieve data for the first screen.
init action in the list. Click on it to see the details and you will see the decrypted request sent to the endpoint. There will also be decrypted response received from endpoint with the initial data payload.
Return back to Preview and proceed to select option from radio button selection. Back in Actions tab notice action has changed to data_exchange and selected option is visible when you click on the last entry in the action log under request tab.
Keep testing out the Flow and observe the data changes in the Actions tab. Similar logs will be generated when users interact with the Flow from their mobile devices.
You can also see decrypted request and responses logged in the Glitch LOGS tab at the bottom of the Glitch screen.
Send draft flow to your device
Before you publish your flow you can also send it and test it on an actual device. To send draft flow to your device, follow instructions here. See alsoPublishing
When you first created your Flow, it entered the Draft state. And as you edited and saved the modified Flow JSON content, it remained in the Draft state. You are able to send the Flow while it’s in the Draft state, but only for testing purposes. If you want to send the Flow to a larger audience, you’ll need to Publish the Flow. You can publish your Flow once you have ensured that:- All validation errors and publishing checks have been resolved.
- The Flow meets the design principles of WhatsApp Flows
- The Flow complies with WhatsApp Terms of Service, the WhatsApp Business Messaging Policy and, if applicable, the WhatsApp Commerce Policy
Sending
You can send your WhatsApp Flow as:- Template messages - these do not require a 24-hour customer service window to be open between you and the message recipient before the message can be sent.
- Interactive Flow messages - these can only be sent to a user when a customer service window is open between you and the user.
Receiving flow response
Upon flow completion a response message will be sent to the WhatsApp chat. You will receive it in the same way as you receive all other messages from the user - via message webhook. Learn more about how to setup messaging webhookMonitoring
Flow monitoring is only applicable to Flows with endpoint. After your Flow is published and being sent to the customers, it is important to monitor your Flow’s health and address any problems as they are discovered by WhatsApp. There are multiple ways how you can monitor your flows:-
Metrics Dashboard in WhatsApp Account Manager
- Navigate to Flow section of Whatsapp Account Manager and click on any published flow with the endpoint. You will be presented with a Details page with a Performance Metrics Dashboard.
-
Metrics API
- All the data presented in the Details page is also available to be queried through Flows Metrics API.
-
Quality Webhooks
- You should also subscribe to Flows Quality Webhooks to be updated in real time about the statuses and performance of your business’ Flows.
Next Steps
Now that you have successfully completed this guide, learn more about what you can do with this Flows in our Guides and Reference sections.Overview of demo backend
There are four JavaScript files in the Glitch example src directory:encryption.js, flow.js, keyGenerator.js, and server.js. The entry file is server.js, so let’s look at it first.
server.js
Theserver.js file starts by configuring the Express application to use the express.json middleware to parse incoming JSON requests. Then, it loads the environment variables needed for the endpoint.
server.js file also contains a POST endpoint that performs different steps:
Checks that the private key is present:
encryption.js
This file contains the logic for encrypting and decrypting messages exchanged for security purposes. See Code examples section of Endpoint implementation guide for encryption examples in other languages.keyGenerator.js
This file helps generate the private and public keys, as you saw earlier.flow.js
The logic for handling the Flow is housed in this file. It starts with an object assigned the nameSCREEN_RESPONSES. The object contains screen IDs with their corresponding details, such as the preset data used in the data exchanges. This object is generated from Flow Builder under ”…” > Endpoint > Snippets > Responses. In the same object, you also have another ID, SUCCESS, that is sent back to the client device when the Flow is successfully completed. This closes the Flow.
The getNextScreen function contains the logic that guides the endpoint on what Flow data to display to the user. It starts by extracting the necessary data from the decrypted message.
- A data_exchange request signified by a
data_exchangeaction - An error notification request signified by a
data.errorelement - A health check request signified by a
pingaction
Health check and Error handler
The function handles the health check and error notifications using if statements and responds accordingly, as shown in the snippet below:INIT handler
When a user clicks the Flow’s call to action (CTA) button, a request withINIT action is sent to the endpoint. This action returns the initial data for the APPLICANTS screen.
data-exchange handlers
Fordata_exchange actions, a switch case structure is used to determine what data to send back based on the screen ID and other request data.
For the first screen with ID APPLICANTS we handle two requests. If the cover_for_additional field of the request is not null, it means that the user has selected to add additional applicant and therefore a new additional_applicants_count and add_additional boolean are returned back to the client to keep track of additional applicants.
If the cover_for_additional field of request is null, it means that the user clicked on the Continue button on the Applicants screen. We return the next screen name in the response (COVER_LEVEL) and data received from the client.
For the next two screens, COVER_LEVEL and EXCESS, we set the initial data for next screen and attach data received from the Flow.
On the DETAILS screen, if user has selected they want to cover only their children we skip YOUR_HEALTH screen.
YOUR_HEALTH and we override specific fields in the initial screen data with data received from Flow.
For YOUR_HEALTH screen if cover is just just for myself we take user to POLICY_SELECTION screen next.
ADDTIONAL_APPLICANT screen.
For the ADDTIONAL_APPLICANT screen while applicant_index < data.additional_applicants_count we keep sending user to ADDTIONAL_APPLICANT screen until we have collected information for all additional applicants.
POLICY_SELECTION screen.
POLICY_SELECTION screen we set policy details based on selected_policy and navigate to SELECTED_POLICY screen.
From SELECTED_POLICY we navigate to YOUR_QUOTE screen, where we set payment_option based on what user selected and then navigate to final SUMMARY screen.
After the SUMMARY screen is submitted from the client, a success response is sent to the client device to mark the Flow as complete.
On This Page
Use Case Guide: Insurance Quote
Intro and Overview
Getting Started
Flows JSON Template
Create new flow from a template
Configure Demo Backend on Glitch
1. Remix (fork) Glitch endpoint
2. Setup encryption key
3. Set endpoint URI
4. Set App Secret (optional)
Testing and Debugging
Debug flow using the interactive preview
Send draft flow to your device
Publishing
Sending
Receiving flow response
Monitoring
Next Steps
Overview of demo backend
server.js
encryption.js
keyGenerator.js
flow.js
