---
url: https://talkjs.com/docs/Guides/Web_Components/Add_Users/
title: "Add users to a group chat | Web Components | TalkJS Docs"
---

For AI agents: Find a documentation index at https://talkjs.com/llms.txt (full content at https://talkjs.com/llms-full.txt). Get a markdown version of any page by appending .md to its URL path.

# Add users to a group chat

Add participants using the Data API or your backend.

You can add users to an existing group chat at any time. Use the JavaScript Data API from your frontend, or the REST API from your backend. This guide uses the Data API with Web Components.

Adding a participant gives them access to the conversation's history, including messages sent before they joined. It also lets them receive notifications according to their participation settings.

For the method reference, see [`ParticipantRef.createIfNotExists()`](https://talkjs.com/docs/Data_APIs/JavaScript/Participants/#ParticipantRef__createIfNotExists).

## Add a participant

You can add a participant from your frontend or backend.

### Frontend

This example assumes you've completed the relevant [Web Components getting-started guide](https://talkjs.com/docs/UI_Components/JavaScript/), and already have a conversation and a user to add.

Get a reference to that user's participation and call `createIfNotExists()`:

```js
import { getTalkSession } from '@talkjs/core';

const session = getTalkSession({
  appId: '<APP_ID>',
  userId: '<CURRENT_USER_ID>',
});

try {
  const conversation = session.conversation('<CONVERSATION_ID>');
  await conversation.participant('<USER_ID_TO_ADD>').createIfNotExists();
  console.log('User is a participant');
} catch (error) {
  console.error('Could not add participant:', error);
}
```

Replace the placeholders with your app ID, the current user's ID, the existing conversation ID, and the ID of the user to add. If authentication is enabled, [authenticate the session](https://talkjs.com/docs/Features/Security/Authentication/) before making the request.

The promise resolves when the operation completes. If the user is already a participant, the call succeeds without changing their existing participation settings.

The conversation becomes available in the added user's inbox or conversation list, subject to any filters. Components update automatically; adding a participant doesn't switch the selected conversation.

#### Create the user first if needed

Adding participation and creating a user are separate operations. If the user doesn't exist in TalkJS yet, create them before adding them:

```js
const user = session.user('<USER_ID_TO_ADD>');
await user.createIfNotExists({ name: 'Nina' });

await session
  .conversation('<CONVERSATION_ID>')
  .participant(user)
  .createIfNotExists();
```

Creating users from the frontend requires browser user synchronization. If your backend manages TalkJS users, [create the user there](https://talkjs.com/docs/REST_API/Users/) instead.

#### Browser synchronization

Adding a new participant through the Data API requires [conversation synchronization from the browser](https://talkjs.com/docs/Features/Security/Browser_Synchronization/#conversation-synchronization). If it's disabled, a call that would add a participant rejects.

If your application needs to restrict who can add participants, perform the operation on your backend. Verify that the signed-in user can add the target user to the conversation before calling TalkJS.

### Backend

Use the [join conversation REST API endpoint](https://talkjs.com/docs/REST_API/Participation/#join-conversation) to add an existing user:

```sh
curl 'https://api.talkjs.com/v1/<APP_ID>/conversations/<CONVERSATION_ID>/participants/<USER_ID_TO_ADD>' \
  -H 'Authorization: Bearer <SECRET_KEY>' \
  -H 'Content-Type: application/json' \
  -X PUT \
  -d '{ "access": "ReadWrite", "notify": true }'
```

Run this request on your backend to keep the secret key out of browser code. Note that the behavior of this endpoint is slightly different from `createIfNotExists()`. Calling the endpoint applies the provided settings if the participant already exists, while `createIfNotExists()` will do nothing if the user is already a participant.

## Choose access and notification settings

By default, a new participant has `ReadWrite` access and `notify: true`. You can choose different settings when adding them. For example, add a read-only participant who receives notifications only when mentioned:

```js
await session
  .conversation('<CONVERSATION_ID>')
  .participant('<USER_ID_TO_ADD>')
  .createIfNotExists({ access: 'Read', notify: 'MentionsOnly' });
```

Use `ReadWrite` to let the participant send messages, or `Read` to let them read without sending. Set `notify` to `true` for notifications about all messages, `false` for none, or `MentionsOnly` for mentions. Notification delivery also depends on your app's notification configuration.

These settings apply only when the participant is newly added. To add the user or update their settings if they already participate, use `set()`:

```js
await session
  .conversation('<CONVERSATION_ID>')
  .participant('<USER_ID>')
  .set({ access: 'ReadWrite', notify: true });
```

Use `edit()` instead if the operation should fail when the user isn't already a participant.

## Re-add a removed participant

You can add a removed participant using the same methods. They regain access to the conversation history, including messages sent while they weren't a participant. Removing and re-adding a participant doesn't limit them to messages sent after they rejoined.

For the reverse operation, see [Remove users from a group chat](https://talkjs.com/docs/Guides/Web_Components/Remove_Users/).
