# Chat Database Setup

Before adding the chat components to your app, you need to set up two collections in your Adalo database: **Conversations** and **Messages**. This guide walks you through every field you need and explains how each one connects to the chat components.

***

{% hint style="info" %}
Ask Ada to set this up. Copy the prompt below and paste it into Ada.
{% endhint %}

{% code expandable="true" %}

```
Add Collection, and name it Conversations. Then add the following properties:
Name, Text Users, Relationship, Many-to-Many relationship to the user collection User1-ID, Number User1-Name, Text User1-ImageURL, Text
User2-ID, Number User2-Name, Text User2-ImageURL, Text
GroupName, Text GroupImage, Image
Last_Message_Time, Date & Time
Last_Message_Text, Text Conversation_Key, Text
TotalUsers, Number
ReadBy, Text
Draft, True/False

Then

Add Collection, and name it Messages. Then add the following properties:
Message, Text
Image, Image
SenderID, Number
SenderName, Text
SenderImageURL, Text
Conversation, Relationship (One-to-Many relationship with the conversation collection. A message belongs to one collection, but a collection can have many messages. )

Then

In the Users collection, if there is not an add an image property add one and name it Profile Picture

```

{% endcode %}

## Before You Begin

* You already have a **Users** collection in your app (Adalo creates this automatically).
* You are using one or more of the following components: **Chat Message List**, **Conversation List**, **Conversation Action Button**, **Chat Header Bar**, or **Chat User Picker**.

***

## Conversations Collection

This collection stores each conversation thread — both 1-on-1 and group chats.

**Go to** your Database, click **Add Collection**, and name it **Conversations**. Then add the following properties:

| Property                | Type         | Notes                                                                                                                                                                                                                                                                                                                                                                                |
| ----------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Name**                | Text         | Default Field from Adalo, can be left blank                                                                                                                                                                                                                                                                                                                                          |
| **Users**               | Relationship | Many-to-Many relationship to the user collection. This is where you add/remove users from a conversation. This is also the property you reference when sending a notification to the conversation.                                                                                                                                                                                   |
| **Messages**            | Relationship | One-to-Many relationship with a message collection. A message belongs to one collection, but a collection can have many messages.                                                                                                                                                                                                                                                    |
| **User1-ID**            | Number       | Stores the Logged-In User ID when a new conversation is started. They are the conversation owner. This field helps identify which user should be shown in the Chat Suite components.                                                                                                                                                                                                 |
| **User1-Name**          | Text         | Stores the Logged-In User Name when a new conversation is started.                                                                                                                                                                                                                                                                                                                   |
| **User1-ImageURL**      | Text         | Stores the Logged-In User Image URL when a new conversation is started.                                                                                                                                                                                                                                                                                                              |
| **User2-ID**            | Number       | Stores the second user added when a new conversation is started. This field helps identify which user should be shown in the Chat Suite components.                                                                                                                                                                                                                                  |
| **User2-Name**          | Text         | Stores the Current User Name when a new conversation is started.                                                                                                                                                                                                                                                                                                                     |
| **User2-ImageURL**      | Text         | Stores the Current User Image URL when a new conversation is started.                                                                                                                                                                                                                                                                                                                |
| **GroupName**           | Text         | Saved when starting a group conversation. Using the **Conversation Action Button**, a field will appear to save.                                                                                                                                                                                                                                                                     |
| **GroupImage**          | Image        | The group photo. Leave blank for 1-on-1 chats.                                                                                                                                                                                                                                                                                                                                       |
| **Last\_Message\_Time** | Date & Time  | Used to sort conversations newest-first in the **Conversation List**. Update this every time a new message is sent.                                                                                                                                                                                                                                                                  |
| **Last\_Message\_Text** | Text         | The preview line shown in the **Conversation List** (e.g., "Sounds good, see you then"). Update this field every time a new message is sent.                                                                                                                                                                                                                                         |
| **Conversation\_Key**   | Text         | A sorted string of participant user IDs joined by an underscore — for example, `12,47` for a 1-on-1 between users 12 and 47, or `12,47,89` for a group. Always put the lowest ID first. Using the **Chat User Picker,** the ID's are sorted for you. The **Conversation Action Button** queries this field to check whether a conversation already exists before creating a new one. |
| **TotalUsers**          | Number       | Stores the total number of users in the group. This can be referenced on setup when using the **Chat User Picker**.                                                                                                                                                                                                                                                                  |
| **ReadyBy**             | Text         | String of UserIDs who have read the conversation. This helps the **Conversation List** show a notification dot or not.                                                                                                                                                                                                                                                               |
| **Draft**               | True/False   | Stores if a conversation is out of draft mode and can be seen in a user's **Conversation List**.                                                                                                                                                                                                                                                                                     |

***

## Messages Collection

This collection stores every individual message sent in your app.

**Go to** your Database, click **Add Collection**, and name it **Messages**. Then add the following properties:

| Property           | Type         | Notes                                                                                                                                                                                                                                                |
| ------------------ | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Message**        | Text         | The message body.                                                                                                                                                                                                                                    |
| **Image**          | Image        | An optional image attachment. Only needed if you are using **Text + Image** mode in the Chat Message List.                                                                                                                                           |
| **SenderID**       | Number       | Stores the Logged-In User ID of the sender. This is what the **Chat Message List** references when moving the message to the right of the Logged-In User.                                                                                            |
| **SenderName**     | Text         | Name of the Logged-In User Name who sent the message.                                                                                                                                                                                                |
| **SenderImageURL** | Text         | Image URL of the Logged-In User Name who sent the message.                                                                                                                                                                                           |
| **Conversation**   | Relationship | One-to-Many relationship with a conversation collection. A message belongs to one collection, but a collection can have many messages. ***\*\*This should already be set up if you have already set up a conversation collection from this guide.*** |

***

## Users Collection

You do not need to create the Users collection — Adalo creates it automatically. Add the following two properties to it:

| Property   | Type  | Notes                                                                                                                    |
| ---------- | ----- | ------------------------------------------------------------------------------------------------------------------------ |
| **avatar** | Image | The user's profile photo. Shown in the **Conversation List** and next to received messages in the **Chat Message List**. |

***

## The participant\_key Field Explained

The `Conversation_Key` is a Text field that makes it fast to look up whether a conversation between a specific set of users already exists.

When you create a conversation, build the key by:

1. Taking all participant user IDs
2. Sorting them from lowest to highest
3. Joining them with an comma

**Examples:**

| Participants         | participant\_key |
| -------------------- | ---------------- |
| User 12 and User 47  | `12,47`          |
| User 3 and User 88   | `3,88`           |
| Users 12, 47, and 89 | `12,47,89`       |

The **Conversation Action Button** filters the Conversations collection where `conversation_key` equals the key you build from the selected users. If it finds a match, it shows **Continue Conversation**. If not, it shows **Start Conversation** and fires your Create Record action.

{% hint style="info" %}
Always sort the IDs lowest-first so the key is consistent regardless of who starts the conversation. If User 47 messages User 12, the key is still `12,47` — not `47,12`.
{% endhint %}

***

Need help? Visit the [Adalo Community Forum](https://forum.adalo.com/) or check the individual component help pages for setup walkthroughs.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.adalo.com/component-basics/marketplace-components/chat-suite/chat-database-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
