Skip to main content

rustigram_api/methods/
verification.rs

1use crate::client::BotClient;
2use crate::error::Result;
3use rustigram_types::user::ChatId;
4use serde::Serialize;
5use std::future::{Future, IntoFuture};
6use std::pin::Pin;
7
8// ─── verifyUser ───────────────────────────────────────────────────────────────
9
10#[derive(Serialize)]
11struct VerifyUserParams {
12    user_id: i64,
13    #[serde(skip_serializing_if = "Option::is_none")]
14    custom_description: Option<String>,
15}
16
17/// Builder for the [`verifyUser`](https://core.telegram.org/bots/api#verifyuser) method.
18pub struct VerifyUser {
19    client: BotClient,
20    params: VerifyUserParams,
21}
22
23impl VerifyUser {
24    pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
25        Self {
26            client,
27            params: VerifyUserParams {
28                user_id,
29                custom_description: None,
30            },
31        }
32    }
33    /// Sets a custom description shown alongside the verification badge (up to 70 characters).
34    pub fn custom_description(mut self, d: impl Into<String>) -> Self {
35        self.params.custom_description = Some(d.into());
36        self
37    }
38}
39
40impl IntoFuture for VerifyUser {
41    type Output = Result<bool>;
42    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
43    fn into_future(self) -> Self::IntoFuture {
44        Box::pin(async move { self.client.post_json("verifyUser", &self.params).await })
45    }
46}
47
48// ─── verifyChat ───────────────────────────────────────────────────────────────
49
50#[derive(Serialize)]
51struct VerifyChatParams {
52    chat_id: ChatId,
53    #[serde(skip_serializing_if = "Option::is_none")]
54    custom_description: Option<String>,
55}
56
57/// Builder for the [`verifyChat`](https://core.telegram.org/bots/api#verifychat) method.
58pub struct VerifyChat {
59    client: BotClient,
60    params: VerifyChatParams,
61}
62
63impl VerifyChat {
64    pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
65        Self {
66            client,
67            params: VerifyChatParams {
68                chat_id: chat_id.into(),
69                custom_description: None,
70            },
71        }
72    }
73    /// Sets a custom description shown alongside the verification badge. (up to 70 characters)
74    pub fn custom_description(mut self, d: impl Into<String>) -> Self {
75        self.params.custom_description = Some(d.into());
76        self
77    }
78}
79
80impl IntoFuture for VerifyChat {
81    type Output = Result<bool>;
82    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
83    fn into_future(self) -> Self::IntoFuture {
84        Box::pin(async move { self.client.post_json("verifyChat", &self.params).await })
85    }
86}
87
88// ─── removeUserVerification ───────────────────────────────────────────────────
89
90#[derive(Serialize)]
91struct RemoveUserVerificationParams {
92    user_id: i64,
93}
94
95/// Builder for the [`removeUserVerification`](https://core.telegram.org/bots/api#removeuserverification) method.
96pub struct RemoveUserVerification {
97    client: BotClient,
98    params: RemoveUserVerificationParams,
99}
100
101impl RemoveUserVerification {
102    pub(crate) fn new(client: BotClient, user_id: i64) -> Self {
103        Self {
104            client,
105            params: RemoveUserVerificationParams { user_id },
106        }
107    }
108}
109
110impl IntoFuture for RemoveUserVerification {
111    type Output = Result<bool>;
112    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
113    fn into_future(self) -> Self::IntoFuture {
114        Box::pin(async move {
115            self.client
116                .post_json("removeUserVerification", &self.params)
117                .await
118        })
119    }
120}
121
122// ─── removeChatVerification ───────────────────────────────────────────────────
123
124#[derive(Serialize)]
125struct RemoveChatVerificationParams {
126    chat_id: ChatId,
127}
128
129/// Builder for the [`removeChatVerification`](https://core.telegram.org/bots/api#removechatverification) method.
130pub struct RemoveChatVerification {
131    client: BotClient,
132    params: RemoveChatVerificationParams,
133}
134
135impl RemoveChatVerification {
136    pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
137        Self {
138            client,
139            params: RemoveChatVerificationParams {
140                chat_id: chat_id.into(),
141            },
142        }
143    }
144}
145
146impl IntoFuture for RemoveChatVerification {
147    type Output = Result<bool>;
148    type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
149    fn into_future(self) -> Self::IntoFuture {
150        Box::pin(async move {
151            self.client
152                .post_json("removeChatVerification", &self.params)
153                .await
154        })
155    }
156}