Skip to main content

Module webhook_event

Module webhook_event 

Source
Expand description

Webhook events: events Discord sends over HTTP to an app’s webhook events URL (D-076).

Each request body is a WebhookEventPayload: either a PING (sent when the URL is configured) or an event whose data depends on its type. Unlike gateway events, webhook events are not realtime and may arrive out of order. Every request must be verified with its X-Signature-Ed25519 and X-Signature-Timestamp headers (answer 401 when the signature is invalid) and acknowledged with 204 No Content within 3 seconds, otherwise Discord retries it.

The events are chosen in the app’s settings or with the application’s event_webhooks_types.

§Examples

use djs_model::webhook_event::{PayloadType, WebhookEventData, WebhookEventPayload};

let body = r#"{
    "version": 1, "application_id": "1234560123453231555", "type": 1,
    "event": {
        "type": "APPLICATION_DEAUTHORIZED", "timestamp": "2024-10-18T14:42:53.064834",
        "data": { "user": { "id": "111178765189277770", "username": "nelly",
                            "discriminator": "0", "global_name": null, "avatar": null } }
    }
}"#;
let payload: WebhookEventPayload = serde_json::from_str(body)?;
assert_eq!(payload.kind, PayloadType::Event);
let event = payload.event.expect("events carry a body");
let WebhookEventData::ApplicationDeauthorized(data) = &event.data else {
    panic!("expected APPLICATION_DEAUTHORIZED");
};
assert_eq!(data.user.username, "nelly");

Structs§

ApplicationAuthorized
The data of an Application Authorized webhook event.
ApplicationDeauthorized
The data of an Application Deauthorized webhook event.
GameDirectMessage
A direct message in a GAME_DIRECT_MESSAGE_* webhook event (D-079).
LobbyMessageDelete
The data of a Lobby Message Delete webhook event.
WebhookEvent
The event body of a webhook event: when it happened and its data.
WebhookEventPayload
The outer payload of a webhook event request.

Enums§

PayloadType
The type of a webhook event payload.
WebhookEventData
The data of a WebhookEvent, by event type.
WebhookEventType
A webhook event type an app can subscribe to.