ChatToWebhook (Offsite Message Logger)

ChatToWebhook

This is a server-side module that logs in-game chat messages and sends them to a generic webhook endpoint (any HTTP receiver you control). It’s designed for moderation/audit logging and avoids spamming your endpoint by batching messages on an interval and whenever the queue nears the content limit.

Features

  • Server-side capture using Player.Chatted

  • Batching + queue

    • flushes every BATCH_INTERVAL
    • flushes early when queued content reaches the soft limit
    • retries safely by re-queueing the batch on request failure
    • caps batches per tick (MAX_BATCHES_PER_TICK)
  • Sanitization

    • removes control chars (keeps \n and \t)
    • prevents accidental @-style pings by inserting a zero-width character
    • clamps to max UTF-8 characters and appends …
  • Content-limit aware

    • uses a soft limit (1900) with truncation to avoid hard cutoffs
    • truncates single oversized lines with …

Use cases

  • Remote logging / audit trails
  • Moderation review logs
  • Basic server telemetry (“what players are saying”) stored off-platform

Setup

  1. Place the module somewhere server-only (ex: ServerScriptService/ChatLogger).

  2. Enable HTTP requests:

    • Game Settings → Security → Enable Http Requests
  3. Open Config and set:

    • WEBHOOK_URL = "https://your-endpoint.example/webhook"

Keep the webhook URL server-side only (do not replicate it to clients).

Configuration

In Config:

  • WEBHOOK_URL — your endpoint URL
  • MAX_NAME_LENGTH — clamp username length
  • MAX_MESSAGE_LENGTH — clamp message length
  • BATCH_INTERVAL — flush interval (seconds)
  • CONTENT_LIMIT / CONTENT_SOFT_LIMIT — request body content sizing

Payload format (what your endpoint receives)

Requests are sent as JSON with a single field:

{
  "content": "...\n..."
}

Each line is formatted like:

[HH:MM:SS] Username: message

How it works

  • Each chat message is turned into a LoggedMessage with:

    • timestampIso, unix
    • userId, username
    • message
  • The logger estimates the total content size and pops batches that fit under CONTENT_SOFT_LIMIT.

  • If the request fails, the batch is prepended back into the queue to avoid losing logs.

Notes about chat capture

This implementation uses Player.Chatted on the server for broad compatibility with existing experiences. If you want true per-channel logging (e.g., team/global/system channels), that typically requires additional integration depending on your chat pipeline.