discord/interactions

Utils for implementing the Discord Interactions API

Maintainers

👁 ianww

Package info

github.com/discord/discord-interactions-php

pkg:composer/discord/interactions

Statistics

Installs: 406 192

Dependents: 7

Suggesters: 0

Stars: 46

Open Issues: 2

2.2.0 2022-02-09 17:58 UTC

Requires

None

Requires (Dev)

Suggests

Provides

None

Conflicts

Replaces

None

MIT a6fc0c877b75cf5ff5811f2ea69c5cc4ad6ac457

  • Ian Webster <ianw_php.woop@ianww.com>

discord

This package is not auto-updated.

Last update: 2026-06-25 15:09:25 UTC


README

Types and helper functions that may come in handy when you implement a Discord Interactions webhook.

Installation

Install from packagist:

composer require discord/interactions

Validating request signatures requires the simplito/elliptic-php package to be installed, which requires the php-gmp extension to be enabled:

composer require simplito/elliptic-php

Usage

Use InteractionType and InteractionResponseType to interpret and respond to webhooks.

Use InteractionResponseFlags to make your response special.

Use verifyKey to check a request signature. Note you must install the simplito/elliptic-php package first. For example:

use Discord\Interaction;
use Discord\InteractionResponseType;

$CLIENT_PUBLIC_KEY = getenv('CLIENT_PUBLIC_KEY');

$signature = $_SERVER['HTTP_X_SIGNATURE_ED25519'];
$timestamp = $_SERVER['HTTP_X_SIGNATURE_TIMESTAMP'];
$postData = file_get_contents('php://input');

if (Interaction::verifyKey($postData, $signature, $timestamp, $CLIENT_PUBLIC_KEY)) {
 echo json_encode(array(
 'type' => InteractionResponseType::PONG
 ));
} else {
 http_response_code(401);
 echo "Not verified";
}