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