> For the complete documentation index, see [llms.txt](https://bizachi-dev.gitbook.io/bullethell-elemental-template/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bizachi-dev.gitbook.io/bullethell-elemental-template/paid-addons/addon-realtime-global-chat.md).

# Addon Realtime Global Chat

A global chat for every player, with highlighted messages, anti-spam limits and a word filter. Works with the Firebase and WebSocket backends.

{% hint style="warning" %}
**Paid addon.** The Realtime Global Chat addon is not included in the BulletHell Elemental Template. It is sold separately on the Unity Asset Store. This page explains how to set it up after you buy and import it.
{% endhint %}

The Global Chat addon adds a chat window and a mini chat preview on the main menu (the "Global Chat / Tap to chat" card). Tapping the mini chat opens the full chat.

The chat needs other players, so it only works online:

| Backend             | How it works                                                                                                                                                                       |
| ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Offline**         | The chat shows an "offline" message.                                                                                                                                               |
| **Firebase**        | Messages are stored in the Realtime Database (`chat` node). The limits of the Global Chat Manager are used, and the database rules enforce a 1 second cooldown and 500 characters. |
| **WebSocket + SQL** | Messages go through the `chat_room` of the server and are stored in the database. The limits come from the server's `CHAT_*` environment keys and override the Inspector values.   |

The chat is the `GlobalChatManager` prefab (`Addons/GlobalChatRealtime/UIElements`). Add it to the **Canvas** of the Home scene; it stays active and shows the mini chat. To open the full chat from your own button, see the end of this page.

***

### Firebase setup

1. Create a **Realtime Database** in your Firebase project (see [Firebase Backend](/bullethell-elemental-template/getting-started/quickstart.md)).
2. Publish the rules of `Core/DataHandler/Backend/FirebaseRules/database.rules.json`. They already contain the chat rules.
3. Leave **Database URL** empty on the Global Chat Manager: the address is read from `google-services.json`. Only fill it if the file was downloaded before the database existed.

The game creates the `chat` and `chatRate` nodes by itself.

### WebSocket setup

Nothing to do in Unity. Set the chat keys in the server env file if you want other values:

| Key                                               | Default | Meaning                                           |
| ------------------------------------------------- | ------- | ------------------------------------------------- |
| `CHAT_HISTORY_SIZE`                               | 50      | Messages sent to a player who joins.              |
| `CHAT_MAX_LENGTH`                                 | 200     | Longest message (maximum 500).                    |
| `CHAT_COOLDOWN_MS`                                | 2000    | Time between two messages of a player.            |
| `CHAT_MAX_PER_MINUTE`                             | 15      | Messages per minute per player.                   |
| `CHAT_RETENTION_HOURS`                            | 24      | Hours messages are kept.                          |
| `CHAT_HIGHLIGHT_CURRENCY` / `CHAT_HIGHLIGHT_COST` | DM / 1  | Price of a highlighted message.                   |
| `CHAT_BANNED_WORDS`                               | empty   | Words replaced by asterisks, separated by commas. |

Support and admin accounts can delete messages.

***

### Global Chat Manager

<figure><img src="https://215355839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fc8AVbPtcUOjcVrQx9Eyu%2Fuploads%2Fgit-blob-c04b2cce0548dc118919ac02c6ae7154d140a7f5%2Fv16-global-chat-manager.png?alt=media" alt="Global Chat Manager in the Inspector"><figcaption></figcaption></figure>

**Message Settings**

Max Messages: Messages loaded when the chat opens (Firebase).

Max Displayed Messages: Messages kept on screen; older ones are removed.

Message Character Limit: Longest message on Firebase (the rules allow up to 500).

**Anti-Spam Settings**

Message Cooldown / Max Messages Per Minute: Limits per player on Firebase.

**Highlight Message Settings**

Highlight Currency Id / Highlight Currency Cost: A player can pay to highlight a message (Firebase). Empty currency hides the highlight toggle. On Firebase the price is refunded if the message is refused.

**History Settings**

Message Retention Hours: On Firebase, messages older than this are deleted by the clients (keep it at 24 or more, the rules only allow deleting messages older than 24 hours).

**Firebase Settings**

Database URL: Leave empty (see above).

**Word Filter**

Banned Words: Words shown as asterisks in every message (whole words, any case).

**Texts**

Every message of the chat (offline, not connected, too long, cooldown, not enough currency, banned...) with its translations.

The **UI Elements** and **Optional UI** groups reference the objects of the chat window: message prefabs, input field, character counter, online count, unread badge and the highlight toggle.

### Opening the chat from your own button

Call `GlobalChatManager.OpenUIChat()` from the button's On Click (and `CloseUIChat()` to close it).

<figure><img src="https://215355839-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fc8AVbPtcUOjcVrQx9Eyu%2Fuploads%2FAaNTpD0dNKQ8B2oVWyI7%2Fbutton.png?alt=media&amp;token=5d97c9f2-b915-4b95-bbd4-ab31f94cbf64" alt="Button calling OpenUIChat"><figcaption></figcaption></figure>
