1#![allow(clippy::too_many_arguments)]
15
16use crate::bot::{Bot, ChatId};
17use crate::error::Result;
18use crate::request::request_parameter::RequestParameter;
19use crate::types::{business, gifts, message_entity, owned_gift, payment};
20use serde::Serialize;
21
22fn push_opt<T: Serialize>(
27 params: &mut Vec<RequestParameter>,
28 name: &'static str,
29 val: &Option<T>,
30) -> std::result::Result<(), serde_json::Error> {
31 if let Some(v) = val {
32 params.push(RequestParameter::new(name, serde_json::to_value(v)?));
33 }
34 Ok(())
35}
36
37fn push_opt_str(params: &mut Vec<RequestParameter>, name: &'static str, val: &Option<String>) {
38 if let Some(v) = val {
39 params.push(RequestParameter::new(
40 name,
41 serde_json::Value::String(v.clone()),
42 ));
43 }
44}
45
46macro_rules! impl_into_future {
47 ($builder:ident, $output:ty) => {
48 impl<'a> std::future::IntoFuture for $builder<'a> {
49 type Output = Result<$output>;
50 type IntoFuture =
51 std::pin::Pin<Box<dyn std::future::Future<Output = Self::Output> + Send + 'a>>;
52 fn into_future(self) -> Self::IntoFuture {
53 Box::pin(self.send())
54 }
55 }
56 };
57}
58
59pub struct GetBusinessConnectionBuilder<'a> {
69 bot: &'a Bot,
70 business_connection_id: String,
71}
72
73impl<'a> GetBusinessConnectionBuilder<'a> {
74 pub async fn send(self) -> Result<business::BusinessConnection> {
76 let params = vec![RequestParameter::new(
77 "business_connection_id",
78 serde_json::Value::String(self.business_connection_id),
79 )];
80 self.bot
81 .do_api_request("getBusinessConnection", params)
82 .await
83 }
84}
85
86impl_into_future!(GetBusinessConnectionBuilder, business::BusinessConnection);
87
88pub struct GetBusinessAccountGiftsBuilder<'a> {
94 bot: &'a Bot,
95 business_connection_id: String,
96 exclude_unsaved: Option<bool>,
97 exclude_saved: Option<bool>,
98 exclude_unlimited: Option<bool>,
99 exclude_unique: Option<bool>,
100 sort_by_price: Option<bool>,
101 offset: Option<String>,
102 limit: Option<i64>,
103 exclude_limited_upgradable: Option<bool>,
104 exclude_limited_non_upgradable: Option<bool>,
105 exclude_from_blockchain: Option<bool>,
106}
107
108impl<'a> GetBusinessAccountGiftsBuilder<'a> {
109 pub fn exclude_unsaved(mut self, val: bool) -> Self {
111 self.exclude_unsaved = Some(val);
112 self
113 }
114 pub fn exclude_saved(mut self, val: bool) -> Self {
116 self.exclude_saved = Some(val);
117 self
118 }
119 pub fn exclude_unlimited(mut self, val: bool) -> Self {
121 self.exclude_unlimited = Some(val);
122 self
123 }
124 pub fn exclude_unique(mut self, val: bool) -> Self {
126 self.exclude_unique = Some(val);
127 self
128 }
129 pub fn sort_by_price(mut self, val: bool) -> Self {
131 self.sort_by_price = Some(val);
132 self
133 }
134 pub fn offset(mut self, val: impl Into<String>) -> Self {
136 self.offset = Some(val.into());
137 self
138 }
139 pub fn limit(mut self, val: i64) -> Self {
141 self.limit = Some(val);
142 self
143 }
144 pub fn exclude_limited_upgradable(mut self, val: bool) -> Self {
146 self.exclude_limited_upgradable = Some(val);
147 self
148 }
149 pub fn exclude_limited_non_upgradable(mut self, val: bool) -> Self {
151 self.exclude_limited_non_upgradable = Some(val);
152 self
153 }
154 pub fn exclude_from_blockchain(mut self, val: bool) -> Self {
156 self.exclude_from_blockchain = Some(val);
157 self
158 }
159
160 pub async fn send(self) -> Result<owned_gift::OwnedGifts> {
162 let mut params = vec![RequestParameter::new(
163 "business_connection_id",
164 serde_json::Value::String(self.business_connection_id),
165 )];
166 push_opt(&mut params, "exclude_unsaved", &self.exclude_unsaved)?;
167 push_opt(&mut params, "exclude_saved", &self.exclude_saved)?;
168 push_opt(&mut params, "exclude_unlimited", &self.exclude_unlimited)?;
169 push_opt(&mut params, "exclude_unique", &self.exclude_unique)?;
170 push_opt(&mut params, "sort_by_price", &self.sort_by_price)?;
171 push_opt_str(&mut params, "offset", &self.offset);
172 push_opt(&mut params, "limit", &self.limit)?;
173 push_opt(
174 &mut params,
175 "exclude_limited_upgradable",
176 &self.exclude_limited_upgradable,
177 )?;
178 push_opt(
179 &mut params,
180 "exclude_limited_non_upgradable",
181 &self.exclude_limited_non_upgradable,
182 )?;
183 push_opt(
184 &mut params,
185 "exclude_from_blockchain",
186 &self.exclude_from_blockchain,
187 )?;
188 self.bot
189 .do_api_request("getBusinessAccountGifts", params)
190 .await
191 }
192}
193
194impl_into_future!(GetBusinessAccountGiftsBuilder, owned_gift::OwnedGifts);
195
196pub struct GetBusinessAccountStarBalanceBuilder<'a> {
202 bot: &'a Bot,
203 business_connection_id: String,
204}
205
206impl<'a> GetBusinessAccountStarBalanceBuilder<'a> {
207 pub async fn send(self) -> Result<payment::stars::star_amount::StarAmount> {
209 let params = vec![RequestParameter::new(
210 "business_connection_id",
211 serde_json::Value::String(self.business_connection_id),
212 )];
213 self.bot
214 .do_api_request("getBusinessAccountStarBalance", params)
215 .await
216 }
217}
218
219impl_into_future!(
220 GetBusinessAccountStarBalanceBuilder,
221 payment::stars::star_amount::StarAmount
222);
223
224pub struct ReadBusinessMessageBuilder<'a> {
230 bot: &'a Bot,
231 business_connection_id: String,
232 chat_id: i64,
233 message_id: i64,
234}
235
236impl<'a> ReadBusinessMessageBuilder<'a> {
237 pub async fn send(self) -> Result<bool> {
239 let params = vec![
240 RequestParameter::new(
241 "business_connection_id",
242 serde_json::Value::String(self.business_connection_id),
243 ),
244 RequestParameter::new("chat_id", serde_json::to_value(self.chat_id)?),
245 RequestParameter::new("message_id", serde_json::to_value(self.message_id)?),
246 ];
247 self.bot.do_api_request("readBusinessMessage", params).await
248 }
249}
250
251impl_into_future!(ReadBusinessMessageBuilder, bool);
252
253pub struct DeleteBusinessMessagesBuilder<'a> {
259 bot: &'a Bot,
260 business_connection_id: String,
261 message_ids: Vec<i64>,
262}
263
264impl<'a> DeleteBusinessMessagesBuilder<'a> {
265 pub async fn send(self) -> Result<bool> {
267 let params = vec![
268 RequestParameter::new(
269 "business_connection_id",
270 serde_json::Value::String(self.business_connection_id),
271 ),
272 RequestParameter::new("message_ids", serde_json::to_value(&self.message_ids)?),
273 ];
274 self.bot
275 .do_api_request("deleteBusinessMessages", params)
276 .await
277 }
278}
279
280impl_into_future!(DeleteBusinessMessagesBuilder, bool);
281
282pub struct SetBusinessAccountNameBuilder<'a> {
288 bot: &'a Bot,
289 business_connection_id: String,
290 first_name: String,
291 last_name: Option<String>,
292}
293
294impl<'a> SetBusinessAccountNameBuilder<'a> {
295 pub fn last_name(mut self, val: impl Into<String>) -> Self {
297 self.last_name = Some(val.into());
298 self
299 }
300
301 pub async fn send(self) -> Result<bool> {
303 let mut params = vec![
304 RequestParameter::new(
305 "business_connection_id",
306 serde_json::Value::String(self.business_connection_id),
307 ),
308 RequestParameter::new("first_name", serde_json::Value::String(self.first_name)),
309 ];
310 push_opt_str(&mut params, "last_name", &self.last_name);
311 self.bot
312 .do_api_request("setBusinessAccountName", params)
313 .await
314 }
315}
316
317impl_into_future!(SetBusinessAccountNameBuilder, bool);
318
319pub struct SetBusinessAccountUsernameBuilder<'a> {
325 bot: &'a Bot,
326 business_connection_id: String,
327 username: Option<String>,
328}
329
330impl<'a> SetBusinessAccountUsernameBuilder<'a> {
331 pub fn username(mut self, val: impl Into<String>) -> Self {
333 self.username = Some(val.into());
334 self
335 }
336
337 pub async fn send(self) -> Result<bool> {
339 let mut params = vec![RequestParameter::new(
340 "business_connection_id",
341 serde_json::Value::String(self.business_connection_id),
342 )];
343 push_opt_str(&mut params, "username", &self.username);
344 self.bot
345 .do_api_request("setBusinessAccountUsername", params)
346 .await
347 }
348}
349
350impl_into_future!(SetBusinessAccountUsernameBuilder, bool);
351
352pub struct SetBusinessAccountBioBuilder<'a> {
358 bot: &'a Bot,
359 business_connection_id: String,
360 bio: Option<String>,
361}
362
363impl<'a> SetBusinessAccountBioBuilder<'a> {
364 pub fn bio(mut self, val: impl Into<String>) -> Self {
366 self.bio = Some(val.into());
367 self
368 }
369
370 pub async fn send(self) -> Result<bool> {
372 let mut params = vec![RequestParameter::new(
373 "business_connection_id",
374 serde_json::Value::String(self.business_connection_id),
375 )];
376 push_opt_str(&mut params, "bio", &self.bio);
377 self.bot
378 .do_api_request("setBusinessAccountBio", params)
379 .await
380 }
381}
382
383impl_into_future!(SetBusinessAccountBioBuilder, bool);
384
385pub struct SetBusinessAccountGiftSettingsBuilder<'a> {
391 bot: &'a Bot,
392 business_connection_id: String,
393 show_gift_button: bool,
394 accepted_gift_types: gifts::AcceptedGiftTypes,
395}
396
397impl<'a> SetBusinessAccountGiftSettingsBuilder<'a> {
398 pub async fn send(self) -> Result<bool> {
400 let params = vec![
401 RequestParameter::new(
402 "business_connection_id",
403 serde_json::Value::String(self.business_connection_id),
404 ),
405 RequestParameter::new(
406 "show_gift_button",
407 serde_json::to_value(self.show_gift_button)?,
408 ),
409 RequestParameter::new(
410 "accepted_gift_types",
411 serde_json::to_value(&self.accepted_gift_types)?,
412 ),
413 ];
414 self.bot
415 .do_api_request("setBusinessAccountGiftSettings", params)
416 .await
417 }
418}
419
420impl_into_future!(SetBusinessAccountGiftSettingsBuilder, bool);
421
422pub struct SetBusinessAccountProfilePhotoBuilder<'a> {
428 bot: &'a Bot,
429 business_connection_id: String,
430 photo: serde_json::Value,
431 is_public: Option<bool>,
432}
433
434impl<'a> SetBusinessAccountProfilePhotoBuilder<'a> {
435 pub fn is_public(mut self, val: bool) -> Self {
437 self.is_public = Some(val);
438 self
439 }
440
441 pub async fn send(self) -> Result<bool> {
443 let mut params = vec![
444 RequestParameter::new(
445 "business_connection_id",
446 serde_json::Value::String(self.business_connection_id),
447 ),
448 RequestParameter::new("photo", self.photo),
449 ];
450 push_opt(&mut params, "is_public", &self.is_public)?;
451 self.bot
452 .do_api_request("setBusinessAccountProfilePhoto", params)
453 .await
454 }
455}
456
457impl_into_future!(SetBusinessAccountProfilePhotoBuilder, bool);
458
459pub struct RemoveBusinessAccountProfilePhotoBuilder<'a> {
465 bot: &'a Bot,
466 business_connection_id: String,
467 is_public: Option<bool>,
468}
469
470impl<'a> RemoveBusinessAccountProfilePhotoBuilder<'a> {
471 pub fn is_public(mut self, val: bool) -> Self {
473 self.is_public = Some(val);
474 self
475 }
476
477 pub async fn send(self) -> Result<bool> {
479 let mut params = vec![RequestParameter::new(
480 "business_connection_id",
481 serde_json::Value::String(self.business_connection_id),
482 )];
483 push_opt(&mut params, "is_public", &self.is_public)?;
484 self.bot
485 .do_api_request("removeBusinessAccountProfilePhoto", params)
486 .await
487 }
488}
489
490impl_into_future!(RemoveBusinessAccountProfilePhotoBuilder, bool);
491
492pub struct ConvertGiftToStarsBuilder<'a> {
498 bot: &'a Bot,
499 business_connection_id: String,
500 owned_gift_id: String,
501}
502
503impl<'a> ConvertGiftToStarsBuilder<'a> {
504 pub async fn send(self) -> Result<bool> {
506 let params = vec![
507 RequestParameter::new(
508 "business_connection_id",
509 serde_json::Value::String(self.business_connection_id),
510 ),
511 RequestParameter::new(
512 "owned_gift_id",
513 serde_json::Value::String(self.owned_gift_id),
514 ),
515 ];
516 self.bot.do_api_request("convertGiftToStars", params).await
517 }
518}
519
520impl_into_future!(ConvertGiftToStarsBuilder, bool);
521
522pub struct UpgradeGiftBuilder<'a> {
528 bot: &'a Bot,
529 business_connection_id: String,
530 owned_gift_id: String,
531 keep_original_details: Option<bool>,
532 star_count: Option<i64>,
533}
534
535impl<'a> UpgradeGiftBuilder<'a> {
536 pub fn keep_original_details(mut self, val: bool) -> Self {
538 self.keep_original_details = Some(val);
539 self
540 }
541 pub fn star_count(mut self, val: i64) -> Self {
543 self.star_count = Some(val);
544 self
545 }
546
547 pub async fn send(self) -> Result<bool> {
549 let mut params = vec![
550 RequestParameter::new(
551 "business_connection_id",
552 serde_json::Value::String(self.business_connection_id),
553 ),
554 RequestParameter::new(
555 "owned_gift_id",
556 serde_json::Value::String(self.owned_gift_id),
557 ),
558 ];
559 push_opt(
560 &mut params,
561 "keep_original_details",
562 &self.keep_original_details,
563 )?;
564 push_opt(&mut params, "star_count", &self.star_count)?;
565 self.bot.do_api_request("upgradeGift", params).await
566 }
567}
568
569impl_into_future!(UpgradeGiftBuilder, bool);
570
571pub struct TransferGiftBuilder<'a> {
577 bot: &'a Bot,
578 business_connection_id: String,
579 owned_gift_id: String,
580 new_owner_chat_id: i64,
581 star_count: Option<i64>,
582}
583
584impl<'a> TransferGiftBuilder<'a> {
585 pub fn star_count(mut self, val: i64) -> Self {
587 self.star_count = Some(val);
588 self
589 }
590
591 pub async fn send(self) -> Result<bool> {
593 let mut params = vec![
594 RequestParameter::new(
595 "business_connection_id",
596 serde_json::Value::String(self.business_connection_id),
597 ),
598 RequestParameter::new(
599 "owned_gift_id",
600 serde_json::Value::String(self.owned_gift_id),
601 ),
602 RequestParameter::new(
603 "new_owner_chat_id",
604 serde_json::to_value(self.new_owner_chat_id)?,
605 ),
606 ];
607 push_opt(&mut params, "star_count", &self.star_count)?;
608 self.bot.do_api_request("transferGift", params).await
609 }
610}
611
612impl_into_future!(TransferGiftBuilder, bool);
613
614pub struct TransferBusinessAccountStarsBuilder<'a> {
620 bot: &'a Bot,
621 business_connection_id: String,
622 star_count: i64,
623}
624
625impl<'a> TransferBusinessAccountStarsBuilder<'a> {
626 pub async fn send(self) -> Result<bool> {
628 let params = vec![
629 RequestParameter::new(
630 "business_connection_id",
631 serde_json::Value::String(self.business_connection_id),
632 ),
633 RequestParameter::new("star_count", serde_json::to_value(self.star_count)?),
634 ];
635 self.bot
636 .do_api_request("transferBusinessAccountStars", params)
637 .await
638 }
639}
640
641impl_into_future!(TransferBusinessAccountStarsBuilder, bool);
642
643pub struct CreateInvoiceLinkBuilder<'a> {
653 bot: &'a Bot,
654 title: String,
655 description: String,
656 payload: String,
657 currency: String,
658 prices: Vec<serde_json::Value>,
659 provider_token: Option<String>,
660 max_tip_amount: Option<i64>,
661 suggested_tip_amounts: Option<Vec<i64>>,
662 provider_data: Option<String>,
663 photo_url: Option<String>,
664 photo_size: Option<i64>,
665 photo_width: Option<i64>,
666 photo_height: Option<i64>,
667 need_name: Option<bool>,
668 need_phone_number: Option<bool>,
669 need_email: Option<bool>,
670 need_shipping_address: Option<bool>,
671 send_phone_number_to_provider: Option<bool>,
672 send_email_to_provider: Option<bool>,
673 is_flexible: Option<bool>,
674 subscription_period: Option<i64>,
675 business_connection_id: Option<String>,
676}
677
678impl<'a> CreateInvoiceLinkBuilder<'a> {
679 pub fn provider_token(mut self, val: impl Into<String>) -> Self {
681 self.provider_token = Some(val.into());
682 self
683 }
684 pub fn max_tip_amount(mut self, val: i64) -> Self {
686 self.max_tip_amount = Some(val);
687 self
688 }
689 pub fn suggested_tip_amounts(mut self, val: Vec<i64>) -> Self {
691 self.suggested_tip_amounts = Some(val);
692 self
693 }
694 pub fn provider_data(mut self, val: impl Into<String>) -> Self {
696 self.provider_data = Some(val.into());
697 self
698 }
699 pub fn photo_url(mut self, val: impl Into<String>) -> Self {
701 self.photo_url = Some(val.into());
702 self
703 }
704 pub fn photo_size(mut self, val: i64) -> Self {
706 self.photo_size = Some(val);
707 self
708 }
709 pub fn photo_width(mut self, val: i64) -> Self {
711 self.photo_width = Some(val);
712 self
713 }
714 pub fn photo_height(mut self, val: i64) -> Self {
716 self.photo_height = Some(val);
717 self
718 }
719 pub fn need_name(mut self, val: bool) -> Self {
721 self.need_name = Some(val);
722 self
723 }
724 pub fn need_phone_number(mut self, val: bool) -> Self {
726 self.need_phone_number = Some(val);
727 self
728 }
729 pub fn need_email(mut self, val: bool) -> Self {
731 self.need_email = Some(val);
732 self
733 }
734 pub fn need_shipping_address(mut self, val: bool) -> Self {
736 self.need_shipping_address = Some(val);
737 self
738 }
739 pub fn send_phone_number_to_provider(mut self, val: bool) -> Self {
741 self.send_phone_number_to_provider = Some(val);
742 self
743 }
744 pub fn send_email_to_provider(mut self, val: bool) -> Self {
746 self.send_email_to_provider = Some(val);
747 self
748 }
749 pub fn is_flexible(mut self, val: bool) -> Self {
751 self.is_flexible = Some(val);
752 self
753 }
754 pub fn subscription_period(mut self, val: i64) -> Self {
756 self.subscription_period = Some(val);
757 self
758 }
759 pub fn business_connection_id(mut self, val: impl Into<String>) -> Self {
761 self.business_connection_id = Some(val.into());
762 self
763 }
764
765 pub async fn send(self) -> Result<String> {
767 let mut params = vec![
768 RequestParameter::new("title", serde_json::Value::String(self.title)),
769 RequestParameter::new("description", serde_json::Value::String(self.description)),
770 RequestParameter::new("payload", serde_json::Value::String(self.payload)),
771 RequestParameter::new("currency", serde_json::Value::String(self.currency)),
772 RequestParameter::new("prices", serde_json::to_value(&self.prices)?),
773 ];
774 push_opt_str(&mut params, "provider_token", &self.provider_token);
775 push_opt(&mut params, "max_tip_amount", &self.max_tip_amount)?;
776 push_opt(
777 &mut params,
778 "suggested_tip_amounts",
779 &self.suggested_tip_amounts,
780 )?;
781 push_opt_str(&mut params, "provider_data", &self.provider_data);
782 push_opt_str(&mut params, "photo_url", &self.photo_url);
783 push_opt(&mut params, "photo_size", &self.photo_size)?;
784 push_opt(&mut params, "photo_width", &self.photo_width)?;
785 push_opt(&mut params, "photo_height", &self.photo_height)?;
786 push_opt(&mut params, "need_name", &self.need_name)?;
787 push_opt(&mut params, "need_phone_number", &self.need_phone_number)?;
788 push_opt(&mut params, "need_email", &self.need_email)?;
789 push_opt(
790 &mut params,
791 "need_shipping_address",
792 &self.need_shipping_address,
793 )?;
794 push_opt(
795 &mut params,
796 "send_phone_number_to_provider",
797 &self.send_phone_number_to_provider,
798 )?;
799 push_opt(
800 &mut params,
801 "send_email_to_provider",
802 &self.send_email_to_provider,
803 )?;
804 push_opt(&mut params, "is_flexible", &self.is_flexible)?;
805 push_opt(
806 &mut params,
807 "subscription_period",
808 &self.subscription_period,
809 )?;
810 push_opt_str(
811 &mut params,
812 "business_connection_id",
813 &self.business_connection_id,
814 );
815 self.bot.do_api_request("createInvoiceLink", params).await
816 }
817}
818
819impl_into_future!(CreateInvoiceLinkBuilder, String);
820
821pub struct EditUserStarSubscriptionBuilder<'a> {
827 bot: &'a Bot,
828 user_id: i64,
829 telegram_payment_charge_id: String,
830 is_canceled: bool,
831}
832
833impl<'a> EditUserStarSubscriptionBuilder<'a> {
834 pub async fn send(self) -> Result<bool> {
836 let params = vec![
837 RequestParameter::new("user_id", serde_json::to_value(self.user_id)?),
838 RequestParameter::new(
839 "telegram_payment_charge_id",
840 serde_json::Value::String(self.telegram_payment_charge_id),
841 ),
842 RequestParameter::new("is_canceled", serde_json::to_value(self.is_canceled)?),
843 ];
844 self.bot
845 .do_api_request("editUserStarSubscription", params)
846 .await
847 }
848}
849
850impl_into_future!(EditUserStarSubscriptionBuilder, bool);
851
852pub struct GetMyStarBalanceBuilder<'a> {
858 bot: &'a Bot,
859}
860
861impl<'a> GetMyStarBalanceBuilder<'a> {
862 pub async fn send(self) -> Result<payment::stars::star_amount::StarAmount> {
864 self.bot
865 .do_api_request("getMyStarBalance", Vec::new())
866 .await
867 }
868}
869
870impl_into_future!(
871 GetMyStarBalanceBuilder,
872 payment::stars::star_amount::StarAmount
873);
874
875pub struct GetStarTransactionsBuilder<'a> {
881 bot: &'a Bot,
882 offset: Option<i64>,
883 limit: Option<i64>,
884}
885
886impl<'a> GetStarTransactionsBuilder<'a> {
887 pub fn offset(mut self, val: i64) -> Self {
889 self.offset = Some(val);
890 self
891 }
892 pub fn limit(mut self, val: i64) -> Self {
894 self.limit = Some(val);
895 self
896 }
897
898 pub async fn send(self) -> Result<payment::stars::star_transactions::StarTransactions> {
900 let mut params = Vec::new();
901 push_opt(&mut params, "offset", &self.offset)?;
902 push_opt(&mut params, "limit", &self.limit)?;
903 self.bot.do_api_request("getStarTransactions", params).await
904 }
905}
906
907impl_into_future!(
908 GetStarTransactionsBuilder,
909 payment::stars::star_transactions::StarTransactions
910);
911
912pub struct RefundStarPaymentBuilder<'a> {
918 bot: &'a Bot,
919 user_id: i64,
920 telegram_payment_charge_id: String,
921}
922
923impl<'a> RefundStarPaymentBuilder<'a> {
924 pub async fn send(self) -> Result<bool> {
926 let params = vec![
927 RequestParameter::new("user_id", serde_json::to_value(self.user_id)?),
928 RequestParameter::new(
929 "telegram_payment_charge_id",
930 serde_json::Value::String(self.telegram_payment_charge_id),
931 ),
932 ];
933 self.bot.do_api_request("refundStarPayment", params).await
934 }
935}
936
937impl_into_future!(RefundStarPaymentBuilder, bool);
938
939pub struct GetAvailableGiftsBuilder<'a> {
949 bot: &'a Bot,
950}
951
952impl<'a> GetAvailableGiftsBuilder<'a> {
953 pub async fn send(self) -> Result<gifts::Gifts> {
955 self.bot
956 .do_api_request("getAvailableGifts", Vec::new())
957 .await
958 }
959}
960
961impl_into_future!(GetAvailableGiftsBuilder, gifts::Gifts);
962
963pub struct SendGiftBuilder<'a> {
969 bot: &'a Bot,
970 gift_id: String,
971 user_id: Option<i64>,
972 chat_id: Option<ChatId>,
973 text: Option<String>,
974 text_parse_mode: Option<String>,
975 text_entities: Option<Vec<message_entity::MessageEntity>>,
976 pay_for_upgrade: Option<bool>,
977}
978
979impl<'a> SendGiftBuilder<'a> {
980 pub fn user_id(mut self, val: i64) -> Self {
982 self.user_id = Some(val);
983 self
984 }
985 pub fn chat_id(mut self, val: impl Into<ChatId>) -> Self {
987 self.chat_id = Some(val.into());
988 self
989 }
990 pub fn text(mut self, val: impl Into<String>) -> Self {
992 self.text = Some(val.into());
993 self
994 }
995 pub fn text_parse_mode(mut self, val: impl Into<String>) -> Self {
997 self.text_parse_mode = Some(val.into());
998 self
999 }
1000 pub fn text_entities(mut self, val: Vec<message_entity::MessageEntity>) -> Self {
1002 self.text_entities = Some(val);
1003 self
1004 }
1005 pub fn pay_for_upgrade(mut self, val: bool) -> Self {
1007 self.pay_for_upgrade = Some(val);
1008 self
1009 }
1010
1011 pub async fn send(self) -> Result<bool> {
1013 let mut params = vec![RequestParameter::new(
1014 "gift_id",
1015 serde_json::Value::String(self.gift_id),
1016 )];
1017 push_opt(&mut params, "user_id", &self.user_id)?;
1018 push_opt(&mut params, "chat_id", &self.chat_id)?;
1019 push_opt_str(&mut params, "text", &self.text);
1020 push_opt_str(&mut params, "text_parse_mode", &self.text_parse_mode);
1021 push_opt(&mut params, "text_entities", &self.text_entities)?;
1022 push_opt(&mut params, "pay_for_upgrade", &self.pay_for_upgrade)?;
1023 self.bot.do_api_request("sendGift", params).await
1024 }
1025}
1026
1027impl_into_future!(SendGiftBuilder, bool);
1028
1029pub struct GiftPremiumSubscriptionBuilder<'a> {
1035 bot: &'a Bot,
1036 user_id: i64,
1037 month_count: i64,
1038 star_count: i64,
1039 text: Option<String>,
1040 text_parse_mode: Option<String>,
1041 text_entities: Option<Vec<message_entity::MessageEntity>>,
1042}
1043
1044impl<'a> GiftPremiumSubscriptionBuilder<'a> {
1045 pub fn text(mut self, val: impl Into<String>) -> Self {
1047 self.text = Some(val.into());
1048 self
1049 }
1050 pub fn text_parse_mode(mut self, val: impl Into<String>) -> Self {
1052 self.text_parse_mode = Some(val.into());
1053 self
1054 }
1055 pub fn text_entities(mut self, val: Vec<message_entity::MessageEntity>) -> Self {
1057 self.text_entities = Some(val);
1058 self
1059 }
1060
1061 pub async fn send(self) -> Result<bool> {
1063 let mut params = vec![
1064 RequestParameter::new("user_id", serde_json::to_value(self.user_id)?),
1065 RequestParameter::new("month_count", serde_json::to_value(self.month_count)?),
1066 RequestParameter::new("star_count", serde_json::to_value(self.star_count)?),
1067 ];
1068 push_opt_str(&mut params, "text", &self.text);
1069 push_opt_str(&mut params, "text_parse_mode", &self.text_parse_mode);
1070 push_opt(&mut params, "text_entities", &self.text_entities)?;
1071 self.bot
1072 .do_api_request("giftPremiumSubscription", params)
1073 .await
1074 }
1075}
1076
1077impl_into_future!(GiftPremiumSubscriptionBuilder, bool);
1078
1079pub struct GetUserGiftsBuilder<'a> {
1085 bot: &'a Bot,
1086 user_id: i64,
1087 exclude_unlimited: Option<bool>,
1088 exclude_limited_upgradable: Option<bool>,
1089 exclude_limited_non_upgradable: Option<bool>,
1090 exclude_from_blockchain: Option<bool>,
1091 exclude_unique: Option<bool>,
1092 sort_by_price: Option<bool>,
1093 offset: Option<String>,
1094 limit: Option<i64>,
1095}
1096
1097impl<'a> GetUserGiftsBuilder<'a> {
1098 pub fn exclude_unlimited(mut self, val: bool) -> Self {
1100 self.exclude_unlimited = Some(val);
1101 self
1102 }
1103 pub fn exclude_limited_upgradable(mut self, val: bool) -> Self {
1105 self.exclude_limited_upgradable = Some(val);
1106 self
1107 }
1108 pub fn exclude_limited_non_upgradable(mut self, val: bool) -> Self {
1110 self.exclude_limited_non_upgradable = Some(val);
1111 self
1112 }
1113 pub fn exclude_from_blockchain(mut self, val: bool) -> Self {
1115 self.exclude_from_blockchain = Some(val);
1116 self
1117 }
1118 pub fn exclude_unique(mut self, val: bool) -> Self {
1120 self.exclude_unique = Some(val);
1121 self
1122 }
1123 pub fn sort_by_price(mut self, val: bool) -> Self {
1125 self.sort_by_price = Some(val);
1126 self
1127 }
1128 pub fn offset(mut self, val: impl Into<String>) -> Self {
1130 self.offset = Some(val.into());
1131 self
1132 }
1133 pub fn limit(mut self, val: i64) -> Self {
1135 self.limit = Some(val);
1136 self
1137 }
1138
1139 pub async fn send(self) -> Result<owned_gift::OwnedGifts> {
1141 let mut params = vec![RequestParameter::new(
1142 "user_id",
1143 serde_json::to_value(self.user_id)?,
1144 )];
1145 push_opt(&mut params, "exclude_unlimited", &self.exclude_unlimited)?;
1146 push_opt(
1147 &mut params,
1148 "exclude_limited_upgradable",
1149 &self.exclude_limited_upgradable,
1150 )?;
1151 push_opt(
1152 &mut params,
1153 "exclude_limited_non_upgradable",
1154 &self.exclude_limited_non_upgradable,
1155 )?;
1156 push_opt(
1157 &mut params,
1158 "exclude_from_blockchain",
1159 &self.exclude_from_blockchain,
1160 )?;
1161 push_opt(&mut params, "exclude_unique", &self.exclude_unique)?;
1162 push_opt(&mut params, "sort_by_price", &self.sort_by_price)?;
1163 push_opt_str(&mut params, "offset", &self.offset);
1164 push_opt(&mut params, "limit", &self.limit)?;
1165 self.bot.do_api_request("getUserGifts", params).await
1166 }
1167}
1168
1169impl_into_future!(GetUserGiftsBuilder, owned_gift::OwnedGifts);
1170
1171pub struct GetChatGiftsBuilder<'a> {
1177 bot: &'a Bot,
1178 chat_id: ChatId,
1179 exclude_unsaved: Option<bool>,
1180 exclude_saved: Option<bool>,
1181 exclude_unlimited: Option<bool>,
1182 exclude_limited_upgradable: Option<bool>,
1183 exclude_limited_non_upgradable: Option<bool>,
1184 exclude_from_blockchain: Option<bool>,
1185 exclude_unique: Option<bool>,
1186 sort_by_price: Option<bool>,
1187 offset: Option<String>,
1188 limit: Option<i64>,
1189}
1190
1191impl<'a> GetChatGiftsBuilder<'a> {
1192 pub fn exclude_unsaved(mut self, val: bool) -> Self {
1194 self.exclude_unsaved = Some(val);
1195 self
1196 }
1197 pub fn exclude_saved(mut self, val: bool) -> Self {
1199 self.exclude_saved = Some(val);
1200 self
1201 }
1202 pub fn exclude_unlimited(mut self, val: bool) -> Self {
1204 self.exclude_unlimited = Some(val);
1205 self
1206 }
1207 pub fn exclude_limited_upgradable(mut self, val: bool) -> Self {
1209 self.exclude_limited_upgradable = Some(val);
1210 self
1211 }
1212 pub fn exclude_limited_non_upgradable(mut self, val: bool) -> Self {
1214 self.exclude_limited_non_upgradable = Some(val);
1215 self
1216 }
1217 pub fn exclude_from_blockchain(mut self, val: bool) -> Self {
1219 self.exclude_from_blockchain = Some(val);
1220 self
1221 }
1222 pub fn exclude_unique(mut self, val: bool) -> Self {
1224 self.exclude_unique = Some(val);
1225 self
1226 }
1227 pub fn sort_by_price(mut self, val: bool) -> Self {
1229 self.sort_by_price = Some(val);
1230 self
1231 }
1232 pub fn offset(mut self, val: impl Into<String>) -> Self {
1234 self.offset = Some(val.into());
1235 self
1236 }
1237 pub fn limit(mut self, val: i64) -> Self {
1239 self.limit = Some(val);
1240 self
1241 }
1242
1243 pub async fn send(self) -> Result<owned_gift::OwnedGifts> {
1245 let mut params = vec![RequestParameter::new(
1246 "chat_id",
1247 serde_json::to_value(&self.chat_id)?,
1248 )];
1249 push_opt(&mut params, "exclude_unsaved", &self.exclude_unsaved)?;
1250 push_opt(&mut params, "exclude_saved", &self.exclude_saved)?;
1251 push_opt(&mut params, "exclude_unlimited", &self.exclude_unlimited)?;
1252 push_opt(
1253 &mut params,
1254 "exclude_limited_upgradable",
1255 &self.exclude_limited_upgradable,
1256 )?;
1257 push_opt(
1258 &mut params,
1259 "exclude_limited_non_upgradable",
1260 &self.exclude_limited_non_upgradable,
1261 )?;
1262 push_opt(
1263 &mut params,
1264 "exclude_from_blockchain",
1265 &self.exclude_from_blockchain,
1266 )?;
1267 push_opt(&mut params, "exclude_unique", &self.exclude_unique)?;
1268 push_opt(&mut params, "sort_by_price", &self.sort_by_price)?;
1269 push_opt_str(&mut params, "offset", &self.offset);
1270 push_opt(&mut params, "limit", &self.limit)?;
1271 self.bot.do_api_request("getChatGifts", params).await
1272 }
1273}
1274
1275impl_into_future!(GetChatGiftsBuilder, owned_gift::OwnedGifts);
1276
1277impl Bot {
1282 pub fn get_business_connection(
1286 &self,
1287 business_connection_id: impl Into<String>,
1288 ) -> GetBusinessConnectionBuilder<'_> {
1289 GetBusinessConnectionBuilder {
1290 bot: self,
1291 business_connection_id: business_connection_id.into(),
1292 }
1293 }
1294
1295 pub fn get_business_account_gifts(
1297 &self,
1298 business_connection_id: impl Into<String>,
1299 ) -> GetBusinessAccountGiftsBuilder<'_> {
1300 GetBusinessAccountGiftsBuilder {
1301 bot: self,
1302 business_connection_id: business_connection_id.into(),
1303 exclude_unsaved: None,
1304 exclude_saved: None,
1305 exclude_unlimited: None,
1306 exclude_unique: None,
1307 sort_by_price: None,
1308 offset: None,
1309 limit: None,
1310 exclude_limited_upgradable: None,
1311 exclude_limited_non_upgradable: None,
1312 exclude_from_blockchain: None,
1313 }
1314 }
1315
1316 pub fn get_business_account_star_balance(
1318 &self,
1319 business_connection_id: impl Into<String>,
1320 ) -> GetBusinessAccountStarBalanceBuilder<'_> {
1321 GetBusinessAccountStarBalanceBuilder {
1322 bot: self,
1323 business_connection_id: business_connection_id.into(),
1324 }
1325 }
1326
1327 pub fn read_business_message(
1329 &self,
1330 business_connection_id: impl Into<String>,
1331 chat_id: i64,
1332 message_id: i64,
1333 ) -> ReadBusinessMessageBuilder<'_> {
1334 ReadBusinessMessageBuilder {
1335 bot: self,
1336 business_connection_id: business_connection_id.into(),
1337 chat_id,
1338 message_id,
1339 }
1340 }
1341
1342 pub fn delete_business_messages(
1344 &self,
1345 business_connection_id: impl Into<String>,
1346 message_ids: Vec<i64>,
1347 ) -> DeleteBusinessMessagesBuilder<'_> {
1348 DeleteBusinessMessagesBuilder {
1349 bot: self,
1350 business_connection_id: business_connection_id.into(),
1351 message_ids,
1352 }
1353 }
1354
1355 pub fn set_business_account_name(
1357 &self,
1358 business_connection_id: impl Into<String>,
1359 first_name: impl Into<String>,
1360 ) -> SetBusinessAccountNameBuilder<'_> {
1361 SetBusinessAccountNameBuilder {
1362 bot: self,
1363 business_connection_id: business_connection_id.into(),
1364 first_name: first_name.into(),
1365 last_name: None,
1366 }
1367 }
1368
1369 pub fn set_business_account_username(
1371 &self,
1372 business_connection_id: impl Into<String>,
1373 ) -> SetBusinessAccountUsernameBuilder<'_> {
1374 SetBusinessAccountUsernameBuilder {
1375 bot: self,
1376 business_connection_id: business_connection_id.into(),
1377 username: None,
1378 }
1379 }
1380
1381 pub fn set_business_account_bio(
1383 &self,
1384 business_connection_id: impl Into<String>,
1385 ) -> SetBusinessAccountBioBuilder<'_> {
1386 SetBusinessAccountBioBuilder {
1387 bot: self,
1388 business_connection_id: business_connection_id.into(),
1389 bio: None,
1390 }
1391 }
1392
1393 pub fn set_business_account_gift_settings(
1395 &self,
1396 business_connection_id: impl Into<String>,
1397 show_gift_button: bool,
1398 accepted_gift_types: gifts::AcceptedGiftTypes,
1399 ) -> SetBusinessAccountGiftSettingsBuilder<'_> {
1400 SetBusinessAccountGiftSettingsBuilder {
1401 bot: self,
1402 business_connection_id: business_connection_id.into(),
1403 show_gift_button,
1404 accepted_gift_types,
1405 }
1406 }
1407
1408 pub fn set_business_account_profile_photo(
1410 &self,
1411 business_connection_id: impl Into<String>,
1412 photo: serde_json::Value,
1413 ) -> SetBusinessAccountProfilePhotoBuilder<'_> {
1414 SetBusinessAccountProfilePhotoBuilder {
1415 bot: self,
1416 business_connection_id: business_connection_id.into(),
1417 photo,
1418 is_public: None,
1419 }
1420 }
1421
1422 pub fn remove_business_account_profile_photo(
1424 &self,
1425 business_connection_id: impl Into<String>,
1426 ) -> RemoveBusinessAccountProfilePhotoBuilder<'_> {
1427 RemoveBusinessAccountProfilePhotoBuilder {
1428 bot: self,
1429 business_connection_id: business_connection_id.into(),
1430 is_public: None,
1431 }
1432 }
1433
1434 pub fn convert_gift_to_stars(
1436 &self,
1437 business_connection_id: impl Into<String>,
1438 owned_gift_id: impl Into<String>,
1439 ) -> ConvertGiftToStarsBuilder<'_> {
1440 ConvertGiftToStarsBuilder {
1441 bot: self,
1442 business_connection_id: business_connection_id.into(),
1443 owned_gift_id: owned_gift_id.into(),
1444 }
1445 }
1446
1447 pub fn upgrade_gift(
1449 &self,
1450 business_connection_id: impl Into<String>,
1451 owned_gift_id: impl Into<String>,
1452 ) -> UpgradeGiftBuilder<'_> {
1453 UpgradeGiftBuilder {
1454 bot: self,
1455 business_connection_id: business_connection_id.into(),
1456 owned_gift_id: owned_gift_id.into(),
1457 keep_original_details: None,
1458 star_count: None,
1459 }
1460 }
1461
1462 pub fn transfer_gift(
1464 &self,
1465 business_connection_id: impl Into<String>,
1466 owned_gift_id: impl Into<String>,
1467 new_owner_chat_id: i64,
1468 ) -> TransferGiftBuilder<'_> {
1469 TransferGiftBuilder {
1470 bot: self,
1471 business_connection_id: business_connection_id.into(),
1472 owned_gift_id: owned_gift_id.into(),
1473 new_owner_chat_id,
1474 star_count: None,
1475 }
1476 }
1477
1478 pub fn transfer_business_account_stars(
1480 &self,
1481 business_connection_id: impl Into<String>,
1482 star_count: i64,
1483 ) -> TransferBusinessAccountStarsBuilder<'_> {
1484 TransferBusinessAccountStarsBuilder {
1485 bot: self,
1486 business_connection_id: business_connection_id.into(),
1487 star_count,
1488 }
1489 }
1490
1491 pub fn create_invoice_link(
1495 &self,
1496 title: impl Into<String>,
1497 description: impl Into<String>,
1498 payload: impl Into<String>,
1499 currency: impl Into<String>,
1500 prices: Vec<serde_json::Value>,
1501 ) -> CreateInvoiceLinkBuilder<'_> {
1502 CreateInvoiceLinkBuilder {
1503 bot: self,
1504 title: title.into(),
1505 description: description.into(),
1506 payload: payload.into(),
1507 currency: currency.into(),
1508 prices,
1509 provider_token: None,
1510 max_tip_amount: None,
1511 suggested_tip_amounts: None,
1512 provider_data: None,
1513 photo_url: None,
1514 photo_size: None,
1515 photo_width: None,
1516 photo_height: None,
1517 need_name: None,
1518 need_phone_number: None,
1519 need_email: None,
1520 need_shipping_address: None,
1521 send_phone_number_to_provider: None,
1522 send_email_to_provider: None,
1523 is_flexible: None,
1524 subscription_period: None,
1525 business_connection_id: None,
1526 }
1527 }
1528
1529 pub fn edit_user_star_subscription(
1531 &self,
1532 user_id: i64,
1533 telegram_payment_charge_id: impl Into<String>,
1534 is_canceled: bool,
1535 ) -> EditUserStarSubscriptionBuilder<'_> {
1536 EditUserStarSubscriptionBuilder {
1537 bot: self,
1538 user_id,
1539 telegram_payment_charge_id: telegram_payment_charge_id.into(),
1540 is_canceled,
1541 }
1542 }
1543
1544 pub fn get_my_star_balance(&self) -> GetMyStarBalanceBuilder<'_> {
1546 GetMyStarBalanceBuilder { bot: self }
1547 }
1548
1549 pub fn get_star_transactions(&self) -> GetStarTransactionsBuilder<'_> {
1551 GetStarTransactionsBuilder {
1552 bot: self,
1553 offset: None,
1554 limit: None,
1555 }
1556 }
1557
1558 pub fn refund_star_payment(
1560 &self,
1561 user_id: i64,
1562 telegram_payment_charge_id: impl Into<String>,
1563 ) -> RefundStarPaymentBuilder<'_> {
1564 RefundStarPaymentBuilder {
1565 bot: self,
1566 user_id,
1567 telegram_payment_charge_id: telegram_payment_charge_id.into(),
1568 }
1569 }
1570
1571 pub fn get_available_gifts(&self) -> GetAvailableGiftsBuilder<'_> {
1575 GetAvailableGiftsBuilder { bot: self }
1576 }
1577
1578 pub fn send_gift(&self, gift_id: impl Into<String>) -> SendGiftBuilder<'_> {
1580 SendGiftBuilder {
1581 bot: self,
1582 gift_id: gift_id.into(),
1583 user_id: None,
1584 chat_id: None,
1585 text: None,
1586 text_parse_mode: None,
1587 text_entities: None,
1588 pay_for_upgrade: None,
1589 }
1590 }
1591
1592 pub fn gift_premium_subscription(
1594 &self,
1595 user_id: i64,
1596 month_count: i64,
1597 star_count: i64,
1598 ) -> GiftPremiumSubscriptionBuilder<'_> {
1599 GiftPremiumSubscriptionBuilder {
1600 bot: self,
1601 user_id,
1602 month_count,
1603 star_count,
1604 text: None,
1605 text_parse_mode: None,
1606 text_entities: None,
1607 }
1608 }
1609
1610 pub fn get_user_gifts(&self, user_id: i64) -> GetUserGiftsBuilder<'_> {
1612 GetUserGiftsBuilder {
1613 bot: self,
1614 user_id,
1615 exclude_unlimited: None,
1616 exclude_limited_upgradable: None,
1617 exclude_limited_non_upgradable: None,
1618 exclude_from_blockchain: None,
1619 exclude_unique: None,
1620 sort_by_price: None,
1621 offset: None,
1622 limit: None,
1623 }
1624 }
1625
1626 pub fn get_chat_gifts(&self, chat_id: impl Into<ChatId>) -> GetChatGiftsBuilder<'_> {
1628 GetChatGiftsBuilder {
1629 bot: self,
1630 chat_id: chat_id.into(),
1631 exclude_unsaved: None,
1632 exclude_saved: None,
1633 exclude_unlimited: None,
1634 exclude_limited_upgradable: None,
1635 exclude_limited_non_upgradable: None,
1636 exclude_from_blockchain: None,
1637 exclude_unique: None,
1638 sort_by_price: None,
1639 offset: None,
1640 limit: None,
1641 }
1642 }
1643}