WhatsApp Flows Tools

repository·main·Indexed 41 days ago

https://github.com/whatsapp/whatsapp-flows-tools

A 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.

Tokens
5.8K
Snippets
16
Records
24
Agent score
48%

What's inside WhatsApp Flows Tools

  1. Overview of WhatsApp Flows Tools

    main
    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.
  2. Set up the WhatsApp Flows Webhook Server

    main

    To use this example webhook server for prototyping WhatsApp Flows, follow these steps:

    1. Configure Environment Variables: Create a .env file 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.
    2. Run the Server: Start the Node.js server and identify its base URL.
    3. Configure Meta Dashboard:
      • Append /webhook to 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_TOKEN in the Verify token field.
      • Click Verify and save.
      • Under Webhook fields, click Manage and ensure the messages field is selected.
    4. Customize Logic: Modify server.js to 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
  3. Generate and upload RSA key pairs for WhatsApp Flows

    main

    To secure your Flow endpoint, you must generate a private/public key pair and upload the public key to your business phone number.

    1. Use the included script src/keyGenerator.js to generate the keys:
      node src/keyGenerator.js {passphrase}
    2. Follow the official WhatsApp documentation to upload the public key to your business phone number.
    node src/keyGenerator.js {passphrase}
  4. Set up the WhatsApp Platform Echo Webhook

    main

    This 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

    1. Run the server: Start the Node.js application and identify its public URL.
    2. Prepare the Webhook URL: Append /webhook to your server's base URL (e.g., https://your-domain.com/webhook).
    3. 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_TOKEN value into the Verify token field.
      • Click Verify and save.
    4. Subscribe to Fields:
      • Under the Webhook fields section, click Manage.
      • Ensure the messages field is selected to receive message notifications.

    Customization

    To implement custom business logic (such as responding to specific messages), edit the server.js file in the project root.

  5. Generate RSA Key Pair for Flow Endpoint

    main

    To secure your Flow Endpoint, you must generate a private and public key pair. Use the src/keyGenerator.js script 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}
  6. Generate and upload RSA key pairs for Flow Endpoints

    main

    To secure your Flow Endpoint, you must generate a private/public key pair. Use the included script src/keyGenerator.js to 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}
  7. Set up the WhatsApp Flow Endpoint Server (Pre-approved Loan Example)

    main

    This 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:

    1. 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.
    2. Configure Environment: Set the PASSPHRASE and PRIVATE_KEY environment variables. Ensure multiline keys maintain correct line breaks.
    3. Deploy: Run the server and provide its URL as your endpoint URL in the WhatsApp Flow configuration.
    4. Customize Logic: Modify src/flow.js to 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-----"