Skip to main content
This section details the Discord channel connector and the generic Webhook integration subsystem. These components allow the Palyra daemon to interact with external platforms for message routing, event ingestion, and administrative operations.

Discord Connector Integration

The Discord integration is implemented as a specialized adapter within the ConnectorSupervisor framework. It handles the translation between Discord-specific events (via Bot API or Webhooks) and the internal InboundMessageEvent and OutboundMessageRequest protocols.

Implementation Architecture

The integration spans several layers:
  1. palyra-connector-discord: Contains the shared logic for identity normalization and specification building crates/palyra-daemon/src/channels/discord.rs#6-10.
  2. palyra-daemon (Channel Subsystem): Manages the lifecycle of Discord connectors, including ID generation via discord_connector_id crates/palyra-daemon/src/channels/discord.rs#6-10.
  3. Admin API: Provides endpoints for onboarding, identity probing, and permission validation crates/palyra-daemon/src/transport/http/handlers/admin/channels/connectors/discord.rs#6-40.

Onboarding and Identity Probing

Discord integration uses an “Onboarding Probe” to verify bot credentials and permissions before final activation. The admin_discord_onboarding_probe_handler triggers a preflight check that validates the bot token and retrieves the bot’s identity crates/palyra-daemon/src/transport/http/handlers/admin/channels/connectors/discord.rs#6-22.

Permission Normalization

Discord permissions are normalized into a standard set of requirements to ensure the bot can function correctly within a channel.

Discord Data Flow

The following diagram illustrates the flow of a message from Discord into the Palyra Gateway. Diagram: Discord Inbound Message Routing Sources: crates/palyra-connector-core/src/supervisor.rs#161-167, crates/palyra-daemon/src/channels/discord.rs#6-21, crates/palyra-connector-core/src/supervisor.rs#128-134

Webhook Integration Subsystem

The Webhook subsystem provides a generic mechanism for receiving signed payloads from external providers. It is managed by the WebhookRegistry, which persists integration metadata in a webhooks.toml file crates/palyra-daemon/src/webhooks.rs#16-17.

Registry and Security

The WebhookRegistry enforces strict security boundaries:

Payload Validation and Replay Protection

The palyra-common crate provides the verify_webhook_payload and parse_webhook_payload utilities used by the daemon crates/palyra-common/src/lib.rs#26-29.
FeatureImplementation
Signature VerificationWebhookSignatureVerifier validates HMAC or RSA signatures crates/palyra-common/src/lib.rs#28-28.
Replay ProtectionReplayNonceStore tracks nonces and timestamps to prevent duplicate attacks crates/palyra-common/src/lib.rs#27-27.
Payload LimitsEnforced via max_payload_bytes (default 64KB, max 1MB) crates/palyra-daemon/src/webhooks.rs#23-24.

Webhook Processing Logic

Diagram: Webhook Ingestion Pipeline Sources: crates/palyra-common/src/webhook.rs#26-29, crates/palyra-daemon/src/webhooks.rs#107-111, crates/palyra-daemon/src/webhooks.rs#218-222

Admin Operations API

The Admin API provides operational visibility into the health and saturation of connectors.

Connector Status and Saturation

The build_channel_status_payload function aggregates data from the ConnectorStore and ConnectorSupervisor to determine the “saturation state” of a channel crates/palyra-daemon/src/transport/http/handlers/admin/channels/mod.rs#29-53. Saturation states include:

Lifecycle Management

Admin handlers support explicit logout and removal of accounts: Sources:
  • crates/palyra-daemon/src/webhooks.rs
  • crates/palyra-common/src/lib.rs
  • crates/palyra-daemon/src/transport/http/handlers/admin/channels/mod.rs
  • crates/palyra-daemon/src/transport/http/handlers/admin/channels/connectors/discord.rs
  • crates/palyra-daemon/src/channels/discord.rs
  • crates/palyra-connector-core/src/supervisor.rs