agentmail/types/webhooks.rs
1use serde::{Deserialize, Serialize};
2
3/// Request body for `create_webhook`.
4#[derive(Clone, Debug, Default, Serialize)]
5pub struct CreateWebhook {
6 /// HTTPS endpoint to deliver events to.
7 pub url: String,
8 /// e.g. `["message.received"]`.
9 pub event_types: Vec<String>,
10 /// Limit delivery to these inboxes; empty means all.
11 #[serde(skip_serializing_if = "Vec::is_empty")]
12 pub inbox_ids: Vec<String>,
13 /// Limit delivery to these pods; empty means all.
14 #[serde(skip_serializing_if = "Vec::is_empty")]
15 pub pod_ids: Vec<String>,
16 /// Your own idempotency/reference id for this webhook.
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub client_id: Option<String>,
19 /// Extra headers to send with every delivery.
20 #[serde(skip_serializing_if = "Option::is_none")]
21 pub headers: Option<serde_json::Value>,
22}
23
24/// Request body for `update_webhook`. Every field is optional; leave
25/// a field empty to keep it unchanged. Inbox and pod targeting is edited by
26/// delta (add/remove lists) rather than by replacing the whole set.
27#[derive(Clone, Debug, Default, Serialize)]
28pub struct UpdateWebhook {
29 /// Replace the subscribed event types.
30 #[serde(skip_serializing_if = "Vec::is_empty")]
31 pub event_types: Vec<String>,
32 /// Pause (`false`) or resume (`true`) delivery.
33 #[serde(skip_serializing_if = "Option::is_none")]
34 pub enabled: Option<bool>,
35 /// Inboxes to add to the subscription.
36 #[serde(skip_serializing_if = "Vec::is_empty")]
37 pub add_inbox_ids: Vec<String>,
38 /// Inboxes to remove from the subscription.
39 #[serde(skip_serializing_if = "Vec::is_empty")]
40 pub remove_inbox_ids: Vec<String>,
41 /// Pods to add to the subscription.
42 #[serde(skip_serializing_if = "Vec::is_empty")]
43 pub add_pod_ids: Vec<String>,
44 /// Pods to remove from the subscription.
45 #[serde(skip_serializing_if = "Vec::is_empty")]
46 pub remove_pod_ids: Vec<String>,
47}
48/// A webhook subscription, as the API returns it.
49#[derive(Clone, Debug, Deserialize)]
50pub struct Webhook {
51 /// Unique id, used to delete the subscription.
52 pub webhook_id: String,
53 /// The subscribed HTTPS endpoint.
54 pub url: String,
55 /// Signing secret, returned once, on creation.
56 #[serde(default)]
57 pub secret: Option<String>,
58 /// Subscribed event types.
59 #[serde(default)]
60 pub event_types: Vec<String>,
61 /// Inboxes the subscription is limited to; empty means all.
62 #[serde(default)]
63 pub inbox_ids: Vec<String>,
64 /// Pods the subscription is limited to; empty means all.
65 #[serde(default)]
66 pub pod_ids: Vec<String>,
67 /// The pod this webhook is scoped to, when created on a pod handle.
68 #[serde(default)]
69 pub pod_id: Option<String>,
70 /// The inbox this webhook is scoped to, when created on an inbox handle.
71 #[serde(default)]
72 pub inbox_id: Option<String>,
73 /// Whether the subscription currently delivers.
74 pub enabled: bool,
75 /// Your own reference id, echoed back if set on creation.
76 #[serde(default)]
77 pub client_id: Option<String>,
78 /// Timestamp the subscription was last updated (RFC 3339).
79 #[serde(default)]
80 pub updated_at: Option<String>,
81 /// Timestamp the subscription was created (RFC 3339).
82 #[serde(default)]
83 pub created_at: Option<String>,
84}
85/// One page of webhooks from `list_webhooks_page`.
86#[derive(Clone, Debug, Deserialize)]
87pub struct WebhookList {
88 /// Total webhooks in the account (not just this page).
89 pub count: u64,
90 /// This page of webhooks.
91 #[serde(default)]
92 pub webhooks: Vec<Webhook>,
93 /// Cursor for the next page; `None` on the last page.
94 #[serde(default)]
95 pub next_page_token: Option<String>,
96}
97
98/// Body for `update_webhook_headers`: headers to set or replace, plus names
99/// to remove. Applied to every delivery of that webhook.
100#[derive(Clone, Debug, Default, Serialize)]
101pub struct UpdateWebhookHeaders {
102 /// Headers to set or overwrite, sent verbatim with each delivery.
103 #[serde(skip_serializing_if = "Option::is_none")]
104 pub headers: Option<serde_json::Value>,
105 /// Header names to delete from the subscription.
106 #[serde(skip_serializing_if = "Vec::is_empty")]
107 pub remove_headers: Vec<String>,
108}
109
110/// The header names configured on a webhook, from `get_webhook_headers`
111/// (values are never returned).
112#[derive(Clone, Debug, Deserialize)]
113pub struct WebhookHeaderNames {
114 /// The configured header names.
115 pub header_names: Vec<String>,
116}