WhatsApp Flows Tools
repository·main·Indexed 41 days ago
https://github.com/whatsapp/whatsapp-flows-toolsA collection of scripts, code examples, and server implementations for building and managing WhatsApp Flows. It includes Node.js and C# examples for Flow Endpoints, RSA key generation tools for secure communication, and webhook implementations for prototyping with the WhatsApp Business Cloud API.
What's inside WhatsApp Flows Tools
- WhatsApp Flows Tools is a collection of scripts and code examples designed to assist developers in building WhatsApp Flows. It provides implementation patterns and server-side components to handle the logic required for interactive WhatsApp Flows.
Set up the WhatsApp Flows Webhook Server
mainTo use this example webhook server for prototyping WhatsApp Flows, follow these steps:
- Configure Environment Variables: Create a
.envfile or set the following variables in your environment:WEBHOOK_VERIFY_TOKEN: A custom string used to verify the webhook connection with Meta.GRAPH_API_TOKEN: A Temporary access token obtained from the Meta for Developers dashboard under WhatsApp > API Setup.FLOW_ID: The specific ID of the WhatsApp Flow you intend to interact with.
- Run the Server: Start the Node.js server and identify its base URL.
- Configure Meta Dashboard:
- Append
/webhookto your server URL (e.g.,https://your-domain.com/webhook). - In the Meta for Developers dashboard, navigate to WhatsApp > Configuration.
- In the Webhook section, click Edit.
- Paste your URL and enter the value used for
WEBHOOK_VERIFY_TOKENin the Verify token field. - Click Verify and save.
- Under Webhook fields, click Manage and ensure the
messagesfield is selected.
- Append
- Customize Logic: Modify
server.jsto implement your specific business logic for handling incoming webhook events.
# Required environment variables WEBHOOK_VERIFY_TOKEN=your_chosen_token GRAPH_API_TOKEN=your_meta_access_token FLOW_ID=your_flow_id- Configure Environment Variables: Create a
Implement Flow screen navigation logic
mainTo customize how the Flow moves between different screens, edit the logic withinsrc/flow.js. This file serves as the core controller for navigating the user through the appointment booking flow.Generate and upload RSA key pairs for WhatsApp Flows
mainTo secure your Flow endpoint, you must generate a private/public key pair and upload the public key to your business phone number.
- Use the included script
src/keyGenerator.jsto generate the keys:node src/keyGenerator.js {passphrase} - Follow the official WhatsApp documentation to upload the public key to your business phone number.
node src/keyGenerator.js {passphrase}- Use the included script
Set up the WhatsApp Platform Echo Webhook
mainThis project provides a simple Node.js webhook implementation designed for prototyping with the WhatsApp Business Cloud API. It mirrors the official Meta webhook setup process, allowing you to receive and acknowledge incoming WhatsApp messages.
Environment Variables
You must configure the following environment variables before running the server:
WEBHOOK_VERIFY_TOKEN: A custom string of your choice. This must match the token you provide in the Meta for Developers dashboard during the webhook verification step.GRAPH_API_TOKEN: Your WhatsApp access token. You can obtain a Temporary access token from the API Setup section under WhatsApp in your Meta for Developers app dashboard.
Deployment and Configuration Steps
- Run the server: Start the Node.js application and identify its public URL.
- Prepare the Webhook URL: Append
/webhookto your server's base URL (e.g.,https://your-domain.com/webhook). - Configure Meta Dashboard:
- Navigate to your app on Meta for Developers.
- Go to WhatsApp > Configuration.
- In the Webhook section, click Edit.
- Paste your URL into the Callback URL field.
- Enter your
WEBHOOK_VERIFY_TOKENvalue into the Verify token field. - Click Verify and save.
- Subscribe to Fields:
- Under the Webhook fields section, click Manage.
- Ensure the
messagesfield is selected to receive message notifications.
Customization
To implement custom business logic (such as responding to specific messages), edit the
server.jsfile in the project root.Generate RSA Key Pair for Flow Endpoint
mainTo secure your Flow Endpoint, you must generate a private and public key pair. Use the
src/keyGenerator.jsscript provided in the example directory. Replace{passphrase}with your chosen secret passphrase.After generation, you must upload the public key to your business phone number to allow WhatsApp to communicate securely with your endpoint.
node src/keyGenerator.js {passphrase}Set up the WhatsApp Flow Endpoint Server for Appointment Booking
mainThis example server is designed to work with the appointment booking Flow template. It provides a Node.js implementation for handling Flow endpoint requests.
Note: This implementation is intended for prototyping only and is not production-ready.
Generate and upload RSA key pairs for Flow Endpoints
mainTo secure your Flow Endpoint, you must generate a private/public key pair. Use the included script
src/keyGenerator.jsto create the pair, then upload the public key to your business phone number following the official WhatsApp documentation.Run the following command in your terminal, replacing
{passphrase}with your chosen secret:node src/keyGenerator.js {passphrase}Set up the WhatsApp Flow Endpoint Server (Pre-approved Loan Example)
mainThis example provides a Node.js implementation of a Flow Endpoint specifically designed for the pre-approved loan Flow template.
Note: This project is intended for prototyping only and is not production-ready.
Setup Steps:
- Generate Keys: Use the included script to create a private/public key pair for testing. You must then upload the public key to your business phone number as per the WhatsApp documentation.
- Configure Environment: Set the
PASSPHRASEandPRIVATE_KEYenvironment variables. Ensure multiline keys maintain correct line breaks. - Deploy: Run the server and provide its URL as your endpoint URL in the WhatsApp Flow configuration.
- Customize Logic: Modify
src/flow.jsto implement your specific screen navigation logic.
# Generate key pair node src/keyGenerator.js {passphrase} # Example Environment Variables export PASSPHRASE="my-secret" export PRIVATE_KEY="-----[REPLACE THIS] BEGIN RSA PRIVATE KEY-----\nMIIE...\n...\n...xyz\n-----[REPLACE THIS] END RSA PRIVATE KEY-----"Implement Flow navigation logic in src/flow.js
mainThe core logic for navigating between different screens in a WhatsApp Flow is located insrc/flow.js. You should edit this file to define how your endpoint responds to requests and how it directs the user through the flow's screens.Set up the WhatsApp Flow Endpoint Server example
mainThis example implements a Flow Endpoint specifically designed for the insurance quote Flow template.
Note: This implementation is for prototyping purposes only and is not production-ready.
Generate and upload RSA key pairs for Flow testing
mainTo secure your Flow endpoint, you must generate a private/public key pair.
- Use the included script
src/keyGenerator.jsto generate the keys:node src/keyGenerator.js {passphrase} - Follow the official steps to upload the generated public key to your WhatsApp Business phone number.
node src/keyGenerator.js {passphrase}- Use the included script