Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/discord/discord-interactions-php
PHP utilities for building Discord Interaction webhooks
https://github.com/discord/discord-interactions-php
Last synced: about 1 month ago
JSON representation
PHP utilities for building Discord Interaction webhooks
- Host: GitHub
- URL: https://github.com/discord/discord-interactions-php
- Owner: discord
- Created: 2020-12-12T02:12:39.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-28T06:15:53.000Z (12 months ago)
- Last Synced: 2024-10-01T03:40:57.138Z (about 1 month ago)
- Language: PHP
- Size: 16.6 KB
- Stars: 42
- Watchers: 13
- Forks: 13
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- discord-api-libs - discord-interactions-php - PHP utilities for building Discord Interaction webhooks (Libraries / PHP)
README
discord-interactions-php
---Types and helper functions that may come in handy when you implement a Discord Interactions webhook.
# Installation
Install from [packagist](https://packagist.org/packages/discord/interactions):
```
composer require discord/interactions
```Validating request signatures requires the [`simplito/elliptic-php`](https://github.com/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:
```php
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";
}
```