---
url: https://talkjs.com/docs/Guides/Web_Components/Group_Chat/
title: "Create 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.

# Create a group chat

Build a group chat with three or more participants.

Build on your first TalkJS chat by creating a new conversation for Frank, Nina, and Juliana.

## Prerequisites

Follow the getting-started guide for [JavaScript](https://talkjs.com/docs/UI_Components/JavaScript/#create-new-users-and-conversations), [Angular](https://talkjs.com/docs/UI_Components/Angular/#create-new-users-and-conversations), [Vue](https://talkjs.com/docs/UI_Components/Vue/#create-new-users-and-conversations), or [Svelte](https://talkjs.com/docs/UI_Components/Svelte/#create-new-users-and-conversations) until you can open the conversation between Frank and Nina. Use the same test app and keep [browser synchronization](https://talkjs.com/docs/Features/Security/Browser_Synchronization/) enabled for users and conversations.

## Create a group conversation

Change `conversationId` from `'my_conversation'` to `'project_group_chat'`. The new ID gives the group its own message history. If you're following the plain HTML example, also change the `<t-chatbox>` element's `conversation-id` attribute to `"project_group_chat"`. The Angular, Vue, and Svelte examples already bind that attribute to `conversationId`.

Keep `userId` set to `'frank'` and `otherUserId` set to `'nina'`.

**JavaScript, Vue, and Svelte**

```js
// Keep the existing `getTalkSession` call and replace the user
// and conversation setup that follows it with this code:
async function createGroupChat() {
  await session.currentUser.createIfNotExists({ name: 'Frank' });
  await session.user(otherUserId).createIfNotExists({ name: 'Nina' });
  await session.user('juliana').createIfNotExists({ name: 'Juliana' });

  const conversation = session.conversation(conversationId);
  await conversation.createIfNotExists({ subject: 'Project chat' });
  await conversation.participant(otherUserId).createIfNotExists();
  await conversation.participant('juliana').createIfNotExists();
}

createGroupChat();
```

**Angular**

```ts
// Replace the existing `ngOnInit` method in `app.ts` with this one:
async ngOnInit() {
  this.session = getTalkSession({
    appId: this.appId,
    userId: this.userId,
  });

  await this.session.currentUser.createIfNotExists({ name: 'Frank' });
  await this.session.user(this.otherUserId).createIfNotExists({ name: 'Nina' });
  await this.session.user('juliana').createIfNotExists({ name: 'Juliana' });

  const conversation = this.session.conversation(this.conversationId);
  await conversation.createIfNotExists({ subject: 'Project chat' });
  await conversation.participant(this.otherUserId).createIfNotExists();
  await conversation.participant('juliana').createIfNotExists();
}
```

Creating the conversation also adds Frank, the current user. Membership is specific to each conversation, so Nina needs to join the new group even though she already belongs to the original chat. The setup creates Juliana's user record and waits for the conversation to exist before adding Nina and Juliana.

## Try the group chat

Send a message in Frank's chatbox. To try it as Juliana, render a second `<t-chatbox>` with the same `app-id` and `conversation-id` and set its `user-id` to `"juliana"`. You should see Frank's message and be able to reply as Juliana. If you're using a [`<t-inbox>`](https://talkjs.com/docs/UI_Components/Web_Components/t-inbox/), pass the group conversation ID as `selected-conversation-id`.

## Next steps

-   [Add users to a group chat](https://talkjs.com/docs/Guides/Web_Components/Add_Users/) to manage participants and their access settings.
-   [Remove users from a group chat](https://talkjs.com/docs/Guides/Web_Components/Remove_Users/) to remove participants or let users leave.
-   [Customize your chat](https://talkjs.com/docs/UI_Components/Web_Components/Customization/) with styles and theme components.

In your app, run membership changes when a group is created or someone is added. Running this tutorial's setup on every visit would re-add participants who have left or been removed.

Before going live, enable [authentication](https://talkjs.com/docs/Features/Security/Authentication/). If it's already enabled, authenticate the user's session before making Data API requests or mounting Components. Enforce membership rules on your backend if users shouldn't be able to change membership directly, and configure browser synchronization accordingly.
