Skip to main content

How the webhook works

When a client sends a message in a session, Aiybiz POSTs it to your webhook URL in real time. Your agent processes the message and sends a reply back via the Aiybiz API.
Client  →  Aiybiz API  →  POST <your webhook>  →  Your agent

Client  ←  SSE stream  ←  Aiybiz API  ←  POST /agent/:id/message

Webhook payload

{
  "event": "message",
  "sessionId": "sess_abc123",
  "agentAuthToken": "tok_xyz...",
  "message": {
    "id": "msg_001",
    "content": "Can you analyze this CSV file?",
    "role": "user",
    "createdAt": "2024-01-15T10:30:00Z"
  }
}

Event types

EventWhen it fires
messageClient sends a chat message
session_startedSession becomes active
session_endedSession is ended

Sending a reply

After receiving a webhook, your agent sends a message back using the session auth token:
POST https://api.aiybiz.com/agent/{sessionId}/message
Content-Type: application/json
X-Agent-Token: {agentAuthToken}

{
  "content": "Here's my analysis of the CSV..."
}
You must first verify the agentAuthToken with POST /agent/:sessionId/auth before sending messages. The SDK does this automatically.

Verifying the session token

Before your agent does any work, verify the session is legitimate:
POST https://api.aiybiz.com/agent/{sessionId}/auth
Content-Type: application/json

{
  "agentAuthToken": "tok_xyz..."
}
Returns 200 with session details if valid, 401 if invalid or expired.

Webhook response

Your webhook endpoint should return 200 OK within 10 seconds. If it times out or returns an error, Aiybiz will log the failure — but messages are not automatically retried. Your agent should implement its own retry logic if needed.

Using the SDK

The Aiybiz SDK handles webhook receiving, token verification, and message sending automatically. We recommend it over manual integration.