How to close a conversation
TalkJS doesn't have a built-in 'close conversation' feature. Instead, you can achieve the equivalent of closing a conversation by changing a participant's access rights access permissions.
- Set access to
Read
if the participant should still be able to read the conversation but not send new messages. - Set access to
None
if the user should still be able to read historical messages, but not read or write messages new messages in the conversation.
Either of these options would amount to closing a conversation for a user.
Here’s how to make two users read-only in a conversation via the REST API: For every participant in a conversation, send a PATCH request that changes user's access
to either "Read"
(for read-only access) or "None"
(for no access), instead of the default "ReadWrite"
.
This way, users won't be able to write new messages to a conversation, and you've for all practical purposes closed the chat.
For example, to set the access of the participants alice
and sebastian
to the conversation with the id sample_conversation
to read-only, you'd send the following requests:
1curl https://api.talkjs.com/v1/<APP_ID>/conversations/sample_conversation/participants/alice \2-H "Content-Type: application/json" \3-H "Authorization: Bearer <SECRET_KEY>" \4-X PATCH5-d '{ "access": "Read" }'67curl https://api.talkjs.com/v1/<APP_ID>/conversations/sample_conversation/participants/sebastian \8-H "Content-Type: application/json" \9-H "Authorization: Bearer <SECRET_KEY>" \10-X PATCH11-d '{ "access": "Read" }'
In adapting these examples, replace <APP_ID>
with your own app ID, and <SECRET_KEY>
with your own secret key. You can find both your app ID and your secret key on the Settings page of your TalkJS dashboard.
For more details on managing user access, see Control access to group chats.