Learn R Programming

whapi

     

R wrapper for whapi.cloud — a lightweight WhatsApp API.

Overview

The whapi package provides a tidyverse-friendly interface to the whapi.cloud API, allowing you to send, receive, and manage WhatsApp messages programmatically in R.

Features include:

  • Sending text, image, document, sticker, and location messages;
  • Sending interactive messages (quick replies, mixed actions, lists);
  • Reacting to or marking messages as read;
  • Fetching message details and contact profiles;
  • Checking channel health and status;
  • Helpers for logging and webhook flattening.

All outputs are returned as tibbles for easy integration into tidyverse workflows.

Installation

The package is under development. Install from source:

# install.packages("devtools")
devtools::install_github("StrategicProjects/whapi")

Setup

  1. Get an API token from Whapi.Cloud.
  2. Store it as an environment variable:
Sys.setenv(WHAPI_TOKEN = "your_api_token_here")
  1. Load the package:
library(whapi)

Example Usage

Send a Text Message

whapi_send_text("5581999999999", "Hello from R! ✅")

Send an Image

whapi_send_image("5581999999999", image = "card.png", type = "file", caption = "Card")

Send a Sticker

whapi_send_sticker("5581999999999", sticker = "sticker.webp", type = "file")

Send an Interactive Quick Reply

whapi_send_quick_reply(
  to = "5581999999999",
  body_text = "Do you confirm?",
  buttons = tibble::tribble(~title, "YES", "NO")
)

React to a Message

whapi_react_to_message("PsqXn5SAD5v7HRA-wHqB9tMeGQ", "❤️")

Mark a Message as Read

whapi_mark_message_read("PsqXn5SAD5v7HRA-wHqB9tMeGQ")

Get a Contact Profile

whapi_get_contact_profile("5581999999999")

Check Channel Health

whapi_check_health()

Contributing

If you find any issues or have feature requests, feel free to create an issue or a pull request on GitHub.


License

This package is licensed under the MIT License. See the LICENSE file for more details.

Copy Link

Version

Install

install.packages('whapi')

Monthly Downloads

135

Version

0.0.2

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Andre Leite

Last Published

September 29th, 2025

Functions in whapi (0.0.2)

whapi_send_quick_reply

Send a WhatsApp interactive message with QUICK REPLY buttons (Whapi.Cloud)
whapi_redact

Redact sensitive values in headers/cookies
whapi_to_ascii_lower

Convert text to lowercase ASCII (remove accents)
whapi_fmt_date

Safe date formatting
whapi_send_document

Send a DOCUMENT via Whapi.Cloud (file, url, or base64)
whapi_send_text

Send a text message via Whapi.Cloud
whapi_scalarize_change

Collapse a "changes" vector into a single string
whapi_parse_body

Parse the raw body of a Plumber request
whapi_only_digits

Keep only digits from a string
whapi_send_sticker

Send a STICKER via Whapi.Cloud (file, url, or base64)
whapi_send_location

Send a geographic location via Whapi.Cloud
whapi_send_mixed_actions

Send a WhatsApp interactive message mixing URL/CALL/COPY buttons (Whapi.Cloud)
whapi_send_list

Send a WhatsApp interactive LIST message (Whapi.Cloud)
whapi_to_num

Safely coerce to numeric
whapi_send_image

Send an image via Whapi.Cloud (file, url, or base64)
whapi_validate_list_sections

Validate list_sections for Whapi LIST interactive messages
whapi_to_posix

Coerce to POSIXct (UTC) safely
whapi_to_posixct

Convert numeric timestamp to POSIXct (UTC)
whapi_slugify

whapi_slugify strings for safe IDs (e.g., button IDs in Whapi)
whapi_trunc

Truncate long strings for logging
whapi_to_pretty_json

Convert R objects into pretty JSON (character)
whapi_date_diff_days

Days between two dates
whapi_coerce_buttons_quick

Coerce and validate QUICK REPLY buttons for Whapi
whapi_clip_text

Clip long text with ellipsis
whapi_check_health

Check Whapi.Cloud channel health and status
whapi_as_array

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

Coerce and validate MIXED buttons (url / call / copy) for Whapi
whapi_common_blocks

Build common message blocks for Whapi interactive messages
whapi_coerce_buttons_base

Coerce and normalize button specs for Whapi interactive messages
whapi_build_servicos_sections

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

Extract common fields from Whapi API responses
whapi_make_unique

Make identifiers unique while preserving order
whapi_get_message

Get a WhatsApp message by ID (Whapi.Cloud)
whapi_flatten_webhook

Flatten Whapi webhook payload into tidy rows for persistence (robust)
whapi_get_contact_profile

Get WhatsApp contact profile(s) via Whapi.Cloud
whapi_log_pretty_json

Convert R objects to pretty JSON for logging
whapi_mark_message_read

Mark a WhatsApp message as READ (Whapi.Cloud)
whapi_log_plumber_req

Log details of a Plumber request object using the cli package
whapi_parse_updates

Parse Whapi "messages_updates" array (patch events) into a tibble
whapi_parse_command

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

Perform an HTTP request to Whapi.Cloud
whapi_parse_messages

Parse Whapi "messages" array into a normalized tibble
whapi_normalize_to

Normalize WhatsApp contact IDs (phone numbers only)
whapi_match_digits

Digit matching helper (with partial threshold)
whapi_react_to_message

React to a WhatsApp message (Whapi.Cloud)