> For the complete documentation index, see [llms.txt](https://devmosaic.gitbook.io/devmosaic/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devmosaic.gitbook.io/devmosaic/resources/devmosaic-dm-chat/exports-and-integrations.md).

# Exports And Integrations

Integrate dm-chat through client and server exports, standard chat events, suggestions, templates, modes, and hooks.

Dm Chat implements the familiar FiveM chat API while also exposing functions directly from the `dm-chat` resource. Prefer the explicit `dm-chat` export name in new integrations.

## Message data

The simplest message uses `title`, `message`, `color`, and `type`:

```lua
local message = {
    title = 'EMS',
    message = 'A medic is now available.',
    color = { 239, 68, 68 },
    type = 'system'
}
```

Dm Chat also accepts the standard `args` form:

```lua
{
    color = { 239, 68, 68 },
    multiline = true,
    args = { 'EMS', 'A medic is now available.' }
}
```

Message types matching `Config.DisabledTypes` can be hidden by each client.

## Client messages

From a client script:

```lua
exports['dm-chat']:addMessage({
    title = 'SYSTEM',
    message = 'Your vehicle was stored.',
    color = { 132, 204, 22 },
    type = 'system'
})
```

The equivalent standard event is:

```lua
TriggerEvent('chat:addMessage', {
    args = { 'SYSTEM', 'Your vehicle was stored.' },
    color = { 132, 204, 22 }
})
```

## Server messages

Send to one player:

```lua
exports['dm-chat']:addMessage(source, {
    title = 'SYSTEM',
    message = 'Welcome to the server.',
    type = 'system'
})
```

Call the export with only the message table to broadcast it:

```lua
exports['dm-chat']:addMessage({
    title = 'ANNOUNCEMENT',
    message = 'Restart in ten minutes.',
    color = { 250, 204, 21 },
    type = 'system'
})
```

You can also use `TriggerClientEvent('chat:addMessage', target, data)`, where `target` is a server ID or `-1` for all players.

## Client exports

| Export             | Arguments            | Purpose                             |
| ------------------ | -------------------- | ----------------------------------- |
| `addMessage`       | `data`               | Display a message locally           |
| `addSuggestion`    | `name, help, params` | Add one command suggestion          |
| `addSuggestions`   | `suggestions`        | Add multiple command suggestions    |
| `removeSuggestion` | `name`               | Remove a suggestion by command name |
| `addMode`          | `mode`               | Register mode data in the NUI       |
| `removeMode`       | `name`               | Remove mode data from the NUI       |
| `addTemplate`      | `id, html`           | Register a message template         |
| `clear`            | none                 | Clear the local chat feed           |

## Suggestions

```lua
exports['dm-chat']:addSuggestion(
    '/repair',
    'Repair the nearest vehicle',
    {
        { name = 'type', help = 'engine or body' }
    }
)
```

Remove it when your resource stops:

```lua
exports['dm-chat']:removeSuggestion('/repair')
```

## Templates

Templates replace `{0}`, `{1}`, and later numbered placeholders with values from `args`:

```lua
exports['dm-chat']:addTemplate(
    'dispatch',
    '<div class="dispatch-message"><strong>{0}</strong>: {1}</div>'
)

exports['dm-chat']:addMessage({
    templateId = 'dispatch',
    args = { 'DISPATCH', 'Store alarm triggered' }
})
```

{% hint style="warning" %}
Template HTML is inserted into the NUI. Never place untrusted player input in a template without escaping or sanitizing it first.
{% endhint %}

## Server message hooks

Hooks can update, cancel, or reroute messages that pass through dm-chat's standard server router:

```lua
exports['dm-chat']:registerMessageHook(function(source, message, hookRef)
    if message.args and message.args[#message.args] == 'blocked text' then
        hookRef.cancel()
        return
    end

    hookRef.updateMessage({
        color = { 132, 204, 22 }
    })
end)
```

Available hook controls are:

| Function                       | Purpose                                         |
| ------------------------------ | ----------------------------------------------- |
| `hookRef.updateMessage(table)` | Merge fields into the outgoing message          |
| `hookRef.cancel()`             | Stop the message                                |
| `hookRef.setRouting(target)`   | Route to one ID, `-1`, or a table of player IDs |

## Server modes

`registerMode` requires `name`, `displayName`, and a callback. Optional fields are `color`, `isChannel`, `isGlobal`, and `seObject`.

```lua
exports['dm-chat']:registerMode({
    name = 'staff',
    displayName = 'Staff',
    color = '#ef4444',
    isChannel = true,
    isGlobal = false,
    seObject = 'chat.staff',
    cb = function(source, message, hookRef)
        -- Validate and route the message here.
    end
})
```

When `seObject` is set, the sender must pass that ACE permission. The current Dm Chat input does not include a player-facing mode selector, so modes are most useful for integrations that already submit a mode through the standard chat router.

## Compatibility notes

Dm Chat listens for the standard `chat:*` client events and the legacy `exports.chat` registration events. This helps existing FiveM resources keep working after the default chat is removed. Test resources that depend on custom HTML templates or mode-selection UI, because their visual assumptions can differ from dm-chat's NUI.
