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 fromstdin.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
stdinfollowing actions that return a message ID. - Http
Client - A
Clientto make Requests with. - Quoted
Message - 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
stdoutfor WhatsRook to execute.
Constants§
- DEFAULT_
USER_ AGENT - Default browser User-Agent used by
create_http_client.
Functions§
- await_
ack - Read one
Ackline fromstdin. ReturnsNoneon EOF or parse error. - create_
http_ client - Build a preconfigured blocking
HttpClientwith 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) andstdout(to reply to the user), then exit the process with code1. - send_
action - Serialize an
Actionframe tostdoutand 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
editframe 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
replyaction, await the acknowledgement, and return themsg_idon 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.