> For the complete documentation index, see [llms.txt](https://docs.kojascripts.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kojascripts.eu/koja-lib/webhooks.md).

# Webhooks

koja-lib includes a built-in Discord webhook logger.

## Configuration

Add webhook URLs to the `KOJA.Server.Webhooks` table in `server/webhook.lua`:

```lua
KOJA.Server.Webhooks = {
    ['cardealer'] = 'https://discord.com/api/webhooks/...',
    ['main']      = 'https://discord.com/api/webhooks/...',
    ['police']    = 'https://discord.com/api/webhooks/...',
}
```

Each key is a channel name you choose. You can add as many as you need.

## LogMessage

Send a message to a Discord webhook channel.

```lua
KOJA.Server.LogMessage(data, channel)
```

| Parameter         | Type      | Description                                   |
| ----------------- | --------- | --------------------------------------------- |
| `data`            | `table`   | Message data                                  |
| `data.message`    | `string`  | Embed description (supports Discord markdown) |
| `data.title`      | `string?` | Embed title                                   |
| `data.footertext` | `string?` | Embed footer                                  |
| `channel`         | `string`  | Webhook key from `KOJA.Server.Webhooks`       |

**Example**

```lua
KOJA.Server.LogMessage({
    title       = 'Vehicle Purchased',
    message     = ('**Player:** %s\n**Vehicle:** %s\n**Plate:** %s\n**Price:** $%d'):format(
        GetPlayerName(source),
        'Adder',
        plate,
        500000
    ),
    footertext  = 'car-dealer',
}, 'cardealer')
```

## Example Output

The webhook sends a Discord embed that looks like:

```
Vehicle Purchased
──────────────────
Player: John Doe
Vehicle: Adder
Plate: ABCD1234
Price: $500,000
──────────────────
car-dealer
```

## Adding Channels

Open `server/webhook.lua` and add entries to the table:

```lua
KOJA.Server.Webhooks = {
    ['cardealer'] = 'https://discord.com/api/webhooks/111/aaa',
    ['heist']     = 'https://discord.com/api/webhooks/222/bbb',
    ['admin']     = 'https://discord.com/api/webhooks/333/ccc',
}
```

Then use the key when calling `LogMessage`:

```lua
KOJA.Server.LogMessage({ message = 'Heist started', title = 'Heist' }, 'heist')
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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://docs.kojascripts.eu/koja-lib/webhooks.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.
