Skip to content

Chat Messages

List of valid attributes:

Attribute Description Specifics
author_id ID of the user who wrote the message Cannot be set
chat_id ID of the chat the message belongs to Cannot be set
content HTML content of the message Must not be empty, Type text
created_at Timestamp the message was created Cannot be set
parent_message_id ID of the message’s parent message Optional, cannot be updated, parent message must belong to the same chat, parent message can’t itself have a parent message
reply_count How many replies the message has, if any Optional integer (>= 0), cannot be set
message_documents Array of message documents Optional, cannot be updated, must be an array of objects with the following attributes: extension, name

The following relationships can be included in requests:

Relationship Type Description
agent_message_feedbacks has_many Feedback given by the current user on the agent message, returned as an array
agent_message_run has_one The agent message run associated with the message, if applicable
author has_one The user who wrote the message
chat has_one The chat the message belongs to
latest_reply has_one The latest message in the message’s thread, if it has one
message_documents has_many The documents attached to the message
message_reactions has_many The reactions to the message
thread_bookmark has_one The bookmark for a message thread

Example request:

{
"data": {
"type": "message",
"attributes": {
"content": "Hello World"
}
}
}

Example response:

{
"data": [
{
"id": "f5139073-dc7d-434e-989e-99786b7535a1",
"type": "message",
"attributes": {
...
}
}
]
}

This endpoint creates a message in a chat. If message_documents are provided, they will be created as well. Created documents will have upload_status set to uploading.

POST /api/v1/chats/:chat_id/messages

Parameter Description
chat_id ID of the chat where the message was written

Example request:

{
"data": {
"type": "message",
"attributes": {
"content": "edited chat message"
}
}
}

Example response:

{
"data": {
"id": "67ac4d91-1883-47f8-a9a1-f379bbd29cce",
"type": "message",
"attributes": {
...
}
}
}

This endpoint updates a chat message. Each user can only update their own chat messages.

PUT /api/v1/chats/:chat_id/messages/:message_id

Parameter Description
chat_id ID of the chat where the message was written
message_id ID of the message to edit

Example response:

{
"data": {
"id": "6d500de8-afc5-4816-ad8d-1b191b97bfd3",
"type": "message",
"attributes": {
...
}
}
}

This endpoint returns a chat message.

GET api/v1/chats/:chat_id/messages/:message_id

Parameter Desription
chat_id ID of the chat where the message was written
message_id ID of the message to get

Example response:

{
"data": [
{
"id": "0e2eb81a-f952-4e8d-a6f8-9f757459a241",
"type": "message",
"attributes": {
...
}
},
{
...
}
]
}

This endpoint returns messages of a chat.

The sort query parameter is not supported by this endpoint; messages are always sorted by created_at descending, i.e. the latest messages come first.

GET /api/v1/chats/:chat_id/messages

Parameter Description
chat_id The ID of the chat from which to return messages

Example response

{
"data": {
"id": "092ff7d2-abad-44e8-af38-d1c427a8b16d",
"type": "message",
"attributes": {
...
}
}
}

This endpoint deletes a chat message, each user can only delete their own chat messages. If the message has associated documents, they will also be deleted.

DELETE /api/v1/chats/:chat_id/messages/:message_id

Parameter Description
chat_id ID of the chat where the message was written
message_id ID of the message to delete