Skip to main content

tbot/methods/
get_chat_members_count.rs

1use super::call_method;
2use crate::{
3    connectors::Client,
4    errors, token,
5    types::parameters::{ChatId, ImplicitChatId},
6};
7use serde::Serialize;
8
9/// Gets a chat's member count.
10///
11/// Reflects the [`getChatMembersCount`][docs] method.
12///
13/// [docs]: https://core.telegram.org/bots/api#getchatmemberscount
14#[derive(Serialize, Debug, Clone)]
15#[must_use = "methods do nothing unless turned into a future"]
16pub struct GetChatMembersCount<'a> {
17    #[serde(skip)]
18    client: &'a Client,
19    #[serde(skip)]
20    token: token::Ref<'a>,
21    chat_id: ChatId<'a>,
22}
23
24impl<'a> GetChatMembersCount<'a> {
25    pub(crate) fn new(
26        client: &'a Client,
27        token: token::Ref<'a>,
28        chat_id: impl ImplicitChatId<'a>,
29    ) -> Self {
30        Self {
31            client,
32            token,
33            chat_id: chat_id.into(),
34        }
35    }
36}
37
38impl GetChatMembersCount<'_> {
39    /// Calls the method.
40    pub async fn call(self) -> Result<u32, errors::MethodCall> {
41        call_method(
42            self.client,
43            self.token,
44            "getChatMembersCount",
45            None,
46            serde_json::to_vec(&self).unwrap(),
47        )
48        .await
49    }
50}