1use crate::client::BotClient;
2use crate::error::Result;
3use reqwest::multipart::{Form, Part};
4use rustigram_types::chat::{ChatInviteLink, ChatPermissions};
5use rustigram_types::file::InputFile;
6use rustigram_types::update::UserChatBoosts;
7use rustigram_types::user::ChatId;
8use serde::Serialize;
9use std::future::{Future, IntoFuture};
10use std::pin::Pin;
11
12macro_rules! impl_into_future {
16 ($builder:ident, $return_ty:ty, $method:literal) => {
17 impl IntoFuture for $builder {
18 type Output = Result<$return_ty>;
19 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
20
21 fn into_future(self) -> Self::IntoFuture {
22 Box::pin(async move { self.client.post_json($method, &self.params).await })
23 }
24 }
25 };
26}
27
28#[derive(Serialize)]
31struct BanChatMemberParams {
32 chat_id: ChatId,
33 user_id: i64,
34 #[serde(skip_serializing_if = "Option::is_none")]
35 until_date: Option<i64>,
36 #[serde(skip_serializing_if = "Option::is_none")]
37 revoke_messages: Option<bool>,
38}
39
40pub struct BanChatMember {
42 client: BotClient,
43 params: BanChatMemberParams,
44}
45
46impl BanChatMember {
47 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
48 Self {
49 client,
50 params: BanChatMemberParams {
51 chat_id: chat_id.into(),
52 user_id,
53 until_date: None,
54 revoke_messages: None,
55 },
56 }
57 }
58 pub fn until_date(mut self, ts: i64) -> Self {
60 self.params.until_date = Some(ts);
61 self
62 }
63 pub fn revoke_messages(mut self, v: bool) -> Self {
65 self.params.revoke_messages = Some(v);
66 self
67 }
68}
69
70impl_into_future!(BanChatMember, bool, "banChatMember");
71
72#[derive(Serialize)]
75struct UnbanChatMemberParams {
76 chat_id: ChatId,
77 user_id: i64,
78 #[serde(skip_serializing_if = "Option::is_none")]
79 only_if_banned: Option<bool>,
80}
81
82pub struct UnbanChatMember {
84 client: BotClient,
85 params: UnbanChatMemberParams,
86}
87
88impl UnbanChatMember {
89 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
90 Self {
91 client,
92 params: UnbanChatMemberParams {
93 chat_id: chat_id.into(),
94 user_id,
95 only_if_banned: None,
96 },
97 }
98 }
99 pub fn only_if_banned(mut self, v: bool) -> Self {
101 self.params.only_if_banned = Some(v);
102 self
103 }
104}
105
106impl_into_future!(UnbanChatMember, bool, "unbanChatMember");
107
108#[derive(Serialize)]
111struct RestrictChatMemberParams {
112 chat_id: ChatId,
113 user_id: i64,
114 permissions: ChatPermissions,
115 #[serde(skip_serializing_if = "Option::is_none")]
116 use_independent_chat_permissions: Option<bool>,
117 #[serde(skip_serializing_if = "Option::is_none")]
118 until_date: Option<i64>,
119}
120
121pub struct RestrictChatMember {
123 client: BotClient,
124 params: RestrictChatMemberParams,
125}
126
127impl RestrictChatMember {
128 pub(crate) fn new(
129 client: BotClient,
130 chat_id: impl Into<ChatId>,
131 user_id: i64,
132 permissions: ChatPermissions,
133 ) -> Self {
134 Self {
135 client,
136 params: RestrictChatMemberParams {
137 chat_id: chat_id.into(),
138 user_id,
139 permissions,
140 use_independent_chat_permissions: None,
141 until_date: None,
142 },
143 }
144 }
145 pub fn until_date(mut self, ts: i64) -> Self {
147 self.params.until_date = Some(ts);
148 self
149 }
150 pub fn use_independent_chat_permissions(mut self, v: bool) -> Self {
152 self.params.use_independent_chat_permissions = Some(v);
153 self
154 }
155}
156
157impl_into_future!(RestrictChatMember, bool, "restrictChatMember");
158
159#[derive(Serialize)]
162pub struct PromoteChatMemberParams {
164 chat_id: ChatId,
165 user_id: i64,
166 #[serde(skip_serializing_if = "Option::is_none")]
168 pub is_anonymous: Option<bool>,
169 #[serde(skip_serializing_if = "Option::is_none")]
171 pub can_manage_chat: Option<bool>,
172 #[serde(skip_serializing_if = "Option::is_none")]
174 pub can_delete_messages: Option<bool>,
175 #[serde(skip_serializing_if = "Option::is_none")]
177 pub can_manage_video_chats: Option<bool>,
178 #[serde(skip_serializing_if = "Option::is_none")]
180 pub can_restrict_members: Option<bool>,
181 #[serde(skip_serializing_if = "Option::is_none")]
183 pub can_promote_members: Option<bool>,
184 #[serde(skip_serializing_if = "Option::is_none")]
186 pub can_change_info: Option<bool>,
187 #[serde(skip_serializing_if = "Option::is_none")]
189 pub can_invite_users: Option<bool>,
190 #[serde(skip_serializing_if = "Option::is_none")]
192 pub can_post_messages: Option<bool>,
193 #[serde(skip_serializing_if = "Option::is_none")]
195 pub can_edit_messages: Option<bool>,
196 #[serde(skip_serializing_if = "Option::is_none")]
198 pub can_pin_messages: Option<bool>,
199 #[serde(skip_serializing_if = "Option::is_none")]
201 pub can_manage_topics: Option<bool>,
202 #[serde(skip_serializing_if = "Option::is_none")]
204 pub can_post_stories: Option<bool>,
205 #[serde(skip_serializing_if = "Option::is_none")]
207 pub can_edit_stories: Option<bool>,
208 #[serde(skip_serializing_if = "Option::is_none")]
210 pub can_delete_stories: Option<bool>,
211 #[serde(skip_serializing_if = "Option::is_none")]
213 pub can_manage_direct_messages: Option<bool>,
214 #[serde(skip_serializing_if = "Option::is_none")]
216 pub can_manage_tags: Option<bool>,
217}
218
219pub struct PromoteChatMember {
221 client: BotClient,
222 params: PromoteChatMemberParams,
223}
224
225impl PromoteChatMember {
226 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
227 Self {
228 client,
229 params: PromoteChatMemberParams {
230 chat_id: chat_id.into(),
231 user_id,
232 is_anonymous: None,
233 can_manage_chat: None,
234 can_delete_messages: None,
235 can_manage_video_chats: None,
236 can_restrict_members: None,
237 can_promote_members: None,
238 can_change_info: None,
239 can_invite_users: None,
240 can_post_messages: None,
241 can_edit_messages: None,
242 can_pin_messages: None,
243 can_manage_topics: None,
244 can_post_stories: None,
245 can_edit_stories: None,
246 can_delete_stories: None,
247 can_manage_direct_messages: None,
248 can_manage_tags: None,
249 },
250 }
251 }
252 pub fn can_manage_chat(mut self, v: bool) -> Self {
254 self.params.can_manage_chat = Some(v);
255 self
256 }
257 pub fn can_delete_messages(mut self, v: bool) -> Self {
259 self.params.can_delete_messages = Some(v);
260 self
261 }
262 pub fn can_manage_video_chats(mut self, v: bool) -> Self {
264 self.params.can_manage_video_chats = Some(v);
265 self
266 }
267 pub fn can_restrict_members(mut self, v: bool) -> Self {
269 self.params.can_restrict_members = Some(v);
270 self
271 }
272 pub fn can_promote_members(mut self, v: bool) -> Self {
274 self.params.can_promote_members = Some(v);
275 self
276 }
277 pub fn can_change_info(mut self, v: bool) -> Self {
279 self.params.can_change_info = Some(v);
280 self
281 }
282 pub fn can_invite_users(mut self, v: bool) -> Self {
284 self.params.can_invite_users = Some(v);
285 self
286 }
287 pub fn can_pin_messages(mut self, v: bool) -> Self {
289 self.params.can_pin_messages = Some(v);
290 self
291 }
292 pub fn can_manage_topics(mut self, v: bool) -> Self {
294 self.params.can_manage_topics = Some(v);
295 self
296 }
297 pub fn can_post_stories(mut self, v: bool) -> Self {
299 self.params.can_post_stories = Some(v);
300 self
301 }
302 pub fn can_manage_direct_messages(mut self, v: bool) -> Self {
304 self.params.can_manage_direct_messages = Some(v);
305 self
306 }
307 pub fn can_manage_tags(mut self, v: bool) -> Self {
309 self.params.can_manage_tags = Some(v);
310 self
311 }
312 pub fn is_anonymous(mut self, v: bool) -> Self {
314 self.params.is_anonymous = Some(v);
315 self
316 }
317 pub fn can_post_messages(mut self, v: bool) -> Self {
319 self.params.can_post_messages = Some(v);
320 self
321 }
322 pub fn can_edit_messages(mut self, v: bool) -> Self {
324 self.params.can_edit_messages = Some(v);
325 self
326 }
327 pub fn can_edit_stories(mut self, v: bool) -> Self {
329 self.params.can_edit_stories = Some(v);
330 self
331 }
332 pub fn can_delete_stories(mut self, v: bool) -> Self {
334 self.params.can_delete_stories = Some(v);
335 self
336 }
337}
338
339impl_into_future!(PromoteChatMember, bool, "promoteChatMember");
340
341#[derive(Serialize)]
344struct CreateChatInviteLinkParams {
345 chat_id: ChatId,
346 #[serde(skip_serializing_if = "Option::is_none")]
347 name: Option<String>,
348 #[serde(skip_serializing_if = "Option::is_none")]
349 expire_date: Option<i64>,
350 #[serde(skip_serializing_if = "Option::is_none")]
351 member_limit: Option<u32>,
352 #[serde(skip_serializing_if = "Option::is_none")]
353 creates_join_request: Option<bool>,
354}
355
356pub struct CreateChatInviteLink {
358 client: BotClient,
359 params: CreateChatInviteLinkParams,
360}
361
362impl CreateChatInviteLink {
363 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
364 Self {
365 client,
366 params: CreateChatInviteLinkParams {
367 chat_id: chat_id.into(),
368 name: None,
369 expire_date: None,
370 member_limit: None,
371 creates_join_request: None,
372 },
373 }
374 }
375 pub fn name(mut self, n: impl Into<String>) -> Self {
377 self.params.name = Some(n.into());
378 self
379 }
380 pub fn expire_date(mut self, ts: i64) -> Self {
382 self.params.expire_date = Some(ts);
383 self
384 }
385 pub fn member_limit(mut self, n: u32) -> Self {
387 self.params.member_limit = Some(n);
388 self
389 }
390 pub fn creates_join_request(mut self, v: bool) -> Self {
392 self.params.creates_join_request = Some(v);
393 self
394 }
395}
396
397impl_into_future!(CreateChatInviteLink, ChatInviteLink, "createChatInviteLink");
398
399#[derive(Serialize)]
402struct PinChatMessageParams {
403 chat_id: ChatId,
404 message_id: i64,
405 #[serde(skip_serializing_if = "Option::is_none")]
406 disable_notification: Option<bool>,
407 #[serde(skip_serializing_if = "Option::is_none")]
408 business_connection_id: Option<String>,
409}
410
411pub struct PinChatMessage {
413 client: BotClient,
414 params: PinChatMessageParams,
415}
416
417impl PinChatMessage {
418 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, message_id: i64) -> Self {
419 Self {
420 client,
421 params: PinChatMessageParams {
422 chat_id: chat_id.into(),
423 message_id,
424 disable_notification: None,
425 business_connection_id: None,
426 },
427 }
428 }
429 pub fn disable_notification(mut self, v: bool) -> Self {
431 self.params.disable_notification = Some(v);
432 self
433 }
434 pub fn business_connection_id(mut self, v: impl Into<String>) -> Self {
436 self.params.business_connection_id = Some(v.into());
437 self
438 }
439}
440
441impl_into_future!(PinChatMessage, bool, "pinChatMessage");
442
443#[derive(Serialize)]
446struct UnpinChatMessageParams {
447 chat_id: ChatId,
448 #[serde(skip_serializing_if = "Option::is_none")]
449 message_id: Option<i64>,
450 #[serde(skip_serializing_if = "Option::is_none")]
451 business_connection_id: Option<String>,
452}
453
454pub struct UnpinChatMessage {
456 client: BotClient,
457 params: UnpinChatMessageParams,
458}
459
460impl UnpinChatMessage {
461 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
462 Self {
463 client,
464 params: UnpinChatMessageParams {
465 chat_id: chat_id.into(),
466 message_id: None,
467 business_connection_id: None,
468 },
469 }
470 }
471 pub fn message_id(mut self, id: i64) -> Self {
473 self.params.message_id = Some(id);
474 self
475 }
476 pub fn business_connection_id(mut self, v: impl Into<String>) -> Self {
478 self.params.business_connection_id = Some(v.into());
479 self
480 }
481}
482
483impl_into_future!(UnpinChatMessage, bool, "unpinChatMessage");
484
485#[derive(Serialize)]
488struct SetChatAdministratorCustomTitleParams {
489 chat_id: ChatId,
490 user_id: i64,
491 custom_title: String,
492}
493
494pub struct SetChatAdministratorCustomTitle {
496 client: BotClient,
497 params: SetChatAdministratorCustomTitleParams,
498}
499
500impl SetChatAdministratorCustomTitle {
501 pub(crate) fn new(
502 client: BotClient,
503 chat_id: impl Into<ChatId>,
504 user_id: i64,
505 custom_title: impl Into<String>,
506 ) -> Self {
507 Self {
508 client,
509 params: SetChatAdministratorCustomTitleParams {
510 chat_id: chat_id.into(),
511 user_id,
512 custom_title: custom_title.into(),
513 },
514 }
515 }
516}
517
518impl_into_future!(
519 SetChatAdministratorCustomTitle,
520 bool,
521 "setChatAdministratorCustomTitle"
522);
523
524#[derive(Serialize)]
527struct SetChatMemberTagParams {
528 chat_id: ChatId,
529 user_id: i64,
530 #[serde(skip_serializing_if = "Option::is_none")]
531 tag: Option<String>,
532}
533
534pub struct SetChatMemberTag {
538 client: BotClient,
539 params: SetChatMemberTagParams,
540}
541
542impl SetChatMemberTag {
543 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
544 Self {
545 client,
546 params: SetChatMemberTagParams {
547 chat_id: chat_id.into(),
548 user_id,
549 tag: None,
550 },
551 }
552 }
553 pub fn tag(mut self, t: impl Into<String>) -> Self {
555 self.params.tag = Some(t.into());
556 self
557 }
558}
559
560impl_into_future!(SetChatMemberTag, bool, "setChatMemberTag");
561
562#[derive(Serialize)]
565struct SetChatPermissionsParams {
566 chat_id: ChatId,
567 permissions: ChatPermissions,
568 #[serde(skip_serializing_if = "Option::is_none")]
569 use_independent_chat_permissions: Option<bool>,
570}
571
572pub struct SetChatPermissions {
574 client: BotClient,
575 params: SetChatPermissionsParams,
576}
577
578impl SetChatPermissions {
579 pub(crate) fn new(
580 client: BotClient,
581 chat_id: impl Into<ChatId>,
582 permissions: ChatPermissions,
583 ) -> Self {
584 Self {
585 client,
586 params: SetChatPermissionsParams {
587 chat_id: chat_id.into(),
588 permissions,
589 use_independent_chat_permissions: None,
590 },
591 }
592 }
593 pub fn use_independent_chat_permissions(mut self, v: bool) -> Self {
595 self.params.use_independent_chat_permissions = Some(v);
596 self
597 }
598}
599
600impl_into_future!(SetChatPermissions, bool, "setChatPermissions");
601
602#[derive(Serialize)]
605struct ExportChatInviteLinkParams {
606 chat_id: ChatId,
607}
608
609pub struct ExportChatInviteLink {
613 client: BotClient,
614 params: ExportChatInviteLinkParams,
615}
616
617impl ExportChatInviteLink {
618 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
619 Self {
620 client,
621 params: ExportChatInviteLinkParams {
622 chat_id: chat_id.into(),
623 },
624 }
625 }
626}
627
628impl_into_future!(ExportChatInviteLink, String, "exportChatInviteLink");
629
630#[derive(Serialize)]
633struct EditChatInviteLinkParams {
634 chat_id: ChatId,
635 invite_link: String,
636 #[serde(skip_serializing_if = "Option::is_none")]
637 name: Option<String>,
638 #[serde(skip_serializing_if = "Option::is_none")]
639 expire_date: Option<i64>,
640 #[serde(skip_serializing_if = "Option::is_none")]
641 member_limit: Option<u32>,
642 #[serde(skip_serializing_if = "Option::is_none")]
643 creates_join_request: Option<bool>,
644}
645
646pub struct EditChatInviteLink {
648 client: BotClient,
649 params: EditChatInviteLinkParams,
650}
651
652impl EditChatInviteLink {
653 pub(crate) fn new(
654 client: BotClient,
655 chat_id: impl Into<ChatId>,
656 invite_link: impl Into<String>,
657 ) -> Self {
658 Self {
659 client,
660 params: EditChatInviteLinkParams {
661 chat_id: chat_id.into(),
662 invite_link: invite_link.into(),
663 name: None,
664 expire_date: None,
665 member_limit: None,
666 creates_join_request: None,
667 },
668 }
669 }
670 pub fn name(mut self, n: impl Into<String>) -> Self {
672 self.params.name = Some(n.into());
673 self
674 }
675 pub fn expire_date(mut self, ts: i64) -> Self {
677 self.params.expire_date = Some(ts);
678 self
679 }
680 pub fn member_limit(mut self, n: u32) -> Self {
682 self.params.member_limit = Some(n);
683 self
684 }
685 pub fn creates_join_request(mut self, v: bool) -> Self {
687 self.params.creates_join_request = Some(v);
688 self
689 }
690}
691
692impl_into_future!(EditChatInviteLink, ChatInviteLink, "editChatInviteLink");
693
694#[derive(Serialize)]
697struct RevokeChatInviteLinkParams {
698 chat_id: ChatId,
699 invite_link: String,
700}
701
702pub struct RevokeChatInviteLink {
704 client: BotClient,
705 params: RevokeChatInviteLinkParams,
706}
707
708impl RevokeChatInviteLink {
709 pub(crate) fn new(
710 client: BotClient,
711 chat_id: impl Into<ChatId>,
712 invite_link: impl Into<String>,
713 ) -> Self {
714 Self {
715 client,
716 params: RevokeChatInviteLinkParams {
717 chat_id: chat_id.into(),
718 invite_link: invite_link.into(),
719 },
720 }
721 }
722}
723
724impl_into_future!(RevokeChatInviteLink, ChatInviteLink, "revokeChatInviteLink");
725
726#[derive(Serialize)]
729struct CreateChatSubscriptionInviteLinkParams {
730 chat_id: ChatId,
731 subscription_period: u32,
732 subscription_price: u32,
733 #[serde(skip_serializing_if = "Option::is_none")]
734 name: Option<String>,
735}
736
737pub struct CreateChatSubscriptionInviteLink {
742 client: BotClient,
743 params: CreateChatSubscriptionInviteLinkParams,
744}
745
746impl CreateChatSubscriptionInviteLink {
747 pub(crate) fn new(
748 client: BotClient,
749 chat_id: impl Into<ChatId>,
750 subscription_period: u32,
751 subscription_price: u32,
752 ) -> Self {
753 Self {
754 client,
755 params: CreateChatSubscriptionInviteLinkParams {
756 chat_id: chat_id.into(),
757 subscription_period,
758 subscription_price,
759 name: None,
760 },
761 }
762 }
763 pub fn name(mut self, n: impl Into<String>) -> Self {
765 self.params.name = Some(n.into());
766 self
767 }
768}
769
770impl_into_future!(
771 CreateChatSubscriptionInviteLink,
772 ChatInviteLink,
773 "createChatSubscriptionInviteLink"
774);
775
776#[derive(Serialize)]
779struct EditChatSubscriptionInviteLinkParams {
780 chat_id: ChatId,
781 invite_link: String,
782 #[serde(skip_serializing_if = "Option::is_none")]
783 name: Option<String>,
784}
785
786pub struct EditChatSubscriptionInviteLink {
788 client: BotClient,
789 params: EditChatSubscriptionInviteLinkParams,
790}
791
792impl EditChatSubscriptionInviteLink {
793 pub(crate) fn new(
794 client: BotClient,
795 chat_id: impl Into<ChatId>,
796 invite_link: impl Into<String>,
797 ) -> Self {
798 Self {
799 client,
800 params: EditChatSubscriptionInviteLinkParams {
801 chat_id: chat_id.into(),
802 invite_link: invite_link.into(),
803 name: None,
804 },
805 }
806 }
807 pub fn name(mut self, n: impl Into<String>) -> Self {
809 self.params.name = Some(n.into());
810 self
811 }
812}
813
814impl_into_future!(
815 EditChatSubscriptionInviteLink,
816 ChatInviteLink,
817 "editChatSubscriptionInviteLink"
818);
819
820#[derive(Serialize)]
823struct ApproveChatJoinRequestParams {
824 chat_id: ChatId,
825 user_id: i64,
826}
827
828pub struct ApproveChatJoinRequest {
830 client: BotClient,
831 params: ApproveChatJoinRequestParams,
832}
833
834impl ApproveChatJoinRequest {
835 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
836 Self {
837 client,
838 params: ApproveChatJoinRequestParams {
839 chat_id: chat_id.into(),
840 user_id,
841 },
842 }
843 }
844}
845
846impl_into_future!(ApproveChatJoinRequest, bool, "approveChatJoinRequest");
847
848#[derive(Serialize)]
851struct DeclineChatJoinRequestParams {
852 chat_id: ChatId,
853 user_id: i64,
854}
855
856pub struct DeclineChatJoinRequest {
858 client: BotClient,
859 params: DeclineChatJoinRequestParams,
860}
861
862impl DeclineChatJoinRequest {
863 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
864 Self {
865 client,
866 params: DeclineChatJoinRequestParams {
867 chat_id: chat_id.into(),
868 user_id,
869 },
870 }
871 }
872}
873
874impl_into_future!(DeclineChatJoinRequest, bool, "declineChatJoinRequest");
875
876#[derive(Serialize)]
879struct BanChatSenderChatParams {
880 chat_id: ChatId,
881 sender_chat_id: i64,
882}
883
884pub struct BanChatSenderChat {
889 client: BotClient,
890 params: BanChatSenderChatParams,
891}
892
893impl BanChatSenderChat {
894 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, sender_chat_id: i64) -> Self {
895 Self {
896 client,
897 params: BanChatSenderChatParams {
898 chat_id: chat_id.into(),
899 sender_chat_id,
900 },
901 }
902 }
903}
904
905impl_into_future!(BanChatSenderChat, bool, "banChatSenderChat");
906
907#[derive(Serialize)]
910struct UnbanChatSenderChatParams {
911 chat_id: ChatId,
912 sender_chat_id: i64,
913}
914
915pub struct UnbanChatSenderChat {
917 client: BotClient,
918 params: UnbanChatSenderChatParams,
919}
920
921impl UnbanChatSenderChat {
922 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, sender_chat_id: i64) -> Self {
923 Self {
924 client,
925 params: UnbanChatSenderChatParams {
926 chat_id: chat_id.into(),
927 sender_chat_id,
928 },
929 }
930 }
931}
932
933impl_into_future!(UnbanChatSenderChat, bool, "unbanChatSenderChat");
934
935#[derive(Serialize)]
938struct UnpinAllChatMessagesParams {
939 chat_id: ChatId,
940}
941
942pub struct UnpinAllChatMessages {
946 client: BotClient,
947 params: UnpinAllChatMessagesParams,
948}
949
950impl UnpinAllChatMessages {
951 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
952 Self {
953 client,
954 params: UnpinAllChatMessagesParams {
955 chat_id: chat_id.into(),
956 },
957 }
958 }
959}
960
961impl_into_future!(UnpinAllChatMessages, bool, "unpinAllChatMessages");
962
963pub struct SetChatPhoto {
969 client: BotClient,
970 chat_id: ChatId,
971 photo: InputFile,
972}
973
974impl SetChatPhoto {
975 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, photo: InputFile) -> Self {
976 Self {
977 client,
978 chat_id: chat_id.into(),
979 photo,
980 }
981 }
982}
983
984impl IntoFuture for SetChatPhoto {
985 type Output = Result<bool>;
986 type IntoFuture = Pin<Box<dyn Future<Output = Self::Output> + Send>>;
987
988 fn into_future(self) -> Self::IntoFuture {
989 Box::pin(async move {
990 match self.photo {
991 InputFile::Bytes {
992 filename,
993 data,
994 mime_type,
995 } => {
996 let part = Part::bytes(data)
997 .file_name(filename)
998 .mime_str(&mime_type)
999 .map_err(|e| crate::error::Error::Decode(e.to_string()))?;
1000 let form = Form::new()
1001 .text("chat_id", self.chat_id.to_string())
1002 .part("photo", part);
1003 self.client.post_multipart("setChatPhoto", form).await
1004 }
1005 other => {
1006 let body = serde_json::json!({
1007 "chat_id": self.chat_id,
1008 "photo": other.as_str(),
1009 });
1010 self.client.post_json("setChatPhoto", &body).await
1011 }
1012 }
1013 })
1014 }
1015}
1016
1017#[derive(Serialize)]
1020struct DeleteChatPhotoParams {
1021 chat_id: ChatId,
1022}
1023
1024pub struct DeleteChatPhoto {
1026 client: BotClient,
1027 params: DeleteChatPhotoParams,
1028}
1029
1030impl DeleteChatPhoto {
1031 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
1032 Self {
1033 client,
1034 params: DeleteChatPhotoParams {
1035 chat_id: chat_id.into(),
1036 },
1037 }
1038 }
1039}
1040
1041impl_into_future!(DeleteChatPhoto, bool, "deleteChatPhoto");
1042
1043#[derive(Serialize)]
1046struct SetChatTitleParams {
1047 chat_id: ChatId,
1048 title: String,
1049}
1050
1051pub struct SetChatTitle {
1053 client: BotClient,
1054 params: SetChatTitleParams,
1055}
1056
1057impl SetChatTitle {
1058 pub(crate) fn new(
1059 client: BotClient,
1060 chat_id: impl Into<ChatId>,
1061 title: impl Into<String>,
1062 ) -> Self {
1063 Self {
1064 client,
1065 params: SetChatTitleParams {
1066 chat_id: chat_id.into(),
1067 title: title.into(),
1068 },
1069 }
1070 }
1071}
1072
1073impl_into_future!(SetChatTitle, bool, "setChatTitle");
1074
1075#[derive(Serialize)]
1078struct SetChatDescriptionParams {
1079 chat_id: ChatId,
1080 #[serde(skip_serializing_if = "Option::is_none")]
1081 description: Option<String>,
1082}
1083
1084pub struct SetChatDescription {
1088 client: BotClient,
1089 params: SetChatDescriptionParams,
1090}
1091
1092impl SetChatDescription {
1093 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
1094 Self {
1095 client,
1096 params: SetChatDescriptionParams {
1097 chat_id: chat_id.into(),
1098 description: None,
1099 },
1100 }
1101 }
1102 pub fn description(mut self, d: impl Into<String>) -> Self {
1104 self.params.description = Some(d.into());
1105 self
1106 }
1107}
1108
1109impl_into_future!(SetChatDescription, bool, "setChatDescription");
1110
1111#[derive(Serialize)]
1114struct SetChatStickerSetParams {
1115 chat_id: ChatId,
1116 sticker_set_name: String,
1117}
1118
1119pub struct SetChatStickerSet {
1121 client: BotClient,
1122 params: SetChatStickerSetParams,
1123}
1124
1125impl SetChatStickerSet {
1126 pub(crate) fn new(
1127 client: BotClient,
1128 chat_id: impl Into<ChatId>,
1129 sticker_set_name: impl Into<String>,
1130 ) -> Self {
1131 Self {
1132 client,
1133 params: SetChatStickerSetParams {
1134 chat_id: chat_id.into(),
1135 sticker_set_name: sticker_set_name.into(),
1136 },
1137 }
1138 }
1139}
1140
1141impl_into_future!(SetChatStickerSet, bool, "setChatStickerSet");
1142
1143#[derive(Serialize)]
1146struct DeleteChatStickerSetParams {
1147 chat_id: ChatId,
1148}
1149
1150pub struct DeleteChatStickerSet {
1152 client: BotClient,
1153 params: DeleteChatStickerSetParams,
1154}
1155
1156impl DeleteChatStickerSet {
1157 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
1158 Self {
1159 client,
1160 params: DeleteChatStickerSetParams {
1161 chat_id: chat_id.into(),
1162 },
1163 }
1164 }
1165}
1166
1167impl_into_future!(DeleteChatStickerSet, bool, "deleteChatStickerSet");
1168
1169#[derive(Serialize)]
1172struct LeaveChatParams {
1173 chat_id: ChatId,
1174}
1175
1176pub struct LeaveChat {
1178 client: BotClient,
1179 params: LeaveChatParams,
1180}
1181
1182impl LeaveChat {
1183 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>) -> Self {
1184 Self {
1185 client,
1186 params: LeaveChatParams {
1187 chat_id: chat_id.into(),
1188 },
1189 }
1190 }
1191}
1192
1193impl_into_future!(LeaveChat, bool, "leaveChat");
1194
1195#[derive(Serialize)]
1198struct GetUserChatBoostsParams {
1199 chat_id: ChatId,
1200 user_id: i64,
1201}
1202
1203pub struct GetUserChatBoosts {
1208 client: BotClient,
1209 params: GetUserChatBoostsParams,
1210}
1211
1212impl GetUserChatBoosts {
1213 pub(crate) fn new(client: BotClient, chat_id: impl Into<ChatId>, user_id: i64) -> Self {
1214 Self {
1215 client,
1216 params: GetUserChatBoostsParams {
1217 chat_id: chat_id.into(),
1218 user_id,
1219 },
1220 }
1221 }
1222}
1223
1224impl_into_future!(GetUserChatBoosts, UserChatBoosts, "getUserChatBoosts");
1225
1226#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
1230#[serde(rename_all = "snake_case")]
1231pub enum JoinRequestResult {
1232 Approve,
1234 Decline,
1236 Queue,
1238}
1239
1240#[derive(Serialize)]
1241struct AnswerChatJoinRequestQueryParams {
1242 chat_join_request_query_id: String,
1243 result: JoinRequestResult,
1244}
1245
1246pub struct AnswerChatJoinRequestQuery {
1248 client: BotClient,
1249 params: AnswerChatJoinRequestQueryParams,
1250}
1251
1252impl AnswerChatJoinRequestQuery {
1253 pub(crate) fn new(
1254 client: BotClient,
1255 chat_join_request_query_id: impl Into<String>,
1256 result: JoinRequestResult,
1257 ) -> Self {
1258 Self {
1259 client,
1260 params: AnswerChatJoinRequestQueryParams {
1261 chat_join_request_query_id: chat_join_request_query_id.into(),
1262 result,
1263 },
1264 }
1265 }
1266}
1267
1268impl_into_future!(
1269 AnswerChatJoinRequestQuery,
1270 bool,
1271 "answerChatJoinRequestQuery"
1272);
1273
1274#[derive(Serialize)]
1277struct SendChatJoinRequestWebAppParams {
1278 chat_join_request_query_id: String,
1279 web_app_url: String,
1280}
1281
1282pub struct SendChatJoinRequestWebApp {
1286 client: BotClient,
1287 params: SendChatJoinRequestWebAppParams,
1288}
1289
1290impl SendChatJoinRequestWebApp {
1291 pub(crate) fn new(
1292 client: BotClient,
1293 chat_join_request_query_id: impl Into<String>,
1294 web_app_url: impl Into<String>,
1295 ) -> Self {
1296 Self {
1297 client,
1298 params: SendChatJoinRequestWebAppParams {
1299 chat_join_request_query_id: chat_join_request_query_id.into(),
1300 web_app_url: web_app_url.into(),
1301 },
1302 }
1303 }
1304}
1305
1306impl_into_future!(SendChatJoinRequestWebApp, bool, "sendChatJoinRequestWebApp");