For the complete documentation index, see llms.txt. This page is also available as Markdown.

Webhook

Conversation platform Webhooks: push visitor messages and AI or human replies to your system in real time, with support for the MaiAgent standard format, Genesys Cloud, and custom Jinja2 templates

Webhooks are configured on a conversation platform (Inbox). Whenever a new message is created in a conversation on that platform, MaiAgent pushes the message to your specified endpoint via an HTTP request. A conversation platform can have multiple Webhooks, each with its own message direction and format.

Configuration path: Customer Support Conversations → Conversation Platforms → Edit platform → Webhook Settings → Add Webhook. For API platforms, Webhook Settings is in the “Integrations and Login” group on the left. For messaging platforms such as LINE, it is in the tab bar at the top. Web and internal platforms do not have this tab. For admin interface instructions, see Webhook in the user manual.

When you send a message through the Create conversations and messages API, the response only confirms that the message was created. The Agent's reply is generated asynchronously and pushed to you through an Outgoing Webhook. This is the standard way to receive replies in an API integration.

How it works

When a human agent replies in the admin console, that reply is also an Outgoing message and is pushed to the Outgoing Webhook as well. The payload's sender.type tells you whether it came from the AI or a human.

Webhook types

Type
Trigger
Typical use

Outgoing

When a reply from the Agent or a human agent is created

Get AI replies; forward replies to your own front end or messaging app

Incoming

When a visitor message is created (all channels, including API, Web Chat, and LINE)

Sync conversation records to a customer service system, data warehouse, or audit log

Receive

Called by an external platform to MaiAgent

Receive messages sent back from an external customer service platform (currently supports Genesys Cloud Open Messaging)

This page covers Outgoing and Incoming. For Receive and the Genesys Cloud format, see Genesys Cloud Integration.

Configuration fields

Field
Description

Name

A custom identifying name

Type

Outgoing / Incoming / Receive

Webhook URL

The URL that receives the pushes

HTTP Method

POST (default) / PUT / PATCH

Headers

