discord/interactions
PHP types and helpers for building Discord Interactions webhooks. Includes enums for interaction/response types and response flags, plus Ed25519 request signature verification via simplito/elliptic-php (requires php-gmp).
Begin by installing the package via Composer: composer require discord/interactions. For production security, also install simplito/elliptic-php and ensure the gmp PHP extension is enabled—signature validation will silently fail otherwise. Your first step is creating a webhook endpoint (e.g., /discord/interactions) that validates the request signature using Interaction::verifyKey(), then responds with InteractionResponseType::PONG for slash commands. This establishes the minimal viable interaction handler for basic slash commands.
verifyKey() in a Laravel middleware to centralize signature checks and prevent boilerplate duplication. Extract raw body via Request::getContent() before middleware like TrimStrings modifies it.Interaction::fromPayload() to convert raw payloads into structured objects, then switch on InteractionType (e.g., APPLICATION_COMMAND, MODAL_SUBMIT) to route logic to dedicated handlers.InteractionResponseType::MODAL and define title/custom_id/components via InteractionResponseData. For autocomplete, return filtered choices using InteractionResponseType::APPLICATION_COMMAND_AUTOCOMPLETE_RESULT.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE (flags like EPHEMERAL可选), then post follow-up messages using Laravel’s HTTP client + Discord webhook URL from the interaction token.json_decode() before passing to verifyKey(). Even trailing newlines break verification.DiscordInteractionController).504 Gateway Timeout.InteractionResponseFlags use bitmasks: combine them with bitwise OR (EPHEMERAL | crossposted) when constructing response data.How can I help you explore Laravel packages today?