Detect New Messages
To notify your system when a conversation has new messages (for example, to display notifications or alert human support agents), use Webhook delivery first; if polling is needed, read only updated co
To display a “new message” notification in your system or notify human support agents when a customer sends a message, choose an approach in this order:
Use Webhook delivery first: The conversation platform’s message Webhook sends one notification per message, with no polling required (see Use Webhooks Instead of Polling).
If you only need human handoff notifications: Use human handoff Webhook events, which are sent only when the handoff workflow changes state.
If polling is required: Follow the recommended polling approach to find only updated conversations and read only the first page of each conversation’s message list.
Use Webhooks Instead of Polling
Receive a notification for every customer message
Use the conversation platform’s message Webhook with type Incoming
For every customer (contact) message
Synchronize replies sent by AI or support agents
Use the conversation platform’s message Webhook with type Outgoing
For every reply sent to the customer’s conversation platform
Receive a notification when a conversation needs a human agent
Only for human handoff, agent assignment, return to AI, or queue timeout; not for every message
Configuration path: Admin console → Customer Conversations → Conversation Platforms → select a conversation platform → Webhook Settings → Add Webhook. Set Type to Incoming or Outgoing (although the admin console describes Incoming as “Receive external requests,” it actually sends each customer message to your configured URL; Receive is the type that receives external messages). Set Payload Format to MaiAgent Standard (MaiAgent’s standard format). See Message Webhook for payload contents, source verification, and retry behavior.
The WhatsApp conversation platform’s settings page currently has no Webhook Settings tab. Use the polling approach below instead.
The two Webhook types are configured independently and can be enabled together; deduplicate their payloads using the message or event id. Message Webhooks automatically retry up to 3 times on timeouts, connection failures, 5xx, or 429 responses (the same message may arrive more than once). If all 3 retries fail, delivery stops; delivery is not guaranteed. The polling approach below can check for missed customer messages (Incoming) at a low frequency. If delivery of an AI or support agent reply (Outgoing) fails, the polling example may not retrieve it. Check the Webhook delivery logs for failed deliveries instead (see Message Webhook → Responses and Retries).
Recommended Polling Approach
If you cannot receive Webhooks (for example, because the receiving endpoint cannot be exposed publicly), poll using the following two APIs together.
1. Find Updated Conversations
The conversation list is always sorted by last message time, newest first (lastMessageCreatedAt in the response). For each conversation, record the last observed lastMessageCreatedAt and the last message’s lastMessage.id. A change to either means the conversation has been updated (timestamps have second precision, so if two messages arrive in the same second, only the id changes). In each polling round, read from the first entry down and stop when you reach a conversation older than “the latest time observed so far minus 10 minutes.” Usually, you only need the first page. Follow the response’s next to the next page only if more than page_size conversations were updated within that window.
The extra 10-minute lookback is necessary because, in API conversations, a conversation’s lastMessageCreatedAt may be written only after the AI reply finishes generating. The value is still the customer message’s timestamp, so it may be older than other conversations you saw in the previous round. Comparing only whether it is newer than the previous round’s latest time would miss these conversations.
2. Read Only the First Page of Messages for Each Updated Conversation
The first page of the message list contains the latest messages: the system selects the latest page_size messages, then sorts them from oldest to newest within the page. The last message is therefore the latest in the entire conversation. The response’s next points to older messages; do not read back through the history in every round when detecting new messages.
Use each message’s id to determine whether it has been processed: unprocessed id values on the first page identify new messages. Pagination is needed in only one case—when all messages on the first page are unprocessed (more than page_size messages arrived between rounds). Only then follow next to older pages until you encounter a processed message.
3. Polling Interval and Page Size
Polling interval
30–60 seconds
Use Webhooks for more immediate notifications; do not shorten the interval to a few seconds
page_size
20
Default 20, maximum 100. Larger pages produce slower responses and more content
Request Examples
An API key has the same permissions as its owner’s role in the organization. The owner must be able to view conversations on the relevant conversation platform. See API Authentication → API Key Permission Scope.
Last updated
Was this helpful?