Skip to main content

WebhookTrigger

Trait WebhookTrigger 

Source
pub trait WebhookTrigger:
    Send
    + Sync
    + 'static {
    // Required methods
    fn start_listener<'life0, 'async_trait>(
        &'life0 self,
        config: WebhookConfig,
    ) -> Pin<Box<dyn Future<Output = Result<WebhookListenerHandle>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn stop_listener<'life0, 'async_trait>(
        &'life0 self,
        handle: WebhookListenerHandle,
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn recv_event<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<Option<WebhookEvent>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn verify_signature(
        &self,
        secret: &str,
        signature: &str,
        body: &[u8],
    ) -> bool;
}
Expand description

Port: accept inbound webhooks and emit WebhookEvents.

Implementations bind an HTTP listener, verify signatures, enforce body-size limits, and forward valid events to registered callbacks. The application layer maps events to pipeline executions.

All methods are async and implementations must be Send + Sync + 'static.

Required Methods§

Source

fn start_listener<'life0, 'async_trait>( &'life0 self, config: WebhookConfig, ) -> Pin<Box<dyn Future<Output = Result<WebhookListenerHandle>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Start the HTTP listener with the given configuration.

Returns a WebhookListenerHandle that can be passed to stop_listener for graceful shutdown.

Source

fn stop_listener<'life0, 'async_trait>( &'life0 self, handle: WebhookListenerHandle, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gracefully stop the listener identified by handle.

In-flight requests should be drained before the listener shuts down.

Source

fn recv_event<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Option<WebhookEvent>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Wait for the next webhook event.

Blocks until an event is received or the listener is stopped (returns Ok(None) in the latter case).

Source

fn verify_signature(&self, secret: &str, signature: &str, body: &[u8]) -> bool

Verify the HMAC-SHA256 signature for a webhook payload.

Returns true if the signature is valid, false if it is invalid, and Ok(true) if no secret is configured (verification is skipped).

§Arguments
  • secret — The shared HMAC secret.
  • signature — The signature header value (e.g. sha256=<hex>).
  • body — The raw request body bytes.

Implementors§