tgbot/types/definitions/
verification.rs

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