WhatsApp.Interactive (WhatsApp SDK v0.1.0)

Copy Markdown View Source

Builders for WhatsApp interactive messages.

Provides a functional pipeline API for constructing interactive message payloads -- buttons, lists, CTAs, flows, and products.

Examples

# Quick reply buttons
payload =
  WhatsApp.Interactive.buttons("Choose an option:")
  |> WhatsApp.Interactive.button("yes", "Yes, proceed")
  |> WhatsApp.Interactive.button("no", "No, cancel")
  |> WhatsApp.Interactive.build()

# List message
payload =
  WhatsApp.Interactive.list("Main Menu", "View options")
  |> WhatsApp.Interactive.section("Products", [
    WhatsApp.Interactive.row("prod_1", "Widget", "Our best widget"),
    WhatsApp.Interactive.row("prod_2", "Gadget", "Our best gadget")
  ])
  |> WhatsApp.Interactive.build()

Summary

Functions

Finalize the builder and return the payload map.

Add a reply button to a button message.

Start building a button message.

Build a Flow trigger message.

Start building a list message.

Build a location request message.

Build a multi-product list message.

Add a product section to a product list message.

Create a row for a list section.

Add a section with rows to a list message.

Types

builder()

@type builder() :: map()

Functions

build(builder)

@spec build(builder()) :: map()

Finalize the builder and return the payload map.

This is an identity function -- the builder map is the payload.

button(builder, id, title)

@spec button(builder(), String.t(), String.t()) :: builder()

Add a reply button to a button message.

OpenAPI Constraints

  • Maximum 3 buttons per message (maxItems: 3)
  • Minimum 1 button required (minItems: 1)
  • id — unique identifier, max 256 characters (maxLength: 256). No leading or trailing spaces.
  • title — button label, max 20 characters (maxLength: 20). Cannot be empty, must be unique across buttons. Emojis supported, no markdown.

buttons(body_text, opts \\ [])

@spec buttons(
  String.t(),
  keyword()
) :: builder()

Start building a button message.

Options

  • :header - Optional header text
  • :footer - Optional footer text (max 60 characters per OpenAPI spec)

cta_url(body_text, display_text, url, opts \\ [])

@spec cta_url(String.t(), String.t(), String.t(), keyword()) :: builder()

Build a CTA URL message.

Options

  • :header - Optional header text
  • :footer - Optional footer text

flow(body_text, flow_id, flow_cta, opts \\ [])

@spec flow(String.t(), String.t(), String.t(), keyword()) :: builder()

Build a Flow trigger message.

Options

  • :header - Optional header text
  • :footer - Optional footer text
  • :flow_action - Flow action, defaults to "navigate"
  • :flow_action_payload - Optional map payload added to parameters

list(body_text, button_text, opts \\ [])

@spec list(String.t(), String.t(), keyword()) :: builder()

Start building a list message.

Options

  • :header - Optional header text
  • :footer - Optional footer text

OpenAPI Constraints

  • button_text — button label, max 20 characters (maxLength: 20). Cannot be empty. Emojis supported, no markdown.

location_request(body_text)

@spec location_request(String.t()) :: builder()

Build a location request message.

product(catalog_id, product_retailer_id, opts \\ [])

@spec product(String.t(), String.t(), keyword()) :: builder()

Build a single product message.

Options

  • :body - Optional body text
  • :footer - Optional footer text

product_list(body_text, catalog_id, opts \\ [])

@spec product_list(String.t(), String.t(), keyword()) :: builder()

Build a multi-product list message.

Options

  • :header - Optional header text
  • :footer - Optional footer text

product_section(builder, title, product_retailer_ids)

@spec product_section(builder(), String.t(), [String.t()]) :: builder()

Add a product section to a product list message.

row(id, title, description \\ nil)

@spec row(String.t(), String.t(), String.t() | nil) :: map()

Create a row for a list section.

Description is optional and only included when provided.

OpenAPI Constraints

  • id — unique row identifier, max 200 characters (maxLength: 200)
  • title — row title, max 24 characters (maxLength: 24)
  • description — optional, max 72 characters (maxLength: 72)

section(builder, title, rows)

@spec section(builder(), String.t(), [map()]) :: builder()

Add a section with rows to a list message.

OpenAPI Constraints

  • title — section title, max 24 characters (maxLength: 24)