Use Case Guide: Capture interest for a personalised Offer
Intro and Overview
WhatsApp is improving the way that you communicate with your customers to tailor products and services - enabling customers to select, customise, and signal an intent to purchase- all without leaving WhatsApp or speaking to an agent. In this guide, we will walk through the entire process to build a Flow for a ‘Personalised Offer’ use case. The templates here can be adapted to suit your use case. Flows we will build will demonstrate how you can:- Present groups of products for your user to select
- Offer customisation options (budget, size, purpose etc.), to narrow down to a specific product
- Based on their inputs, make recommendations of a list of products, including detailed overview of each product
- Confirm product selection and allow users to proceed with a purchase
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. PRODUCT_SELECTOR Preview Flow What would you like to buy now
- Mobile phones
- eBook readers
- Cameras
Create 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 Personalised offer, or choose another name you like.
- Categories - Select Lead generation.
- Template - Choose Capture interest for a personalised offer. 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 change tenure by selecting an option from the Tenure dropdown. Back in Actions tab notice how the tenure is set to selected new tenure and the action has changed to data_exchange.
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 offer data and pre-sets the radio buttons on the PRODUCT_SELECTOR 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 PRODUCT_SELECTOR we parse selected product_type and based on that set variables for OPTIONS screen. The phone_use_case boolean controls whether the phone related questions are shown on the the OPTIONS screen.
OPTIONS screen response, you should return personalised offer based on the users inputs.
OFFER screen, we receive user’s selected device and should return appropriate device details in response.
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: Capture interest for a personalised Offer
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
