Skip to main content
The Discord Connector and Webhook sub-systems provide the primary interface for external asynchronous communication with the Palyra daemon. This integration is handled via a multi-layered architecture: a specialized adapter crate (palyra-connector-discord), a daemon-side management layer (channels.rs), and a standardized webhook registry for inbound event processing.

Discord Connector Architecture

The Discord integration is implemented as a specialized adapter within the palyra-connectors framework. It enables the daemon to act as a Discord bot, handling inbound messages and executing outbound actions (messages, edits, reactions).

Key Components

Data Flow: Outbound Message

The following diagram illustrates how a message initiated by the daemon reaches Discord. Sources: crates/palyra-daemon/src/channels.rs#167-174, crates/palyra-connectors/src/connectors/echo.rs#43-76 (Patterned after Echo), crates/palyra-daemon/src/channels/discord.rs#20-23.

Message Mutation Governance

Palyra enforces strict safety boundaries for Discord operations. The classify_discord_message_mutation_governance function evaluates the risk of operations like Edit, Delete, and React crates/palyra-daemon/src/channels/discord.rs#61-141.
OperationWindow (ms)Risk LevelApproval Required
Edit< 15 minsLowNo (if private & authored by bot)
Edit< 24 hoursHighYes (if public or default profile)
Delete< 15 minsMediumYes
React< 6 hoursLowNo (if private & scoped profile)
Any> 24 hoursCriticalYes (Always)
Sources: crates/palyra-daemon/src/channels/discord.rs#31-33, crates/palyra-daemon/src/channels/discord.rs#77-114.

Webhook Management

The WebhookRegistry manages inbound HTTP webhooks from various providers. It handles secret validation, payload size limits, and event filtering crates/palyra-daemon/src/webhooks.rs#107-111.

Registry Implementation

The registry persists configuration in a webhooks.toml file crates/palyra-daemon/src/webhooks.rs#16-16. It enforces limits such as a maximum of 1,024 integrations crates/palyra-daemon/src/webhooks.rs#17-17 and a default payload limit of 64KB crates/palyra-daemon/src/webhooks.rs#23-23.

Webhook Processing Pipeline

The system uses palyra_common::parse_webhook_payload to validate incoming data against the registered secret in the Vault crates/palyra-daemon/src/webhooks.rs#9-11. Sources: crates/palyra-daemon/src/webhooks.rs#178-222, crates/palyra-daemon/src/webhooks.rs#51-72.

Discord Onboarding Wizard

The onboarding flow is a multi-step process managed by the admin_discord_onboarding_probe_handler and admin_discord_onboarding_apply_handler crates/palyra-daemon/src/transport/http/handlers/admin/channels/connectors/discord.rs#6-40.

CLI Interaction

The CLI provides an interactive setup via palyra channels discord setup crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#10-19.
  1. Probe: Calls /admin/v1/channels/discord/onboarding/probe to validate the bot token and check permissions crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#33-46.
  2. Configuration: Prompts the user for inbound_scope (e.g., open_guild_channels), allow_from filters, and broadcast_strategy crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#53-66.
  3. Apply: Submits the final configuration to /admin/v1/channels/discord/onboarding/apply to instantiate the connector crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#73-95.

Safety Controls

During setup, if a user selects open_guild_channels, the CLI forces an explicit confirmation because it is considered high-risk crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#67-71. Sources: crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#27-97, crates/palyra-daemon/src/transport/http/handlers/admin/channels/connectors/discord.rs#113-176.

Dead Letter & Reliability

The ChannelPlatform utilizes a DeadLetterRecord to store messages that fail delivery after exhausting retries crates/palyra-daemon/src/channels.rs#17-20. The ConnectorSupervisor manages the retry logic, using RetryClass to distinguish between transient network issues and permanent failures (like invalid tokens) crates/palyra-connectors/src/connectors/echo.rs#48-60. Sources: crates/palyra-daemon/src/channels.rs#88-102, crates/palyra-connectors/src/connectors/echo.rs#144-182.