Learn R Programming

whapi (version 0.0.2)

whapi_as_array: Ensure "messages" or "updates" input is always a list of objects

Description

Utility to normalize webhook payloads so downstream parsers can safely map_dfr(). Accepts single objects, arrays of objects, or NULL, and always returns a list.

Usage

whapi_as_array(x, kind = c("message", "update"))

Value

A list of message/update objects (possibly length 0).

Arguments

x

Input object: NULL, a list (single message/update), or a list of lists.

kind

Either "message" or "update". Defines which keys to look for when deciding if input is a single object.

Examples

Run this code
whapi_as_array(list(id="abc", type="text"), kind="message")
whapi_as_array(NULL, "update") # empty list

Run the code above in your browser using DataLab