Learn R Programming

whapi (version 0.0.2)

whapi_build_servicos_sections: Build Whapi service sections from a tibble (with section column)

Description

Converts 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.

Usage

whapi_build_servicos_sections(tbl, section_order = NULL)

Value

A list of sections, where each section is a list with:

  • title: section title

  • rows: a list of rows, each being a list with id, title, and description

Arguments

tbl

A tibble/data.frame containing at least:

  • section (chr): section name

  • id (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.

Details

  • If section_order = NULL, all sections are included, ordered alphabetically.

  • If section_order is 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

Run this code
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)

# Custom order and filter
whapi_build_servicos_sections(
  de_para_servicos,
  section_order = c("Anuencia Previa","Outros Servicos")
)

Run the code above in your browser using DataLab