RTM API Reference
Introduction
Versioning
This document describes the Customer Chat Real-Time Messaging API v3.6. This is the developer preview version that provides a preview of the upcoming changes to the API. It's not open to public use. However, if you want to test some features, contact us at developers@text.com or ask on the chat, and we'll give you access. Read more about versioning...
What is RTM API
Real-Time Messaging API (RTM API) is based on a websocket-like connection. Client can send a request message that results in getting a response message. It's also possible to get push messages.
When to use RTM API
If you're wondering which API to use - Customer Chat RTM API or Web API, keep on reading.
Real-Time Messaging API allows for building stateful integrations that require logging in and maintaining the connection. Since connection maintenance is required, the implementation might be more challenging than with Web API.
Customer Chat RTM API enables communication in real time. It supports pushes like sneak peek
, typing indicator
, and other. Web API doesn’t have equivalent webhooks, which means you won't be informed about certain events using Web API.
Also, the RTM API will be a better choice if you want to avoid time delays or presume significant traffic.
Not what you're looking for? Perhaps, you need to use Customer Chat Web API instead.
Access
The basics on authorization and server pinging in the Customer Chat RTM API.
Authorization
Customer authorization is handled with access tokens. Find out how to get an access token from Customer authorization flow. You need to authorize within 30 seconds from establishing the connection. Otherwise, the connection will be closed. Given that the connection is continuosly maintained, you only need to authorize once.
Server pinging
After successful authorization, the client needs to ping the server every 15 seconds. Otherwise, the connection will be closed after about 30 seconds of inactivity. Until authorization is completed, ping is a no-op.
Use one of these 2 ways of pinging the server:
- Protocol message with the ping action
For web applications and backend integrations (e.g. in Python, Go). Send the following request every 15 seconds:
After pinging the server, the client will receive a response with the ping
action. Thanks to that, the client can make sure the connection is still alive.
- The control frame ping in the websocket protocol
For backend integrations; unavailable in web browsers. Read more about the control frame ping.
Data centers
LiveChat system operates in two data centers: dal
(USA) and fra
(Europe). The default data center is dal
.
For backend applications, you can specify the region in the request header. The mechanism is the same as in Customer Chat Web API reference. It doesn't work for frontend applications, though.
Instead, frontend apps connect to a region different than the default one by specifying the region suffix in the URL.
fra
: wss://api-fra.livechatinc.com/v3.6/customer/rtm/ws
dal
: wss://api.livechatinc.com/v3.6/customer/rtm/ws
Pagination
Pagination is a mechanism that allows splitting the database output into more manageable chunks of data.
Based on the limit
and sort order
parameters, pagination is able to decide how many records will be returned at once and whether it should fetch the oldest or the latest data first.
Any filters that could be applied should be provided in first pagination request. In the response, you'll get the next_page_id
and previous_page_id
parameters.
You should make the subsequent request using one of these parameters as page_id
, depending on the direction of iteration: forward or backward.
The filters
, limit
, and sort_order
parameters can't be provided along with page_id
.
💡 The maximum duration of the page_id
parameter before it expires is one month.
Data structures
To find sample payloads of events, users, and other common structures such as chats or threads visit the Data structures document.
Methods
The API endpoint |
---|
wss://api.livechatinc.com/v3.6/customer/rtm/ws |
When connecting to the Customer Chat RTM API, clients have to send over the required query string parameters.
Required parameter | Data type |
---|
organization_id | string |
GENERAL RTM API RESPONSE FORMAT Chats
List Chats
It returns summaries of the chats a Customer participated in.
Specifics
| |
---|
Action | list_chats |
Web API equivalent | list_chats |
Push message | - |
Request
Parameter | Required | Type | Notes |
---|
limit | No | number | Default: 10, maximum: 25 |
sort_order | No | string | Possible values: asc , desc (default). Chat summaries are sorted by the creation date of its last thread. |
page_id | No | string | |
Response
Field | Data type | Notes |
---|
total_chats | number | An estimated number. The real number of found chats can slightly differ. |
next_page_id | string | In relation to page_id specified in the request. Appears in the response only when there's the next page. |
previous_page_id | string | In relation to page_id specified in the request. Appears in the response only when there's the previous page. |
chats_summary | array | Array of Chat summary data structures. |
List Threads
It returns threads that the current Customer has access to in a given chat.
Specifics
| |
---|
Action | list_threads |
Web API equivalent | list_threads |
Push message | - |
Request
Parameter | Required | Data type | Notes |
---|
chat_id | Yes | string | |
sort_order | No | string | Possible values: asc - oldest threads first and desc - newest threads first (default). |
limit | No | number | Default: 3, maximum: 100 |
page_id | No | string | |
min_events_count | No | number | Range: 1-100; Specifies the minimum number of events to be returned in the response. It's the total number of events, so they can come from more than one thread. You'll get as many latest threads as needed to meet the min_events_count condition. |
You cannot use both limit
and min_events_count
at the same time.
Get Chat
Specifics
| |
---|
Action | get_chat |
Web API equivalent | get_chat |
Push message | - |
Request
Parameter | Required | Data type | |
---|
chat_id | Yes | string | |
thread_id | No | string | Default: the latest thread (if exists) |
Start Chat
Starts a chat.
The method updates the requester's events_seen_up_to
as if they've seen all chat events.
Specifics
Request
Parameter | Required | Data type | Notes |
---|
chat | No | object | |
chat.properties | No | object | Initial chat properties |
chat.access | No | object | Chat access to set, default: all agents. |
chat.users | No | array | List of existing users. Only one user is allowed (type customer ). |
chat.thread | No | object | |
chat.thread.events | No | array | Initial chat events array. Does not support the form type event in the LiveChat app. |
chat.thread.properties | No | object | Initial thread properties |
active | No | bool | When set to false , creates an inactive thread; default: true . |
continuous | No | bool | Starts chat as continuous (online group is not required); default: false . |
Response
Field | Data type | Notes |
---|
chat_id | string | |
thread_id | string | |
event_ids | []string | Returned only when the chat was started with initial events. Returns only the IDs of user-generated events; server-side generated events are not included in the array. |
Resume Chat
Restarts an archived chat.
The method updates the requester's events_seen_up_to
as if they've seen all chat events.
Specifics
Request
Parameter | Required | Type | Notes |
---|
chat | Yes | object | |
chat.id | Yes | string | The ID of the chat that will be resumed. |
chat.access | No | object | Chat access to set, default: all agents. |
chat.properties | No | object | Initial chat properties |
chat.thread | No | object | |
chat.thread.events | No | array | Initial chat events array |
chat.thread.properties | No | object | Initial thread properties |
active | No | bool | When set to false , creates an inactive thread; default: true . |
continuous | No | bool | Sets a chat to the continuous mode. When unset, leaves the mode unchanged. |
Response
Field | Data type | Notes |
---|
thread_id | string | |
event_ids | []string | Returned only when the chat was resumed with initial events. Returns only the IDs of user-generated events; server-side generated events are not included in the array. |
Deactivate Chat
Deactivates a chat by closing the currently open thread. Sending messages to this thread will no longer be possible.
Specifics
Request
Parameter | Required | Data type | |
---|
id | Yes | string | |
Events
Send Event
Sends an Event object. Use this method to send a message by specifying the Message event type in the request.
The method updates the requester's events_seen_up_to
as if they've seen all chat events.
Specifics
Request
Parameter | Required | Data type | Notes |
---|
chat_id | Yes | string | Id of the chat you want to send the message to. |
event | Yes | object | Event object. Does not support the form type event in the LiveChat app. |
attach_to_last_thread | No | bool | The flag is ignored for active chats. For inactive chats: true – the event will be added to the last thread; false – the request will fail. Default: false . |
Send Rich Message Postback
Specifics
*) incoming_rich_message_postback
will be sent only for active threads.
Request
Parameter | Required | Data type | Notes |
---|
chat_id | Yes | string | |
event_id | Yes | string | |
postback | Yes | object | |
postback.id | Yes | string | Postback name of the button |
postback.toggled | Yes | bool | Postback toggled, true or false |
thread_id | Yes | string | |
Send Sneak Peek
Sends a sneak peek to a chat.
Specifics
Request
Parameter | Required | Data type | Notes |
---|
chat_id | Yes | string | Id of the chat to send a sneak peek to. |
sneak_peek_text | Yes | string | Sneak peek text |
Properties
Update Chat Properties
Specifics
Request
Parameter | Required | Data type | Notes |
---|
id | Yes | string | Id of the chat you to set a property for. |
properties | Yes | object | Chat properties to set. You should stick to the general properties format and include namespace, property name and value. |
Delete Chat Properties
Specifics
Request
Parameter | Required | Data type | Notes |
---|
id | Yes | string | Id of the chat you want to delete properties of. |
properties | Yes | object | Chat properties to delete. |
Update Thread Properties
Specifics
Request
Parameter | Required | Data type | Notes |
---|
chat_id | Yes | string | Id of the chat you want to set properties for. |
thread_id | Yes | string | Id of the thread you want to set properties for. |
properties | Yes | object | Chat properties to set. You should stick to the general properties format and include namespace, property name and value. |
Delete Thread Properties
Specifics
Request
Parameter | Required | Data type | Notes |
---|
chat_id | Yes | string | Id of the chat you want to delete the properties of. |
thread_id | Yes | string | Id of the thread you want to delete the properties of. |
properties | Yes | object | Thread properties to delete. |
Update Event Properties
Specifics
Request
Parameter | Required | Data type | Notes |
---|
chat_id | Yes | string | Id of the chat you want to set properties for. |
thread_id | Yes | string | Id of the thread you want to set properties for. |
event_id | Yes | string | Id of the event you want to set properties for. |
properties | Yes | object | Chat properties to set. You should stick to the general properties format and include namespace, property name and value. |
Delete Event Properties
Specifics
Request
Parameter | Required | Data type | Notes |
---|
chat_id | Yes | string | Id of the chat you want to delete the properties of. |
thread_id | Yes | string | Id of the thread you want to delete the properties of. |
event_id | Yes | string | Id of the event you want to delete the properties of. |
properties | Yes | object | Event properties to delete. |
Customers
Update Customer
Specifics
Request
Parameter | Required | Data type | Notes |
---|
name | No | string | |
email | No | string | |
avatar | No | string | URL of the Customer's avatar. |
session_fields | No | []object | An array of custom object-enclosed key:value pairs. Respects the order of items. |
At least one optional parameter needs to be included in the request payload.
When updating customer data while the customer has an active chat, the update will take effect after the chat has ended.
Update Customer Page
Specifics
| |
---|
Action | update_customer_page |
Web API equivalent | - |
Push message | - |
Agent and referrer are updated by default using the browser’s headers.
Request
Parameter | Required | Data type | |
---|
url | Yes | string | |
title | No | string | |
Set Customer Session Fields
Specifics
Request
Parameter | Required | Data type | Notes |
---|
session_fields | Yes | []object | An array of custom object-enclosed key:value pairs. Respects the order of items. Max keys: 100 |
Agent and referrer are updated by default using the browser’s headers.
Get Customer
Returns the info about the Customer requesting it.
Specifics
| |
---|
Action | get_customer |
Web API equivalent | get_customer |
Push message | - |
Response
| |
---|
name | Customer's name. Returned only if set. |
email | Customer's email. Returned only if set. |
avatar | Customer's avatar. Returned only if set. |
session_fields | An array of custom object-enclosed key:value pairs. Returned only if set. Available for the session duration. |
Status
Login
It returns the initial state of the current Customer.
Specifics
| |
---|
Action | login |
Web API equivalent | - |
Push message | - |
Request
Parameter | Required | Data type | Notes |
---|
token | Yes | string | OAuth token from the Customer's account |
customer | No | object | |
customer.avatar | No | string | The URL of the Customer's avatar |
customer.email | No | string | |
customer.name | No | string | |
customer.session_fields | No | []object | An array of custom object-enclosed key:value pairs. Respects the order of items. |
customer_page.title | No | string | |
customer_page.url | No | string | |
customer_side_storage * | No | object | A map in the "key": "value" format |
is_mobile | No | bool | Informs if logging in is performed from a mobile device. |
group_id | No | number | |
referrer | No | string | |
application | No | object | Application info |
application.name | No | string | Application name |
application.version | No | string | Application version |
application.channel_type | No | string | Application channel type |
pushes | No | object | Use case: when you want to receive only specific pushes. By default, it's set to all for the version of your currently established RTM connection. |
pushes.<version> | Yes | []string | A list of push subscriptions for a specific version;<version> is a version number, without v prefix. Possible values: push names. |
*) We use customer_side_storage
to keep some data on the client side. You should pass a map from the customer_side_storage_updated
push payload to this field.
List Group Statuses
Specifics
Request
Parameter | Required | Data type | Notes |
---|
all | No | bool | If set to true , you will get statuses of all the groups. |
group_ids | No | array | A table of a groups' IDs |
One of the optional parameters needs to be included in the request payload.
Response
| | |
---|
Group Not Found | If you send group_id of a group that doesn't exists, the id won't be included in the resposne payload. | |
Other
Get Form
Returns an empty ticket form of a prechat or postchat survey.
Specifics
| |
---|
Action | get_form |
Web API equivalent | get_form |
Push message | - |
Request
Parameter | Required | Data type | Notes |
---|
group_id | Yes | number | Id of the group from which you want the form. |
type | Yes | string | Form type. Possible values: prechat , postchat , or ticket . |
Response
Field | Notes |
---|
enabled | If enabled: false , the form object is not returned. Prechat/postchat survey disabled in the LiveChat Agent App UI. |
form | The Form data structure. |
Get Predicted Agent
Gets the predicted Agent - the one the Customer will chat with when the chat starts.
Specifics
Response
Field | Data type | Notes |
---|
queue | bool | If true , the chat will be queued. |
Get URL Info
It returns the info on a given URL.
Specifics
| |
---|
Action | get_url_info |
Web API equivalent | get_url_info |
Push message | - |
Request
Parameter | Required | Data type | Notes |
---|
url | Yes | string | Valid website URL |
Response
Field | Data type | Notes |
---|
image_url | string | URL of the minified image hosted on the LiveChat's CDN |
image_original_url | string | URL of the original image |
Mark Events As Seen
Specifics
Request
Parameter | Required | Data type | Notes |
---|
chat_id | Yes | string | |
seen_up_to | Yes | string | RFC 3339 date-time format |
Response
No response payload (200 OK
).
Accept Greeting
Marks an incoming greeting as seen.
How it's implemented in LiveChat:
The Chat Widget uses this method to inform that a Customer has seen a greeting. Based on that, the Reports section displays the greetings
that were actually seen by Customers, not all the sent greetings. If a Customer started a chat from a greeting, but the Accept Method wasn't executed,
the greeting is still counted as seen in Reports.
Specifics
Request
Parameter | Required | Data type | Notes |
---|
greeting_id | Yes | number | ID of the greeting configured within the license to accept. |
unique_id | Yes | string | ID of the greeting to accept. You can get it from the incoming_greeting push. |
Cancel Greeting
Cancels a greeting (an invitation to the chat). For example, Customers could cancel greetings by minimizing the chat widget with a greeting.
Specifics
Request
Parameter | Required | Data type | Notes |
---|
unique_id | Yes | string | ID of the greeting to cancel. You can get it from the incoming_greeting push. |
Pushes
Here's what you need to know about pushes:
- They are generated primarily by RTM API actions, but also by Web API actions.
- They notify you when specific events occur.
- Can be delivered only in the websocket transport.
- You don't need to register pushes to receive them.
- Their equivalents in Web API are webhooks. Pushes and webhooks have similar payloads.
- There are no retries for pushes. To determine if a customer has seen an event, compare the event's
created_at
parameter with the customer's events_seen_up_to
field.
See available pushesErrors
Possible errors
Error type | Default message | Description |
---|
authentication | Authentication error | An invalid or expired access token. |
authorization | Authorization error | User is not allowed to perform the action. |
chat_anonymized | Chat anonymized | The request couldn't be performed on an anonymized chat. |
chat_inactive | Chat is inactive | An action that requires an active thread performed on a chat with no active threads. |
customer_banned | Customer is banned | The customer had been banned. |
greeting_not_found | Greeting not found | |
group_not_found | Group not found | |
group_offline | Group is offline | Thrown in response to Get Predicted Agent. |
group_unavailable | No agent available for group | Thrown in response to Get Predicted Agent. The group is online, but there are no available Agents. |
groups_offline | Groups offline | |
internal | Internal server error | |
license_expired | License expired | The end of license trial or subcription. |
limit_reached | Limit reached | Resource cannot be created/modified because the change would exceed the limit |
not_allowed | Not allowed | The action is not allowed. |
not_found | Not found | The requested resource wasn't found. |
pending_requests_limit_reached | Requests limit reached | The limit of pending requests within one websocket connection has been reached. The limit is 10. |
request_timeout | Request timed out | Timeout threshold is 15 seconds. |
service_unavailable | Service unavailable | New requests are temporarily not being accepted. |
too_many_requests | Too many requests | The request's rate limit was exceeded. It'll be unblocked automatically after some time. |
unsupported_version | Cannot call unsupported API versions. | Unsupported protocol version. |
users_limit_reached | Users limit reached | Displayed on the attempt of logging in. The limit of online Customers for a given license has been reached. |
validation | Wrong format of request | |
wrong_product_version | Wrong product version | License is not LiveChat 3 (probably still LiveChat 2). |
Contact us
If you found a bug or a typo, you can let us know directly on GitHub.
In case of any questions or feedback, don't hesitate to contact us at developers@text.com. We'll be happy to hear from you!