pub struct OpenAIWebhookHandler { /* private fields */ }Expand description
OpenAI webhook event handler.
Provides an Axum router that receives POST requests at the configured path,
verifies each delivery’s Standard Webhooks signature and timestamp, parses the
event payload, and broadcasts parsed events to subscribers via a tokio
broadcast channel. A redelivery of a webhook-id already broadcast is
acknowledged and not broadcast again.
Implementations§
Source§impl OpenAIWebhookHandler
impl OpenAIWebhookHandler
Sourcepub fn new(config: OpenAIWebhookConfig) -> Result<Self, WebhookError>
pub fn new(config: OpenAIWebhookConfig) -> Result<Self, WebhookError>
Creates a webhook handler with the given configuration.
The broadcast channel has a capacity of 64 events. If subscribers fall behind, older events will be dropped.
§Errors
Returns WebhookError::InvalidSecret when webhook_secret is not a
whsec_-prefixed or bare base64 secret.
Sourcepub fn with_verifier(
config: OpenAIWebhookConfig,
verifier: WebhookVerifier,
) -> Self
pub fn with_verifier( config: OpenAIWebhookConfig, verifier: WebhookVerifier, ) -> Self
Creates a webhook handler that verifies deliveries with verifier.
Use it to accept two secrets while one rotates, or to set the timestamp
tolerance; config.webhook_secret is not read.
Sourcepub fn router(&self) -> Router
pub fn router(&self) -> Router
Create an Axum router for the webhook endpoint.
The router handles POST requests at the configured path. It returns HTTP 401 for a delivery that fails verification and HTTP 400 for a payload that does not parse.
Sourcepub fn subscribe(&self) -> Receiver<WebhookEvent>
pub fn subscribe(&self) -> Receiver<WebhookEvent>
Subscribe to webhook events.
Returns a broadcast receiver that will receive all parsed webhook events. Multiple subscribers can be active simultaneously.
Sourcepub fn verify(
&self,
headers: &WebhookHeaders<'_>,
body: &[u8],
) -> Result<VerifiedWebhook, WebhookError>
pub fn verify( &self, headers: &WebhookHeaders<'_>, body: &[u8], ) -> Result<VerifiedWebhook, WebhookError>
Verifies the timestamp and signature of one delivery.
body must be the raw request body.
§Errors
Returns a WebhookError when the timestamp is malformed or outside the
tolerance, or the signature matches no configured secret.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for OpenAIWebhookHandler
impl !UnwindSafe for OpenAIWebhookHandler
impl Forget for OpenAIWebhookHandler
impl Freeze for OpenAIWebhookHandlerwhere
*const ArcInner<OpenAIWebhookConfig> is !null: Freeze,
PhantomData<ArcInner<OpenAIWebhookConfig>>: Freeze,
*const ArcInner<WebhookVerifier> is !null: Freeze,
PhantomData<ArcInner<WebhookVerifier>>: Freeze,
*const ArcInner<InMemoryWebhookReplayGuard> is !null: Freeze,
PhantomData<ArcInner<InMemoryWebhookReplayGuard>>: Freeze,
*const ArcInner<Shared<WebhookEvent>> is !null: Freeze,
PhantomData<ArcInner<Shared<WebhookEvent>>>: Freeze,
impl Move for OpenAIWebhookHandler
impl Send for OpenAIWebhookHandlerwhere
Arc<OpenAIWebhookConfig>: Send,
Arc<WebhookVerifier>: Send,
Arc<InMemoryWebhookReplayGuard>: Send,
Arc<Shared<WebhookEvent>>: Send,
impl Sync for OpenAIWebhookHandlerwhere
Arc<OpenAIWebhookConfig>: Sync,
Arc<WebhookVerifier>: Sync,
Arc<InMemoryWebhookReplayGuard>: Sync,
Arc<Shared<WebhookEvent>>: Sync,
impl Unpin for OpenAIWebhookHandlerwhere
Arc<OpenAIWebhookConfig>: Unpin,
Arc<WebhookVerifier>: Unpin,
Arc<InMemoryWebhookReplayGuard>: Unpin,
Arc<Shared<WebhookEvent>>: Unpin,
impl UnsafeUnpin for OpenAIWebhookHandlerwhere
*const ArcInner<OpenAIWebhookConfig> is !null: UnsafeUnpin,
PhantomData<ArcInner<OpenAIWebhookConfig>>: UnsafeUnpin,
*const ArcInner<WebhookVerifier> is !null: UnsafeUnpin,
PhantomData<ArcInner<WebhookVerifier>>: UnsafeUnpin,
*const ArcInner<InMemoryWebhookReplayGuard> is !null: UnsafeUnpin,
PhantomData<ArcInner<InMemoryWebhookReplayGuard>>: UnsafeUnpin,
*const ArcInner<Shared<WebhookEvent>> is !null: UnsafeUnpin,
PhantomData<ArcInner<Shared<WebhookEvent>>>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more