Skip to main content

Overview

The messaging infrastructure provides real-time communication between clients and the ElizaOS server using Socket.IO. This enables instant message delivery, presence tracking, and bidirectional communication.

Architecture

How WebSockets Work in ElizaOS

The project uses Socket.IO (not raw WebSockets) for real-time communication between clients and the Eliza server.

Key Components

  1. Direct Connection: Socket.IO connects directly to the Eliza server (default: http://localhost:3000)
  2. Channel-Based Communication: Messages are organized by channels (or rooms for backward compatibility)
  3. Message Filtering: Clients filter incoming broadcasts by channel/room ID

Socket.IO Events and Message Types

Message Types Enum

Key Events

  • messageBroadcast - Incoming messages from agents/users
  • messageComplete - Message processing complete
  • controlMessage - UI control (enable/disable input)
  • connection_established - Connection confirmed

Socket.IO Client Implementation

Minimal Socket.IO Client

Here’s a minimal Socket.IO client implementation:

Modern Implementation (Socket.IO v4.x)

For newer Socket.IO versions, here’s a cleaner implementation:

Key Points to Check

1. Event Name

2. Room Joining Required

3. Exact Message Format

Complete Message Flow

  1. Client connects → Server accepts connection
  2. Client joins room → Server adds client to room
  3. Client sends message → Server receives and processes
  4. Server broadcasts response → All clients in room receive
  5. Clients filter by room ID → Only relevant messages shown

Debugging Steps

1. Verify Events

2. Check Room ID

  • Ensure the room ID matches exactly between your extension and the server
  • Even a single character difference will prevent message delivery

3. CORS Issues

For browser extensions, ensure your manifest includes:

4. Transport Issues

If WebSocket fails, force polling:

Socket.IO Version Compatibility

Version Issues

  • v1.3.0 (2015) - Very old, may have compatibility issues
  • v4.x (Current) - Recommended for new implementations

Upgrading

Common Mistakes

  1. Wrong event name - Using message instead of messageBroadcast
  2. Not joining room - Forgetting the ROOM_JOINING step
  3. ID mismatch - Room/channel IDs don’t match exactly
  4. Missing fields - Payload missing required fields
  5. CORS blocked - Extension lacks permissions

Testing Your Implementation

  1. Open browser console
  2. Check for connection logs
  3. Verify room join confirmation
  4. Send test message
  5. Check for broadcast reception

Common Issue: Extension Not Receiving Responses

The Problem

Your extension can send messages to Eliza (server receives them), but doesn’t receive responses back.

Root Causes

  1. Not listening for the correct event - Must listen for messageBroadcast, not message
  2. Not joining the room/channel - Must emit a ROOM_JOINING message first
  3. Room/Channel ID mismatch - IDs must match exactly
  4. Incorrect message payload structure

Solution Checklist

  1. Verify you’re listening to messageBroadcast event
  2. Ensure you join the room on connection
  3. Check room ID matches exactly
  4. Verify message payload structure
  5. Check browser console for errors
  6. Test with debug logging enabled

Advanced Features

Presence Tracking

Typing Indicators

Message Acknowledgments

Server-Side Implementation

The Socket.IO server handles message routing and broadcasting:

Reference Implementation

Eliza NextJS Starter

A complete working example demonstrating Socket.IO integration with Eliza, including real-time messaging, agent participation management, and comprehensive error handling.

REST API Response Modes

When sending messages via REST endpoints (e.g., POST /api/messaging/channels/{channelId}/messages), you can control how responses are delivered using the mode parameter.

Available Modes

WebSocket Mode (Default)

Returns immediately after message is queued. Agent response is delivered via WebSocket connection.
Response:
Agent response arrives via the messageBroadcast WebSocket event (see above).

Stream Mode (SSE)

Uses Server-Sent Events to stream response chunks progressively.
SSE Events:
JavaScript client:

Sync Mode

Waits for complete agent response before returning. Useful for scripts and testing.
Response:

Stream Extractors (Advanced)

For plugin developers, ElizaOS provides stream extractors to control what content is streamed from LLM responses.
Available extractors:

See Also

Sessions API

Build persistent conversations on messaging

Services

Create messaging service integrations

Events

Handle real-time messaging events

Providers

Supply message context to providers