Connector Architecture
All platform integrations are built upon theConnectorAdapter trait. This trait abstracts the specificities of each platform’s API, providing a unified interface for the ConnectorSupervisor to manage lifecycle, message routing, and delivery guarantees.
Key Code Entities
| Entity | Role | Source |
|---|---|---|
ConnectorAdapter | Trait defining send_outbound and platform metadata. | crates/palyra-connector-core/src/supervisor.rs |
ConnectorSupervisor | Orchestrates the lifecycle of active connector instances. | crates/palyra-connector-core/src/supervisor.rs |
ConnectorStore | SQLite-backed persistence for outbox and dead-letter queues. | crates/palyra-connector-core/src/storage.rs |
OutboundMessageRequest | Internal representation of a message to be sent to a platform. | crates/palyra-connector-core/src/protocol.rs |
DeliveryOutcome | Result of a send attempt (Delivered, Retry, or PermanentFailure). | crates/palyra-connector-core/src/protocol.rs |
Data Flow: Outbound Message Routing
The following diagram illustrates how an internal agent request is routed to an external platform like Discord. Outbound Message Flow Sources: crates/palyra-connectors/src/lib.rs#1-13, crates/palyra-connector-core/src/protocol.rsDiscord Connector Implementation
The Discord integration is implemented in thepalyra-connector-discord crate. It handles the complexities of the Discord WebSocket Gateway and REST API, including DM pairing and guild (server) message routing.
Implementation Details
- Identity Mapping: Discord users are mapped to internal principals using the
discord_principalfunction crates/palyra-daemon/src/channels/discord.rs#8-8. - Normalization: The system enforces canonical formats for account IDs and target channels via
normalize_discord_account_idcrates/palyra-daemon/src/channels/discord.rs#13-16. - Egress Control: Default egress allowlists are managed to prevent data exfiltration to unauthorized Discord servers crates/palyra-daemon/src/channels/discord.rs#7-10.
Connection Setup and Onboarding
Discord setup is an interactive process managed via the CLI. It involves a “probe” phase to validate tokens and permissions followed by an “apply” phase to persist the configuration.| CLI Function | Purpose |
|---|---|
run_setup | Interactive TTY flow for onboarding a new Discord bot. |
run_verify | Sends a test message to verify connector health. |
probe_payload | Generates the pre-flight check request for the admin API. |
Channel Admin CLI Commands
Thepalyra CLI provides a comprehensive suite of commands for managing channel routing and pairings under the channels router subcommand.
Command Reference
- Rules: Displays the current routing rules for mapping inbound messages to agents crates/palyra-cli/src/commands/channels/router.rs#11-26.
- Preview: Allows operators to simulate a message and see how the
ConnectorRouterwould handle it crates/palyra-cli/src/commands/channels/router.rs#43-91. - Pairings: Lists established pairings between platform identities (e.g., a Discord User ID) and Palyra accounts crates/palyra-cli/src/commands/channels/router.rs#92-120.
- MintPairingCode: Generates a temporary code that a user can type into a chat (e.g.,
/pair 123456) to link their platform identity to the daemon crates/palyra-cli/src/commands/channels/router.rs#121-153.
Connection Management
CLI commands resolve their target daemon usingRootCommandContext crates/palyra-cli/src/app/mod.rs#29-39. It supports:
- gRPC Transport: Used for real-time interaction and status updates via
resolve_grpc_connectioncrates/palyra-cli/src/app/mod.rs#173-186. - HTTP Admin API: Used for configuration and onboarding via
resolve_http_connectioncrates/palyra-cli/src/app/mod.rs#188-201.
Dead-Letter Management and Idempotency
To ensure reliability, the connector framework implements strict idempotency and dead-letter handling.Idempotency Logic
TheEchoConnectorAdapter (used for testing) demonstrates the platform’s approach to idempotency. Every outbound request includes an envelope_id. Adapters must track these IDs to ensure that retries (e.g., after a network failure) do not result in duplicate messages on the platform crates/palyra-connectors/src/connectors/echo.rs#68-75.
Retry Classification
When a delivery fails, the adapter returns aRetryClass to the supervisor:
- ConnectorRestarting: Temporary failure; the supervisor should restart the connector and retry crates/palyra-connectors/src/connectors/echo.rs#55-59.
- RateLimited: The platform has throttled the bot.
- PermanentFailure: The message is moved to the
DeadLetterRecordtable inConnectorStore.
Platform Stubs
While Discord is fully implemented, the codebase includes stubs and patterns for Slack and Telegram. These follow the sameConnectorAdapter pattern, utilizing reqwest for API communication and tokio-tungstenite for WebSocket-based “Socket Mode” or “Long Polling” implementations where applicable.
Sources: crates/palyra-connectors/Cargo.toml#17-24