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.
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
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
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
MaiAgent standard format
Content-Type: application/json, with the following content (Outgoing and Incoming share the same structure, distinguished by type):
Field descriptions
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
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:
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
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.
Take
X-MaiAgent-Timestampand 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.Compute
HMAC-SHA256(secret, f"{timestamp}.".encode() + raw_body)with the Secret Token, convert it to hexadecimal, and prefix it withsha256=.Compare it with
X-MaiAgent-Signature-256using a constant-time comparison (for example, Python'shmac.compare_digest); if they do not match, respond with401.
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
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-Attemptis2,3, and4in 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 (theconversationparameter is required; see Conversation and message replies (streaming/synchronous)).The resend intervals are fixed; the
Retry-Afterheader in the response is not read.When the payload format is Genesys Cloud, a
401first 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 still401, 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
idin the payload, and return2xxdirectly for anyidyou have already processed. When using a custom template, keepmessage.idin the template; otherwise you cannot deduplicate.Deduplicate by message
id, not byX-MaiAgent-Timestampor 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), return5xxor429so 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?