1use serde::{Deserialize, Serialize};
2
3use crate::file::{InputFile, InputFileVariant, InputMedia};
4use crate::markup::InlineKeyboardMarkup;
5use crate::message::{
6 ChatActionKind, DeleteMessage, EditMessageCaption, EditMessageMedia, EditMessageReplyMarkup,
7 EditMessageText, Location, Message, SendAnimation, SendAudio, SendChatAction, SendContact,
8 SendDice, SendDocument, SendLocation, SendMediaGroup, SendMessage, SendPhoto, SendPoll,
9 SendVenue, SendVideo, SendVideoNote, SendVoice, StopPoll,
10};
11use crate::user::User;
12use crate::{JsonMethod, TelegramMethod};
13
14#[derive(Debug, Deserialize)]
16pub struct Chat {
17 pub id: i64,
19 #[serde(flatten)]
21 pub kind: ChatKind,
22 pub title: Option<String>,
24 pub username: Option<String>,
26 pub first_name: Option<String>,
28 pub last_name: Option<String>,
30 pub photo: Option<ChatPhoto>,
33 pub bio: Option<String>,
36 pub description: Option<String>,
39 pub invite_link: Option<String>,
42 pub pinned_message: Option<Box<Message>>,
45 pub permissions: Option<ChatPermissions>,
48 pub slow_mode_delay: Option<i32>,
51 pub message_auto_delete_time: Option<i32>,
54 pub sticker_set_name: Option<String>,
57 pub can_get_sticker_set: Option<bool>,
60 pub linked_chat_id: Option<i32>,
65 pub location: Option<ChatLocation>,
68}
69
70impl Chat {
71 pub fn send_animation(&self, animation: impl Into<InputFileVariant>) -> SendAnimation {
72 SendAnimation::new(self.id, animation)
73 }
74
75 pub fn send_audio(&self, audio: impl Into<InputFileVariant>) -> SendAudio {
76 SendAudio::new(self.id, audio)
77 }
78
79 pub fn send_chat_action(&self, action: ChatActionKind) -> SendChatAction {
80 SendChatAction::new(self.id, action)
81 }
82
83 pub fn send_contact(
84 &self,
85 phone_number: impl Into<String>,
86 first_name: impl Into<String>,
87 ) -> SendContact {
88 SendContact::new(self.id, phone_number, first_name)
89 }
90
91 pub fn send_dice(&self) -> SendDice {
92 SendDice::new(self.id)
93 }
94
95 pub fn send_document(&self, document: impl Into<InputFileVariant>) -> SendDocument {
96 SendDocument::new(self.id, document)
97 }
98
99 pub fn send_location(
100 &self,
101 latitude: f32,
102 longitude: f32,
103 horizontal_accuracy: f32,
104 ) -> SendLocation {
105 SendLocation::new(self.id, latitude, longitude, horizontal_accuracy)
106 }
107
108 pub fn send_media_group(&self) -> SendMediaGroup {
109 SendMediaGroup::new(self.id)
110 }
111
112 pub fn send_message(&self, text: impl Into<String>) -> SendMessage {
113 SendMessage::new(self.id, text)
114 }
115
116 pub fn send_photo(&self, photo: impl Into<InputFileVariant>) -> SendPhoto {
117 SendPhoto::new(self.id, photo)
118 }
119
120 pub fn send_poll(&self, question: impl Into<String>, options: Vec<String>) -> SendPoll {
121 SendPoll::new_regular(self.id, question, options)
122 }
123
124 pub fn send_quiz(
125 &self,
126 question: impl Into<String>,
127 options: Vec<String>,
128 correct_option_id: u32,
129 ) -> SendPoll {
130 SendPoll::new_quiz(self.id, question, options, correct_option_id)
131 }
132
133 pub fn send_venue(
134 &self,
135 latitude: f32,
136 longitude: f32,
137 title: impl Into<String>,
138 address: impl Into<String>,
139 ) -> SendVenue {
140 SendVenue::new(self.id, latitude, longitude, title, address)
141 }
142
143 pub fn send_video(&self, video: impl Into<InputFileVariant>) -> SendVideo {
144 SendVideo::new(self.id, video)
145 }
146
147 pub fn send_video_note(&self, video_note: impl Into<InputFileVariant>) -> SendVideoNote {
148 SendVideoNote::new(self.id, video_note)
149 }
150
151 pub fn send_voice(&self, voice: impl Into<InputFileVariant>) -> SendVoice {
152 SendVoice::new(self.id, voice)
153 }
154
155 pub fn ban(&self, user_id: i64) -> BanChatMember {
156 BanChatMember::new(self.id, user_id)
157 }
158
159 pub fn unban(&self, user_id: i64) -> UnbanChatMember {
160 UnbanChatMember::new(self.id, user_id)
161 }
162
163 pub fn restrict(&self, user_id: i64, permissions: ChatPermissions) -> RestrictChatMember {
164 RestrictChatMember::new(self.id, user_id, permissions)
165 }
166
167 pub fn promote(&self, user_id: i64) -> PromoteChatMember {
168 PromoteChatMember::new(self.id, user_id)
169 }
170
171 pub fn set_administrator_title(
172 &self,
173 user_id: i64,
174 custom_title: impl Into<String>,
175 ) -> SetChatAdministratorCustomTitle {
176 SetChatAdministratorCustomTitle::new(self.id, user_id, custom_title)
177 }
178
179 pub fn set_permissions(&self, permissions: ChatPermissions) -> SetChatPermissions {
180 SetChatPermissions::new(self.id, permissions)
181 }
182
183 pub fn export_invite_link(&self) -> ExportChatInviteLink {
184 ExportChatInviteLink::new(self.id)
185 }
186
187 pub fn create_invite_link(&self) -> CreateChatInviteLink {
188 CreateChatInviteLink::new(self.id)
189 }
190
191 pub fn edit_invite_link(&self, invite_link: impl Into<String>) -> EditChatInviteLink {
192 EditChatInviteLink::new(self.id, invite_link)
193 }
194
195 pub fn revoke_invite_link(&self, invite_link: impl Into<String>) -> RevokeChatInviteLink {
196 RevokeChatInviteLink::new(self.id, invite_link)
197 }
198
199 pub fn approve_join(&self, user_id: i64) -> ApproveChatJoinRequest {
200 ApproveChatJoinRequest::new(self.id, user_id)
201 }
202
203 pub fn decline_join(&self, user_id: i64) -> DeclineChatJoinRequest {
204 DeclineChatJoinRequest::new(self.id, user_id)
205 }
206
207 pub fn set_photo(&self, photo: InputFile) -> SetChatPhoto {
208 SetChatPhoto::new(self.id, photo)
209 }
210
211 pub fn delete_photo(&self) -> DeleteChatPhoto {
212 DeleteChatPhoto::new(self.id)
213 }
214
215 pub fn set_title(&self, title: impl Into<String>) -> SetChatTitle {
216 SetChatTitle::new(self.id, title)
217 }
218
219 pub fn set_description(&self, description: impl Into<String>) -> SetChatDescription {
220 SetChatDescription::new(self.id, description)
221 }
222
223 pub fn remove_description(&self) -> SetChatDescription {
224 SetChatDescription::new_empty(self.id)
225 }
226
227 pub fn pin_message(&self, message_id: i64) -> PinChatMessage {
228 PinChatMessage::new(self.id, message_id)
229 }
230
231 pub fn unpin_message(&self, message_id: i64) -> UnpinChatMessage {
232 UnpinChatMessage::new(self.id, message_id)
233 }
234
235 pub fn unpin_latest_message(&self) -> UnpinChatMessage {
236 UnpinChatMessage::new_recent(self.id)
237 }
238
239 pub fn unpin_all_messages(&self) -> UnpinAllChatMessages {
240 UnpinAllChatMessages::new(self.id)
241 }
242
243 pub fn leave(&self) -> LeaveChat {
244 LeaveChat::new(self.id)
245 }
246
247 pub fn get_details(&self) -> GetChat {
248 GetChat::new(self.id)
249 }
250
251 pub fn get_administrators(&self) -> GetChatAdministrators {
252 GetChatAdministrators::new(self.id)
253 }
254
255 pub fn get_member_count(&self) -> GetChatMemberCount {
256 GetChatMemberCount::new(self.id)
257 }
258
259 pub fn get_member(&self, user_id: i64) -> GetChatMember {
260 GetChatMember::new(self.id, user_id)
261 }
262
263 pub fn set_sticker_set(&self, sticker_set_name: impl Into<String>) -> SetChatStickerSet {
264 SetChatStickerSet::new(self.id, sticker_set_name)
265 }
266
267 pub fn delete_sticker_set(&self) -> DeleteChatStickerSet {
268 DeleteChatStickerSet::new(self.id)
269 }
270
271 pub fn edit_text_of(&self, message_id: i64, text: impl Into<String>) -> EditMessageText {
272 EditMessageText::new(self.id, message_id, text)
273 }
274
275 pub fn remove_caption_of(&self, message_id: i64) -> EditMessageCaption {
276 EditMessageCaption::new_empty(self.id, message_id)
277 }
278
279 pub fn edit_caption_of(
280 &self,
281 message_id: i64,
282 caption: impl Into<String>,
283 ) -> EditMessageCaption {
284 EditMessageCaption::new(self.id, message_id, caption)
285 }
286
287 pub fn edit_media_of(&self, message_id: i64, media: impl Into<InputMedia>) -> EditMessageMedia {
288 EditMessageMedia::new(self.id, message_id, media)
289 }
290
291 pub fn remove_reply_markup_of(&self, message_id: i64) -> EditMessageReplyMarkup {
292 EditMessageReplyMarkup::new_empty(self.id, message_id)
293 }
294
295 pub fn edit_reply_markup_of(
296 &self,
297 message_id: i64,
298 reply_markup: impl Into<InlineKeyboardMarkup>,
299 ) -> EditMessageReplyMarkup {
300 EditMessageReplyMarkup::new(self.id, message_id, reply_markup)
301 }
302
303 pub fn stop_poll(&self, message_id: i64) -> StopPoll {
304 StopPoll::new(self.id, message_id)
305 }
306
307 pub fn delete_message(&self, message_id: i64) -> DeleteMessage {
308 DeleteMessage::new(self.id, message_id)
309 }
310}
311
312#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
313#[serde(rename_all = "snake_case", tag = "type")]
314pub enum ChatKind {
315 Private,
316 Group,
317 Supergroup,
318 Channel,
319}
320
321#[derive(Debug, Deserialize)]
323pub struct ChatPhoto {
324 pub small_file_id: String,
328 pub small_file_unique_id: String,
332 pub big_file_id: String,
336 pub big_file_unique_id: String,
340}
341
342#[derive(Debug, Deserialize)]
343pub struct ChatLocation {
344 pub location: Location,
347 pub address: String,
349}
350
351#[derive(Debug, Clone, Serialize, Deserialize, Default)]
353pub struct ChatPermissions {
354 #[serde(skip_serializing_if = "Option::is_none")]
356 pub can_send_messages: Option<bool>,
357 #[serde(skip_serializing_if = "Option::is_none")]
360 pub can_send_media_messages: Option<bool>,
361 #[serde(skip_serializing_if = "Option::is_none")]
363 pub can_send_polls: Option<bool>,
364 #[serde(skip_serializing_if = "Option::is_none")]
367 pub can_send_other_messages: Option<bool>,
368 #[serde(skip_serializing_if = "Option::is_none")]
371 pub can_add_web_page_previews: Option<bool>,
372 #[serde(skip_serializing_if = "Option::is_none")]
375 pub can_change_info: Option<bool>,
376 #[serde(skip_serializing_if = "Option::is_none")]
378 pub can_invite_users: Option<bool>,
379 #[serde(skip_serializing_if = "Option::is_none")]
382 pub can_pin_messages: Option<bool>,
383}
384
385impl ChatPermissions {
386 pub fn new() -> Self {
388 Default::default()
389 }
390 pub fn allow_send_messages(self) -> Self {
392 Self {
393 can_send_messages: Some(true),
394 ..self
395 }
396 }
397 pub fn allow_send_media_messages(self) -> Self {
399 Self {
400 can_send_media_messages: Some(true),
401 ..self
402 }
403 }
404 pub fn allow_send_polls(self) -> Self {
406 Self {
407 can_send_polls: Some(true),
408 ..self
409 }
410 }
411 pub fn allow_send_other_messages(self) -> Self {
413 Self {
414 can_send_other_messages: Some(true),
415 ..self
416 }
417 }
418 pub fn allow_add_web_page_previews(self) -> Self {
420 Self {
421 can_add_web_page_previews: Some(true),
422 ..self
423 }
424 }
425 pub fn allow_change_info(self) -> Self {
427 Self {
428 can_change_info: Some(true),
429 ..self
430 }
431 }
432 pub fn allow_invite_users(self) -> Self {
434 Self {
435 can_invite_users: Some(true),
436 ..self
437 }
438 }
439 pub fn allow_pin_messages(self) -> Self {
441 Self {
442 can_pin_messages: Some(true),
443 ..self
444 }
445 }
446}
447
448#[derive(Debug, Deserialize)]
449#[serde(rename_all = "snake_case", tag = "status")]
450pub enum ChatMember {
451 #[serde(rename = "creator")]
454 Owner {
455 user: User,
457 is_anonymous: bool,
459 custom_title: Option<String>,
461 },
462 Administrator {
465 user: User,
467 can_be_edited: bool,
469 is_anonymous: bool,
471 can_manage_chat: bool,
475 can_delete_messages: bool,
477 can_manage_voice_chats: bool,
479 can_restrict_members: bool,
481 can_promote_members: bool,
484 can_change_info: bool,
486 can_invite_users: bool,
488 can_post_messages: Option<bool>,
490 can_edit_messages: Option<bool>,
492 can_pin_messages: Option<bool>,
494 custom_title: Option<String>,
496 },
497 Member {
500 user: User,
502 },
503 Restricted {
506 user: User,
508 is_member: bool,
510 can_change_info: bool,
512 can_invite_users: bool,
514 can_pin_messages: bool,
516 can_send_messages: bool,
518 can_send_media_messages: bool,
520 can_send_polls: bool,
522 can_send_other_messages: bool,
524 can_add_web_page_previews: bool,
526 until_date: u64,
529 },
530 Left {
533 user: User,
535 },
536 #[serde(rename = "kicked")]
539 Banned {
540 user: User,
542 until_date: u64,
545 },
546}
547
548impl ChatMember {
549 pub fn user(&self) -> &User {
550 match self {
551 ChatMember::Owner { user, .. }
552 | ChatMember::Administrator { user, .. }
553 | ChatMember::Member { user }
554 | ChatMember::Restricted { user, .. }
555 | ChatMember::Left { user }
556 | ChatMember::Banned { user, .. } => user,
557 }
558 }
559
560 pub fn is_anonymous(&self) -> Option<bool> {
561 match self {
562 ChatMember::Owner { is_anonymous, .. }
563 | ChatMember::Administrator { is_anonymous, .. } => Some(*is_anonymous),
564 _ => None,
565 }
566 }
567
568 pub fn custom_title(&self) -> Option<&str> {
569 match self {
570 Self::Owner { custom_title, .. } | Self::Administrator { custom_title, .. } => {
571 custom_title.as_deref()
572 }
573 _ => None,
574 }
575 }
576
577 pub fn can_be_edited(&self) -> Option<bool> {
578 match self {
579 Self::Administrator { can_be_edited, .. } => Some(*can_be_edited),
580 _ => None,
581 }
582 }
583
584 pub fn can_manage_chat(&self) -> Option<bool> {
585 match self {
586 Self::Administrator {
587 can_manage_chat, ..
588 } => Some(*can_manage_chat),
589 _ => None,
590 }
591 }
592
593 pub fn can_delete_messages(&self) -> Option<bool> {
594 match self {
595 Self::Administrator {
596 can_delete_messages,
597 ..
598 } => Some(*can_delete_messages),
599 _ => None,
600 }
601 }
602
603 pub fn can_manage_voice_chats(&self) -> Option<bool> {
604 match self {
605 Self::Administrator {
606 can_manage_voice_chats,
607 ..
608 } => Some(*can_manage_voice_chats),
609 _ => None,
610 }
611 }
612
613 pub fn can_restrict_members(&self) -> Option<bool> {
614 match self {
615 Self::Administrator {
616 can_restrict_members,
617 ..
618 } => Some(*can_restrict_members),
619 _ => None,
620 }
621 }
622
623 pub fn can_promote_members(&self) -> Option<bool> {
624 match self {
625 Self::Administrator {
626 can_promote_members,
627 ..
628 } => Some(*can_promote_members),
629 _ => None,
630 }
631 }
632
633 pub fn can_change_info(&self) -> Option<bool> {
634 match self {
635 Self::Administrator {
636 can_change_info, ..
637 }
638 | Self::Restricted {
639 can_change_info, ..
640 } => Some(*can_change_info),
641 _ => None,
642 }
643 }
644
645 pub fn can_invite_users(&self) -> Option<bool> {
646 match self {
647 Self::Administrator {
648 can_invite_users, ..
649 }
650 | Self::Restricted {
651 can_invite_users, ..
652 } => Some(*can_invite_users),
653 _ => None,
654 }
655 }
656
657 pub fn can_edit_messages(&self) -> Option<bool> {
658 match self {
659 Self::Administrator {
660 can_edit_messages, ..
661 } => *can_edit_messages,
662 _ => None,
663 }
664 }
665
666 pub fn can_pin_messages(&self) -> Option<bool> {
667 match self {
668 Self::Administrator {
669 can_pin_messages, ..
670 } => *can_pin_messages,
671 Self::Restricted {
672 can_pin_messages, ..
673 } => Some(*can_pin_messages),
674 _ => None,
675 }
676 }
677
678 pub fn can_post_messages(&self) -> Option<bool> {
679 match self {
680 Self::Administrator {
681 can_post_messages, ..
682 } => *can_post_messages,
683 _ => None,
684 }
685 }
686
687 pub fn can_send_messages(&self) -> Option<bool> {
688 match self {
689 Self::Restricted {
690 can_send_messages, ..
691 } => Some(*can_send_messages),
692 _ => None,
693 }
694 }
695
696 pub fn can_send_media_messages(&self) -> Option<bool> {
697 match self {
698 Self::Restricted {
699 can_send_media_messages,
700 ..
701 } => Some(*can_send_media_messages),
702 _ => None,
703 }
704 }
705
706 pub fn can_send_polls(&self) -> Option<bool> {
707 match self {
708 Self::Restricted { can_send_polls, .. } => Some(*can_send_polls),
709 _ => None,
710 }
711 }
712
713 pub fn can_send_other_messages(&self) -> Option<bool> {
714 match self {
715 Self::Restricted {
716 can_send_other_messages,
717 ..
718 } => Some(*can_send_other_messages),
719 _ => None,
720 }
721 }
722
723 pub fn can_add_web_page_previews(&self) -> Option<bool> {
724 match self {
725 Self::Restricted {
726 can_add_web_page_previews,
727 ..
728 } => Some(*can_add_web_page_previews),
729 _ => None,
730 }
731 }
732
733 pub fn is_member(&self) -> bool {
734 match self {
735 Self::Owner { .. } | Self::Administrator { .. } | Self::Member { .. } => true,
736 Self::Restricted { is_member, .. } => *is_member,
737 ChatMember::Left { .. } | ChatMember::Banned { .. } => false,
738 }
739 }
740
741 pub fn banned_until(&self) -> Option<u64> {
742 match self {
743 Self::Banned { until_date, .. } => Some(*until_date),
744 _ => None,
745 }
746 }
747
748 pub fn restricted_until(&self) -> Option<u64> {
749 match self {
750 Self::Restricted { until_date, .. } => Some(*until_date),
751 _ => None,
752 }
753 }
754}
755
756#[derive(Debug, Deserialize)]
758pub struct ChatInviteLink {
759 pub invite_link: String,
763 pub creator: User,
765 pub is_primary: bool,
767 pub is_revoked: bool,
769 pub expire_date: Option<u64>,
771 pub member_limit: Option<u32>,
773}
774
775#[derive(Debug, Deserialize)]
777pub struct ChatMemberUpdated {
778 pub chat: Chat,
780 pub from: User,
782 pub date: u64,
784 pub old_chat_member: ChatMember,
786 pub new_chat_member: ChatMember,
788 pub invite_link: Option<ChatInviteLink>,
791}
792
793#[derive(Clone, Serialize)]
795#[serde(untagged)]
796pub enum ChatId {
797 Id(i64),
798 Username(String),
799}
800
801impl From<i64> for ChatId {
802 fn from(id: i64) -> Self {
803 Self::Id(id)
804 }
805}
806
807impl From<String> for ChatId {
808 fn from(username: String) -> Self {
809 Self::Username(username)
810 }
811}
812
813impl From<&str> for ChatId {
814 fn from(username: &str) -> Self {
815 Self::Username(username.to_string())
816 }
817}
818
819#[derive(Clone, Serialize)]
825pub struct BanChatMember {
826 pub chat_id: ChatId,
828 pub user_id: i64,
830 #[serde(skip_serializing_if = "Option::is_none")]
835 pub until_date: Option<u64>,
836 #[serde(skip_serializing_if = "Option::is_none")]
840 pub revoke_messages: Option<bool>,
841}
842
843impl BanChatMember {
844 pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
846 Self {
847 chat_id: chat_id.into(),
848 user_id,
849 until_date: None,
850 revoke_messages: None,
851 }
852 }
853
854 pub fn until_date(self, date: u64) -> Self {
856 Self {
857 until_date: Some(date),
858 ..self
859 }
860 }
861
862 pub fn revoke_messages(self) -> Self {
864 Self {
865 revoke_messages: Some(true),
866 ..self
867 }
868 }
869}
870
871impl TelegramMethod for BanChatMember {
872 type Response = bool;
873
874 fn name() -> &'static str {
875 "banChatMember"
876 }
877}
878
879impl JsonMethod for BanChatMember {}
880
881#[derive(Clone, Serialize)]
889pub struct UnbanChatMember {
890 pub chat_id: ChatId,
892 pub user_id: i64,
894 #[serde(skip_serializing_if = "Option::is_none")]
896 pub only_if_banned: Option<bool>,
897}
898
899impl UnbanChatMember {
900 pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
902 Self {
903 chat_id: chat_id.into(),
904 user_id,
905 only_if_banned: None,
906 }
907 }
908
909 pub fn only_if_banned(self) -> Self {
911 Self {
912 only_if_banned: Some(true),
913 ..self
914 }
915 }
916}
917
918impl TelegramMethod for UnbanChatMember {
919 type Response = bool;
920
921 fn name() -> &'static str {
922 "unbanChatMember"
923 }
924}
925
926impl JsonMethod for UnbanChatMember {}
927
928#[derive(Clone, Serialize)]
933pub struct RestrictChatMember {
934 pub chat_id: ChatId,
936 pub user_id: i64,
938 pub permissions: ChatPermissions,
940 #[serde(skip_serializing_if = "Option::is_none")]
944 pub until_date: Option<u64>,
945}
946
947impl RestrictChatMember {
948 pub fn new(chat_id: impl Into<ChatId>, user_id: i64, permissions: ChatPermissions) -> Self {
950 Self {
951 chat_id: chat_id.into(),
952 user_id,
953 permissions,
954 until_date: None,
955 }
956 }
957
958 pub fn until_date(self, date: u64) -> Self {
960 Self {
961 until_date: Some(date),
962 ..self
963 }
964 }
965}
966
967impl TelegramMethod for RestrictChatMember {
968 type Response = bool;
969
970 fn name() -> &'static str {
971 "restrictChatMember"
972 }
973}
974
975impl JsonMethod for RestrictChatMember {}
976
977#[derive(Clone, Serialize)]
982pub struct PromoteChatMember {
983 pub chat_id: ChatId,
985 pub user_id: i64,
987 #[serde(skip_serializing_if = "Option::is_none")]
989 pub is_anonymous: Option<bool>,
990 #[serde(skip_serializing_if = "Option::is_none")]
994 pub can_manage_chat: Option<bool>,
995 #[serde(skip_serializing_if = "Option::is_none")]
997 pub can_delete_messages: Option<bool>,
998 #[serde(skip_serializing_if = "Option::is_none")]
1000 pub can_manage_voice_chats: Option<bool>,
1001 #[serde(skip_serializing_if = "Option::is_none")]
1003 pub can_restrict_members: Option<bool>,
1004 #[serde(skip_serializing_if = "Option::is_none")]
1007 pub can_promote_members: Option<bool>,
1008 #[serde(skip_serializing_if = "Option::is_none")]
1010 pub can_change_info: Option<bool>,
1011 #[serde(skip_serializing_if = "Option::is_none")]
1013 pub can_invite_users: Option<bool>,
1014 #[serde(skip_serializing_if = "Option::is_none")]
1016 pub can_post_messages: Option<bool>,
1017 #[serde(skip_serializing_if = "Option::is_none")]
1019 pub can_edit_messages: Option<bool>,
1020 #[serde(skip_serializing_if = "Option::is_none")]
1022 pub can_pin_messages: Option<bool>,
1023}
1024
1025impl PromoteChatMember {
1026 pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1028 Self {
1029 chat_id: chat_id.into(),
1030 user_id,
1031 is_anonymous: None,
1032 can_manage_chat: None,
1033 can_delete_messages: None,
1034 can_manage_voice_chats: None,
1035 can_restrict_members: None,
1036 can_promote_members: None,
1037 can_change_info: None,
1038 can_invite_users: None,
1039 can_post_messages: None,
1040 can_edit_messages: None,
1041 can_pin_messages: None,
1042 }
1043 }
1044
1045 pub fn demote(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1049 Self {
1050 chat_id: chat_id.into(),
1051 user_id,
1052 is_anonymous: Some(false),
1053 can_manage_chat: Some(false),
1054 can_delete_messages: Some(false),
1055 can_manage_voice_chats: Some(false),
1056 can_restrict_members: Some(false),
1057 can_promote_members: Some(false),
1058 can_change_info: Some(false),
1059 can_invite_users: Some(false),
1060 can_post_messages: Some(false),
1061 can_edit_messages: Some(false),
1062 can_pin_messages: Some(false),
1063 }
1064 }
1065
1066 pub fn anonymous(self) -> Self {
1068 Self {
1069 is_anonymous: Some(true),
1070 ..self
1071 }
1072 }
1073
1074 pub fn allow_manage_chat(self) -> Self {
1076 Self {
1077 can_manage_chat: Some(true),
1078 ..self
1079 }
1080 }
1081
1082 pub fn allow_delete_messages(self) -> Self {
1084 Self {
1085 can_delete_messages: Some(true),
1086 ..self
1087 }
1088 }
1089
1090 pub fn allow_manage_voice_chats(self) -> Self {
1092 Self {
1093 can_manage_voice_chats: Some(true),
1094 ..self
1095 }
1096 }
1097
1098 pub fn allow_restrict_members(self) -> Self {
1100 Self {
1101 can_restrict_members: Some(true),
1102 ..self
1103 }
1104 }
1105
1106 pub fn allow_promote_members(self) -> Self {
1108 Self {
1109 can_promote_members: Some(true),
1110 ..self
1111 }
1112 }
1113
1114 pub fn allow_change_info(self) -> Self {
1116 Self {
1117 can_change_info: Some(true),
1118 ..self
1119 }
1120 }
1121
1122 pub fn allow_invite_users(self) -> Self {
1124 Self {
1125 can_invite_users: Some(true),
1126 ..self
1127 }
1128 }
1129
1130 pub fn allow_post_messages(self) -> Self {
1132 Self {
1133 can_post_messages: Some(true),
1134 ..self
1135 }
1136 }
1137
1138 pub fn allow_edit_messages(self) -> Self {
1140 Self {
1141 can_edit_messages: Some(true),
1142 ..self
1143 }
1144 }
1145
1146 pub fn allow_pin_messages(self) -> Self {
1148 Self {
1149 can_pin_messages: Some(true),
1150 ..self
1151 }
1152 }
1153}
1154
1155impl TelegramMethod for PromoteChatMember {
1156 type Response = bool;
1157
1158 fn name() -> &'static str {
1159 "promoteChatMember"
1160 }
1161}
1162
1163impl JsonMethod for PromoteChatMember {}
1164
1165#[derive(Clone, Serialize)]
1168pub struct SetChatAdministratorCustomTitle {
1169 pub chat_id: ChatId,
1171 pub user_id: i64,
1173 pub custom_title: String,
1175}
1176
1177impl SetChatAdministratorCustomTitle {
1178 pub fn new(chat_id: impl Into<ChatId>, user_id: i64, custom_title: impl Into<String>) -> Self {
1180 Self {
1181 chat_id: chat_id.into(),
1182 user_id,
1183 custom_title: custom_title.into(),
1184 }
1185 }
1186}
1187
1188impl TelegramMethod for SetChatAdministratorCustomTitle {
1189 type Response = bool;
1190
1191 fn name() -> &'static str {
1192 "setChatAdministratorCustomTitle"
1193 }
1194}
1195
1196impl JsonMethod for SetChatAdministratorCustomTitle {}
1197
1198#[derive(Clone, Serialize)]
1202pub struct SetChatPermissions {
1203 pub chat_id: ChatId,
1205 pub permissions: ChatPermissions,
1207}
1208
1209impl SetChatPermissions {
1210 pub fn new(chat_id: impl Into<ChatId>, permissions: ChatPermissions) -> Self {
1212 Self {
1213 chat_id: chat_id.into(),
1214 permissions,
1215 }
1216 }
1217}
1218
1219impl TelegramMethod for SetChatPermissions {
1220 type Response = bool;
1221
1222 fn name() -> &'static str {
1223 "setChatPermissions"
1224 }
1225}
1226
1227impl JsonMethod for SetChatPermissions {}
1228
1229#[derive(Clone, Serialize)]
1242pub struct ExportChatInviteLink {
1243 pub chat_id: ChatId,
1245}
1246
1247impl ExportChatInviteLink {
1248 pub fn new(chat_id: impl Into<ChatId>) -> Self {
1250 Self {
1251 chat_id: chat_id.into(),
1252 }
1253 }
1254}
1255
1256impl TelegramMethod for ExportChatInviteLink {
1257 type Response = String;
1258
1259 fn name() -> &'static str {
1260 "exportChatInviteLink"
1261 }
1262}
1263
1264impl JsonMethod for ExportChatInviteLink {}
1265
1266#[derive(Clone, Serialize)]
1271pub struct CreateChatInviteLink {
1272 pub chat_id: ChatId,
1274 #[serde(skip_serializing_if = "Option::is_none")]
1276 pub name: Option<String>,
1277 #[serde(skip_serializing_if = "Option::is_none")]
1279 pub expire_date: Option<u64>,
1280 #[serde(skip_serializing_if = "Option::is_none")]
1282 pub member_limit: Option<u32>,
1283 #[serde(skip_serializing_if = "Option::is_none")]
1285 pub creates_join_request: Option<bool>,
1286}
1287
1288impl CreateChatInviteLink {
1289 pub fn new(chat_id: impl Into<ChatId>) -> Self {
1291 Self {
1292 chat_id: chat_id.into(),
1293 name: None,
1294 expire_date: None,
1295 member_limit: None,
1296 creates_join_request: None,
1297 }
1298 }
1299 pub fn with_name(self, name: impl Into<String>) -> Self {
1301 Self {
1302 name: Some(name.into()),
1303 ..self
1304 }
1305 }
1306 pub fn with_expire_date(self, expire_date: u64) -> Self {
1308 Self {
1309 expire_date: Some(expire_date),
1310 ..self
1311 }
1312 }
1313 pub fn with_member_limit(self, member_limit: u32) -> Self {
1315 Self {
1316 member_limit: Some(member_limit),
1317 ..self
1318 }
1319 }
1320 pub fn create_join_reqeuest(self) -> Self {
1322 Self {
1323 creates_join_request: Some(true),
1324 ..self
1325 }
1326 }
1327}
1328
1329impl TelegramMethod for CreateChatInviteLink {
1330 type Response = ChatInviteLink;
1331
1332 fn name() -> &'static str {
1333 "createChatInviteLink"
1334 }
1335}
1336
1337impl JsonMethod for CreateChatInviteLink {}
1338
1339#[derive(Clone, Serialize)]
1343pub struct EditChatInviteLink {
1344 pub chat_id: ChatId,
1346 pub invite_link: String,
1348 #[serde(skip_serializing_if = "Option::is_none")]
1350 pub name: Option<String>,
1351 #[serde(skip_serializing_if = "Option::is_none")]
1353 pub expire_date: Option<u64>,
1354 #[serde(skip_serializing_if = "Option::is_none")]
1356 pub member_limit: Option<u32>,
1357 #[serde(skip_serializing_if = "Option::is_none")]
1359 pub creates_join_request: Option<bool>,
1360}
1361
1362impl EditChatInviteLink {
1363 pub fn new(chat_id: impl Into<ChatId>, invite_link: impl Into<String>) -> Self {
1365 Self {
1366 chat_id: chat_id.into(),
1367 invite_link: invite_link.into(),
1368 name: None,
1369 expire_date: None,
1370 member_limit: None,
1371 creates_join_request: None,
1372 }
1373 }
1374 pub fn with_name(self, name: impl Into<String>) -> Self {
1376 Self {
1377 name: Some(name.into()),
1378 ..self
1379 }
1380 }
1381 pub fn with_expire_date(self, expire_date: u64) -> Self {
1383 Self {
1384 expire_date: Some(expire_date),
1385 ..self
1386 }
1387 }
1388 pub fn with_member_limit(self, member_limit: u32) -> Self {
1390 Self {
1391 member_limit: Some(member_limit),
1392 ..self
1393 }
1394 }
1395 pub fn create_join_reqeuest(self) -> Self {
1397 Self {
1398 creates_join_request: Some(true),
1399 ..self
1400 }
1401 }
1402}
1403
1404#[derive(Clone, Serialize)]
1409pub struct RevokeChatInviteLink {
1410 pub chat_id: ChatId,
1412 pub invite_link: String,
1414}
1415
1416impl RevokeChatInviteLink {
1417 pub fn new(chat_id: impl Into<ChatId>, invite_link: impl Into<String>) -> Self {
1419 Self {
1420 chat_id: chat_id.into(),
1421 invite_link: invite_link.into(),
1422 }
1423 }
1424}
1425
1426impl TelegramMethod for RevokeChatInviteLink {
1427 type Response = ChatInviteLink;
1428
1429 fn name() -> &'static str {
1430 "revokeChatInviteLink"
1431 }
1432}
1433
1434impl JsonMethod for RevokeChatInviteLink {}
1435
1436#[derive(Clone, Serialize)]
1440pub struct ApproveChatJoinRequest {
1441 pub chat_id: ChatId,
1443 pub user_id: i64,
1445}
1446
1447impl ApproveChatJoinRequest {
1448 pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1450 Self {
1451 chat_id: chat_id.into(),
1452 user_id,
1453 }
1454 }
1455}
1456
1457impl TelegramMethod for ApproveChatJoinRequest {
1458 type Response = bool;
1459
1460 fn name() -> &'static str {
1461 "approveChatJoinRequest"
1462 }
1463}
1464
1465impl JsonMethod for ApproveChatJoinRequest {}
1466
1467#[derive(Clone, Serialize)]
1471pub struct DeclineChatJoinRequest {
1472 pub chat_id: ChatId,
1474 pub user_id: i64,
1476}
1477
1478impl DeclineChatJoinRequest {
1479 pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1481 Self {
1482 chat_id: chat_id.into(),
1483 user_id,
1484 }
1485 }
1486}
1487
1488impl TelegramMethod for DeclineChatJoinRequest {
1489 type Response = bool;
1490
1491 fn name() -> &'static str {
1492 "declineChatJoinRequest"
1493 }
1494}
1495
1496impl JsonMethod for DeclineChatJoinRequest {}
1497
1498#[derive(Clone, Serialize)]
1503pub struct SetChatPhoto {
1504 pub chat_id: ChatId,
1506 pub photo: InputFile,
1508}
1509
1510impl SetChatPhoto {
1511 pub fn new(chat_id: impl Into<ChatId>, photo: InputFile) -> Self {
1513 Self {
1514 chat_id: chat_id.into(),
1515 photo,
1516 }
1517 }
1518}
1519
1520impl TelegramMethod for SetChatPhoto {
1521 type Response = bool;
1522
1523 fn name() -> &'static str {
1524 "setChatPhoto"
1525 }
1526}
1527
1528impl JsonMethod for SetChatPhoto {}
1529
1530#[derive(Clone, Serialize)]
1535pub struct DeleteChatPhoto {
1536 pub chat_id: ChatId,
1538}
1539
1540impl DeleteChatPhoto {
1541 pub fn new(chat_id: impl Into<ChatId>) -> Self {
1543 Self {
1544 chat_id: chat_id.into(),
1545 }
1546 }
1547}
1548
1549impl TelegramMethod for DeleteChatPhoto {
1550 type Response = bool;
1551
1552 fn name() -> &'static str {
1553 "deleteChatPhoto"
1554 }
1555}
1556
1557impl JsonMethod for DeleteChatPhoto {}
1558
1559#[derive(Clone, Serialize)]
1564pub struct SetChatTitle {
1565 pub chat_id: ChatId,
1567 pub title: String,
1569}
1570
1571impl SetChatTitle {
1572 pub fn new(chat_id: impl Into<ChatId>, title: impl Into<String>) -> Self {
1574 Self {
1575 chat_id: chat_id.into(),
1576 title: title.into(),
1577 }
1578 }
1579}
1580
1581impl TelegramMethod for SetChatTitle {
1582 type Response = bool;
1583
1584 fn name() -> &'static str {
1585 "setChatTitle"
1586 }
1587}
1588
1589impl JsonMethod for SetChatTitle {}
1590
1591#[derive(Clone, Serialize)]
1595pub struct SetChatDescription {
1596 pub chat_id: ChatId,
1598 #[serde(skip_serializing_if = "Option::is_none")]
1600 pub description: Option<String>,
1601}
1602
1603impl SetChatDescription {
1604 pub fn new_empty(chat_id: impl Into<ChatId>) -> Self {
1606 Self {
1607 chat_id: chat_id.into(),
1608 description: None,
1609 }
1610 }
1611
1612 pub fn new(chat_id: impl Into<ChatId>, description: impl Into<String>) -> Self {
1614 Self {
1615 chat_id: chat_id.into(),
1616 description: Some(description.into()),
1617 }
1618 }
1619}
1620
1621impl TelegramMethod for SetChatDescription {
1622 type Response = bool;
1623
1624 fn name() -> &'static str {
1625 "setChatDescription"
1626 }
1627}
1628
1629#[derive(Clone, Serialize)]
1634pub struct PinChatMessage {
1635 pub chat_id: ChatId,
1637 pub message_id: i64,
1639 #[serde(skip_serializing_if = "Option::is_none")]
1642 pub disable_notification: Option<bool>,
1643}
1644
1645impl PinChatMessage {
1646 pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
1648 Self {
1649 chat_id: chat_id.into(),
1650 message_id,
1651 disable_notification: None,
1652 }
1653 }
1654
1655 pub fn disable_notification(self) -> Self {
1657 Self {
1658 disable_notification: Some(true),
1659 ..self
1660 }
1661 }
1662}
1663
1664impl TelegramMethod for PinChatMessage {
1665 type Response = bool;
1666
1667 fn name() -> &'static str {
1668 "pinChatMessage"
1669 }
1670}
1671
1672impl JsonMethod for PinChatMessage {}
1673
1674#[derive(Clone, Serialize)]
1679pub struct UnpinChatMessage {
1680 pub chat_id: ChatId,
1682 #[serde(skip_serializing_if = "Option::is_none")]
1684 pub message_id: Option<i64>,
1685}
1686
1687impl UnpinChatMessage {
1688 pub fn new_recent(chat_id: impl Into<ChatId>) -> Self {
1690 Self {
1691 chat_id: chat_id.into(),
1692 message_id: None,
1693 }
1694 }
1695
1696 pub fn new(chat_id: impl Into<ChatId>, message_id: i64) -> Self {
1698 Self {
1699 chat_id: chat_id.into(),
1700 message_id: Some(message_id),
1701 }
1702 }
1703}
1704
1705impl TelegramMethod for UnpinChatMessage {
1706 type Response = bool;
1707
1708 fn name() -> &'static str {
1709 "unpinChatMessage"
1710 }
1711}
1712
1713impl JsonMethod for UnpinChatMessage {}
1714
1715#[derive(Clone, Serialize)]
1720pub struct UnpinAllChatMessages {
1721 pub chat_id: ChatId,
1723}
1724
1725impl UnpinAllChatMessages {
1726 pub fn new(chat_id: impl Into<ChatId>) -> Self {
1728 Self {
1729 chat_id: chat_id.into(),
1730 }
1731 }
1732}
1733
1734impl TelegramMethod for UnpinAllChatMessages {
1735 type Response = bool;
1736
1737 fn name() -> &'static str {
1738 "unpinAllChatMessages"
1739 }
1740}
1741
1742impl JsonMethod for UnpinAllChatMessages {}
1743
1744#[derive(Clone, Serialize)]
1746pub struct LeaveChat {
1747 pub chat_id: ChatId,
1749}
1750
1751impl LeaveChat {
1752 pub fn new(chat_id: impl Into<ChatId>) -> Self {
1754 Self {
1755 chat_id: chat_id.into(),
1756 }
1757 }
1758}
1759
1760impl TelegramMethod for LeaveChat {
1761 type Response = bool;
1762
1763 fn name() -> &'static str {
1764 "leaveChat"
1765 }
1766}
1767
1768impl JsonMethod for LeaveChat {}
1769
1770#[derive(Clone, Serialize)]
1774pub struct GetChat {
1775 pub chat_id: ChatId,
1777}
1778
1779impl GetChat {
1780 pub fn new(chat_id: impl Into<ChatId>) -> Self {
1782 Self {
1783 chat_id: chat_id.into(),
1784 }
1785 }
1786}
1787
1788impl TelegramMethod for GetChat {
1789 type Response = Chat;
1790
1791 fn name() -> &'static str {
1792 "getChat"
1793 }
1794}
1795
1796impl JsonMethod for GetChat {}
1797
1798#[derive(Clone, Serialize)]
1803pub struct GetChatAdministrators {
1804 pub chat_id: ChatId,
1806}
1807
1808impl GetChatAdministrators {
1809 pub fn new(chat_id: impl Into<ChatId>) -> Self {
1811 Self {
1812 chat_id: chat_id.into(),
1813 }
1814 }
1815}
1816
1817impl TelegramMethod for GetChatAdministrators {
1818 type Response = Vec<ChatMember>;
1819
1820 fn name() -> &'static str {
1821 "getChatAdministrators"
1822 }
1823}
1824
1825impl JsonMethod for GetChatAdministrators {}
1826
1827#[derive(Clone, Serialize)]
1829pub struct GetChatMemberCount {
1830 pub chat_id: ChatId,
1832}
1833
1834impl GetChatMemberCount {
1835 pub fn new(chat_id: impl Into<ChatId>) -> Self {
1837 Self {
1838 chat_id: chat_id.into(),
1839 }
1840 }
1841}
1842
1843impl TelegramMethod for GetChatMemberCount {
1844 type Response = u32;
1845
1846 fn name() -> &'static str {
1847 "getChatMemberCount"
1848 }
1849}
1850
1851impl JsonMethod for GetChatMemberCount {}
1852
1853#[derive(Clone, Serialize)]
1856pub struct GetChatMember {
1857 pub chat_id: ChatId,
1859 pub user_id: i64,
1861}
1862
1863impl GetChatMember {
1864 pub fn new(chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1866 Self {
1867 chat_id: chat_id.into(),
1868 user_id,
1869 }
1870 }
1871}
1872
1873impl TelegramMethod for GetChatMember {
1874 type Response = ChatMember;
1875
1876 fn name() -> &'static str {
1877 "getChatMember"
1878 }
1879}
1880
1881#[derive(Clone, Serialize)]
1886pub struct SetChatStickerSet {
1887 pub chat_id: ChatId,
1889 pub sticker_set_name: String,
1891}
1892
1893impl SetChatStickerSet {
1894 pub fn new(chat_id: impl Into<ChatId>, sticker_set_name: impl Into<String>) -> Self {
1896 Self {
1897 chat_id: chat_id.into(),
1898 sticker_set_name: sticker_set_name.into(),
1899 }
1900 }
1901}
1902
1903impl TelegramMethod for SetChatStickerSet {
1904 type Response = bool;
1905
1906 fn name() -> &'static str {
1907 "setChatStickerSet"
1908 }
1909}
1910
1911impl JsonMethod for SetChatStickerSet {}
1912
1913#[derive(Clone, Serialize)]
1918pub struct DeleteChatStickerSet {
1919 pub chat_id: ChatId,
1921}
1922
1923impl DeleteChatStickerSet {
1924 pub fn new(chat_id: impl Into<ChatId>) -> Self {
1926 Self {
1927 chat_id: chat_id.into(),
1928 }
1929 }
1930}
1931
1932impl TelegramMethod for DeleteChatStickerSet {
1933 type Response = bool;
1934
1935 fn name() -> &'static str {
1936 "deleteChatStickerSet"
1937 }
1938}
1939
1940impl JsonMethod for DeleteChatStickerSet {}