Learn R Programming

whapi (version 0.0.2)

whapi_send_list: Send a WhatsApp interactive LIST message (Whapi.Cloud)

Description

Sends an interactive LIST message via Whapi. Sections/rows are validated by whapi_validate_list_sections(). The payload reuses whapi_common_blocks() to keep structure consistent across interactive message types.

Usage

whapi_send_list(
  to,
  body_text,
  list_sections,
  list_label = "Choose...",
  header_text = NULL,
  footer_text = NULL,
  token = Sys.getenv("WHAPI_TOKEN", unset = ""),
  timeout = 30,
  verbose = TRUE
)

Value

A tibble with id, to, status, timestamp, and the raw response in resp.

Arguments

to

Character(1). Phone in E.164 digits (without "+") or group id.

body_text

Character(1). Main body text.

list_sections

A list of sections. Each section is a named list: list(title = <chr>, rows = list(list(id=<chr>, title=<chr>, description=<chr>?), ...)).

list_label

Character(1), optional. Button label that opens the list. Default: "Choose..."

header_text, footer_text

Character(1), optional. Header/footer texts.

token

Bearer token. Defaults to env var WHAPI_TOKEN.

timeout

Numeric. Request timeout in seconds. Default 30.

verbose

Logical. Print CLI messages? Default TRUE.

See Also

whapi_validate_list_sections(), whapi_common_blocks(), whapi_perform_request(), whapi_extract_common_fields()

Examples

Run this code
if (FALSE) {
 Sys.setenv(WHAPI_TOKEN = "your_token_here")
 sections <- list(
   list(
     title = "Burgers",
     rows = list(
       list(id="b1", title="Plain",  description="No cheese, no sauce"),
       list(id="b2", title="Cheese", description="With melted cheese")
     )
   ),
   list(
     title = "Drinks",
     rows = list(
       list(id="d1", title="Water"),
       list(id="d2", title="Soda", description="Assorted flavors")
     )
   )
 )
 whapi_send_list(
   to = "5581999999999",
   body_text = "Choose your order:",
   list_sections = sections,
   list_label = "Open menu",
   header_text = "Our Menu",
   footer_text = "Thanks!"
 )
}

Run the code above in your browser using DataLab