tgbot/types/verification/
mod.rs

1use serde::Serialize;
2
3use crate::{
4    api::{Method, Payload},
5    types::{ChatId, Integer},
6};
7
8#[cfg(test)]
9mod tests;
10
11#[derive(Clone, Debug, Serialize)]
12/// Removes verification from a chat that is currently verified on behalf of the organization represented by the bot.
13pub struct RemoveChatVerification {
14    chat_id: ChatId,
15}
16
17impl RemoveChatVerification {
18    /// Creates a new `RemoveChatVerification`.
19    ///
20    /// # Arguments
21    ///
22    /// * `chat_id` - Unique identifier for the target chat
23    ///   or username of the target channel (in the format @channelusername).
24    pub fn new<T>(chat_id: T) -> Self
25    where
26        T: Into<ChatId>,
27    {
28        Self {
29            chat_id: chat_id.into(),
30        }
31    }
32}
33
34impl Method for RemoveChatVerification {
35    type Response = bool;
36
37    fn into_payload(self) -> Payload {
38        Payload::json("removeChatVerification", self)
39    }
40}
41
42#[derive(Clone, Copy, Debug, Serialize)]
43/// Removes verification from a user who is currently verified on behalf of the organization represented by the bot.
44pub struct RemoveUserVerification {
45    user_id: Integer,
46}
47
48impl RemoveUserVerification {
49    /// Creates a new `RemoveUserVerification`.
50    ///
51    /// # Arguments
52    ///
53    /// * `user_id` - Unique identifier of the target user.
54    pub fn new(user_id: Integer) -> Self {
55        Self { user_id }
56    }
57}
58
59impl Method for RemoveUserVerification {
60    type Response = bool;
61
62    fn into_payload(self) -> Payload {
63        Payload::json("removeUserVerification", self)
64    }
65}
66
67/// Verifies a chat on behalf of the organization which is represented by the bot.
68#[serde_with::skip_serializing_none]
69#[derive(Clone, Debug, Serialize)]
70pub struct VerifyChat {
71    chat_id: ChatId,
72    custom_description: Option<String>,
73}
74
75impl VerifyChat {
76    /// Creates a new `VerifyChat`.
77    ///
78    /// # Arguments
79    ///
80    /// * `chat_id` - Unique identifier for the target chat
81    ///   or username of the target channel (in the format @channelusername).
82    pub fn new<T>(chat_id: T) -> Self
83    where
84        T: Into<ChatId>,
85    {
86        Self {
87            chat_id: chat_id.into(),
88            custom_description: None,
89        }
90    }
91
92    /// Sets a new custom description.
93    ///
94    /// # Arguments
95    ///
96    /// * `value` - Custom description for the verification; 0-70 characters.
97    ///   Must be empty if the organization isn't allowed to provide a custom verification description.
98    pub fn with_custom_description<T>(mut self, value: T) -> Self
99    where
100        T: Into<String>,
101    {
102        self.custom_description = Some(value.into());
103        self
104    }
105}
106
107impl Method for VerifyChat {
108    type Response = bool;
109
110    fn into_payload(self) -> Payload {
111        Payload::json("verifyChat", self)
112    }
113}
114
115/// Verifies a user on behalf of the organization which is represented by the bot.
116#[serde_with::skip_serializing_none]
117#[derive(Clone, Debug, Serialize)]
118pub struct VerifyUser {
119    user_id: Integer,
120    custom_description: Option<String>,
121}
122
123impl VerifyUser {
124    /// Creates a new `VerifyUser`.
125    ///
126    /// # Arguments
127    ///
128    /// * `user_id` - Unique identifier of the target user.
129    pub fn new(user_id: Integer) -> Self {
130        Self {
131            user_id,
132            custom_description: None,
133        }
134    }
135
136    /// Sets a new custom description.
137    ///
138    /// # Arguments
139    ///
140    /// * `value` - Custom description for the verification; 0-70 characters.
141    ///   Must be empty if the organization isn't allowed to provide a custom verification description.
142    pub fn with_custom_description<T>(mut self, value: T) -> Self
143    where
144        T: Into<String>,
145    {
146        self.custom_description = Some(value.into());
147        self
148    }
149}
150
151impl Method for VerifyUser {
152    type Response = bool;
153
154    fn into_payload(self) -> Payload {
155        Payload::json("verifyUser", self)
156    }
157}