1use serde::{Deserialize, Serialize};
2
3use crate::traits::{EventId, EventType};
4
5#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
7pub struct WebhookBatchCancelled {
8 pub created_at: i64,
10
11 pub id: String,
13
14 pub data: WebhookBatchData,
16
17 #[serde(skip_serializing_if = "Option::is_none")]
19 pub object: Option<String>,
20}
21
22#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
24pub struct WebhookBatchCompleted {
25 pub created_at: i64,
27
28 pub id: String,
30
31 pub data: WebhookBatchData,
33
34 #[serde(skip_serializing_if = "Option::is_none")]
36 pub object: Option<String>,
37}
38
39#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
41pub struct WebhookBatchExpired {
42 pub created_at: i64,
44
45 pub id: String,
47
48 pub data: WebhookBatchData,
50
51 #[serde(skip_serializing_if = "Option::is_none")]
53 pub object: Option<String>,
54}
55
56#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
58pub struct WebhookBatchFailed {
59 pub created_at: i64,
61
62 pub id: String,
64
65 pub data: WebhookBatchData,
67
68 #[serde(skip_serializing_if = "Option::is_none")]
70 pub object: Option<String>,
71}
72
73#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
75pub struct WebhookBatchData {
76 pub id: String,
78}
79
80impl EventType for WebhookBatchCancelled {
83 fn event_type(&self) -> &'static str {
84 "batch.cancelled"
85 }
86}
87
88impl EventId for WebhookBatchCancelled {
89 fn event_id(&self) -> &str {
90 &self.id
91 }
92}
93
94impl EventType for WebhookBatchCompleted {
95 fn event_type(&self) -> &'static str {
96 "batch.completed"
97 }
98}
99
100impl EventId for WebhookBatchCompleted {
101 fn event_id(&self) -> &str {
102 &self.id
103 }
104}
105
106impl EventType for WebhookBatchExpired {
107 fn event_type(&self) -> &'static str {
108 "batch.expired"
109 }
110}
111
112impl EventId for WebhookBatchExpired {
113 fn event_id(&self) -> &str {
114 &self.id
115 }
116}
117
118impl EventType for WebhookBatchFailed {
119 fn event_type(&self) -> &'static str {
120 "batch.failed"
121 }
122}
123
124impl EventId for WebhookBatchFailed {
125 fn event_id(&self) -> &str {
126 &self.id
127 }
128}
129
130#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
132pub struct WebhookEvalRunCanceled {
133 pub created_at: i64,
135
136 pub id: String,
138
139 pub data: WebhookEvalRunData,
141
142 #[serde(skip_serializing_if = "Option::is_none")]
144 pub object: Option<String>,
145}
146
147#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
149pub struct WebhookEvalRunFailed {
150 pub created_at: i64,
152
153 pub id: String,
155
156 pub data: WebhookEvalRunData,
158
159 #[serde(skip_serializing_if = "Option::is_none")]
161 pub object: Option<String>,
162}
163
164#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
166pub struct WebhookEvalRunSucceeded {
167 pub created_at: i64,
169
170 pub id: String,
172
173 pub data: WebhookEvalRunData,
175
176 #[serde(skip_serializing_if = "Option::is_none")]
178 pub object: Option<String>,
179}
180
181#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
183pub struct WebhookEvalRunData {
184 pub id: String,
186}
187
188impl EventType for WebhookEvalRunCanceled {
191 fn event_type(&self) -> &'static str {
192 "eval.run.canceled"
193 }
194}
195
196impl EventId for WebhookEvalRunCanceled {
197 fn event_id(&self) -> &str {
198 &self.id
199 }
200}
201
202impl EventType for WebhookEvalRunFailed {
203 fn event_type(&self) -> &'static str {
204 "eval.run.failed"
205 }
206}
207
208impl EventId for WebhookEvalRunFailed {
209 fn event_id(&self) -> &str {
210 &self.id
211 }
212}
213
214impl EventType for WebhookEvalRunSucceeded {
215 fn event_type(&self) -> &'static str {
216 "eval.run.succeeded"
217 }
218}
219
220impl EventId for WebhookEvalRunSucceeded {
221 fn event_id(&self) -> &str {
222 &self.id
223 }
224}
225
226#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
228pub struct WebhookFineTuningJobCancelled {
229 pub created_at: i64,
231
232 pub id: String,
234
235 pub data: WebhookFineTuningJobData,
237
238 #[serde(skip_serializing_if = "Option::is_none")]
240 pub object: Option<String>,
241}
242
243#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
245pub struct WebhookFineTuningJobFailed {
246 pub created_at: i64,
248
249 pub id: String,
251
252 pub data: WebhookFineTuningJobData,
254
255 #[serde(skip_serializing_if = "Option::is_none")]
257 pub object: Option<String>,
258}
259
260#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
262pub struct WebhookFineTuningJobSucceeded {
263 pub created_at: i64,
265
266 pub id: String,
268
269 pub data: WebhookFineTuningJobData,
271
272 #[serde(skip_serializing_if = "Option::is_none")]
274 pub object: Option<String>,
275}
276
277#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
279pub struct WebhookFineTuningJobData {
280 pub id: String,
282}
283
284impl EventType for WebhookFineTuningJobCancelled {
287 fn event_type(&self) -> &'static str {
288 "fine_tuning.job.cancelled"
289 }
290}
291
292impl EventId for WebhookFineTuningJobCancelled {
293 fn event_id(&self) -> &str {
294 &self.id
295 }
296}
297
298impl EventType for WebhookFineTuningJobFailed {
299 fn event_type(&self) -> &'static str {
300 "fine_tuning.job.failed"
301 }
302}
303
304impl EventId for WebhookFineTuningJobFailed {
305 fn event_id(&self) -> &str {
306 &self.id
307 }
308}
309
310impl EventType for WebhookFineTuningJobSucceeded {
311 fn event_type(&self) -> &'static str {
312 "fine_tuning.job.succeeded"
313 }
314}
315
316impl EventId for WebhookFineTuningJobSucceeded {
317 fn event_id(&self) -> &str {
318 &self.id
319 }
320}
321
322#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
324pub struct WebhookRealtimeCallIncoming {
325 pub created_at: i64,
327
328 pub id: String,
330
331 pub data: WebhookRealtimeCallData,
333
334 #[serde(skip_serializing_if = "Option::is_none")]
336 pub object: Option<String>,
337}
338
339#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
341pub struct WebhookRealtimeCallData {
342 pub call_id: String,
344
345 pub sip_headers: Vec<SipHeader>,
347}
348
349#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
351pub struct SipHeader {
352 pub name: String,
354
355 pub value: String,
357}
358
359impl EventType for WebhookRealtimeCallIncoming {
362 fn event_type(&self) -> &'static str {
363 "realtime.call.incoming"
364 }
365}
366
367impl EventId for WebhookRealtimeCallIncoming {
368 fn event_id(&self) -> &str {
369 &self.id
370 }
371}
372
373#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
375pub struct WebhookResponseCancelled {
376 pub created_at: i64,
378
379 pub id: String,
381
382 pub data: WebhookResponseData,
384
385 #[serde(skip_serializing_if = "Option::is_none")]
387 pub object: Option<String>,
388}
389
390#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
392pub struct WebhookResponseCompleted {
393 pub created_at: i64,
395
396 pub id: String,
398
399 pub data: WebhookResponseData,
401
402 #[serde(skip_serializing_if = "Option::is_none")]
404 pub object: Option<String>,
405}
406
407#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
409pub struct WebhookResponseFailed {
410 pub created_at: i64,
412
413 pub id: String,
415
416 pub data: WebhookResponseData,
418
419 #[serde(skip_serializing_if = "Option::is_none")]
421 pub object: Option<String>,
422}
423
424#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
426pub struct WebhookResponseIncomplete {
427 pub created_at: i64,
429
430 pub id: String,
432
433 pub data: WebhookResponseData,
435
436 #[serde(skip_serializing_if = "Option::is_none")]
438 pub object: Option<String>,
439}
440
441#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
443pub struct WebhookResponseData {
444 pub id: String,
446}
447
448impl EventType for WebhookResponseCancelled {
451 fn event_type(&self) -> &'static str {
452 "response.cancelled"
453 }
454}
455
456impl EventId for WebhookResponseCancelled {
457 fn event_id(&self) -> &str {
458 &self.id
459 }
460}
461
462impl EventType for WebhookResponseCompleted {
463 fn event_type(&self) -> &'static str {
464 "response.completed"
465 }
466}
467
468impl EventId for WebhookResponseCompleted {
469 fn event_id(&self) -> &str {
470 &self.id
471 }
472}
473
474impl EventType for WebhookResponseFailed {
475 fn event_type(&self) -> &'static str {
476 "response.failed"
477 }
478}
479
480impl EventId for WebhookResponseFailed {
481 fn event_id(&self) -> &str {
482 &self.id
483 }
484}
485
486impl EventType for WebhookResponseIncomplete {
487 fn event_type(&self) -> &'static str {
488 "response.incomplete"
489 }
490}
491
492impl EventId for WebhookResponseIncomplete {
493 fn event_id(&self) -> &str {
494 &self.id
495 }
496}
497
498#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
499#[serde(tag = "type")]
500pub enum WebhookEvent {
501 #[serde(rename = "batch.cancelled")]
502 BatchCancelled(WebhookBatchCancelled),
503
504 #[serde(rename = "batch.completed")]
505 BatchCompleted(WebhookBatchCompleted),
506
507 #[serde(rename = "batch.expired")]
508 BatchExpired(WebhookBatchExpired),
509
510 #[serde(rename = "batch.failed")]
511 BatchFailed(WebhookBatchFailed),
512
513 #[serde(rename = "eval.run.canceled")]
514 EvalRunCanceled(WebhookEvalRunCanceled),
515
516 #[serde(rename = "eval.run.failed")]
517 EvalRunFailed(WebhookEvalRunFailed),
518
519 #[serde(rename = "eval.run.succeeded")]
520 EvalRunSucceeded(WebhookEvalRunSucceeded),
521
522 #[serde(rename = "fine_tuning.job.cancelled")]
523 FineTuningJobCancelled(WebhookFineTuningJobCancelled),
524
525 #[serde(rename = "fine_tuning.job.failed")]
526 FineTuningJobFailed(WebhookFineTuningJobFailed),
527
528 #[serde(rename = "fine_tuning.job.succeeded")]
529 FineTuningJobSucceeded(WebhookFineTuningJobSucceeded),
530
531 #[serde(rename = "realtime.call.incoming")]
532 RealtimeCallIncoming(WebhookRealtimeCallIncoming),
533
534 #[serde(rename = "response.cancelled")]
535 ResponseCancelled(WebhookResponseCancelled),
536
537 #[serde(rename = "response.completed")]
538 ResponseCompleted(WebhookResponseCompleted),
539
540 #[serde(rename = "response.failed")]
541 ResponseFailed(WebhookResponseFailed),
542
543 #[serde(rename = "response.incomplete")]
544 ResponseIncomplete(WebhookResponseIncomplete),
545}
546
547impl EventType for WebhookEvent {
550 fn event_type(&self) -> &'static str {
551 match self {
552 WebhookEvent::BatchCancelled(e) => e.event_type(),
553 WebhookEvent::BatchCompleted(e) => e.event_type(),
554 WebhookEvent::BatchExpired(e) => e.event_type(),
555 WebhookEvent::BatchFailed(e) => e.event_type(),
556 WebhookEvent::EvalRunCanceled(e) => e.event_type(),
557 WebhookEvent::EvalRunFailed(e) => e.event_type(),
558 WebhookEvent::EvalRunSucceeded(e) => e.event_type(),
559 WebhookEvent::FineTuningJobCancelled(e) => e.event_type(),
560 WebhookEvent::FineTuningJobFailed(e) => e.event_type(),
561 WebhookEvent::FineTuningJobSucceeded(e) => e.event_type(),
562 WebhookEvent::RealtimeCallIncoming(e) => e.event_type(),
563 WebhookEvent::ResponseCancelled(e) => e.event_type(),
564 WebhookEvent::ResponseCompleted(e) => e.event_type(),
565 WebhookEvent::ResponseFailed(e) => e.event_type(),
566 WebhookEvent::ResponseIncomplete(e) => e.event_type(),
567 }
568 }
569}
570
571impl EventId for WebhookEvent {
572 fn event_id(&self) -> &str {
573 match self {
574 WebhookEvent::BatchCancelled(e) => e.event_id(),
575 WebhookEvent::BatchCompleted(e) => e.event_id(),
576 WebhookEvent::BatchExpired(e) => e.event_id(),
577 WebhookEvent::BatchFailed(e) => e.event_id(),
578 WebhookEvent::EvalRunCanceled(e) => e.event_id(),
579 WebhookEvent::EvalRunFailed(e) => e.event_id(),
580 WebhookEvent::EvalRunSucceeded(e) => e.event_id(),
581 WebhookEvent::FineTuningJobCancelled(e) => e.event_id(),
582 WebhookEvent::FineTuningJobFailed(e) => e.event_id(),
583 WebhookEvent::FineTuningJobSucceeded(e) => e.event_id(),
584 WebhookEvent::RealtimeCallIncoming(e) => e.event_id(),
585 WebhookEvent::ResponseCancelled(e) => e.event_id(),
586 WebhookEvent::ResponseCompleted(e) => e.event_id(),
587 WebhookEvent::ResponseFailed(e) => e.event_id(),
588 WebhookEvent::ResponseIncomplete(e) => e.event_id(),
589 }
590 }
591}
592
593impl WebhookEvent {
594 pub fn created_at(&self) -> i64 {
596 match self {
597 WebhookEvent::BatchCancelled(w) => w.created_at,
598 WebhookEvent::BatchCompleted(w) => w.created_at,
599 WebhookEvent::BatchExpired(w) => w.created_at,
600 WebhookEvent::BatchFailed(w) => w.created_at,
601 WebhookEvent::EvalRunCanceled(w) => w.created_at,
602 WebhookEvent::EvalRunFailed(w) => w.created_at,
603 WebhookEvent::EvalRunSucceeded(w) => w.created_at,
604 WebhookEvent::FineTuningJobCancelled(w) => w.created_at,
605 WebhookEvent::FineTuningJobFailed(w) => w.created_at,
606 WebhookEvent::FineTuningJobSucceeded(w) => w.created_at,
607 WebhookEvent::RealtimeCallIncoming(w) => w.created_at,
608 WebhookEvent::ResponseCancelled(w) => w.created_at,
609 WebhookEvent::ResponseCompleted(w) => w.created_at,
610 WebhookEvent::ResponseFailed(w) => w.created_at,
611 WebhookEvent::ResponseIncomplete(w) => w.created_at,
612 }
613 }
614}