Official Python SDK for the WhatsRB Cloud API
Project description
WhatsRB Cloud Python SDK
Official Python client for the WhatsRB Cloud API.
Send WhatsApp messages, run AI agents, manage templates, and handle webhooks — all from Python.
Installation
pip install whatsrb-cloud
Quick Start
import whatsrb_cloud
# Global configuration
whatsrb_cloud.configure(api_key="wrb_live_xxx")
client = whatsrb_cloud.client()
# Or direct initialization
client = whatsrb_cloud.WhatsrbCloud("wrb_live_xxx")
Business Accounts
# List accounts
accounts = client.business_accounts.list()
for account in accounts:
print(account.display_name, account.phone_number)
# Send a text message
account = accounts[0]
message = account.send_text(to="+33612345678", text="Hello from Python!")
# Send a template
message = account.send_template(
to="+33612345678",
template_name="hello_world",
template_language="en",
)
# Check conversation window
if account.window_open("+33612345678"):
account.send_text(to="+33612345678", text="Window is open!")
Sessions (WhatsApp Web)
# Create a session
session = client.sessions.create(name="My Bot")
# Wait for QR scan
session.wait_for_qr(
timeout=60,
on_qr=lambda qr: print(f"Scan this QR: {qr}"),
)
# Send messages
session.send_message(to="+33612345678", text="Hello!")
session.send_image(to="+33612345678", url="https://example.com/image.jpg")
session.send_location(to="+33612345678", latitude=48.8566, longitude=2.3522)
AI Agents
# Create an agent
agent = client.agents.create(
name="Support Bot",
system_prompt="You are a helpful support agent.",
model="gpt-4",
allowed_actions=["support.ticket.create"],
)
# Run synchronously (blocks until complete)
run = agent.run(input={"message": "I need help"}, timeout=30)
print(run.suggested_reply)
print(run.intent, run.confidence)
# Run asynchronously
run = agent.run_async(input={"message": "I need help"})
# ... do other things ...
run.wait(timeout=30)
# Dispatch actions
from whatsrb_cloud import ActionRegistry
registry = ActionRegistry()
registry.register("support.ticket.create", lambda payload: create_ticket(payload))
results = run.dispatch(registry)
Templates
templates = client.templates("ba_xxx")
# List and filter
all_templates = templates.list()
approved = templates.list(status="approved")
# Find by name
welcome = templates.find_by_name("welcome_message")
# Sync from Meta
synced = templates.sync()
# Send test
templates.send_test("tpl_xxx", to="+33612345678", variables=["John"])
Webhooks
# Create a webhook
webhook = client.webhooks.create(
url="https://example.com/webhook",
events=["message.received", "agent_run.completed"],
)
print(webhook.secret) # Only returned on creation
# Verify signatures
from whatsrb_cloud import WebhookSignature
is_valid = WebhookSignature.verify(
payload=request_body,
secret="whsec_xxx",
signature=request.headers["X-Webhook-Signature"],
timestamp=request.headers.get("X-Webhook-Timestamp"),
)
# Event registry
from whatsrb_cloud import EventRegistry
events = EventRegistry()
events.on("message.received", lambda data: print(f"New message: {data}"))
events.on("agent_run.completed", lambda data: handle_run(data))
events.dispatch(webhook_payload)
Error Handling
from whatsrb_cloud import WhatsrbCloud, NotFoundError, ValidationError, RateLimitError
client = WhatsrbCloud("wrb_live_xxx")
try:
agent = client.agents.retrieve("agt_nonexistent")
except NotFoundError as e:
print(f"Not found: {e} (status={e.status})")
except ValidationError as e:
print(f"Validation: {e.details}")
except RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after}s")
Requirements
- Python 3.10+
- httpx >= 0.27
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
whatsrb_cloud-0.1.0.tar.gz
(220.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file whatsrb_cloud-0.1.0.tar.gz.
File metadata
- Download URL: whatsrb_cloud-0.1.0.tar.gz
- Upload date:
- Size: 220.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c6da4a40eaee516b581004bc764a16d6c9c5eb46da940e81951df11be72661f
|
|
| MD5 |
70084d79ba9bdcbdc110f051ffedc3d5
|
|
| BLAKE2b-256 |
0b7776c47cd052b5a37877cb519c192c26f3560e9ade0503f63a7599131b853e
|
File details
Details for the file whatsrb_cloud-0.1.0-py3-none-any.whl.
File metadata
- Download URL: whatsrb_cloud-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a6d0a029e4f40a73af75325e691474690be9b3b5d523519dbe044dfa1999488
|
|
| MD5 |
9b724104033b28113e1f3acd4bd27962
|
|
| BLAKE2b-256 |
e7cd87988bcdaa3c714ad1e0114185fd08f139dce756efbdacecd80fdbf024d4
|