Skip to main content
The Discord integration in Palyra provides a high-fidelity connector for asynchronous agent communication, enabling the daemon to interact with users via Direct Messages (DMs) and Guild channels. It encompasses a specialized onboarding flow, real-time health monitoring, and administrative controls for account lifecycle management.

Architecture and Data Flow

The Discord integration is implemented as a provider within the palyra-connectors framework, but it features extensive support in the palyra-palyrad daemon for complex operations like permission auditing and automated onboarding.

Request Handling Pipeline

When a Discord-specific request is initiated from the Web UI or CLI, it traverses the following path:
  1. Transport Layer: Axum handlers in crates/palyra-daemon/src/transport/http/handlers/console/channels/connectors/discord.rs 9-49 or admin equivalents 7-117 receive the request.
  2. Application Dispatch: The request is routed to crates/palyra-daemon/src/application/channels/providers/discord/mod.rs 1-172.
  3. Vault Interaction: The daemon resolves the bot token via resolve_discord_connector_token 123-158, which fetches the secret from the palyra-vault 143-146.
  4. Connector Execution: Actual Discord API calls (via serenity or internal HTTP clients) are managed by the connector instance 124-129.

Discord Integration Component Map

Sources: crates/palyra-daemon/src/transport/http/handlers/admin/channels/connectors/discord.rs:25-41(), crates/palyra-daemon/src/application/channels/providers/discord/mod.rs:30-63(), crates/palyra-daemon/src/application/channels/status.rs:13-37()

Onboarding Flow

The onboarding process is designed to be “preflight-first,” ensuring that bot tokens are valid and permissions are sufficient before a connector is persisted.

Onboarding Stages

  1. Probe/Preflight: build_discord_onboarding_preflight crates/palyra-daemon/src/application/channels/providers/discord/mod.rs#20 validates the token and retrieves the bot’s identity and application metadata.
  2. Identity Verification: probe_discord_bot_identity crates/palyra-daemon/src/application/channels/providers/discord/mod.rs#77-80 checks if the bot can see the target verify_channel_id.
  3. Permission Audit: The system checks for mandatory permissions such as View Channels, Send Messages, and Read Message History crates/palyra-daemon/src/application/channels/providers/discord/mod.rs#42-52.
  4. Application: apply_discord_onboarding crates/palyra-daemon/src/application/channels/providers/discord/mod.rs#39 persists the configuration and enables the connector.
Sources: crates/palyra-daemon/src/application/channels/providers/discord/mod.rs:18-23(), crates/palyra-daemon/src/transport/http/handlers/admin/channels/connectors/discord.rs:7-41()

Channel Status and Health Monitoring

Palyra maintains a detailed “Saturation” and “Health” model for Discord connectors to help operators debug connectivity or permission issues.

Status Aggregation Logic

The build_channel_operations_snapshot function crates/palyra-daemon/src/application/channels/status.rs#55-162 calculates the operational state of a Discord connector:
StateCondition
pausedConnector is disabled or queue is explicitly paused 91-97.
rate_limitedGlobal retry_after_ms is active or route-specific limits are hit 101-108.
auth_failedLast error contains keywords like “token”, “unauthorized”, or “missing credential” 109-111, 164-184.
backpressureOutbox has claimed or due messages waiting for processing 112-119.
healthyNo errors, limits, or pending backlogs 124.

Health Refresh

Operators can trigger a refreshChannelHealth apps/web/src/consoleApi/channels/discord.ts#31-44 which executes build_discord_channel_health_refresh_payload. This performs a live check of: Sources: crates/palyra-daemon/src/application/channels/status.rs:55-184(), crates/palyra-daemon/src/application/channels/providers/discord/mod.rs:66-117()

Management Interfaces

Web UI (Console)

The ChannelsSection apps/web/src/console/sections/ChannelsSection.tsx provides a dedicated “Discord” tab for management. It uses the DiscordChannelController apps/web/src/features/channels/connectors/discord/controller.ts to drive:

Webhook Handling

While Discord primarily uses a Gateway (WebSocket) for inbound messages, Palyra includes a WebhookRegistry crates/palyra-daemon/src/webhooks.rs#107 for handling platform-specific webhooks (e.g., interactions or external triggers).
  • Registry: Stores integration records in webhooks.toml 16.
  • Validation: Enforces signature_required and max_payload_bytes 41-42.
Sources: apps/web/src/console/sections/ChannelsSection.tsx:4-5, 72-84(), crates/palyra-daemon/src/webhooks.rs:15-43, 107-124()

Implementation Details

Message Mutation Governance

Discord message operations (Edit, Delete, React) are governed by a risk-based policy system. Sources: crates/palyra-daemon/src/application/channels/providers/mod.rs:55-85(), crates/palyra-daemon/src/application/channels/providers/discord/mod.rs:160-170()

Boundary Enforcement

To prevent “Discord leakage” into generic daemon logic, the project uses a check script scripts/check-channel-provider-boundaries.sh 1-110 which ensures:
  • Direct usage of Discord helpers is restricted to provider-specific directories 17-37.
  • ConnectorKind::Discord branching is isolated 38-54.
Sources: scripts/check-channel-provider-boundaries.sh:15-54()