Learn R Programming

whapi (version 0.0.2)

whapi_coerce_buttons_mixed: Coerce and validate MIXED buttons (url / call / copy) for Whapi

Description

Internal helper that prepares mixed action buttons for Whapi interactive messages. It first normalizes input via whapi_coerce_buttons_base() (accepts data.frame/tibble or list, maps aliases to title, auto-creates id with slug + uniqueness) and then validates each button according to its declared type:

  • url -> requires fields: title, id, url

  • call -> requires fields: title, id, phone_number

  • copy -> requires fields: title, id, copy_code

Enforces WhatsApp constraints: 1 to 3 buttons per message.

Usage

whapi_coerce_buttons_mixed(buttons, verbose = TRUE)

Value

A list-of-lists of buttons, each validated to contain the fields required for its type.

Arguments

buttons

A data.frame/tibble (one row per button) or a list of named lists. title is required (or via alias), id is auto-generated when missing by whapi_coerce_buttons_base(). Each button must provide a valid type among {"url","call","copy"}.

verbose

Logical (default TRUE). If TRUE, prints progress messages via cli.

See Also

whapi_coerce_buttons_base() for normalization; whapi_coerce_buttons_quick() for quick-reply buttons.

Examples

Run this code
# Example with a tibble:
 tibble::tribble(
   ~title,        ~type, ~url, ~phone_number,
   "Website",     "url", "https://example.com", NA,
   "Call Support","call", NA, "5581999999999"
 ) |>
   whapi_coerce_buttons_base() |>
   whapi_coerce_buttons_mixed()

# Example with a list:
 whapi_coerce_buttons_mixed(list(
   list(type="url",  title="Website", url="https://example.com"),
   list(type="call", title="Call us", phone_number="5581999999999"),
   list(type="copy", title="Copy OTP", copy_code="123456")
 ))

Run the code above in your browser using DataLab