Skip to main content

Crate whatsrook_sdk

Crate whatsrook_sdk 

Source
Expand description

§whatsrook-sdk

Rust SDK for building WhatsRook external plugins.

External plugins are standalone executables — written in any language — that WhatsRook spawns as child processes. This crate provides everything a Rust plugin author needs:

  • Request — deserializes the incoming JSON payload from stdin.
  • Action — typed, serializable frames for every response the protocol supports.
  • High-level helpers — send_reply_live, send_image, send_poll, etc.
  • create_http_client — preconfigured blocking HTTP client.

§Communication Protocol

WhatsRook writes one JSON line to the plugin’s stdin when a command is triggered. The plugin reads it, does its work, and writes newline-delimited JSON action frames to stdout. WhatsRook executes each frame and, for actions that return a message ID, writes an Ack back to the plugin’s stdin.

WhatsRook  ──stdin──▶  plugin (reads Request)
plugin     ──stdout─▶  WhatsRook (reads Action frames)
WhatsRook  ──stdin──▶  plugin (reads Ack, for live actions)

§Quick Start

use whatsrook_sdk::{respond, Request};

fn main() {
    let req = Request::load();
    let query = req.query();

    if query.is_empty() {
        respond("Usage: .hello <name>");
        return;
    }

    respond(format!("Hello, {}! 👋", query));
}

See the examples/ directory for more complete plugin examples.

Re-exports§

pub use reqwest;

Structs§

Ack
Acknowledgement sent by WhatsRook on stdin following actions that return a message ID.
HttpClient
A Client to make Requests with.
QuotedMessage
Quoted message context payload — the message the user was replying to.
Request
Incoming request payload written by WhatsRook to the plugin’s stdin.

Enums§

Action
A single action frame written to stdout for WhatsRook to execute.

Constants§

DEFAULT_USER_AGENT
Default browser User-Agent used by create_http_client.

Functions§

await_ack
Read one Ack line from stdin. Returns None on EOF or parse error.
create_http_client
Build a preconfigured blocking HttpClient with a timeout and standard browser headers.
respond
Send a plain-text response to WhatsRook via stdout (simple mode).
respond_err
Send an error message to stderr (for logs) and stdout (to reply to the user), then exit the process with code 1.
send_action
Serialize an Action frame to stdout and flush immediately.
send_audio
Send audio or a voice note (PTT) from a URL or base64-encoded data.
send_delete
Revoke (delete for everyone) a message by its ID.
send_document
Send a document file from a URL or base64-encoded data.
send_done
Signal that the plugin session is complete.
send_edit_live
Send an edit frame to update a previously sent message in-place.
send_gif
Send a GIF (looping video) from a URL or base64-encoded data.
send_image
Send an image from a URL or base64-encoded data with an optional caption.
send_loader
Show the typing / processing loader indicator with an optional status message.
send_poll
Send an interactive single-select poll.
send_react
React to the triggering message with an emoji.
send_reply_live
Send a text reply action, await the acknowledgement, and return the msg_id on success.
send_sticker
Send a WebP sticker from a URL or base64-encoded data.
send_video
Send a video from a URL or base64-encoded data with an optional caption.