# 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')
```

## Related pages

- [Getting Started](/koja-lib/getting-started) — Configuration and Installation for Getting Started.
- [API Reference](/koja-lib/api-reference) — Client API and Server API for API Reference.
- [Frameworks](/koja-lib/frameworks) — Custom Framework and Overview for Frameworks.
- [Inventory](/koja-lib/inventory) — Custom Inventory and Overview for Inventory.
- [Weapon](/koja-lib/weapon) — Utility function for reading the player's current weapon state.
- [Text UI](/koja-lib/text-ui) — A small on-screen prompt that shows an action key and a label.
