use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchCancelled {
pub created_at: u64,
pub id: String,
pub data: WebhookBatchData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchCompleted {
pub created_at: u64,
pub id: String,
pub data: WebhookBatchData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchExpired {
pub created_at: u64,
pub id: String,
pub data: WebhookBatchData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchFailed {
pub created_at: u64,
pub id: String,
pub data: WebhookBatchData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookBatchData {
pub id: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookEvalRunCanceled {
pub created_at: u64,
pub id: String,
pub data: WebhookEvalRunData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookEvalRunFailed {
pub created_at: u64,
pub id: String,
pub data: WebhookEvalRunData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookEvalRunSucceeded {
pub created_at: u64,
pub id: String,
pub data: WebhookEvalRunData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookEvalRunData {
pub id: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookFineTuningJobCancelled {
pub created_at: u64,
pub id: String,
pub data: WebhookFineTuningJobData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookFineTuningJobFailed {
pub created_at: u64,
pub id: String,
pub data: WebhookFineTuningJobData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookFineTuningJobSucceeded {
pub created_at: u64,
pub id: String,
pub data: WebhookFineTuningJobData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookFineTuningJobData {
pub id: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookRealtimeCallIncoming {
pub created_at: u64,
pub id: String,
pub data: WebhookRealtimeCallData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookRealtimeCallData {
pub call_id: String,
pub sip_headers: Vec<SipHeader>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct SipHeader {
pub name: String,
pub value: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseCancelled {
pub created_at: u64,
pub id: String,
pub data: WebhookResponseData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseCompleted {
pub created_at: u64,
pub id: String,
pub data: WebhookResponseData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseFailed {
pub created_at: u64,
pub id: String,
pub data: WebhookResponseData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseIncomplete {
pub created_at: u64,
pub id: String,
pub data: WebhookResponseData,
#[serde(skip_serializing_if = "Option::is_none")]
pub object: Option<String>,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct WebhookResponseData {
pub id: String,
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
#[serde(tag = "type")]
pub enum WebhookEvent {
#[serde(rename = "batch.cancelled")]
BatchCancelled(WebhookBatchCancelled),
#[serde(rename = "batch.completed")]
BatchCompleted(WebhookBatchCompleted),
#[serde(rename = "batch.expired")]
BatchExpired(WebhookBatchExpired),
#[serde(rename = "batch.failed")]
BatchFailed(WebhookBatchFailed),
#[serde(rename = "eval.run.canceled")]
EvalRunCanceled(WebhookEvalRunCanceled),
#[serde(rename = "eval.run.failed")]
EvalRunFailed(WebhookEvalRunFailed),
#[serde(rename = "eval.run.succeeded")]
EvalRunSucceeded(WebhookEvalRunSucceeded),
#[serde(rename = "fine_tuning.job.cancelled")]
FineTuningJobCancelled(WebhookFineTuningJobCancelled),
#[serde(rename = "fine_tuning.job.failed")]
FineTuningJobFailed(WebhookFineTuningJobFailed),
#[serde(rename = "fine_tuning.job.succeeded")]
FineTuningJobSucceeded(WebhookFineTuningJobSucceeded),
#[serde(rename = "realtime.call.incoming")]
RealtimeCallIncoming(WebhookRealtimeCallIncoming),
#[serde(rename = "response.cancelled")]
ResponseCancelled(WebhookResponseCancelled),
#[serde(rename = "response.completed")]
ResponseCompleted(WebhookResponseCompleted),
#[serde(rename = "response.failed")]
ResponseFailed(WebhookResponseFailed),
#[serde(rename = "response.incomplete")]
ResponseIncomplete(WebhookResponseIncomplete),
}
#[cfg(feature = "_api")]
macro_rules! impl_event_type {
($($ty:ty => $event_type:expr),* $(,)?) => {
$(
impl crate::traits::EventType for $ty {
fn event_type(&self) -> &'static str {
$event_type
}
}
)*
};
}
#[cfg(feature = "_api")]
macro_rules! impl_event_id {
($($ty:ty),* $(,)?) => {
$(
impl crate::traits::EventId for $ty {
fn event_id(&self) -> &str {
&self.id
}
}
)*
};
}
#[cfg(feature = "_api")]
impl_event_type! {
WebhookBatchCancelled => "batch.cancelled",
WebhookBatchCompleted => "batch.completed",
WebhookBatchExpired => "batch.expired",
WebhookBatchFailed => "batch.failed",
WebhookEvalRunCanceled => "eval.run.canceled",
WebhookEvalRunFailed => "eval.run.failed",
WebhookEvalRunSucceeded => "eval.run.succeeded",
WebhookFineTuningJobCancelled => "fine_tuning.job.cancelled",
WebhookFineTuningJobFailed => "fine_tuning.job.failed",
WebhookFineTuningJobSucceeded => "fine_tuning.job.succeeded",
WebhookRealtimeCallIncoming => "realtime.call.incoming",
WebhookResponseCancelled => "response.cancelled",
WebhookResponseCompleted => "response.completed",
WebhookResponseFailed => "response.failed",
WebhookResponseIncomplete => "response.incomplete",
}
#[cfg(feature = "_api")]
impl_event_id! {
WebhookBatchCancelled,
WebhookBatchCompleted,
WebhookBatchExpired,
WebhookBatchFailed,
WebhookEvalRunCanceled,
WebhookEvalRunFailed,
WebhookEvalRunSucceeded,
WebhookFineTuningJobCancelled,
WebhookFineTuningJobFailed,
WebhookFineTuningJobSucceeded,
WebhookRealtimeCallIncoming,
WebhookResponseCancelled,
WebhookResponseCompleted,
WebhookResponseFailed,
WebhookResponseIncomplete,
}
#[cfg(feature = "_api")]
impl crate::traits::EventType for WebhookEvent {
fn event_type(&self) -> &'static str {
match self {
WebhookEvent::BatchCancelled(e) => e.event_type(),
WebhookEvent::BatchCompleted(e) => e.event_type(),
WebhookEvent::BatchExpired(e) => e.event_type(),
WebhookEvent::BatchFailed(e) => e.event_type(),
WebhookEvent::EvalRunCanceled(e) => e.event_type(),
WebhookEvent::EvalRunFailed(e) => e.event_type(),
WebhookEvent::EvalRunSucceeded(e) => e.event_type(),
WebhookEvent::FineTuningJobCancelled(e) => e.event_type(),
WebhookEvent::FineTuningJobFailed(e) => e.event_type(),
WebhookEvent::FineTuningJobSucceeded(e) => e.event_type(),
WebhookEvent::RealtimeCallIncoming(e) => e.event_type(),
WebhookEvent::ResponseCancelled(e) => e.event_type(),
WebhookEvent::ResponseCompleted(e) => e.event_type(),
WebhookEvent::ResponseFailed(e) => e.event_type(),
WebhookEvent::ResponseIncomplete(e) => e.event_type(),
}
}
}
#[cfg(feature = "_api")]
impl crate::traits::EventId for WebhookEvent {
fn event_id(&self) -> &str {
match self {
WebhookEvent::BatchCancelled(e) => e.event_id(),
WebhookEvent::BatchCompleted(e) => e.event_id(),
WebhookEvent::BatchExpired(e) => e.event_id(),
WebhookEvent::BatchFailed(e) => e.event_id(),
WebhookEvent::EvalRunCanceled(e) => e.event_id(),
WebhookEvent::EvalRunFailed(e) => e.event_id(),
WebhookEvent::EvalRunSucceeded(e) => e.event_id(),
WebhookEvent::FineTuningJobCancelled(e) => e.event_id(),
WebhookEvent::FineTuningJobFailed(e) => e.event_id(),
WebhookEvent::FineTuningJobSucceeded(e) => e.event_id(),
WebhookEvent::RealtimeCallIncoming(e) => e.event_id(),
WebhookEvent::ResponseCancelled(e) => e.event_id(),
WebhookEvent::ResponseCompleted(e) => e.event_id(),
WebhookEvent::ResponseFailed(e) => e.event_id(),
WebhookEvent::ResponseIncomplete(e) => e.event_id(),
}
}
}
impl WebhookEvent {
pub fn created_at(&self) -> u64 {
match self {
WebhookEvent::BatchCancelled(w) => w.created_at,
WebhookEvent::BatchCompleted(w) => w.created_at,
WebhookEvent::BatchExpired(w) => w.created_at,
WebhookEvent::BatchFailed(w) => w.created_at,
WebhookEvent::EvalRunCanceled(w) => w.created_at,
WebhookEvent::EvalRunFailed(w) => w.created_at,
WebhookEvent::EvalRunSucceeded(w) => w.created_at,
WebhookEvent::FineTuningJobCancelled(w) => w.created_at,
WebhookEvent::FineTuningJobFailed(w) => w.created_at,
WebhookEvent::FineTuningJobSucceeded(w) => w.created_at,
WebhookEvent::RealtimeCallIncoming(w) => w.created_at,
WebhookEvent::ResponseCancelled(w) => w.created_at,
WebhookEvent::ResponseCompleted(w) => w.created_at,
WebhookEvent::ResponseFailed(w) => w.created_at,
WebhookEvent::ResponseIncomplete(w) => w.created_at,
}
}
}