Learn R Programming

whapi (version 0.0.2)

whapi_coerce_buttons_base: Coerce and normalize button specs for Whapi interactive messages

Description

Internal helper that converts a data.frame/tibble or list of button definitions into a normalized list-of-lists, applying a few rules:

  • Accepts aliases label / name and maps them to title;

  • Requires a non-empty title;

  • Auto-generates id when missing using slugification plus uniqueness enforcement (e.g., "Buy Now" -> "buy_now", duplicates become "buy_now_2", "buy_now_3", ...).

This is useful before building payloads for Whapi interactive endpoints (e.g., buttons, mixed actions, etc.).

Usage

whapi_coerce_buttons_base(buttons, verbose = TRUE)

Value

A list of named lists (one per button), each guaranteed to have at least title (non-empty). If a button had no id, a slugified, unique id is created.

Arguments

buttons

A data.frame/tibble with columns per button (e.g. title, id, etc.) or a list of named lists. Can be NULL (returns empty list).

verbose

Logical (default TRUE). If TRUE, prints progress messages via cli (how many buttons, how many ids auto-generated, etc.).

See Also

whapi_slugify(), whapi_make_unique()

Examples

Run this code
# From tibble (title only -> ids auto-generated)
 tibble::tribble(~title, "Buy Now", "Buy Now", "Learn More") |>
   whapi_coerce_buttons_base()

# From list (mix with/without id)
 whapi_coerce_buttons_base(list(
   list(title = "Website", url = "https://example.com"),
   list(title = "Website")  # will get an auto id too
 ))

Run the code above in your browser using DataLab