Run automation
Webhooks
Get a call to your server when a task ends or a phone needs attention.
Add a webhook
In the dashboard: Settings → Connections → Events → Webhooks. Or through the API:
POST /v1/webhooks
{"url": "https://example.com/clousd", "events": ["run.completed", "run.failed"], "description": "orders bot"}
# → 201 {"webhook": {"id": "wh_3c1a", …}, "secret": "whsec_…"} the secret is shown onceEmpty events means all of them. A key can have up to ten webhooks; each one has its own secret. POST /v1/webhooks/{id}/rotate gives a new secret, /toggle pauses deliveries, /test sends a test event now, GET …/deliveries lists recent deliveries with the response code and time.
Events
| Event | When |
|---|---|
| run.completed | A task finished; the body has the run with its answer. |
| run.failed | A task could not be finished; the body says why. |
| run.cancelled | A task was stopped. |
| run.waiting | A task stopped to ask a question or for permission. |
| device.problem | A phone's health check failed. |
| device.resolved | The problem cleared. |
Verify the signature
Each delivery is a POST with a JSON body and the header X-Clousd-Signature: t=<unix time>,v1=<hex>, where the hex is HMAC-SHA256 of "<t>.<raw body>" keyed with your webhook secret. Reject old timestamps to stop replays.
import hashlib, hmac, time
def valid(body: bytes, header: str, secret: str, tolerance: int = 300) -> bool:
parts = dict(p.split("=", 1) for p in header.split(","))
t, sig = parts.get("t", ""), parts.get("v1", "")
if not t.isdigit() or abs(time.time() - int(t)) > tolerance:
return False
mac = hmac.new(secret.encode(), t.encode() + b"." + body, hashlib.sha256).hexdigest()
return hmac.compare_digest(mac, sig)Retries
Each event is tried up to four times: at once, after 30 seconds, after 5 minutes and after 30 minutes. Answer with any 2xx to confirm. The body is {"id", "type", "created", "data"} and the same id comes in X-Clousd-Event-Id: if a retry reaches you after a slow success, skip the id you have already handled. After 20 failed deliveries in a row the webhook pauses itself; turn it back on in the dashboard or with /toggle.