Learn R Programming

whapi (version 0.0.2)

whapi_parse_command: Parse a text message into command and arguments (Whapi helper)

Description

Splits an incoming text (usually from a WhatsApp message) into a command (the first token, starting with /) and its associated arguments. Supports collapsing arguments into a single string or preserving them as a character vector.

Usage

whapi_parse_command(text, collapse_args = TRUE)

Value

A list with two elements:

command

The command string (first token), trimmed (e.g. "/groe").

arguments

The arguments, either collapsed as a single string (default) or as a character vector, depending on collapse_args.

Arguments

text

A character string containing the full message (e.g. "/groe ajuda").

collapse_args

Logical, default TRUE. If TRUE, all arguments are collapsed into a single space-separated string. If FALSE, arguments are returned as a character vector of tokens.

See Also

Examples

Run this code
whapi_parse_command("/groe ajuda")
#> $command
#> [1] "/groe"
#>
#> $arguments
#> [1] "ajuda"

whapi_parse_command("/groe nome empresa", collapse_args = FALSE)
#> $command
#> [1] "/groe"
#>
#> $arguments
#> [1] "nome" "empresa"

Run the code above in your browser using DataLab