Event System

Event System

Central pub/sub event routing system. Events from multiple sources are matched against listener filters and trigger configurable actions, from posting messages to running AI-generated responses.

Event Bus Architecture

The event bus is the central hub that receives every event produced across the bot. Listeners subscribe with filters, and when an incoming event matches, the associated action fires.

â„šī¸ How It Works

Events flow through a single bus: Source → Bus → Filter Match → Action. Each listener has its own cooldown to prevent accidental spam loops.

  • Central event bus receives events from all five sources.
  • Listeners subscribe with type and field filters.
  • Matched events trigger the listener's configured action.
  • Rate limiting per listener prevents repeated firing.

Event Sources

VexAI ingests events from five distinct sources. Each source produces typed event payloads that flow into the central bus.

1. Discord Events

Native Discord gateway events captured by discord.js. These are the most common source of events.

EventDescription
messageNew message in any channel
reactionReaction added or removed
member_joinUser joins the server
member_leaveUser leaves the server
role_changeRole added or removed from a member
channel_changeChannel created, updated, or deleted
thread_changeThread created, archived, or deleted

Each event includes rich context: user, channel, guild, content, timestamps, and more.

2. Webhook Events

Inbound HTTP payloads from external services are parsed and emitted as events.

ProviderEvent Types
GitHubpush, pull_request, issues, release, workflow_run
GitLabpush, merge_request, pipeline, issue
GenericAny JSON payload, matched by custom field conditions

3. WebSocket Events

Persistent WebSocket connections to external services. Events are emitted on connection lifecycle changes and incoming messages.

  • ws_connect: Connection established
  • ws_message: Message received
  • ws_disconnect: Connection lost (automatic reconnection is attempted)
💡 Reconnection

WebSocket connections automatically attempt to reconnect with exponential backoff when the remote end drops the connection.

4. REST Polling

Poll any REST API on a configurable schedule. Events are emitted only when the response changes, making it ideal for monitoring external services.

  • Configurable poll interval
  • Change detection: compares current response to previous and only emits when data differs
  • Supports all HTTP methods and custom headers
â„šī¸ Change Detection

REST polls store the last response hash. An event fires only when the new response differs, so you won't be flooded with duplicate events from static endpoints.

5. Cron Events

Time-based triggers using standard cron expressions. Use these for scheduled tasks that don't depend on external input.

# Every day at 9 AM
0 9 * * *

# Every 30 minutes
*/30 * * * *

# Weekdays at 6 PM
0 18 * * 1-5

Listener Configuration

Each listener is a subscription to the event bus. It declares which events it cares about and what to do when one arrives.

âš ī¸ Listener Scope

Listeners are scoped to the guild where they are created. A listener in Guild A will never fire for events in Guild B.

Every listener specifies:

  • Event source: which of the 5 sources to listen on
  • Event type filter: the specific event type (e.g. message, push)
  • Field conditions: optional filters on event payload fields
  • Action: what to do when the event matches
  • Cooldown: minimum interval between triggers

Filtering

Filters narrow which events trigger a listener. Combine multiple conditions for precise targeting.

Filter Operators

Filter TypeDescriptionExample
equalsExact match on a field valueuser.id equals "123"
containsSubstring matchcontent contains "deploy"
regexRegular expression matchcontent regex "^!\\w+"
gtGreater than (numeric)memberCount gt 100
ltLess than (numeric)age lt 30
existsField exists in payloadattachments exists true

Filterable Fields

In addition to custom payload fields, every event supports these built-in filters:

  • Event type: message, push, ws_message, etc.
  • Event source: discord, webhook, websocket, rest, cron
  • Guild ID: restrict to a specific server
  • Channel ID: restrict to a specific channel
  • User ID: restrict to events from a specific user

Listener Actions

When a listener's filters match, one of these actions executes:

ActionDescription
Post messageSend a templated message to a target channel. Supports variable interpolation from the event payload.
AI generateSend the event context to the LLM and post the generated response. Useful for auto-summarisation or smart replies.
Execute toolRun any registered VexAI tool (from any skill). Passes event data as tool arguments.
Forward webhookPOST the event payload to an external webhook URL.
💡 Template Variables

The "Post message" action supports {{event.field}} placeholders that are replaced with values from the event payload at runtime.

Rate Limiting

Every listener has a configurable cooldown, which is the minimum time that must elapse between successive triggers. If an event matches during the cooldown window, it is silently discarded.

âš ī¸ Prevent Loops

If a listener's action produces an event that matches the same listener (e.g. a "Post message" action triggering a "message" event), the cooldown is your first line of defence against infinite loops. Always set a reasonable cooldown.

Event System Tools

The event-system skill exposes 13 tools for managing every aspect of event routing:

Listener Management

ToolDescription
create_event_listenerCreate a new listener with source, filters, and action
edit_event_listenerModify an existing listener's configuration
delete_event_listenerRemove a listener
list_event_listenersList all listeners (optionally filtered by source)
toggle_event_listenerEnable or disable a listener without deleting it

WebSocket Connections

ToolDescription
connect_websocketOpen a persistent WebSocket connection
disconnect_websocketClose a WebSocket connection
list_websocketsList active WebSocket connections

REST Polling

ToolDescription
create_rest_pollRegister a REST endpoint to poll on a schedule
delete_rest_pollStop polling a REST endpoint
list_rest_pollsList all active REST polls

Utilities

ToolDescription
emit_eventManually emit a custom event into the bus
view_event_logView the recent event log with timestamps and matched listeners