Skip to main content
The Channel Connector and Message Routing subsystem enables the Palyra daemon to communicate across diverse platforms such as Discord, Slack, and Telegram. It provides a unified abstraction for inbound message ingestion and outbound message delivery, incorporating robust backpressure, retry logic, and security governance.

Connector Architecture

The system is built on a provider-agnostic architecture where platform-specific logic is encapsulated in Adapters, managed by a central Supervisor.

Key Components

ComponentClass/TraitResponsibility
SupervisorConnectorSupervisorManages the lifecycle of all connector instances, including startup, heartbeats, and error recovery. crates/palyra-connectors/src/lib.rs#13
AdapterConnectorAdapterPlatform-specific implementation (e.g., Discord) for sending messages and handling gateway events. crates/palyra-connectors/src/lib.rs#3
StoreConnectorStoreSQLite-backed persistence for connector configurations, outbox queues, and dead letters. crates/palyra-connectors/src/lib.rs#12
RouterConnectorRouterLogic for dispatching inbound messages to the appropriate internal sessions. crates/palyra-connectors/src/lib.rs#12

Data Flow: Code Entity Mapping

The following diagram maps the natural language flow of a message to the specific code entities in the palyra-connectors and palyra-daemon crates. Message Inbound and Outbound Flow Sources: crates/palyra-daemon/src/channels.rs#148-182, crates/palyra-connector-discord/src/adapter.rs#77-118, crates/palyra-connectors/src/lib.rs#1-18

Message Routing and Backpressure

Routing is handled by the ChannelRouter, which applies rules for session isolation, broadcast strategies, and concurrency limits.

Routing Policies

The system supports several policies defined in ChannelRouterConfig:

Backpressure and Queue Model

To prevent overwhelming external APIs and handle transient failures, the system implements a multi-stage queue:
  1. Outbox: Pending messages are stored in OutboxEntryRecord. crates/palyra-connectors/src/lib.rs#16
  2. Retry Logic: Messages failing with RetryClass::RateLimit or RetryClass::ConnectorRestarting are rescheduled with exponential backoff. crates/palyra-connectors/src/lib.rs#16, crates/palyra-daemon/src/channel_router.rs#12
  3. Dead Letters: Messages that exceed max_retry_attempts are moved to DeadLetterRecord for manual operator intervention. crates/palyra-connectors/src/lib.rs#14, crates/palyra-daemon/src/channel_router.rs#182
Connector Queue State Transitions Sources: crates/palyra-daemon/src/channel_router.rs#178-192, crates/palyra-connectors/src/lib.rs#1-18, crates/palyra-daemon/src/transport/http/handlers/admin/channels/mod.rs#124-158

Connector Implementations

Discord (palyra-connector-discord)

The Discord connector is the most feature-complete, supporting:

Webhooks

The WebhookRegistry manages generic HTTP inbound integrations.

Other Connectors

Sources: crates/palyra-connector-discord/src/adapter.rs#1-165, crates/palyra-daemon/src/webhooks.rs#1-118, crates/palyra-daemon/src/channels/discord.rs#61-141

Administration and Monitoring

The daemon exposes an HTTP API for monitoring connector health and managing queues.

Health Diagnostics

The admin_channels_list_handler provides a snapshot of all active connectors, including:

Queue Draining

Operators can trigger a DrainOutcome to clear queues or move specific messages out of dead letters. This is managed via the ConnectorSupervisor which handles the concurrent execution of these operations. crates/palyra-connectors/src/lib.rs#14 Sources: crates/palyra-daemon/src/transport/http/handlers/admin/channels/mod.rs#22-64, crates/palyra-connectors/src/lib.rs#13-17