telers/methods/
create_chat_invite_link.rs

1use super::base::{Request, TelegramMethod};
2
3use crate::{
4    client::Bot,
5    types::{ChatIdKind, ChatInviteLink},
6};
7
8use serde::Serialize;
9use serde_with::skip_serializing_none;
10
11/// Use this method to create an additional invite link for a chat. The bot must be an administrator in the chat for this to work and must have the appropriate administrator rights. The link can be revoked using the method [`RevokeChatInviteLink`](crate::methods::RevokeChatInviteLink).
12/// # Documentation
13/// <https://core.telegram.org/bots/api#createchatinvitelink>
14/// # Returns
15/// Returns the new invite link as [`ChatInviteLink`] object
16#[skip_serializing_none]
17#[derive(Debug, Clone, Hash, PartialEq, Eq, Serialize)]
18pub struct CreateChatInviteLink {
19    /// Unique identifier for the target chat or username of the target channel (in the format `@channelusername`)
20    pub chat_id: ChatIdKind,
21    /// Invite link name; 0-32 characters
22    pub invite_link: Option<String>,
23    /// Point in time (Unix timestamp) when the link will expire
24    pub expire_date: Option<i64>,
25    /// The maximum number of users that can be members of the chat simultaneously after joining the chat via this invite link; 1-99999
26    pub member_limit: Option<i64>,
27    /// `true`, if users joining the chat via the link need to be approved by chat administrators. If `true`, `member_limit` can't be specified
28    pub creates_join_request: Option<bool>,
29}
30
31impl CreateChatInviteLink {
32    #[must_use]
33    pub fn new(chat_id: impl Into<ChatIdKind>) -> Self {
34        Self {
35            chat_id: chat_id.into(),
36            invite_link: None,
37            expire_date: None,
38            member_limit: None,
39            creates_join_request: None,
40        }
41    }
42
43    #[must_use]
44    pub fn chat_id(self, val: impl Into<ChatIdKind>) -> Self {
45        Self {
46            chat_id: val.into(),
47            ..self
48        }
49    }
50
51    #[must_use]
52    pub fn invite_link(self, val: impl Into<String>) -> Self {
53        Self {
54            invite_link: Some(val.into()),
55            ..self
56        }
57    }
58
59    #[must_use]
60    pub fn expire_date(self, val: i64) -> Self {
61        Self {
62            expire_date: Some(val),
63            ..self
64        }
65    }
66
67    #[must_use]
68    pub fn member_limit(self, val: i64) -> Self {
69        Self {
70            member_limit: Some(val),
71            ..self
72        }
73    }
74
75    #[must_use]
76    pub fn creates_join_request(self, val: bool) -> Self {
77        Self {
78            creates_join_request: Some(val),
79            ..self
80        }
81    }
82}
83
84impl CreateChatInviteLink {
85    #[must_use]
86    pub fn invite_link_option(self, val: Option<impl Into<String>>) -> Self {
87        Self {
88            invite_link: val.map(Into::into),
89            ..self
90        }
91    }
92
93    #[must_use]
94    pub fn expire_date_option(self, val: Option<i64>) -> Self {
95        Self {
96            expire_date: val,
97            ..self
98        }
99    }
100
101    #[must_use]
102    pub fn member_limit_option(self, val: Option<i64>) -> Self {
103        Self {
104            member_limit: val,
105            ..self
106        }
107    }
108
109    #[must_use]
110    pub fn creates_join_request_option(self, val: Option<bool>) -> Self {
111        Self {
112            creates_join_request: val,
113            ..self
114        }
115    }
116}
117
118impl TelegramMethod for CreateChatInviteLink {
119    type Method = Self;
120    type Return = ChatInviteLink;
121
122    fn build_request<Client>(&self, _bot: &Bot<Client>) -> Request<Self::Method> {
123        Request::new("createChatInviteLink", self, None)
124    }
125}
126
127impl AsRef<CreateChatInviteLink> for CreateChatInviteLink {
128    fn as_ref(&self) -> &Self {
129        self
130    }
131}