
Validate list_sections for Whapi LIST interactive messages
Source: R/utils.R
whapi_validate_list_sections.RdInternal helper that validates the structure of list_sections used in
Whapi LIST messages. Each section must provide a non-empty title
and a non-empty rows list. Each row must provide non-empty id and
title. The description field is optional.
Arguments
- list_sections
A list of sections; each section is a named list with
title(character) androws(list of row objects).- verbose
Logical (default
TRUE). IfTRUE, prints progress messages via cli.- trim
Logical (default
TRUE). IfTRUE, trims whitespace fromsection$title,row$title, androw$idbefore validating.
Details
Expected structure:
list_sections <- list(
list(
title = "Section title",
rows = list(
list(id = "r1", title = "Row title", description = "Optional"),
...
)
),
...
)This function performs lightweight validation and (optionally) trims whitespace from titles and ids to avoid subtle formatting issues.
See also
Helpers for interactive payloads such as whapi_coerce_buttons_base(),
whapi_coerce_buttons_quick(), and whapi_coerce_buttons_mixed().
Examples
sections <- list(
list(
title = "Burgers",
rows = list(
list(id = "r1", title = "Plain", description = "No cheese, no sauce"),
list(id = "r2", title = "Cheese", description = "With melted cheese")
)
)
)
whapi_validate_list_sections(sections)
#> ℹ Validating 1 section(s) for LIST message...
#> ✔ LIST sections validated successfully.
#> [[1]]
#> [[1]]$title
#> [1] "Burgers"
#>
#> [[1]]$rows
#> [[1]]$rows[[1]]
#> [[1]]$rows[[1]]$id
#> [1] "r1"
#>
#> [[1]]$rows[[1]]$title
#> [1] "Plain"
#>
#> [[1]]$rows[[1]]$description
#> [1] "No cheese, no sauce"
#>
#>
#> [[1]]$rows[[2]]
#> [[1]]$rows[[2]]$id
#> [1] "r2"
#>
#> [[1]]$rows[[2]]$title
#> [1] "Cheese"
#>
#> [[1]]$rows[[2]]$description
#> [1] "With melted cheese"
#>
#>
#>
#>