The Messaging API lets you use the Virtual Assistant conversational engine in channels without a direct integration. For example, if you want to embed the bot inside an application without opening the chat window, or integrate it into your own channel, the API is the right path.
It is a stateful conversational API that operates through a single endpoint. "Stateful" refers to a system or application that keeps information about previous interactions so it can continue processes or respond in context.
Each interaction represents one conversation turn: you send a message (sentence) and receive a response from the Virtual Assistant along with optional UI components (complements).
The Virtual Assistant's response arrives in the same HTTP response as each message, with the corresponding text and complements. The API does not use webhooks or send "push" messages: each response is obtained by sending a message.
This type of integration requires a development team due to its level of complexity. |
Here you will find all the documentation you need to use the Messaging API: Conversation Public Api
General flow: the integration follows this cycle:
- You must authenticate with a username and password and obtain a Bearer Token (JWT).
- Request the channel's X-Token through a Service Request in the Support Center.
- With the Bearer Token you obtained and the X-Token you received, send messages to the conversation endpoint along with the user's data.
- The Virtual Assistant responds with text and, optionally, UI components (buttons, lists, etc.).
- The cycle repeats until the user ends the interaction or is transferred to a human agent.
Through the user parameter, you can send additional data to use in Integrations or to save the user's information in the Chat Report. |
Authentication: You must obtain the Bearer Token required for all calls to the Messaging API.
Endpoint: POST https://gateway.aivo.co/api/v1/auth
- The Bearer Token lasts 10 hours and can be reused. We recommend not generating a new token for every request.
- The user is created based on the email address you provided; the password is defined by your team.
Sending messages: All interactions (queries, flows, actions) are made through this single endpoint, which is the main endpoint of the conversational API.
Endpoint: POST https://gateway.aivo.co/api/v1/conversation/messages
Required headers
| Header | Type | Required | Description |
| Content-Type | string | Yes | Always application/json |
| X-Token | string | Yes | Token provided by your team |
| Authorization | string | Yes | Bearer token obtained from the Auth API |
Request Body example
{ |
| Field | Type | Required | Description |
| sentence | string | Yes | The user's message, the option chosen by the user, or the intent that starts the desired flow. |
| user | object | Yes | User data. |
| user.hash | string | Yes | Unique user identifier (keeps the session). It must be exactly 32 characters long; otherwise, the API returns an error. |
| user.id | string | No | Unique user ID. It is optional; if sent, it is usually the same as the hash. |
| user.name | string | Yes | User's first name. |
| user.lastname | string | Yes | User's last name. |
| user.email | string | Yes | User's email address. |
You do not have to use real data. The name, last name, and email fields do not necessarily need to contain the user's real information. |
Key facts about Complements
Complements let you display content in a friendlier way, with visual and interactive formats, making it faster to read and understand than plain text alone. When implementing them through the API, your technical team must build them entirely. The API only provides the information as JSON.
- Image: returns an image link and a reference ID to position it when there are placeholders available in the text, such as { ref: xxxx}.
- Cobrowsing: the chat history cannot be preserved when redirecting to another page unless this is specifically implemented.
- Transfer to an online human agent via open_agentlive/Firebase (customToken, Room).
- Response with derivation to a human agent: when the flow requires human attention, the response includes a specific complement. How to detect and process it:
- Look for the route complements with param = "live".
- Extract the customToken from open_agentlive to authenticate against the live chat service (Firebase).
- Room identifies the room assigned to the user.
- Live_agent is null until an agent takes the session.
- Response with derivation to a human agent: when the flow requires human attention, the response includes a specific complement. How to detect and process it:
- Forms: arrive in "callback" format, one field at a time. If the channel adapts them to callback, they will work correctly.
- Dropdown menu: not supported by the API. The options do not arrive correctly.
- Existing integrations: If you already have integrations, you do not need to adjust them when migrating to the API. However, if they contain complements (carousel, buttons, etc.), you need to validate that they work in the channel where you implement them. The integration_response field indicates that the response was processed by an integration.
- Buttons: Let you add a button with a link or a question, in the form of options for the user.
- If the button is of type "Next step", the next interaction must be the "label" of the option chosen by the user. The expected behavior is to advance the flow.
- If the button is of type "Message", the next interaction must be the "value" of the option chosen by the user. The expected behavior is to send a message.
- For links, the URL format is validated (https), and you can choose whether it opens in the same window (_self) or a new one (_blank). When the user opens the link, you do not need to send any message to the Messaging API.
- Interactive dropdown list: the behavior is the same as the message button type, and the next interaction must be the ID of the item chosen by the user.
| Type | Behavior | What to send as a sentence |
| Next step button | Advances the flow | The button's LABEL |
| Message button | Sends a message | The button's VALUE |
| Interactive list | Sends a message | The ID of the item chosen by the user. |
The value field of step-type buttons is an internal reference. Never send it as a sentence. |
| Field | Type | Description |
| blockInput | boolean | true: the user can only choose a button; false: the user can also type |
| oneChoice | boolean | true: the button disappears after being selected |
For full integration with human agents, consult the CSM team about the Live APIs and Webhooks documentation. |
Other formats:
- Conditions: if you need conditional content (for example, different answers by country), you must use a separate channel for each condition. When making the request from the Messaging API, you must use one channel or the other, sending the corresponding token. Example:
- If you want to differentiate the response for customers in Argentina and Uruguay, you will need two channels on the platform, each conditioned on "Argentina" and "Uruguay". When making the request from the Messaging API, you must send the Argentina channel's xtoken for requests from Argentina and the Uruguay channel's xtoken for requests from Uruguay.
- Satisfaction surveys: there are no events or ways to send satisfaction surveys through the API.
Aivo does not provide support for the external tools used for the integration, as they are platforms outside the Suite. |
Session management:
- The API maintains one conversational session per user. Understanding the session is key to integrating correctly.
- The session is identified by user.hash, which must be exactly 32 characters long.
- All calls with the same hash belong to the same session.
Lifecycle
| Event | Description | Action you must take |
| Start | Created when the first message with a hash is sent. | Send the initial sentence with the user's data |
| Active | Each message keeps the session alive and accumulates context. | Keep sending sentences according to the flow |
| Expiration | Expires due to inactivity (configurable timeout). | Detect the expiration and start a new session |
| Explicit close | Closed with POST /api/v1/conversation/events/close | Call close when finished. |
| Transfer to live | The route changes to live and the conversation passes to a human agent. | Open the Live channel with the customToken. |
Closing the conversation:
- We recommend explicitly closing the session when the user finishes the interaction, with POST https://gateway.aivo.co/api/v1/conversation/events/close, sending the conversation's user.hash.
- If the session is not closed explicitly, it expires automatically according to the TTL (Time to Live), the mechanism that sets the maximum duration of an active session.
Signs of an expired session:
- The response does not match the flow in progress.
- user_data loses variables accumulated during the flow.
- The route changes unexpectedly.
Recommended action for an expired session:
- Re-authenticate.
- Obtain a new Bearer token.
- Resend the flow's initial sentence.
- Let the user know that the session was restarted.
User data variables: The user_data complement contains the accumulated state of the session. As the user progresses, useful variables are added for debugging and tracking.
Variables common to all flows
| Variable | Type | Description |
| canal_nombre | string | Channel name (e.g., HELP- Messaging API). |
| canal_tipo | string | Channel type (e.g., Web) |
| string | User's email address | |
| id | string | User ID/hash |
| name | string | User's first name |
| lastname | string | User's last name |
| lastSessionId | string | ID of the last active session |
Analytics: channels implemented with the API are analyzed under the "Public API" filter. It is not possible to distinguish between multiple channels connected through the API. |
See also:
FAQs and best practices for the Messaging API
Error mapping and technical considerations for the Messaging API
This type of integration requires a development team due to its level of complexity.
The value field of step-type buttons is an internal reference. Never send it as a sentence.