Skip to main content

Client Chat Messages

Messages Request​

Under certain circumstances, there may be a need to refresh chat messages for a client. This is particularly useful when the client is inactive, for example, when they are navigating to a new page on their website and the visitor's connection isn't open to store the new message.
To address such scenarios, we provide a messages endpoint. This can be used to populate the local visitor's chat box, ensuring that messages are updated and current regardless of user activity.

You will need to send a GET request with the visitor's current chatId.
Here is a basic example using fetch.

fetch("https://chat2.visitor.chat/api/v2/messages?chatId=vZGlk8BbCe4J06WnJNquo5S1Bm2doknT");
[
{
"created_at": "2024-03-07T08:23:55.000000Z",
"chat_id": "vZGlk8BbCe4J06WnJNquo5S1Bm2doknT",
"message": "Hello can I enquire about the McLaren 720s",
"message_type": "text",
"type": "human",
"visitor_id": "EUUEnhja54z95u1tzYf5OcOREDxbPc5W",
"operator_id": null,
"operator": null
},
{
"created_at": "2024-03-07T08:24:00.000000Z",
"chat_id": "F9rdc7wkm49YlkkmGGu6LrYP1wLayE6S",
"message": "Can I help you with anything else?",
"message_type": "text",
"type": "human",
"visitor_id": null,
"operator_id": 123,
"operator": {
"name": "Operator",
"avatar": 'image.png'
}
}
]

Error Responses​

Missing parameters
// Status Code 422
{
"message": "The chat id field is required.",
"errors": {
"chatId": [
"The chat id field is required."
]
}
}
Server error
// Status Code 500
{
"message": "Server Error"
}

Message Format Types​

We utilise different kinds of message format types to determine how chat messages are displayed.
This is referring to the field message_type on a message object.

  • text - Plain alphanumeric string.
  • card - JSON encoded metadata for a given URL, we currently use this for showing URLs in a structured prettier way, such as with images and descriptions. The contents of the message for this type is currently the raw output from https://jsonlink.io/.
  • url - Plain alphanumeric string.

Message Types​

In addition to our message format types, we also have specific message types that guide us on how to process each message.
This is referring to the field type on a message object.

  • human - Standard messages to be displayed as either visitor or operator.
  • audit - Audit messages advise us to any actions within the visitor's chat. These types of messages aren't returned for visitors.