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 thepalyra-connectors framework. It enables the daemon to act as a Discord bot, handling inbound messages and executing outbound actions (messages, edits, reactions).
Key Components
palyra-connector-discord: The low-level adapter that handles the Discord API protocol, token management, and payload normalization crates/palyra-connectors/Cargo.toml#16-16.ChannelPlatform: The central supervisor in the daemon that initializes theConnectorSupervisorwith the Discord adapter crates/palyra-daemon/src/channels.rs#148-182.DiscordMessageMutationGovernance: A logic engine that determines if an LLM-requested action (like editing or deleting a Discord message) requires human approval based on message age, channel type, and risk level crates/palyra-daemon/src/channels/discord.rs#55-141.
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. Theclassify_discord_message_mutation_governance function evaluates the risk of operations like Edit, Delete, and React crates/palyra-daemon/src/channels/discord.rs#61-141.
| Operation | Window (ms) | Risk Level | Approval Required |
|---|---|---|---|
| Edit | < 15 mins | Low | No (if private & authored by bot) |
| Edit | < 24 hours | High | Yes (if public or default profile) |
| Delete | < 15 mins | Medium | Yes |
| React | < 6 hours | Low | No (if private & scoped profile) |
| Any | > 24 hours | Critical | Yes (Always) |
Webhook Management
TheWebhookRegistry 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 awebhooks.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 usespalyra_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 theadmin_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 viapalyra channels discord setup crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#10-19.
- Probe: Calls
/admin/v1/channels/discord/onboarding/probeto validate the bot token and check permissions crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#33-46. - Configuration: Prompts the user for
inbound_scope(e.g.,open_guild_channels),allow_fromfilters, andbroadcast_strategycrates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#53-66. - Apply: Submits the final configuration to
/admin/v1/channels/discord/onboarding/applyto instantiate the connector crates/palyra-cli/src/commands/channels/connectors/discord/setup.rs#73-95.
Safety Controls
During setup, if a user selectsopen_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
TheChannelPlatform 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.