Skip to main content

zulip_api/message/
bot_service.rs

1use serde::{Deserialize, Serialize};
2use serde_repr::{Deserialize_repr, Serialize_repr};
3
4/// Represents extra configuration details for the bot.
5///
6/// The fields in the object depend on the type of bot.
7///
8/// Modified from `openapi-generator-cli` output:
9///
10/// ```shell,no_build,no_run
11/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
12/// ```
13///
14/// ```text
15/// /*
16/// * Zulip REST API
17/// *
18/// * Powerful open source group chat
19/// *
20/// * The version of the OpenAPI document: 1.0.0
21/// *
22/// * Generated by: https://openapi-generator.tech
23/// */
24/// ```
25///
26/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
27///
28/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
29#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum BotService {
32    OutgoingWebhook(BotServiceOutgoingWebhook),
33    Embedded(BotServiceEmbedded),
34}
35
36impl BotService {
37    /// Creates a new [BotService].
38    pub const fn new() -> Self {
39        Self::OutgoingWebhook(BotServiceOutgoingWebhook::new())
40    }
41}
42
43impl Default for BotService {
44    fn default() -> Self {
45        Self::new()
46    }
47}
48
49/// Represents when the bot is an outgoing webhook.
50///
51/// Modified from `openapi-generator-cli` output:
52///
53/// ```shell,no_build,no_run
54/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
55/// ```
56///
57/// ```text
58/// /*
59/// * Zulip REST API
60/// *
61/// * Powerful open source group chat
62/// *
63/// * The version of the OpenAPI document: 1.0.0
64/// *
65/// * Generated by: https://openapi-generator.tech
66/// */
67/// ```
68///
69/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
70///
71/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
72#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
73pub struct BotServiceOutgoingWebhook {
74    /// The URL the outgoing webhook is configured to post to.
75    #[serde(skip_serializing_if = "Option::is_none")]
76    pub base_url: Option<String>,
77    /// A unique token that the third-party service can use to confirm that the request is indeed coming from Zulip.
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub token: Option<String>,
80    /// An integer indicating what format requests are posted in:  - 1 = Zulip's native outgoing webhook format. - 2 = Emulate the Slack outgoing webhook format.
81    #[serde(skip_serializing_if = "Option::is_none")]
82    pub interface: Option<OutgoingWebhookInterface>,
83}
84
85/// Represents An integer indicating what format requests are posted in
86///
87/// Modified from `openapi-generator-cli` output:
88///
89/// ```shell,no_build,no_run
90/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
91/// ```
92///
93/// ```text
94/// /*
95/// * Zulip REST API
96/// *
97/// * Powerful open source group chat
98/// *
99/// * The version of the OpenAPI document: 1.0.0
100/// *
101/// * Generated by: https://openapi-generator.tech
102/// */
103/// ```
104///
105/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
106///
107/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
108#[repr(u8)]
109#[derive(Clone, Copy, Debug, Eq, PartialEq, Deserialize_repr, Serialize_repr)]
110pub enum OutgoingWebhookInterface {
111    /// Zulip's native outgoing webhook format
112    Native = 1,
113    /// Emulate the Slack outgoing webhook format.
114    EmulateSlack = 2,
115}
116
117impl BotServiceOutgoingWebhook {
118    /// When the bot is an outgoing webhook.
119    pub const fn new() -> Self {
120        Self {
121            base_url: None,
122            token: None,
123            interface: None,
124        }
125    }
126}
127
128impl Default for BotServiceOutgoingWebhook {
129    fn default() -> Self {
130        Self::new()
131    }
132}
133
134/// Represents when the bot is an embedded bot.
135///
136/// Modified from `openapi-generator-cli` output:
137///
138/// ```shell,no_build,no_run
139/// $ openapi-generator-cli generate -g rust -i ./zerver/openapi/zulip.yaml -o zulip-openapi --skip-validate-spec
140/// ```
141///
142/// ```text
143/// /*
144/// * Zulip REST API
145/// *
146/// * Powerful open source group chat
147/// *
148/// * The version of the OpenAPI document: 1.0.0
149/// *
150/// * Generated by: https://openapi-generator.tech
151/// */
152/// ```
153///
154/// See [zerver/openapi/zulip.yaml](https://github.com/zulip/zulip/blob/main/zerver/openapi/zulip.yaml) for the original OpenAPI configuration.
155///
156/// Configuration slightly modified to work with the Rust generator of [`openapi-generator-cli`](https://openapi-generator.tech).
157#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
158pub struct BotServiceEmbedded {
159    /// The name of the bot.
160    #[serde(rename = "service_name", skip_serializing_if = "Option::is_none")]
161    pub service_name: Option<String>,
162    /// A dictionary of string key/value pairs, which describe the configuration for the bot. These are usually details like API keys, and are unique to the integration/bot. Can be an empty dictionary.
163    #[serde(rename = "config_data", skip_serializing_if = "Option::is_none")]
164    pub config_data: Option<std::collections::HashMap<String, String>>,
165}
166
167impl BotServiceEmbedded {
168    /// Creates a new [BotServiceEmbedded].
169    pub const fn new() -> Self {
170        Self {
171            service_name: None,
172            config_data: None,
173        }
174    }
175}
176
177impl Default for BotServiceEmbedded {
178    fn default() -> Self {
179        Self::new()
180    }
181}