Message Webhook
Whenever an Inbox receives a customer message or sends a reply, MaiAgent can push that message to a URL you specify. This guide covers Incoming and Outgoing webhooks, admin console and API configurati
After you configure message webhooks for an Inbox, MaiAgent pushes each message to your system without polling. Common uses include displaying new message notifications in your own system, syncing customer messages to a CRM, and logging AI replies in a data warehouse.
An Inbox can have multiple message webhooks. Each has its own type, URL, and format, and delivers messages independently.
Types: Incoming and Outgoing
Type
When it is sent
Payload type
Incoming
Whenever the Inbox receives a customer (contact) message
incoming
Outgoing
Whenever a reply is sent to the customer's conversation platform, including automatic AI replies and replies from human support agents
outgoing
The admin console describes
Incomingas “Receive external requests,” but it actually pushes each customer message to the URL you configure.Receivein the same menu works in the opposite direction: an external platform sends messages into MaiAgent. This is outside the scope of this guide. Messages received throughReceivedo not triggerIncomingorOutgoingwebhooks for the same Inbox, preventing messages from looping between the two systems.To receive both customer messages and replies, configure one
Incomingwebhook and oneOutgoingwebhook. Both can use the same URL; distinguish them by the payload'stype.
Configuration
Configure in the admin console
Admin console → Customer Conversations → Inboxes → Select an Inbox → Webhook Settings → Add Webhook
Enter a Name, set Type to Incoming or Outgoing, enter the Webhook URL, and select an HTTP Method (default
POST).(Recommended) Add an authentication header under Headers, such as
Authorization: Bearer <YOUR_RANDOM_STRING>. The receiver can use it to confirm that requests come from MaiAgent (see Verify the source).Set Payload Format to MaiAgent Standard (see Payload). Choose Custom Template if you need custom fields.
Make sure Enabled is on, then save. Turning it off pauses delivery and retains the configuration.
The WhatsApp Inbox settings page currently has no Webhook Settings tab. Use the API configuration below instead.
Configure through the API
Message webhooks belong to an Inbox:
List
GET /api/v1/inboxes/{inbox_id}/webhooks/
Create
POST /api/v1/inboxes/{inbox_id}/webhooks/
Retrieve one
GET /api/v1/inboxes/{inbox_id}/webhooks/{id}/
Update
PATCH /api/v1/inboxes/{inbox_id}/webhooks/{id}/ (send only the fields to change)
Delete
DELETE /api/v1/inboxes/{inbox_id}/webhooks/{id}/
The API key owner must have permission to manage the Inbox. See API Authentication → API key permissions.
name
Yes
A name for easy identification
direction
Yes
incoming or outgoing
url
Yes
The URL that receives deliveries; it must be accessible from the internet (https:// recommended). Delivery to URLs pointing to internal networks or local addresses is blocked
method
No
POST (default), PUT, or PATCH
headers
No
Custom headers included with every delivery, as a JSON object, such as {"Authorization": "Bearer ..."}
templatePreset
No
maiagent_standard (default), custom, or genesys_cloud for Genesys Cloud integration
customTemplate
Required for custom
A Jinja2 template whose rendered output must be JSON. A test render runs when saving; invalid formatting returns 400
secretToken
No
The signing secret. When set, each delivery includes an HMAC-SHA256 signature and timestamp headers (see Verify the source). Write-only; never returned in queries
isEnabled
No
Whether the webhook is enabled; defaults to true
A successful request returns 201 and the configuration (excluding secretToken). To also receive replies, create another webhook with "direction": "outgoing".
Payload
Each message is delivered as a single HTTP request:
Headers:
Content-Type: application/json, your custom headers,X-MaiAgent-Delivery-Attempt(the attempt number, starting at1), and, whensecretTokenis set,X-MaiAgent-TimestampandX-MaiAgent-Signature-256. Custom headers with the same names as these three headers (case-insensitive) are removed before sending.Body: JSON generated according to the Payload Format.
MaiAgent Standard format
All fields use snake_case, unlike the camelCase used in API responses. The following is an Outgoing (AI reply) payload:
id
Message ID; use it for deduplication or look it up through the Message API
type
incoming (customer message) or outgoing (reply); use this field to determine the direction
content
Message text
created_at
Message creation time (ISO 8601, UTC)
conversation
The conversation this message belongs to. A progress_status of human_serving means a human support agent is handling it. assignee is the assigned support agent as { "id", "name" }, or null if unassigned
inbox
Inbox as { "id", "name", "channel_type" }; examples of channel_type include web, line, and messenger
contact
The customer (contact); email and phone_number are null when unavailable
sender
The speaker. type is contact (customer), chatbot (Agent), or user (organization member, such as a human support agent; messages sent on a customer's behalf using an API key also have type user)
attachments
An array of attachments, each containing id, type (image / video / audio / sticker / other), filename, and source_url
metadata
Additional message information; its contents vary by Inbox
Custom templates
Custom Template (templatePreset: "custom" in the API) uses Jinja2 syntax to build the JSON you need. Available variables are message (id, type, content, created_at, metadata), conversation, inbox, contact, sender, sender_type (contact / chatbot / user), attachments, and now. Output strings with the tojson filter to prevent quotes or line breaks from breaking the JSON:
If the template fails to render at delivery time, that message is not sent.
Verify the source
When you set secretToken (the API field, or Secret Token in the admin console's webhook form; this field is hidden in the console when the payload format is Genesys Cloud), each delivery includes these headers:
X-MaiAgent-Timestamp
Unix time at the moment of sending, in seconds
X-MaiAgent-Signature-256
sha256= followed by the hexadecimal value of HMAC-SHA256(secretToken, "{timestamp}." + raw body)
Verification steps for the receiver:
Calculate the signature using the original raw body bytes you received. Do not parse the JSON and serialize it again first; the bytes will differ and the signature will not match.
Compare it against
X-MaiAgent-Signature-256using a constant-time comparison, such as Python'shmac.compare_digest.Reject requests when
X-MaiAgent-Timestampdiffers from the receiver's current time by more than the allowed tolerance (for example, 5 minutes) to prevent replay attacks. The timestamp and signature are recalculated at send time for every attempt, including retries.
For details, see Verify signatures and timestamps in the technical manual.
If you do not use signatures, you can set an authentication header in
headers, such asAuthorization: Bearer <RANDOM_STRING>. Values inheadersare returned unchanged when querying webhook settings and are visible to any organization member who can view that Inbox's settings.secretTokenis write-only and is never returned.When
secretTokenis set, the legacyX-Webhook-Secretheader (containing the rawsecretTokenvalue) is also sent for compatibility with existing receivers. New integrations should verify the signature instead.Use a sufficiently long random secret for authentication and receive requests over HTTPS.
Responses and retries
Delivery runs in the background after the message is saved, usually arriving within a few seconds. Messages are sent independently, and arrival order is not guaranteed. Sort by
created_atand deduplicate byid.The receiver must return a 2xx response within 30 seconds. Timeouts, connection failures, and non-2xx responses count as failures.
Temporary failures are retried automatically: timeouts, connection failures,
5xx, and429are retried once each after approximately 1, 5, and 15 minutes, for a maximum of 3 retries (4 attempts including the initial delivery). Other4xxresponses, destinations blocked by security protections, and custom template rendering failures are not retried. The retry body is identical to the initial body;X-MaiAgent-Delivery-Attemptincrements to2,3, and4. Intervals are fixed; the response'sRetry-Afteris not used. Retries stop if the webhook is disabled or deleted, or the message is deleted, before the next attempt. See Automatic retries in the technical manual for details.With retries, a message can be delivered “at least once”: if the receiver has processed it but its response times out or returns
5xx, the same message will arrive again. Deduplicate by messageid. Save the content before responding with 2xx and move time-consuming processing to the background. Return4xxonly when the message can never be processed; return5xxor429for temporary problems, such as a downstream service outage.Delivery stops after all 3 retries fail; message webhooks do not guarantee delivery. The polling approach in Detect new messages can check for missed customer messages (Incoming) at a low frequency. AI and support replies (Outgoing) often appear after the customer message, and the polling example may not read them again, so it cannot recover replies whose webhook delivery failed. To identify failed deliveries, query the delivery records described below. A
statusCodethat is not 2xx or is empty (timeout or connection failure) indicates a failed delivery.requestBodycontains the payload sent at the time (the MaiAgent Standard format includes the messageidandconversation.id); then read the first page of that conversation's message list to recover the missing messages.Each attempt, including retries, creates its own delivery record with the URL, body, and response status code. Query them with
GET /api/v1/chatbots/{chatbot_id}/webhook-records/(requires edit permission for that Agent;chatbot_idis the Agent linked to the Inbox). This API also returns camelCase fields, while the actual delivered payload uses snake_case.Failed webhook deliveries do not affect message sending, receiving, or AI replies.
Minimal receiver example
The following Python (Flask) receiver can be started directly. It verifies signatures and timestamps, deduplicates by message id (the same message may arrive again on retries), routes by type, and returns 2xx before processing. Set MESSAGE_WEBHOOK_SECRET to your configured secretToken. If you use a custom authentication header instead, read the corresponding header.
Use the following commands to simulate a delivery with a valid signature for local testing:
Last updated
Was this helpful?