glopenai/webhook

Types

A header from a SIP Invite, included in realtime call events.

pub type SipHeader {
  SipHeader(name: String, value: String)
}

Constructors

  • SipHeader(name: String, value: String)

Data payload for batch webhook events.

pub type WebhookBatchData {
  WebhookBatchData(id: String)
}

Constructors

  • WebhookBatchData(id: String)

Errors returned by webhook verification or decoding.

pub type WebhookError {
  InvalidSignature
  Invalid(message: String)
  Deserialization(body: String, error: json.DecodeError)
}

Constructors

  • InvalidSignature

    Signature did not match the computed HMAC.

  • Invalid(message: String)

    Timestamp, secret, or other input was malformed.

  • Deserialization(body: String, error: json.DecodeError)

    Body could not be decoded as a WebhookEvent.

Data payload for eval run webhook events.

pub type WebhookEvalRunData {
  WebhookEvalRunData(id: String)
}

Constructors

  • WebhookEvalRunData(id: String)

A webhook event delivered by OpenAI.

All variants share the common fields created_at, id, and object. The data field carries the variant-specific payload.

pub type WebhookEvent {
  BatchCancelled(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookBatchData,
  )
  BatchCompleted(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookBatchData,
  )
  BatchExpired(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookBatchData,
  )
  BatchFailed(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookBatchData,
  )
  EvalRunCanceled(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookEvalRunData,
  )
  EvalRunFailed(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookEvalRunData,
  )
  EvalRunSucceeded(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookEvalRunData,
  )
  FineTuningJobCancelled(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookFineTuningJobData,
  )
  FineTuningJobFailed(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookFineTuningJobData,
  )
  FineTuningJobSucceeded(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookFineTuningJobData,
  )
  RealtimeCallIncoming(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookRealtimeCallData,
  )
  ResponseCancelled(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookResponseData,
  )
  ResponseCompleted(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookResponseData,
  )
  ResponseFailed(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookResponseData,
  )
  ResponseIncomplete(
    created_at: Int,
    id: String,
    object: option.Option(String),
    data: WebhookResponseData,
  )
}

Constructors

Data payload for fine-tuning job webhook events.

pub type WebhookFineTuningJobData {
  WebhookFineTuningJobData(id: String)
}

Constructors

  • WebhookFineTuningJobData(id: String)

Data payload for realtime call webhook events.

pub type WebhookRealtimeCallData {
  WebhookRealtimeCallData(
    call_id: String,
    sip_headers: List(SipHeader),
  )
}

Constructors

  • WebhookRealtimeCallData(
      call_id: String,
      sip_headers: List(SipHeader),
    )

Data payload for response webhook events.

pub type WebhookResponseData {
  WebhookResponseData(id: String)
}

Constructors

  • WebhookResponseData(id: String)

Values

pub fn build_event(
  body body: String,
  signature signature: String,
  timestamp timestamp: String,
  webhook_id webhook_id: String,
  secret secret: String,
  now now: Int,
) -> Result(WebhookEvent, WebhookError)

Verify a signature and decode the body in one step.

pub fn build_event_with_tolerance(
  body body: String,
  signature signature: String,
  timestamp timestamp: String,
  webhook_id webhook_id: String,
  secret secret: String,
  now now: Int,
  tolerance_seconds tolerance_seconds: Int,
) -> Result(WebhookEvent, WebhookError)

Verify with explicit tolerance, then decode the body.

pub fn created_at(event: WebhookEvent) -> Int

Return the created_at timestamp of any webhook event variant.

pub const default_tolerance_seconds: Int

Default freshness tolerance window (seconds).

pub fn event_type(event: WebhookEvent) -> String

Return the wire string for the event’s type discriminator.

pub fn parse_event(
  body: String,
) -> Result(WebhookEvent, WebhookError)

Decode a webhook payload string into a WebhookEvent. Does NOT verify the signature; use verify_signature first.

pub fn verify_signature(
  body body: String,
  signature signature: String,
  timestamp timestamp: String,
  webhook_id webhook_id: String,
  secret secret: String,
  now now: Int,
) -> Result(Nil, WebhookError)

Verify a webhook signature using the default 300-second tolerance.

now is the current Unix timestamp in seconds. Pass a clock you trust; this keeps verification sans-IO.

pub fn verify_signature_with_tolerance(
  body body: String,
  signature signature: String,
  timestamp timestamp: String,
  webhook_id webhook_id: String,
  secret secret: String,
  now now: Int,
  tolerance_seconds tolerance_seconds: Int,
) -> Result(Nil, WebhookError)

Verify a webhook signature with an explicit tolerance window in seconds.

pub fn webhook_event_decoder() -> decode.Decoder(WebhookEvent)

Decode a WebhookEvent from JSON. The variant is chosen by the type field on the envelope.

Search Document