13 KiB
Chat API
Base endpoint is: /ocs/v2.php/apps/spreed/api/v1
Receive chat messages of a conversation
-
Method:
GET
-
Endpoint:
/chat/{token}
-
Data:
field type Description lookIntoFuture
int 1
Poll and wait for new message or0
get history of a conversationlimit
int Number of chat messages to receive (100 by default, 200 at most) lastKnownMessageId
int Serves as an offset for the query. The lastKnownMessageId for the next page is available in the X-Chat-Last-Given
header.lastCommonReadId
int Send the last X-Chat-Last-Common-Read
header you got, if you are interested in updates of the common read value. A 304 response does not allow custom headers and otherwise the server can not know if your value is modified or not.timeout
int $lookIntoFuture = 1
only, Number of seconds to wait for new messages (30 by default, 60 at most)setReadMarker
int 1
to automatically set the read timer after fetching the messages, use0
when your client callsMark chat as read
manually. (Default:1
)includeLastKnown
int 1
to include the last known message as well (Default:0
) -
Response:
-
Status code:
200 OK
304 Not Modified
When there were no older/newer messages404 Not Found
When the conversation could not be found for the participant412 Precondition Failed
When the lobby is active and the user is not a moderator
-
Header:
field type Description X-Chat-Last-Given
int Offset (lastKnownMessageId) for the next page. X-Chat-Last-Common-Read
int ID of the last message read by every user that has read privacy set to public. When the user themself has it set to private the value the header is not set (only available with chat-read-status
capability and when lastCommonReadId was sent) -
Data: Array of messages, each message has at least:
field type Description id
int ID of the comment token
string Conversation token actorType
string guests
orusers
actorId
string User id of the message author actorDisplayName
string Display name of the message author timestamp
int Timestamp in seconds and UTC time zone systemMessage
string empty for normal chat message or the type of the system message (untranslated) messageType
string Currently known types are comment
,comment_deleted
,system
andcommand
isReplyable
bool True if the user can post a reply to this message (only available with chat-replies
capability)referenceId
string A reference string that was given while posting the message to be able to identify a sent message again (only available with chat-reference-id
capability)message
string Message string with placeholders (see Rich Object String) messageParameters
array Message parameters for message
(see Rich Object String)parent
array Optional: See Parent data
below
-
Parent data
-
When deleted:
field type Description id
int ID of the parent comment deleted
bool true
when the parent is deleted -
Regular message:
Full message array as shown above, but
parent
will never be set for a parent message.
Sending a new chat message
-
Method:
POST
-
Endpoint:
/chat/{token}
-
Data:
field type Description message
string The message the user wants to say actorDisplayName
string Guest display name (ignored for logged in users) replyTo
int The message ID this message is a reply to (only allowed for messages from the same conversation and when the message type is not system
orcommand
)referenceId
string A reference string to be able to identify the message again in a "get messages" request, should be a random sha256 (only available with chat-reference-id
capability) -
Response:
-
Status code:
201 Created
400 Bad Request
In case of any other error403 Forbidden
When the conversation is read-only404 Not Found
When the conversation could not be found for the participant412 Precondition Failed
When the lobby is active and the user is not a moderator413 Payload Too Large
When the message was longer than the allowed limit of 32000 characters (or 1000 until Nextcloud 16.0.1, check thespreed => config => chat => max-length
capability for the limit)
-
Header:
field type Description X-Chat-Last-Common-Read
int ID of the last message read by every user that has read privacy set to public. When the user themself has it set to private the value the header is not set (only available with chat-read-status
capability) -
Data: The full message array of the new message, as defined in Receive chat messages of a conversation
-
Share a rich object to the chat
See OCP\RichObjectStrings\Definitions for more details on supported rich objects and required data.
-
Required capability:
rich-object-sharing
-
Method:
POST
-
Endpoint:
/chat/{token}/share
-
Data:
field type Description objectType
string The object type objectId
string The object id metaData
string JSON encoded array of the rich objects data actorDisplayName
string Guest display name (ignored for logged in users) referenceId
string A reference string to be able to identify the message again in a "get messages" request, should be a random sha256 (only available with chat-reference-id
capability) -
Response:
-
Status code:
201 Created
400 Bad Request
In case the meta data is invalid403 Forbidden
When the conversation is read-only404 Not Found
When the conversation could not be found for the participant412 Precondition Failed
When the lobby is active and the user is not a moderator413 Payload Too Large
When the message was longer than the allowed limit of 32000 characters (or 1000 until Nextcloud 16.0.1, check thespreed => config => chat => max-length
capability for the limit)
-
Header:
field type Description X-Chat-Last-Common-Read
int ID of the last message read by every user that has read privacy set to public. When the user themself has it set to private the value the header is not set (only available with chat-read-status
capability) -
Data: The full message array of the new message, as defined in Receive chat messages of a conversation
-
Deleting a chat message
-
Method:
DELETE
-
Endpoint:
/chat/{token}/{messageId}
-
Response:
-
Status code:
200 OK
- When deleting was successful202 Accepted
- When deleting was successful but Matterbridge is enabled so the message was leaked to other services400 Bad Request
The message is already older than 6 hours403 Forbidden
When the message is not from the current user and the user not a moderator403 Forbidden
When the conversation is read-only404 Not Found
When the conversation or chat message could not be found for the participant405 Method Not Allowed
When the message is not a normal chat message412 Precondition Failed
When the lobby is active and the user is not a moderator
-
Header:
field type Description X-Chat-Last-Common-Read
int ID of the last message read by every user that has read privacy set to public. When the user themself has it set to private the value the header is not set (only available with chat-read-status
capability) -
Data: The full message array of the new system message "You deleted a message", as defined in Receive chat messages of a conversation The parent message is the object of the deleted message with the replaced text "Message deleted by you". This message should not be displayed to the user but instead be used to remove the original message from any cache/storage of the device.
-
Mark chat as read
-
Method:
POST
-
Endpoint:
/chat/{token}/read
-
Data:
field type Description lastReadMessage
int The last read message ID -
Response:
-
Status code:
200 OK
404 Not Found
When the room could not be found for the participant, or the participant is a guest.
-
Header:
field type Description X-Chat-Last-Common-Read
int ID of the last message read by every user that has read privacy set to public. When the user themself has it set to private the value the header is not set (only available with chat-read-status
capability)
-
Get mention autocomplete suggestions
-
Method:
GET
-
Endpoint:
/chat/{token}/mentions
-
Data:
field type Description search
string Search term for name suggestions (should at least be 1 character) limit
int Number of suggestions to receive (20 by default) includeStatus
bool Whether the user status information also needs to be loaded -
Response:
-
Status code:
200 OK
403 Forbidden
When the conversation is read-only404 Not Found
When the conversation could not be found for the participant412 Precondition Failed
When the lobby is active and the user is not a moderator
-
Data: Array of suggestions, each suggestion has at least:
field type Description id
string The user id which should be sent as @<id>
in the message (user ids that contain spaces as well as guest ids need to be wrapped in double-quotes when sending in a message:@"space user"
and@"guest/random-string"
)label
string The displayname of the user source
string The type of the user, currently only users
,guests
orcalls
(for mentioning the whole conversationstatus
string Optional: Only available with includeStatus=true
and for users with a set statusstatusIcon
string Optional: Only available with includeStatus=true
and for users with a set statusstatusMessage
string Optional: Only available with includeStatus=true
and for users with a set status
-
System messages
conversation_created
- {actor} created the conversationconversation_renamed
- {actor} renamed the conversation from "foo" to "bar"call_started
- {actor} started a callcall_joined
- {actor} joined the callcall_left
- {actor} left the callcall_ended
- Call with {user1}, {user2}, {user3}, {user4} and {user5} (Duration 30:23)read_only_off
- {actor} unlocked the conversationread_only
- {actor} locked the conversationlistable_none
- {actor} limited the conversation to the current participantslistable_users
- {actor} opened the conversation accessible to registered userslistable_all
- {actor} opened the conversation accessible to registered and guest app userslobby_timer_reached
- The conversation is now open to everyonelobby_none
- {actor} opened the conversation to everyonelobby_non_moderators
- {actor} restricted the conversation to moderatorsguests_allowed
- {actor} allowed guests in the conversationguests_disallowed
- {actor} disallowed guests in the conversationpassword_set
- {actor} set a password for the conversationpassword_removed
- {actor} removed the password for the conversationuser_added
- {actor} added {user} to the conversationuser_removed
- {actor} removed {user} from the conversationmoderator_promoted
- {actor} promoted {user} to moderatormoderator_demoted
- {actor} demoted {user} from moderatorguest_moderator_promoted
- {actor} promoted {user} to moderatorguest_moderator_demoted
- {actor} demoted {user} from moderatormessage_deleted
- Message deleted by {actor} (Should not be shown to the user)