Learn R Programming

whapi (version 0.0.2)

whapi_parse_messages: Parse Whapi "messages" array into a normalized tibble

Description

Converts the webhook field messages (from Whapi.Cloud) into a row-per-message tibble with a stable schema. It extracts common metadata (ids, chat, author, timestamps, source), plain text content, action edits/reactions, and interactive replies along with the quoted context (headers, body, sections/buttons as JSON).

Usage

whapi_parse_messages(
  lst,
  channel_id = NULL,
  event_type = NULL,
  event_act = NULL
)

Value

A tibble with one row per message. Includes contextual columns (channel_id, event_type, event_action).

Arguments

lst

A list or single object representing Whapi webhook messages. Accepts NULL, a single message, or an array of messages.

channel_id

Character. Channel identifier (usually passed down from whapi_flatten_webhook()).

event_type

Character. Event type ("messages" by default).

event_act

Character. Event action ("post" by default).

Details

  • Handles multiple shapes and normalizes to a list of messages via a helper whapi_as_array(lst, "message").

  • Reply types supported:

    • reply$type == "list_reply" -> uses reply$list_reply$id/title/description

    • reply$type == "buttons_reply" (or "button_reply") -> uses reply$buttons_reply$id/title (or reply$button_reply)

    • Fallback: reply$id/title/description/body when available

  • Context of the quoted message is captured in: context_quoted_id, context_quoted_author, context_header, context_body, context_label, context_footer, and serialized JSON for sections and buttons (context_sections_json, context_buttons_json) via whapi_to_pretty_json().

  • The column change is set to "reply" for reply messages, "reactions" when a reaction is present, or "text" for edit operations.

  • Time fields: timestamp (epoch seconds, numeric) and timestamp_dt (POSIXct UTC).