tgbot/types/definitions/chat/join_request.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{
4 api::{Method, Payload},
5 types::{Chat, ChatId, ChatInviteLink, Integer, User},
6};
7
8/// Represents a join request sent to a chat.
9#[serde_with::skip_serializing_none]
10#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
11pub struct ChatJoinRequest {
12 /// Chat to which the request was sent.
13 pub chat: Chat,
14 /// Date the request was sent in Unix time.
15 pub date: Integer,
16 /// User that sent the join request.
17 pub from: User,
18 /// Bio of the user.
19 pub bio: Option<String>,
20 /// Chat invite link that was used by the user to send the join request.
21 pub invite_link: Option<ChatInviteLink>,
22 /// Identifier of a private chat with the user who sent the join request.
23 ///
24 /// A bot can use this identifier for 5 minutes to
25 /// send messages until the join request is processed,
26 /// assuming no other administrator contacted the user.
27 pub user_chat_id: Option<Integer>,
28}
29
30impl ChatJoinRequest {
31 /// Creates a new `ChatJoinRequest`.
32 ///
33 /// # Arguments
34 ///
35 /// * `chat` - Chat to which the request was sent.
36 /// * `date` - Date the request was sent in Unix time.
37 /// * `from` - User that sent the join request.
38 pub fn new(chat: Chat, date: Integer, from: User) -> Self {
39 Self {
40 chat,
41 date,
42 from,
43 bio: None,
44 invite_link: None,
45 user_chat_id: None,
46 }
47 }
48
49 /// Sets a new bio.
50 ///
51 /// # Arguments
52 ///
53 /// * `value` - The bio of the user.
54 pub fn with_bio<T>(mut self, value: T) -> Self
55 where
56 T: Into<String>,
57 {
58 self.bio = Some(value.into());
59 self
60 }
61
62 /// Sets a new invite link.
63 ///
64 /// # Arguments
65 ///
66 /// * `value` - The chat invite link that was used by the user to send the join request.
67 pub fn with_invite_link(mut self, value: ChatInviteLink) -> Self {
68 self.invite_link = Some(value);
69 self
70 }
71
72 /// Sets a new user chat ID.
73 ///
74 /// # Arguments
75 ///
76 /// * `value` - The identifier of a private chat with the user who sent the join request.
77 pub fn with_user_chat_id(mut self, value: Integer) -> Self {
78 self.user_chat_id = Some(value);
79 self
80 }
81}
82
83/// Approves a chat join request.
84///
85/// The bot must be an administrator in the chat for this to work
86/// and must have the `can_invite_users` administrator right.
87#[derive(Clone, Debug, Serialize)]
88pub struct ApproveChatJoinRequest {
89 chat_id: ChatId,
90 user_id: Integer,
91}
92
93impl ApproveChatJoinRequest {
94 /// Creates a new `ApproveChatJoinRequest`.
95 ///
96 /// # Arguments
97 ///
98 /// * `chat_id` - Unique identifier of the target chat.
99 /// * `user_id` - Unique identifier of the target user.
100 pub fn new<T>(chat_id: T, user_id: Integer) -> Self
101 where
102 T: Into<ChatId>,
103 {
104 Self {
105 chat_id: chat_id.into(),
106 user_id,
107 }
108 }
109}
110
111impl Method for ApproveChatJoinRequest {
112 type Response = bool;
113
114 fn into_payload(self) -> Payload {
115 Payload::json("approveChatJoinRequest", self)
116 }
117}
118
119/// Declines a chat join request.
120///
121/// The bot must be an administrator in the chat for this to work
122/// and must have the `can_invite_users` administrator right.
123#[derive(Clone, Debug, Serialize)]
124pub struct DeclineChatJoinRequest {
125 chat_id: ChatId,
126 user_id: Integer,
127}
128
129impl DeclineChatJoinRequest {
130 /// Creates a new `DeclineChatJoinRequest`.
131 ///
132 /// # Arguments
133 ///
134 /// * `chat_id` - Unique identifier of the target chat.
135 /// * `user_id` - Unique identifier of the target user.
136 pub fn new<T>(chat_id: T, user_id: Integer) -> Self
137 where
138 T: Into<ChatId>,
139 {
140 Self {
141 chat_id: chat_id.into(),
142 user_id,
143 }
144 }
145}
146
147impl Method for DeclineChatJoinRequest {
148 type Response = bool;
149
150 fn into_payload(self) -> Payload {
151 Payload::json("declineChatJoinRequest", self)
152 }
153}