WebhookEventReceiver
in package
Receives the events Discord sends to the application's Webhook Events URL, and emits them on the client.
Lobby messages, game direct messages and application authorizations only arrive this way. Each request's
signature is checked against the application's verify_key, acknowledged at once, and its event then runs
through the same handlers as gateway events, so it is listened for the same way:
$discord->on(Event::LOBBY_MESSAGE_CREATE, fn (\Discord\Parts\Lobby\Message $message) => ...);
$discord->getWebhookEvents()->listen('127.0.0.1:8080');
Discord needs a public HTTPS URL, so put a reverse proxy in front of the address it listens on. The receiver
is also a ReactPHP request handler, so an application with its own React\Http\HttpServer can route to it instead.
Get it from Discord::getWebhookEvents().
Tags
Table of Contents
Constants
- EVENTS : mixed = [\Discord\WebSockets\Event::APPLICATION_AUTHORI...
- The events Discord sends as webhooks. Any other type is acknowledged and dropped.
- GATEWAY_EVENTS : mixed = [\Discord\WebSockets\Event::ENTITLEMENT_CREATE,...
- The events the gateway delivers as well. A webhook copy of one the gateway already delivered is dropped.
- TYPE_EVENT : mixed = 1
- A request carrying an event.
- TYPE_PING : mixed = 0
- A request Discord sends to check the URL is ready.
Properties
- $delivered : DeliveredEvents
- The events already delivered, to drop copies of them.
- $discord : Discord
- $dispatch : callable(object): void
- Runs a packet through the client's dispatch handlers.
- $sockets : array<string|int, SocketServer>
- The sockets opened by {@see WebhookEventReceiver::listen()}.
Methods
- __invoke() : ResponseInterface
- Handles one request from Discord.
- close() : void
- Stops listening on every socket opened by {@see WebhookEventReceiver::listen()}.
- listen() : SocketServer
- Receives webhook events on a socket.
- deliver() : void
- Emits an event, unless it is unknown or a copy of one already delivered.
Constants
EVENTS
The events Discord sends as webhooks. Any other type is acknowledged and dropped.
public
mixed
EVENTS
= [\Discord\WebSockets\Event::APPLICATION_AUTHORIZED, \Discord\WebSockets\Event::APPLICATION_DEAUTHORIZED, \Discord\WebSockets\Event::ENTITLEMENT_CREATE, \Discord\WebSockets\Event::ENTITLEMENT_UPDATE, \Discord\WebSockets\Event::ENTITLEMENT_DELETE, \Discord\WebSockets\Event::LOBBY_MESSAGE_CREATE, \Discord\WebSockets\Event::LOBBY_MESSAGE_UPDATE, \Discord\WebSockets\Event::LOBBY_MESSAGE_DELETE, \Discord\WebSockets\Event::GAME_DIRECT_MESSAGE_CREATE, \Discord\WebSockets\Event::GAME_DIRECT_MESSAGE_UPDATE, \Discord\WebSockets\Event::GAME_DIRECT_MESSAGE_DELETE]
GATEWAY_EVENTS
The events the gateway delivers as well. A webhook copy of one the gateway already delivered is dropped.
public
mixed
GATEWAY_EVENTS
= [\Discord\WebSockets\Event::ENTITLEMENT_CREATE, \Discord\WebSockets\Event::ENTITLEMENT_UPDATE, \Discord\WebSockets\Event::ENTITLEMENT_DELETE]
TYPE_EVENT
A request carrying an event.
public
mixed
TYPE_EVENT
= 1
TYPE_PING
A request Discord sends to check the URL is ready.
public
mixed
TYPE_PING
= 0
Properties
$delivered
The events already delivered, to drop copies of them.
protected
DeliveredEvents
$delivered
$discord
protected
Discord
$discord
$dispatch
Runs a packet through the client's dispatch handlers.
protected
callable(object): void
$dispatch
$sockets
The sockets opened by {@see WebhookEventReceiver::listen()}.
protected
array<string|int, SocketServer>
$sockets
= []
Methods
__invoke()
Handles one request from Discord.
public
__invoke(ServerRequestInterface $request) : ResponseInterface
A signed request is acknowledged with 204 before its event is handled, since Discord only waits 3 seconds.
Parameters
- $request : ServerRequestInterface
-
The request, with its body buffered.
Return values
ResponseInterfaceclose()
Stops listening on every socket opened by {@see WebhookEventReceiver::listen()}.
public
close() : void
listen()
Receives webhook events on a socket.
public
listen(string $uri[, array<string|int, mixed> $context = [] ]) : SocketServer
Parameters
- $uri : string
-
The address to listen on, such as
127.0.0.1:8080; seeReact\Socket\SocketServer. - $context : array<string|int, mixed> = []
-
Socket context options, such as
['tls' => [...]]to serve HTTPS directly.
Tags
Return values
SocketServerdeliver()
Emits an event, unless it is unknown or a copy of one already delivered.
protected
deliver(object $event, string $body) : void
Parameters
- $event : object
-
The payload's
eventobject. - $body : string
-
The raw request body, which a retry repeats.