---
url: https://talkjs.com/docs/Guides/Use_Your_Block_List/
title: "Use your block list | Guides | 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.

# Use your block list

Use your app's block list to control who users can message.

A user's block list should work across your platform, including chat. This guide shows how to use your app's existing block list to decide who users can message in TalkJS.

## Apply your block list in your app

Your application decides how users reach a chat. Apply the block list where they find someone to contact, whether that's booking a service or choosing a person from a list:

-   **Booking marketplaces:** If a seller has blocked a buyer, leave that seller out of the buyer's catalogue and prevent the buyer from booking them. A booking then can't create a chat between those users.
-   **People lists:** Leave out people who have blocked the current user when building the list of people they can message.
-   **Profile pages:** Hide or disable the Message button when contact is blocked.

Your application can filter these lists before returning them to the frontend, or include a `canMessage` flag with each person. That flag tells the frontend whether the signed-in user can contact that person, without needing to load a separate block list in the browser.

For example, check `canMessage` in your start-chat function as well as using it to decide whether to show the Message button. `createAndOpenConversation` represents your existing code for starting a chat:

```javascript
async function startChat(person) {
  if (!person.canMessage) {
    showError("You can't message this person.");
    return;
  }

  await createAndOpenConversation(person.id);
}
```

Your frontend can continue creating TalkJS conversations as it does now.

## For stricter enforcement

A technically minded user could skip your UI and ask TalkJS directly to create a chat with someone who blocked them. For most customers, this isn't a concern. If your platform needs stricter enforcement, create conversations on your backend instead.

### Create conversations from your backend

Rather than creating the conversation directly from the frontend, send the ID of the person to contact to an endpoint on your backend. The endpoint should:

1.  Read the signed-in user's ID from your existing session.
2.  Check the block list and return HTTP `403` if contact is blocked.
3.  Generate the conversation ID in the same way your frontend does today, create the conversation through the TalkJS REST API, and return `{ "conversationId": "..." }`.

The server sends this [request to TalkJS](https://talkjs.com/docs/REST_API/Conversations/#a-single-conversation), using your usual [REST API authentication](https://talkjs.com/docs/REST_API/#authentication):

```http
PUT https://api.talkjs.com/v1/<APP_ID>/conversations/<CONVERSATION_ID>
Authorization: Bearer <ADMIN_JWT>
Content-Type: application/json

{
  "participants": ["<CURRENT_USER_ID>", "<OTHER_USER_ID>"]
}
```

For an endpoint named `/api/chats`, the frontend code becomes the following. `openConversation` represents your existing code for displaying a conversation:

```javascript
async function startChat(person) {
  const response = await fetch('/api/chats', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ otherUserId: person.id }),
  });

  if (response.status === 403) {
    showError("You can't message this person.");
    return;
  }

  if (!response.ok) {
    showError("Couldn't start the chat. Please try again.");
    return;
  }

  const { conversationId } = await response.json();
  openConversation(conversationId);
}
```

### Disable conversation synchronization

TalkJS must reject requests to create conversations from the frontend, so users cannot skip the block list check on your backend.

In the [TalkJS dashboard](https://talkjs.com/dashboard/), open **Settings → Security settings** and disable conversation synchronization. See [Browser synchronization](https://talkjs.com/docs/Features/Security/Browser_Synchronization/#how-to-disable-browser-synchronization).

Updates to conversation details and participants must also go through your backend. Apply the block list check wherever your backend adds participants. Users can still read and send messages in their conversations as before.
