Add or remove users to or from a group chat
You can add or remove users from a group chat. You can add or remove participants directly, either from your frontend or from your backend using the REST API. You cannot directly add or remove guests from a group chat, as guests are not members of a conversation, but you can enable and disable guest access.
Users can join a group chat at any time during the lifetime of a conversation. Joining a chat works differently for participants and guests, in the following way.
You can programmatically add participants to a group chat either from your frontend or from your backend, as follows.
To add a participant to a conversation from your frontend, use the setParticipant method from the JavaScript SDK.
To add a participant to a conversation from your backend, call the Join conversation endpoint of our REST API.
You cannot add guests to a conversation in the same way as you can add participants. Instead, you can set things up so that users who are not participants in a conversation can themselves access that conversation as a guest.
To allow a user to join a conversation as a guest, enable guest access and make a chat interface with that conversation available to the user. Any user who knows the conversation’s ID and is not already a participant in that conversation, can now access this conversation as a guest.
You can remove a participant from a group chat at any time during the lifetime of a conversation. You cannot remove guests in the same way as you can remove participants.
To remove a participant from a conversation from your backend, use a DELETE operation on the participant using the REST API.
A guest never becomes a member of a group chat in the first place, and so you cannot remove an individual guest from a group chat either.
You can, however, disallow guest access completely. To disallow guest access, take the following steps:
- Login to your TalkJS dashboard and go to the Settings tab. Under Security settings, disallow browser synchronization of users and conversations by selecting the following two boxes:
Disallow user synchronization via the browser
Disallow conversation synchronization via the browser
Selecting these boxes ensures that data on both users and conversations cannot be updated via the JavaScript SDK.
- In the code where you use the select method to select the active conversation, remove the extra
asGuest
parameter.
You now have disallowed guest access to the group chat. With guest access disallowed, no user will able to join this conversation as a guest.