jacquard_api/place_stream/server/
create_webhook.rs

1// @generated by jacquard-lexicon. DO NOT EDIT.
2//
3// Lexicon: place.stream.server.createWebhook
4//
5// This file was automatically generated from Lexicon schemas.
6// Any manual changes will be overwritten on the next regeneration.
7
8#[jacquard_derive::lexicon]
9#[derive(
10    serde::Serialize,
11    serde::Deserialize,
12    Debug,
13    Clone,
14    PartialEq,
15    Eq,
16    bon::Builder,
17    jacquard_derive::IntoStatic
18)]
19#[serde(rename_all = "camelCase")]
20#[builder(start_fn = new)]
21pub struct CreateWebhook<'a> {
22    /// Whether this webhook should be active upon creation.
23    #[serde(skip_serializing_if = "std::option::Option::is_none")]
24    #[builder(into)]
25    pub active: Option<bool>,
26    /// A description of what this webhook is used for.
27    #[serde(skip_serializing_if = "std::option::Option::is_none")]
28    #[builder(into)]
29    #[serde(borrow)]
30    pub description: Option<jacquard_common::CowStr<'a>>,
31    /// The types of events this webhook should receive.
32    #[serde(borrow)]
33    pub events: Vec<jacquard_common::CowStr<'a>>,
34    /// Words to filter out from chat messages. Messages containing any of these words will not be forwarded.
35    #[serde(skip_serializing_if = "std::option::Option::is_none")]
36    #[builder(into)]
37    #[serde(borrow)]
38    pub mute_words: Option<Vec<jacquard_common::CowStr<'a>>>,
39    /// A user-friendly name for this webhook.
40    #[serde(skip_serializing_if = "std::option::Option::is_none")]
41    #[builder(into)]
42    #[serde(borrow)]
43    pub name: Option<jacquard_common::CowStr<'a>>,
44    /// Text to prepend to webhook messages.
45    #[serde(skip_serializing_if = "std::option::Option::is_none")]
46    #[builder(into)]
47    #[serde(borrow)]
48    pub prefix: Option<jacquard_common::CowStr<'a>>,
49    /// Text replacement rules for webhook messages.
50    #[serde(skip_serializing_if = "std::option::Option::is_none")]
51    #[builder(into)]
52    #[serde(borrow)]
53    pub rewrite: Option<Vec<crate::place_stream::server::RewriteRule<'a>>>,
54    /// Text to append to webhook messages.
55    #[serde(skip_serializing_if = "std::option::Option::is_none")]
56    #[builder(into)]
57    #[serde(borrow)]
58    pub suffix: Option<jacquard_common::CowStr<'a>>,
59    /// The webhook URL where events will be sent.
60    #[serde(borrow)]
61    pub url: jacquard_common::types::string::Uri<'a>,
62    #[serde(flatten)]
63    #[serde(borrow)]
64    #[builder(default)]
65    pub extra_data: ::std::collections::BTreeMap<
66        ::jacquard_common::smol_str::SmolStr,
67        ::jacquard_common::types::value::Data<'a>,
68    >,
69}
70
71#[jacquard_derive::lexicon]
72#[derive(
73    serde::Serialize,
74    serde::Deserialize,
75    Debug,
76    Clone,
77    PartialEq,
78    Eq,
79    jacquard_derive::IntoStatic
80)]
81#[serde(rename_all = "camelCase")]
82pub struct CreateWebhookOutput<'a> {
83    #[serde(borrow)]
84    pub webhook: crate::place_stream::server::Webhook<'a>,
85}
86
87#[jacquard_derive::open_union]
88#[derive(
89    serde::Serialize,
90    serde::Deserialize,
91    Debug,
92    Clone,
93    PartialEq,
94    Eq,
95    thiserror::Error,
96    miette::Diagnostic,
97    jacquard_derive::IntoStatic
98)]
99#[serde(tag = "error", content = "message")]
100#[serde(bound(deserialize = "'de: 'a"))]
101pub enum CreateWebhookError<'a> {
102    /// The provided webhook URL is invalid or unreachable.
103    #[serde(rename = "InvalidUrl")]
104    InvalidUrl(std::option::Option<String>),
105    /// A webhook with this URL already exists for this user.
106    #[serde(rename = "DuplicateWebhook")]
107    DuplicateWebhook(std::option::Option<String>),
108    /// The user has reached their maximum number of webhooks.
109    #[serde(rename = "TooManyWebhooks")]
110    TooManyWebhooks(std::option::Option<String>),
111}
112
113impl std::fmt::Display for CreateWebhookError<'_> {
114    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
115        match self {
116            Self::InvalidUrl(msg) => {
117                write!(f, "InvalidUrl")?;
118                if let Some(msg) = msg {
119                    write!(f, ": {}", msg)?;
120                }
121                Ok(())
122            }
123            Self::DuplicateWebhook(msg) => {
124                write!(f, "DuplicateWebhook")?;
125                if let Some(msg) = msg {
126                    write!(f, ": {}", msg)?;
127                }
128                Ok(())
129            }
130            Self::TooManyWebhooks(msg) => {
131                write!(f, "TooManyWebhooks")?;
132                if let Some(msg) = msg {
133                    write!(f, ": {}", msg)?;
134                }
135                Ok(())
136            }
137            Self::Unknown(err) => write!(f, "Unknown error: {:?}", err),
138        }
139    }
140}
141
142/// Response type for
143///place.stream.server.createWebhook
144pub struct CreateWebhookResponse;
145impl jacquard_common::xrpc::XrpcResp for CreateWebhookResponse {
146    const NSID: &'static str = "place.stream.server.createWebhook";
147    const ENCODING: &'static str = "application/json";
148    type Output<'de> = CreateWebhookOutput<'de>;
149    type Err<'de> = CreateWebhookError<'de>;
150}
151
152impl<'a> jacquard_common::xrpc::XrpcRequest for CreateWebhook<'a> {
153    const NSID: &'static str = "place.stream.server.createWebhook";
154    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
155        "application/json",
156    );
157    type Response = CreateWebhookResponse;
158}
159
160/// Endpoint type for
161///place.stream.server.createWebhook
162pub struct CreateWebhookRequest;
163impl jacquard_common::xrpc::XrpcEndpoint for CreateWebhookRequest {
164    const PATH: &'static str = "/xrpc/place.stream.server.createWebhook";
165    const METHOD: jacquard_common::xrpc::XrpcMethod = jacquard_common::xrpc::XrpcMethod::Procedure(
166        "application/json",
167    );
168    type Request<'de> = CreateWebhook<'de>;
169    type Response = CreateWebhookResponse;
170}