Skip to main content
The Connector Framework and Channel Router provide the infrastructure for Palyra to communicate with external messaging platforms (Discord, Slack, Telegram, etc.). This system manages the lifecycle of connector instances, handles the reliable delivery of outbound messages with backpressure, and routes inbound events to the appropriate internal sessions based on configurable pairing rules and security policies.

Connector Supervisor and Adapters

The ConnectorSupervisor is the central orchestrator for all active connector instances. It manages their lifecycle (Running, Stopped, or Quarantined) and delegates platform-specific logic to implementations of the ConnectorAdapter trait.

Implementation Details

Connector Lifecycle and Data Flow

The following diagram illustrates how the ConnectorSupervisor manages an adapter and its persistent state. Connector Management Architecture Sources: crates/palyra-connectors/src/supervisor.rs#34-47, crates/palyra-connectors/src/storage.rs#105-123, crates/palyra-connectors/src/connectors/mod.rs#15-18

Channel Router and Concurrency Model

The ChannelRouter acts as the traffic controller between external platforms and the Palyra daemon. It enforces per-channel concurrency limits, manages backpressure, and handles message retry logic.

Concurrency and Backpressure

Routing Rules

Routing is governed by ChannelRoutingRule crates/palyra-daemon/src/channel_router.rs#161-175, which includes:
  • mention_patterns: Patterns that trigger the bot (e.g., @botname).
  • allow_from / deny_from: ACLs for specific sender handles.
  • isolate_session_by_sender: If true, each user in a channel gets a private session context.
  • broadcast_strategy: Determines if the bot can use @everyone or @here crates/palyra-daemon/src/channel_router.rs#28-32.
Inbound Message Routing Flow Sources: crates/palyra-daemon/src/channel_router.rs#161-175, crates/palyra-daemon/src/channel_router.rs#215-230

Pairing Rules and DM Policy

For Direct Messages (DMs), Palyra implements a strict pairing protocol to prevent unauthorized access.

Direct Message Policies

The DirectMessagePolicy enum defines three modes crates/palyra-daemon/src/channel_router.rs#57-61:
  1. Deny: All DMs are ignored.
  2. Allow: DMs are accepted from any sender.
  3. Pairing: Requires a user to provide a valid pairing code before a session is established.

Pairing Lifecycle

  1. Code Issuance: An admin generates a PairingCodeRecord via the console crates/palyra-daemon/src/channel_router.rs#85-91.
  2. Consumption: The user sends the code to the bot in a DM.
  3. Pending State: A PairingPendingRecord is created, which may require manual approval crates/palyra-daemon/src/channel_router.rs#94-101.
  4. Grant: Upon approval, a PairingGrantRecord is stored, enabling future communication crates/palyra-daemon/src/channel_router.rs#104-110.
FeatureConfiguration SymbolDefault Value
Pairing Code LengthDM_PAIRING_CODE_LENGTH8 characters crates/palyra-daemon/src/channel_router.rs#19
Code TTLDEFAULT_DM_PAIRING_CODE_TTL_MS10 minutes crates/palyra-daemon/src/channel_router.rs#17
Session TTLDEFAULT_DM_PAIRING_SESSION_TTL_MS8 hours crates/palyra-daemon/src/channel_router.rs#21
Sources: crates/palyra-daemon/src/channel_router.rs#57-110

Reliability and Dead-Letter Handling

The framework is designed for high reliability, handling connector crashes and message delivery failures gracefully.

Dead-Letter Handling

If a message exceeds max_retry_attempts (default 3), it is moved to a dead-letter state.

Idempotency

Adapters like the EchoConnectorAdapter demonstrate idempotency by tracking delivered_native_ids crates/palyra-connectors/src/connectors/echo.rs#22. If the framework retries a send due to a simulated crash (CRASH_ONCE_MARKER), the adapter ensures the same message is not delivered twice to the end-user crates/palyra-connectors/src/connectors/echo.rs#48-75. Outbound Delivery and Retry Logic Sources: crates/palyra-daemon/src/channel_router.rs#181-183, crates/palyra-connectors/src/connectors/echo.rs#48-75, crates/palyra-connectors/src/protocol.rs#12