Custom headers added to every request (for example, your system's API key)

Payload format

MaiAgent standard format / Genesys Cloud / Custom template (Jinja2)

Enabled

When off, nothing is pushed, but the settings are kept

Secret Token (API field secretToken)

Signing secret. Once set, every push carries an HMAC-SHA256 signature and a timestamp header; see Verifying signatures and timestamps. Write-only and never returned in queries; leaving it blank when editing in the admin console keeps the existing value. This field is not shown in the admin console when the Payload format is Genesys Cloud

If Headers contains a custom header with the same name (case-insensitive) as X-MaiAgent-Signature-256, X-MaiAgent-Timestamp, or X-MaiAgent-Delivery-Attempt, it is removed before sending, and the value generated by MaiAgent is always used.

MaiAgent standard format

Content-Type: application/json, with the following content (Outgoing and Incoming share the same structure, distinguished by type):

Field descriptions

Field
Type
Description

id

string

Message ID (UUID)

type

string

incoming (visitor message) / outgoing (AI or human reply)

content

string

Message text

created_at

string

ISO 8601 time

conversation.id

string

Conversation ID

conversation.title

string

Conversation title

conversation.type

string

individual / group

conversation.status

string

open / queued (waiting for a human) / resolved

conversation.progress_status

string

Who is currently handling it: ai_processing / waiting_for_human / human_serving / resolved / open

conversation.auto_reply_enabled

boolean

false means the AI has stopped auto-replying (handed off to a human)

conversation.assignee

object | null

The support member who took over, { id, name }; null if unassigned

inbox.id / inbox.name

string

Conversation platform ID and name

inbox.channel_type

string

web / line / messenger / instagram / telegram / teams / email / whatsapp / slack / team_plus / line_works / viber

contact

object | null

The visitor (contact) { id, name, email, phone_number }

sender.type

string

chatbot (Agent) / user (human agent) / contact (visitor)

attachments[]

array

Attachments { id, type, filename, source_url }; type is image / video / audio / sticker / other

metadata

object

Additional message data

Custom templates (Jinja2)

When your system requires a specific JSON structure, select Custom template and write the payload in Jinja2 syntax. The rendered result must be valid JSON; it is validated once with test data when you save.

Available variables

Variable
Contents

message

id, type, content, created_at (datetime), metadata

conversation

id, title, type, status, progress_status, auto_reply_enabled, assignee (may be None; when set, assignee.id and assignee.user.name)

inbox

id, name, channel_type

contact

id, name, email, phone_number, source_id (the sourceId you passed in through the identity sync API); may be None

sender

id, name; sender_type is chatbot / user / contact

attachments

List of attachments, each with id, type, filename, source_url, and file (file.url is the downloadable URL)

now

The time at render (datetime)

Always output strings through the | tojson filter so that quotes and line breaks are escaped correctly.

Example: return your system's user ID and downloadable attachment URLs

Verifying signatures and timestamps

When a Secret Token is set on a Webhook, every push carries the following headers. The receiver can use them to confirm that the request came from MaiAgent, that the content has not been tampered with, and to reject stale replayed requests:

Header
Contents

X-MaiAgent-Timestamp

The Unix time (in seconds) at the moment of this send

X-MaiAgent-Signature-256

sha256=<hex>: the HMAC-SHA256 computed with the Secret Token as the key over "timestamp + . + raw request body", in lowercase hexadecimal

X-MaiAgent-Delivery-Attempt

Which attempt this is; the first is 1 (always included, whether or not a Secret Token is set)

X-Webhook-Secret

The Secret Token in plain text. It is still sent for now for compatibility with existing receivers that only compare this value; it is no longer recommended, so verify the signature instead

Verification steps

  1. Read the raw bytes of the request body; do not parse the JSON and then re-serialize it. MaiAgent sends compact (no whitespace), UTF-8 encoded JSON without escaping Chinese characters. The bytes after re-serialization usually differ, and the signature will not match.

  2. Take X-MaiAgent-Timestamp and compare it with the receiver's current time; reject the request if it exceeds the tolerance you set (for example, 5 minutes). Every attempt (including resends) recomputes the timestamp and signature at the moment of sending, so a resend is not rejected for having a stale timestamp.

  3. Compute HMAC-SHA256(secret, f"{timestamp}.".encode() + raw_body) with the Secret Token, convert it to hexadecimal, and prefix it with sha256=.

  4. Compare it with X-MaiAgent-Signature-256 using a constant-time comparison (for example, Python's hmac.compare_digest); if they do not match, respond with 401.

Delivery behavior

  • Each message is pushed once for each enabled Webhook; the request times out after 30 seconds.

  • A 2xx response is treated as success.

  • Endpoint URLs go through SSRF protection: destinations on private network ranges or internal addresses are rejected.

  • Every attempt (including resends) keeps its own record of the request content, response, and status code, which you can view for troubleshooting in the Webhook tab of the Agent page.

Automatic resends

Result of each attempt
Handling

Timeout, connection failure, 5xx, 429

Treated as a temporary failure; resent once each after about 1, 5, and 15 minutes, for up to 3 resends (4 attempts in total including the first)

Other 4xx (for example, 400, 401, 404)

Recorded as failed; not resent

Destination blocked by SSRF protection (a domain name resolution failure also counts, including a temporary DNS failure), or custom template rendering failure

Recorded as failed; not resent

  • The request body of a resend is byte-for-byte identical to the first one; X-MaiAgent-Delivery-Attempt is 2, 3, and 4 in order, and the timestamp and signature are recomputed at the moment of sending.

  • The URL, custom headers, and Secret Token are taken from the Webhook settings at the time of the resend; if the Webhook has been disabled or deleted, or the message has been deleted, before a resend, it is not resent.

  • After all 3 resends fail, MaiAgent gives up and does not send again. To backfill data, call GET /api/v1/messages/?conversation={conversationId} to query the messages of that conversation (the conversation parameter is required; see Conversation and message replies (streaming/synchronous)).

  • The resend intervals are fixed; the Retry-After header in the response is not read.

  • When the payload format is Genesys Cloud, a 401 first refreshes the access token and immediately resends once, without using up the 3 resends above; if that resend hits a temporary failure, it is resent on the schedule in the table above, and if it is still 401, it stops.

Idempotency recommendations

With resends, the delivery semantics are "at least once": if your endpoint has actually processed a request but the response timed out or returned 5xx, you will receive the same message again. We recommend that you:

  • Deduplicate by the message id in the payload, and return 2xx directly for any id you have already processed. When using a custom template, keep message.id in the template; otherwise you cannot deduplicate.

  • Deduplicate by message id, not by X-MaiAgent-Timestamp or the signature: both change on every attempt.

  • Persist the received content (write it to a database or queue) before returning 2xx, and move time-consuming processing to run asynchronously, so you do not exceed the 30-second timeout and trigger unnecessary resends.

  • Return 4xx (which is not resent) only when you are sure the request can never be processed; if it temporarily cannot be processed (for example, a downstream service is down), return 5xx or 429 so that MaiAgent resends it later.

Managing Webhooks via API

In addition to the admin interface, you can also create and maintain Webhooks through the API (the fields correspond to the admin console settings). For authentication, see Quick start.

You can get inboxId from the inbox.id in the response of Create conversation, or look it up on the conversation platform settings page in the admin console.

Differences from the "human handoff Webhook"

The Webhook on this page pushes by message. If your system needs to know when a conversation is handed off to a human and when it returns to the AI (for example, when your customer service system takes over the service), use the separate human handoff Webhook, which pushes by conversation lifecycle; see Third-party customer service system integration (including human handoff).

Last updated

Was this helpful?