Skip to main content

Module webhook

Module webhook 

Source
Available on crate feature webhook only.
Expand description

The receiving side of push notifications (spec §4.3.3, §13.2).

An agent POSTs each task update to the webhook URL a client registered with CreateTaskPushNotificationConfig. The specification puts the checks on the client: it MUST validate the request with the credentials it supplied, MUST (§4.3.3) or SHOULD (§13.2) check the task ID is one it expects, MUST answer 2xx to acknowledge, SHOULD process duplicates idempotently, SHOULD rate-limit, and SHOULD give every config its own single-purpose token. WebhookReceiver does those checks. It is not an HTTP server: hand it the request’s headers and body from whatever server you run, and answer with WebhookOutcome::status.

use a2a_protocol_client::webhook::{new_notification_token, WebhookOutcome, WebhookReceiver};
use a2a_protocol_types::TaskPushNotificationConfig;

let receiver = WebhookReceiver::new();

// One fresh token per config (§13.2). Register the config the agent
// stored — `create_push_config` returns it, with the id the agent assigned.
let mut config = TaskPushNotificationConfig::new("task-1", "https://hooks.example.com/a2a");
config.token = Some(new_notification_token());
receiver.register(&config)?;

// In the webhook's HTTP handler:
let outcome = receiver.receive(&headers, &body);
let status = outcome.status(); // answer the agent with this
if let WebhookOutcome::Accepted { event, .. } = outcome {
    // handle the event
}

§What “duplicate” means

A sender that retries re-sends the same bytes — this SDK’s HttpPushSender serializes an event once and POSTs that body on every attempt — so a duplicate is the same body again for the same config, within the cache’s lifetime. Two deliveries of one event serialized twice, with different bytes, are not recognised as one.

Structs§

WebhookReceiver
Checks webhook requests against the push configs a client registered (spec §4.3.3, §13.2).

Enums§

WebhookError
Why WebhookReceiver::register refused a push config.
WebhookOutcome
What became of one webhook request.
WebhookRejection
Why a webhook request was refused.

Constants§

NOTIFICATION_TOKEN_HEADER
The X-A2A-Notification-Token spelling, which a2a-sdk (Python) sends and reads.
NOTIFICATION_TOKEN_HEADER_UNPREFIXED
The A2A-Notification-Token spelling, which a2a-go sends and reads.

Functions§

new_notification_token
A fresh notification token: 32 bytes carrying 244 random bits, encoded base64url without padding — 43 characters, safe in a header and a URL.
notification_token
Reads the push notification token from a webhook request’s headers, under either spelling.