
Build Whapi service sections from a tibble (with section column)
Source: R/utils.R
whapi_build_servicos_sections.RdConverts a tibble of services (with columns id, title, description, and section)
into a nested list of sections/rows in the format expected by Whapi interactive
messages.
Arguments
- tbl
A tibble/data.frame containing at least:
section(chr): section nameid(chr): unique identifier (e.g.,"ap1","r2","os3")title(chr): display title (can include emoji)descricao(chr): short description of the service
- section_order
Character vector defining desired order (and subset) of sections. If
NULL, all sections are included in alphabetical order.
Value
A list of sections, where each section is a list with:
title: section titlerows: a list of rows, each being a list withid,title, anddescription
Details
If
section_order = NULL, all sections are included, ordered alphabetically.If
section_orderis provided, it acts as both:a filter: only sections listed will be included,
and an order: sections appear in the same order as in
section_order.
Within each section, rows are ordered by the numeric part of id
(via readr::parse_number(id)).
Examples
de_para_servicos <- tibble::tibble(
section = c("Outros Servicos","Renovacoes","Anuencia Previa"),
id = c("os2","r4","ap1"),
title = c("Consulta Previa",
"Renovacao de Consulta Previa",
"Desmembramento"),
descricao = c("Initial analysis...","Renewal...","Technical authorization...")
)
# All sections (alphabetical)
whapi_build_servicos_sections(de_para_servicos)
#> [[1]]
#> [[1]]$title
#> [1] "Anuencia Previa"
#>
#> [[1]]$rows
#> [[1]]$rows[[1]]
#> [[1]]$rows[[1]]$id
#> [1] "ap1"
#>
#> [[1]]$rows[[1]]$title
#> [1] "Desmembramento"
#>
#> [[1]]$rows[[1]]$description
#> [1] "Technical authorization..."
#>
#>
#>
#>
#> [[2]]
#> [[2]]$title
#> [1] "Outros Servicos"
#>
#> [[2]]$rows
#> [[2]]$rows[[1]]
#> [[2]]$rows[[1]]$id
#> [1] "os2"
#>
#> [[2]]$rows[[1]]$title
#> [1] "Consulta Previa"
#>
#> [[2]]$rows[[1]]$description
#> [1] "Initial analysis..."
#>
#>
#>
#>
#> [[3]]
#> [[3]]$title
#> [1] "Renovacoes"
#>
#> [[3]]$rows
#> [[3]]$rows[[1]]
#> [[3]]$rows[[1]]$id
#> [1] "r4"
#>
#> [[3]]$rows[[1]]$title
#> [1] "Renovacao de Consulta Previa"
#>
#> [[3]]$rows[[1]]$description
#> [1] "Renewal..."
#>
#>
#>
#>
# Custom order and filter
whapi_build_servicos_sections(
de_para_servicos,
section_order = c("Anuencia Previa","Outros Servicos")
)
#> [[1]]
#> [[1]]$title
#> [1] "Anuencia Previa"
#>
#> [[1]]$rows
#> [[1]]$rows[[1]]
#> [[1]]$rows[[1]]$id
#> [1] "ap1"
#>
#> [[1]]$rows[[1]]$title
#> [1] "Desmembramento"
#>
#> [[1]]$rows[[1]]$description
#> [1] "Technical authorization..."
#>
#>
#>
#>
#> [[2]]
#> [[2]]$title
#> [1] "Outros Servicos"
#>
#> [[2]]$rows
#> [[2]]$rows[[1]]
#> [[2]]$rows[[1]]$id
#> [1] "os2"
#>
#> [[2]]$rows[[1]]$title
#> [1] "Consulta Previa"
#>
#> [[2]]$rows[[1]]$description
#> [1] "Initial analysis..."
#>
#>
#>
#>