WhatsApp Cloud API SDK for Rust
A Rust SDK for the WhatsApp Cloud API hosted by Meta. This library provides a type-safe, async interface for integrating WhatsApp Business messaging into your Rust applications.
Features
- Messages API - Send text, media, templates, interactive messages, and more
- Media API - Upload, download, and manage media files
- Templates API - Create and manage message templates
- Phone Numbers API - Manage business phone numbers
- Webhooks - Type-safe webhook payload parsing
- Async/Await - Built on Tokio for async operations
- Type-Safe - Strongly typed API with Serde serialization
Installation
Add this to your Cargo.toml:
[]
= "0.1"
= { = "1", = ["full"] }
Quick Start
use Client;
async
Usage Examples
Send Text Message
let response = client
.messages
.send_text
.await?;
Send Text with URL Preview
let response = client
.messages
.send_text_with_preview
.await?;
Send Image
// By URL
let response = client
.messages
.send_image_url
.await?;
// By Media ID (after upload)
let response = client
.messages
.send_image_id
.await?;
Send Video
let response = client
.messages
.send_video_url
.await?;
Send Document
let response = client
.messages
.send_document_url
.await?;
Send Location
let response = client
.messages
.send_location
.await?;
Send Reaction
// Add reaction
let response = client
.messages
.send_reaction
.await?;
// Remove reaction
let response = client
.messages
.remove_reaction
.await?;
Send Interactive Buttons
use Button;
let buttons = vec!;
let response = client
.messages
.send_buttons
.await?;
Send Interactive List
use ;
let sections = vec!;
let response = client
.messages
.send_list
.await?;
Send Template Message
use ;
let components = vec!;
let response = client
.messages
.send_template
.await?;
Upload Media
// From file
let response = client
.media
.upload_file
.await?;
println!;
// From bytes
let response = client
.media
.upload_bytes
.await?;
Handle Webhooks
use ;
API Reference
Client
| Method | Description |
|---|---|
Client::new(token, phone_id) |
Create a new client |
Client::with_version(token, phone_id, version) |
Create with custom API version |
client.messages() |
Access Messages API |
client.media() |
Access Media API |
client.phone_numbers() |
Access Phone Numbers API |
client.templates() |
Access Templates API |
Messages API
| Method | Description |
|---|---|
send_text(to, text) |
Send text message |
send_text_with_preview(to, text) |
Send text with URL preview |
send_reply(to, text, message_id) |
Reply to a message |
send_reaction(to, message_id, emoji) |
React to a message |
send_image_url(to, url, caption) |
Send image by URL |
send_image_id(to, media_id, caption) |
Send image by media ID |
send_video_url(to, url, caption) |
Send video by URL |
send_audio_url(to, url) |
Send audio by URL |
send_document_url(to, url, filename, caption) |
Send document by URL |
send_sticker_url(to, url) |
Send sticker by URL |
send_location(to, lat, lng, name, address) |
Send location |
send_contacts(to, contacts) |
Send contact card |
send_template(to, name, lang, components) |
Send template message |
send_list(to, header, body, footer, btn, sections) |
Send list message |
send_buttons(to, header, body, footer, buttons) |
Send button message |
mark_as_read(message_id) |
Mark message as read |
Media API
| Method | Description |
|---|---|
upload_file(path) |
Upload media from file |
upload_bytes(data, filename, mime) |
Upload media from bytes |
upload_base64(data, filename, mime) |
Upload media from base64 |
get_url(media_id) |
Get media download URL |
download(media_id) |
Download media content |
delete(media_id) |
Delete media |
Environment Variables
You can set these environment variables:
WHATSAPP_ACCESS_TOKEN=your_access_token
WHATSAPP_PHONE_NUMBER_ID=your_phone_number_id
Getting Started with WhatsApp Cloud API
- Create a Meta Developer Account
- Create a new app and add the WhatsApp product
- Get your access token and phone number ID from the app dashboard
- Set up webhooks to receive messages
For more information, see the WhatsApp Cloud API documentation.
License
MIT
Author
Abdul Muttaqin - @taqin