WhatsappElixir.Flows (whatsapp_elixir v0.1.9)
View SourceModule for managing WhatsApp Flows including creation, publishing, updating, and lifecycle management.
Key Functions
create_flow/2: Create a new Flow with optional publishingupdate_flow_metadata/3: Update Flow name, categories, or endpointupdate_flow_json/3: Update Flow's JSON content via file uploadpublish_flow/2: Publish a Flow to make it available for customersdeprecate_flow/2: Mark a published Flow as deprecateddelete_flow/2: Delete a Flow (only available for DRAFT status)get_flows/2: List all Flows for a WhatsApp Business Accountget_flow/2: Retrieve details of a specific Flowget_flow_assets/2: List all assets attached to a Flowgenerate_preview/2: Generate a web preview URL for Flow visualizationmigrate_flows/3: Migrate Flows between WhatsApp Business Accounts
Flows Overview
WhatsApp Flows are interactive experiences that allow businesses to create structured conversations with customers. Flows can be used for various purposes including:
- Sign up and sign in processes
- Appointment booking
- Lead generation
- Customer support
- Surveys and feedback collection
Flow Categories
SIGN_UP: User registration flowsSIGN_IN: User authentication flowsAPPOINTMENT_BOOKING: Scheduling and booking flowsLEAD_GENERATION: Lead capture flowsCONTACT_US: Contact and inquiry flowsCUSTOMER_SUPPORT: Support and help flowsSURVEY: Survey and feedback flowsOTHER: General purpose flows
Flow Status
DRAFT: Flow is under development, can be tested with draft modePUBLISHED: Flow is live and can be sent to customersDEPRECATED: Flow is retired and cannot be sent or openedBLOCKED: Flow endpoint is unhealthy, cannot be sent or openedTHROTTLED: Flow endpoint has issues, limited to 10 messages per hour
Prerequisites
To use the Flows API, you need:
- Message templates (view and manage) permissions
- Phone Numbers (view and manage) permissions
- Verified business with high message quality
- Meta application connected to Flows with endpoints
For complete details, see the WhatsApp Flows API documentation.
Summary
Functions
Creates a new Flow.
Deletes a Flow. Only Flows in DRAFT status can be deleted.
Deprecates a published Flow, preventing it from being sent or opened.
Generates a web preview URL for visualizing and testing a Flow.
Retrieves details of a specific Flow.
Lists all assets attached to a specific Flow.
Lists all Flows for a WhatsApp Business Account.
Migrates Flows from one WhatsApp Business Account to another.
Publishes a Flow, making it available to send to customers.
Updates a Flow's JSON content by uploading a JSON file.
Updates a Flow's metadata (name, categories, endpoint_uri, application_id).
Functions
Creates a new Flow.
Parameters
flow_data: A map containing the following keys::name(string, required): Flow name:categories(list, required): List of Flow categories (at least one required):flow_json(string, optional): Flow's JSON encoded as string:publish(boolean, optional): Whether to publish the Flow immediately (requires flow_json):clone_flow_id(string, optional): ID of source Flow to clone:endpoint_uri(string, optional): URL of the WhatsApp Flow Endpoint (for Flow JSON v3.0+)
custom_config(keyword, optional): Custom configuration for the HTTP request
Examples
# Create a simple draft Flow
iex> flow_data = %{
...> name: "Customer Survey",
...> categories: ["SURVEY", "CUSTOMER_SUPPORT"]
...> }
iex> WhatsappElixir.Flows.create_flow(flow_data)
{:ok, %{"id" => "flow123", "success" => true, "validation_errors" => []}}
# Create and publish a Flow with JSON content
iex> flow_data = %{
...> name: "Lead Generation Form",
...> categories: ["LEAD_GENERATION"],
...> flow_json: "{"version":"5.0","screens":[...]}",
...> publish: true,
...> endpoint_uri: "https://example.com/webhook"
...> }
iex> WhatsappElixir.Flows.create_flow(flow_data)
{:ok, %{"id" => "flow456", "success" => true}}Returns
{:ok, response}on success with Flow ID and validation errors if any{:error, response}on failure
Validation
- Raises
ArgumentErrorif required fields (name,categories) are missing - Raises
ArgumentErrorif categories contain invalid values - Raises
ArgumentErrorifpublishis true butflow_jsonis not provided
Deletes a Flow. Only Flows in DRAFT status can be deleted.
Parameters
flow_id(string): ID of the Flow to deletecustom_config(keyword, optional): Custom configuration for the HTTP request
Examples
iex> WhatsappElixir.Flows.delete_flow("flow123")
{:ok, %{"success" => true}}Returns
{:ok, response}on success{:error, response}on failure
Deprecates a published Flow, preventing it from being sent or opened.
Parameters
flow_id(string): ID of the Flow to deprecatecustom_config(keyword, optional): Custom configuration for the HTTP request
Examples
iex> WhatsappElixir.Flows.deprecate_flow("flow123")
{:ok, %{"success" => true}}Returns
{:ok, response}on success{:error, response}on failure
Generates a web preview URL for visualizing and testing a Flow.
Parameters
flow_id(string): ID of the Flowinvalidate_existing(boolean, optional): Whether to invalidate existing preview URLcustom_config(keyword, optional): Custom configuration for the HTTP request
Examples
# Generate new preview URL
iex> WhatsappElixir.Flows.generate_preview("flow123")
{:ok, %{
"preview" => %{
"preview_url" => "https://business.facebook.com/wa/manage/flows/123/preview/?token=abc...",
"expires_at" => "2023-05-21T11:18:09+0000"
},
"id" => "flow123"
}}Returns
{:ok, response}containing preview URL and expiration time{:error, response}on failure
Retrieves details of a specific Flow.
Parameters
flow_id(string): ID of the Flow to retrievefields(string, optional): Comma-separated list of fields to includephone_number_id(string, optional): Phone number ID for health status checkcustom_config(keyword, optional): Custom configuration for the HTTP request
Examples
# Get Flow with default fields
iex> WhatsappElixir.Flows.get_flow("flow123")
{:ok, %{
"id" => "flow123",
"name" => "Customer Survey",
"status" => "PUBLISHED",
"categories" => ["SURVEY"],
"validation_errors" => []
}}Returns
{:ok, response}containing Flow details{:error, response}on failure
Lists all assets attached to a specific Flow.
Parameters
flow_id(string): ID of the Flowcustom_config(keyword, optional): Custom configuration for the HTTP request
Examples
iex> WhatsappElixir.Flows.get_flow_assets("flow123")
{:ok, %{
"data" => [
%{
"name" => "flow.json",
"asset_type" => "FLOW_JSON",
"download_url" => "https://scontent.xx.fbcdn.net/..."
}
]
}}Returns
{:ok, response}containing assets data and paging information{:error, response}on failure
Lists all Flows for a WhatsApp Business Account.
Parameters
fields(string, optional): Comma-separated list of fields to include in responsecustom_config(keyword, optional): Custom configuration for the HTTP request
Examples
# List all Flows with default fields
iex> WhatsappElixir.Flows.get_flows()
{:ok, %{
"data" => [
%{"id" => "flow1", "name" => "Survey", "status" => "PUBLISHED", "categories" => ["SURVEY"]},
%{"id" => "flow2", "name" => "Lead Gen", "status" => "DRAFT", "categories" => ["LEAD_GENERATION"]}
],
"paging" => %{"cursors" => %{"before" => "...", "after" => "..."}}
}}Returns
{:ok, response}containing data array and paging information{:error, response}on failure
Migrates Flows from one WhatsApp Business Account to another.
Parameters
destination_waba_id(string): Destination WABA IDsource_waba_id(string): Source WABA IDsource_flow_names(list, optional): Specific Flow names to migrate (max 100)custom_config(keyword, optional): Custom configuration for the HTTP request
Examples
# Migrate all Flows
iex> WhatsappElixir.Flows.migrate_flows("dest_waba", "source_waba")
{:ok, %{
"migrated_flows" => [
%{"source_name" => "survey", "source_id" => "123", "migrated_id" => "456"}
],
"failed_flows" => []
}}
# Migrate specific Flows
iex> WhatsappElixir.Flows.migrate_flows("dest_waba", "source_waba", ["survey", "lead-gen"])
{:ok, %{"migrated_flows" => [...], "failed_flows" => [...]}}Returns
{:ok, response}containing migrated and failed Flows{:error, response}on failure
Publishes a Flow, making it available to send to customers.
Parameters
flow_id(string): ID of the Flow to publishcustom_config(keyword, optional): Custom configuration for the HTTP request
Examples
iex> WhatsappElixir.Flows.publish_flow("flow123")
{:ok, %{"success" => true}}Returns
{:ok, response}on success{:error, response}on failure
Updates a Flow's JSON content by uploading a JSON file.
Parameters
flow_id(string): ID of the Flow to updatejson_file_path(string): Path to the JSON file containing Flow contentcustom_config(keyword, optional): Custom configuration for the HTTP request
Examples
iex> WhatsappElixir.Flows.update_flow_json("flow123", "/path/to/flow.json")
{:ok, %{"success" => true, "validation_errors" => []}}Returns
{:ok, response}on success with validation errors if any{:error, response}on failure
Notes
- The JSON file must be valid Flow JSON format
- File size is limited to 10 MB
- The file is uploaded as multipart form data
Updates a Flow's metadata (name, categories, endpoint_uri, application_id).
Parameters
flow_id(string): ID of the Flow to updateupdate_data(map): Data to update containing::name(string, optional): New Flow name:categories(list, optional): New Flow categories (at least one required if provided):endpoint_uri(string, optional): New endpoint URI (for Flow JSON v3.0+):application_id(string, optional): Meta application ID to connect to the Flow
custom_config(keyword, optional): Custom configuration for the HTTP request
Examples
# Update Flow name
iex> WhatsappElixir.Flows.update_flow_metadata("flow123", %{name: "Updated Survey"})
{:ok, %{"success" => true}}Returns
{:ok, response}on success{:error, response}on failure