tgbot/types/definitions/message/methods.rs
1use serde::Serialize;
2
3use crate::{
4 api::{Form, Method, Payload},
5 types::{
6 ChatId,
7 EditMessageResult,
8 Float,
9 InlineKeyboardError,
10 InlineKeyboardMarkup,
11 InputMedia,
12 Integer,
13 LinkPreviewOptions,
14 Message,
15 MessageId,
16 ParseMode,
17 ReplyMarkup,
18 ReplyParameters,
19 SuggestedPostParameters,
20 TextEntities,
21 TextEntity,
22 },
23};
24
25/// Copies a message.
26///
27/// Service messages, paid media messages, giveaway messages, giveaway winners messages,
28/// and invoice messages can't be copied.
29/// A quiz poll can be copied only if the value of the field `correct_option_id` is known to the bot.
30/// The method is analogous to the method [`ForwardMessage`],
31/// but the copied message doesn't have a link to the original message.
32#[serde_with::skip_serializing_none]
33#[derive(Clone, Debug, Serialize)]
34pub struct CopyMessage {
35 chat_id: ChatId,
36 from_chat_id: ChatId,
37 message_id: Integer,
38 allow_paid_broadcast: Option<bool>,
39 caption: Option<String>,
40 caption_entities: Option<TextEntities>,
41 direct_messages_topic_id: Option<Integer>,
42 disable_notification: Option<bool>,
43 message_effect_id: Option<String>,
44 message_thread_id: Option<Integer>,
45 parse_mode: Option<ParseMode>,
46 protect_content: Option<bool>,
47 reply_markup: Option<ReplyMarkup>,
48 reply_parameters: Option<ReplyParameters>,
49 show_caption_above_media: Option<bool>,
50 suggested_post_parameters: Option<SuggestedPostParameters>,
51 video_start_timestamp: Option<Integer>,
52}
53
54impl CopyMessage {
55 /// Creates a new `CopyMessage`.
56 ///
57 /// # Arguments
58 ///
59 /// * `chat_id` - Unique identifier of the target chat.
60 /// * `from_chat_id` - Unique identifier of the chat where the original message was sent.
61 /// * `message_id` - Message identifier in the chat specified in `from_chat_id`.
62 pub fn new<A, B>(chat_id: A, from_chat_id: B, message_id: Integer) -> Self
63 where
64 A: Into<ChatId>,
65 B: Into<ChatId>,
66 {
67 Self {
68 chat_id: chat_id.into(),
69 from_chat_id: from_chat_id.into(),
70 message_id,
71 allow_paid_broadcast: None,
72 caption: None,
73 caption_entities: None,
74 direct_messages_topic_id: None,
75 disable_notification: None,
76 message_effect_id: None,
77 message_thread_id: None,
78 parse_mode: None,
79 protect_content: None,
80 reply_markup: None,
81 reply_parameters: None,
82 show_caption_above_media: None,
83 suggested_post_parameters: None,
84 video_start_timestamp: None,
85 }
86 }
87
88 /// Sets a new value for the `allow_paid_broadcast` flag.
89 ///
90 /// # Arguments
91 ///
92 /// * `value` - Whether to allow up to 1000 messages per second, ignoring broadcasting limits
93 /// for a fee of 0.1 Telegram Stars per message.
94 /// The relevant Stars will be withdrawn from the bot's balance.
95 pub fn with_allow_paid_broadcast(mut self, value: bool) -> Self {
96 self.allow_paid_broadcast = Some(value);
97 self
98 }
99
100 /// Sets a new caption.
101 ///
102 /// # Arguments
103 ///
104 /// * `value` - Caption; 0-1024 characters after entities parsing.
105 ///
106 /// If not specified, the original caption is kept.
107 pub fn with_caption<T>(mut self, value: T) -> Self
108 where
109 T: Into<String>,
110 {
111 self.caption = Some(value.into());
112 self
113 }
114
115 /// Sets a new list of caption entities.
116 ///
117 /// # Arguments
118 ///
119 /// * `value` - The list of special entities that appear in the caption.
120 ///
121 /// Caption parse mode will be set to [`None`] when this method is called.
122 pub fn with_caption_entities<T>(mut self, value: T) -> Self
123 where
124 T: IntoIterator<Item = TextEntity>,
125 {
126 self.caption_entities = Some(value.into_iter().collect());
127 self.parse_mode = None;
128 self
129 }
130
131 /// Sets a new caption parse mode.
132 ///
133 /// # Arguments
134 ///
135 /// * `value` - Parse mode.
136 ///
137 /// Caption entities will be set to [`None`] when this method is called.
138 pub fn with_caption_parse_mode(mut self, value: ParseMode) -> Self {
139 self.parse_mode = Some(value);
140 self.caption_entities = None;
141 self
142 }
143
144 /// Sets a new direct messages topic ID
145 ///
146 /// * `value` - Identifier of the direct messages topic to which the message will be sent.
147 ///
148 /// Required if the message is sent to a direct messages chat.
149 pub fn with_direct_messages_topic_id(mut self, value: Integer) -> Self {
150 self.direct_messages_topic_id = Some(value);
151 self
152 }
153
154 /// Sets a new value for the `disable_notification` flag.
155 ///
156 /// # Arguments
157 ///
158 /// * `value` - Indicates whether to send the message silently or not;
159 /// a user will receive a notification without sound.
160 pub fn with_disable_notification(mut self, value: bool) -> Self {
161 self.disable_notification = Some(value);
162 self
163 }
164
165 /// Sets a new message effect ID.
166 ///
167 /// # Arguments
168 ///
169 /// * `value` - Unique identifier of the message effect to be added to the message;
170 /// only available when forwarding to private chats.
171 pub fn with_message_effect_id<T>(mut self, value: T) -> Self
172 where
173 T: Into<String>,
174 {
175 self.message_effect_id = Some(value.into());
176 self
177 }
178
179 /// Sets a new message thread ID.
180 ///
181 /// # Arguments
182 ///
183 /// * `value` - Unique identifier of the target message thread;
184 /// for forum supergroups and private chats of bots with forum topic mode enabled only.
185 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
186 self.message_thread_id = Some(value);
187 self
188 }
189
190 /// Sets a new value for the `protect_content` flag.
191 ///
192 /// # Arguments
193 ///
194 /// * `value` - Indicates whether to protect the contents
195 /// of the sent message from forwarding and saving.
196 pub fn with_protect_content(mut self, value: bool) -> Self {
197 self.protect_content = Some(value);
198 self
199 }
200
201 /// Sets a new reply markup.
202 ///
203 /// # Arguments
204 ///
205 /// * `value` - Reply markup.
206 pub fn with_reply_markup<T>(mut self, value: T) -> Self
207 where
208 T: Into<ReplyMarkup>,
209 {
210 self.reply_markup = Some(value.into());
211 self
212 }
213
214 /// Sets new reply parameters.
215 ///
216 /// # Arguments
217 ///
218 /// * `value` - Description of the message to reply to.
219 pub fn with_reply_parameters(mut self, value: ReplyParameters) -> Self {
220 self.reply_parameters = Some(value);
221 self
222 }
223
224 /// Sets a new value for the `show_caption_above_media` flag.
225 ///
226 /// # Arguments
227 ///
228 /// `value` - Whether the caption must be shown above the message media;
229 /// ignored if a new caption isn't specified.
230 pub fn with_show_caption_above_media(mut self, value: bool) -> Self {
231 self.show_caption_above_media = Some(value);
232 self
233 }
234
235 /// Sets a new suggested post parameters.
236 ///
237 /// # Arguments
238 ///
239 /// * `value` - An object containing the parameters of the suggested post to send.
240 ///
241 /// For direct messages chats only.
242 ///
243 /// If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
244 pub fn with_suggested_post_parameters(mut self, value: SuggestedPostParameters) -> Self {
245 self.suggested_post_parameters = Some(value);
246 self
247 }
248
249 /// Sets a new video start timestamp.
250 ///
251 /// # Arguments
252 ///
253 /// * `value` - New start timestamp for the copied video in the message.
254 pub fn with_video_start_timestamp(mut self, value: Integer) -> Self {
255 self.video_start_timestamp = Some(value);
256 self
257 }
258}
259
260impl Method for CopyMessage {
261 type Response = MessageId;
262
263 fn into_payload(self) -> Payload {
264 Payload::json("copyMessage", self)
265 }
266}
267
268/// Copies messages of any kind.
269///
270/// If some of the specified messages can't be found or copied, they are skipped.
271/// Service messages, paid media messages, giveaway messages, giveaway winners messages,
272/// and invoice messages can't be copied.
273/// A quiz poll can be copied only if the value of the field `correct_option_id` is known to the bot.
274/// The method is analogous to the method [`ForwardMessages`],
275/// but the copied messages don't have a link to the original message.
276/// Album grouping is kept for copied messages.
277#[serde_with::skip_serializing_none]
278#[derive(Clone, Debug, Serialize)]
279pub struct CopyMessages {
280 chat_id: ChatId,
281 from_chat_id: ChatId,
282 message_ids: Vec<Integer>,
283 direct_messages_topic_id: Option<Integer>,
284 disable_notification: Option<bool>,
285 message_thread_id: Option<Integer>,
286 protect_content: Option<bool>,
287 remove_caption: Option<bool>,
288}
289
290impl CopyMessages {
291 /// Creates a new `CopyMessages`.
292 ///
293 /// # Arguments
294 ///
295 /// * `chat_id` - Unique identifier for the target chat.
296 /// * `from_chat_id` - Unique identifier for the chat where the original messages were sent.
297 /// * `message_ids` - Identifiers of 1-100 messages in the chat from_chat_id to copy;
298 /// the identifiers must be specified in a strictly increasing order.
299 pub fn new<A, B, C>(chat_id: A, from_chat_id: B, message_ids: C) -> Self
300 where
301 A: Into<ChatId>,
302 B: Into<ChatId>,
303 C: IntoIterator<Item = Integer>,
304 {
305 Self {
306 chat_id: chat_id.into(),
307 from_chat_id: from_chat_id.into(),
308 message_ids: message_ids.into_iter().collect(),
309 direct_messages_topic_id: None,
310 disable_notification: None,
311 message_thread_id: None,
312 protect_content: None,
313 remove_caption: None,
314 }
315 }
316
317 /// Sets a new direct messages topic ID
318 ///
319 /// * `value` - Identifier of the direct messages topic to which the message will be sent.
320 ///
321 /// Required if the message is sent to a direct messages chat.
322 pub fn with_direct_messages_topic_id(mut self, value: Integer) -> Self {
323 self.direct_messages_topic_id = Some(value);
324 self
325 }
326
327 /// Sets a new value for the `disable_notification` flag.
328 ///
329 /// # Arguments
330 ///
331 /// * `value` - Indicates whether to send the message silently or not;
332 /// a user will receive a notification without sound.
333 pub fn with_disable_notification(mut self, value: bool) -> Self {
334 self.disable_notification = Some(value);
335 self
336 }
337
338 /// Sets a new message thread ID.
339 ///
340 /// # Arguments
341 ///
342 /// * `value` - Unique identifier of the target message thread;
343 /// for forum supergroups and private chats of bots with forum topic mode enabled only.
344 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
345 self.message_thread_id = Some(value);
346 self
347 }
348
349 /// Sets a new value for the `protect_content` flag.
350 ///
351 /// # Arguments
352 ///
353 /// * `value` - Indicates whether to protect the contents
354 /// of the sent message from forwarding and saving.
355 pub fn with_protect_content(mut self, value: bool) -> Self {
356 self.protect_content = Some(value);
357 self
358 }
359
360 /// Sets a new value for the `remove_caption` flag.
361 ///
362 /// # Arguments
363 ///
364 /// * `value` - Indicates whether to copy the messages without their captions.
365 pub fn with_remove_caption(mut self, value: bool) -> Self {
366 self.remove_caption = Some(value);
367 self
368 }
369}
370
371impl Method for CopyMessages {
372 type Response = Vec<MessageId>;
373
374 fn into_payload(self) -> Payload {
375 Payload::json("copyMessages", self)
376 }
377}
378
379/// Deletes a message.
380///
381/// Limitations:
382///
383/// - A message can only be deleted if it was sent less than 48 hours ago.
384/// - Service messages about a supergroup, channel, or forum topic creation can't be deleted.
385/// - A dice message in a private chat can only be deleted if it was sent more than 24 hours ago.
386/// - Bots can delete outgoing messages in private chats, groups, and supergroups.
387/// - Bots can delete incoming messages in private chats.
388/// - Bots granted can_post_messages permissions can delete outgoing messages in channels.
389/// - If the bot is an administrator of a group, it can delete any message there.
390/// - If the bot has `can_delete_messages` permission in a supergroup or a channel,
391/// it can delete any message there.
392#[derive(Clone, Debug, Serialize)]
393pub struct DeleteMessage {
394 chat_id: ChatId,
395 message_id: Integer,
396}
397
398impl DeleteMessage {
399 /// Creates a new `DeleteMessage`.
400 ///
401 /// # Arguments
402 ///
403 /// * `chat_id` - Unique identifier of the target chat.
404 /// * `message_id` - Identifier of the message to delete.
405 pub fn new<T>(chat_id: T, message_id: Integer) -> Self
406 where
407 T: Into<ChatId>,
408 {
409 Self {
410 chat_id: chat_id.into(),
411 message_id,
412 }
413 }
414}
415
416impl Method for DeleteMessage {
417 type Response = bool;
418
419 fn into_payload(self) -> Payload {
420 Payload::json("deleteMessage", self)
421 }
422}
423
424/// Deletes multiple messages simultaneously.
425///
426/// If some of the specified messages can't be found, they are skipped.
427///
428/// See [`DeleteMessage`] for limitations on which messages can be deleted.
429#[derive(Clone, Debug, Serialize)]
430pub struct DeleteMessages {
431 chat_id: ChatId,
432 message_ids: Vec<Integer>,
433}
434
435impl DeleteMessages {
436 /// Creates a new `DeleteMessages`.
437 ///
438 /// # Arguments
439 ///
440 /// * `chat_id` - Unique identifier of the target chat.
441 /// * `message_ids` - Identifiers of 1-100 messages to delete.
442 pub fn new<A, B>(chat_id: A, message_ids: B) -> Self
443 where
444 A: Into<ChatId>,
445 B: IntoIterator<Item = Integer>,
446 {
447 Self {
448 chat_id: chat_id.into(),
449 message_ids: message_ids.into_iter().collect(),
450 }
451 }
452}
453
454impl Method for DeleteMessages {
455 type Response = bool;
456
457 fn into_payload(self) -> Payload {
458 Payload::json("deleteMessages", self)
459 }
460}
461
462/// Changes a caption of a message.
463#[serde_with::skip_serializing_none]
464#[derive(Clone, Debug, Serialize)]
465pub struct EditMessageCaption {
466 business_connection_id: Option<String>,
467 caption: Option<String>,
468 caption_entities: Option<TextEntities>,
469 chat_id: Option<ChatId>,
470 inline_message_id: Option<String>,
471 message_id: Option<Integer>,
472 parse_mode: Option<ParseMode>,
473 reply_markup: Option<InlineKeyboardMarkup>,
474 show_caption_above_media: Option<bool>,
475}
476
477impl EditMessageCaption {
478 /// Creates a new `EditMessageCaption` for a chat message.
479 ///
480 /// # Arguments
481 ///
482 /// * `chat_id` - Unique identifier of the target chat.
483 /// * `message_id` - Identifier of the sent message.
484 pub fn for_chat_message<T>(chat_id: T, message_id: Integer) -> Self
485 where
486 T: Into<ChatId>,
487 {
488 Self {
489 business_connection_id: None,
490 caption: None,
491 caption_entities: None,
492 chat_id: Some(chat_id.into()),
493 inline_message_id: None,
494 message_id: Some(message_id),
495 parse_mode: None,
496 reply_markup: None,
497 show_caption_above_media: None,
498 }
499 }
500
501 /// Creates a new `EditMessageCaption` for an inline message.
502 ///
503 /// # Arguments
504 ///
505 /// * `inline_message_id` - Identifier of the inline message.
506 pub fn for_inline_message<T>(inline_message_id: T) -> Self
507 where
508 T: Into<String>,
509 {
510 Self {
511 business_connection_id: None,
512 caption: None,
513 caption_entities: None,
514 chat_id: None,
515 inline_message_id: Some(inline_message_id.into()),
516 message_id: None,
517 parse_mode: None,
518 reply_markup: None,
519 show_caption_above_media: None,
520 }
521 }
522
523 /// Sets a new business connection ID.
524 ///
525 /// # Arguments
526 ///
527 /// * `value` - Unique identifier of the business connection on behalf of which the message to be edited was sent.
528 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
529 where
530 T: Into<String>,
531 {
532 self.business_connection_id = Some(value.into());
533 self
534 }
535
536 /// Sets a new caption.
537 ///
538 /// # Arguments
539 ///
540 /// * `value` - Caption; 0-1024 characters.
541 pub fn with_caption<T>(mut self, value: T) -> Self
542 where
543 T: Into<String>,
544 {
545 self.caption = Some(value.into());
546 self
547 }
548
549 /// Sets a new list of caption entities.
550 ///
551 /// # Arguments
552 ///
553 /// * `value` - The list of special entities that appear in the caption.
554 ///
555 /// Caption parse mode will be set to [`None`] when this method is called.
556 pub fn with_caption_entities<T>(mut self, value: T) -> Self
557 where
558 T: IntoIterator<Item = TextEntity>,
559 {
560 self.caption_entities = Some(value.into_iter().collect());
561 self.parse_mode = None;
562 self
563 }
564
565 /// Sets a new caption parse mode.
566 ///
567 /// # Arguments
568 ///
569 /// * `value` - Parse mode.
570 ///
571 /// Caption entities will be set to [`None`] when this method is called.
572 pub fn with_caption_parse_mode(mut self, value: ParseMode) -> Self {
573 self.parse_mode = Some(value);
574 self.caption_entities = None;
575 self
576 }
577
578 /// Sets a new reply markup.
579 ///
580 /// # Arguments
581 ///
582 /// * `value` - Reply markup.
583 pub fn with_reply_markup<T>(mut self, value: T) -> Self
584 where
585 T: Into<InlineKeyboardMarkup>,
586 {
587 self.reply_markup = Some(value.into());
588 self
589 }
590
591 /// Sets a new value for the `show_caption_above_media` flag.
592 ///
593 /// # Arguments
594 ///
595 /// `value` - Whether the caption must be shown above the message media;
596 /// supported only for animation, photo and video messages.
597 pub fn with_show_caption_above_media(mut self, value: bool) -> Self {
598 self.show_caption_above_media = Some(value);
599 self
600 }
601}
602
603impl Method for EditMessageCaption {
604 type Response = EditMessageResult;
605
606 fn into_payload(self) -> Payload {
607 Payload::json("editMessageCaption", self)
608 }
609}
610
611/// Changes a live location message.
612///
613/// A location can be edited until its `live_period` expires or editing
614/// is explicitly disabled by a call to [`StopMessageLiveLocation`].
615#[serde_with::skip_serializing_none]
616#[derive(Clone, Debug, Serialize)]
617pub struct EditMessageLiveLocation {
618 latitude: Float,
619 longitude: Float,
620 business_connection_id: Option<String>,
621 chat_id: Option<ChatId>,
622 heading: Option<Integer>,
623 horizontal_accuracy: Option<Float>,
624 inline_message_id: Option<String>,
625 live_period: Option<Integer>,
626 message_id: Option<Integer>,
627 proximity_alert_radius: Option<Integer>,
628 reply_markup: Option<InlineKeyboardMarkup>,
629}
630
631impl EditMessageLiveLocation {
632 /// Creates a new `EditMessageLiveLocation` for a chat message.
633 ///
634 /// # Arguments
635 ///
636 /// * `chat_id` - Unique identifier of the target chat.
637 /// * `message_id` - Identifier of the sent message.
638 /// * `latitude` - Latitude of new location.
639 /// * `longitude` Longitude of new location.
640 pub fn for_chat_message<T>(chat_id: T, message_id: Integer, latitude: Float, longitude: Float) -> Self
641 where
642 T: Into<ChatId>,
643 {
644 Self {
645 latitude,
646 longitude,
647 business_connection_id: None,
648 chat_id: Some(chat_id.into()),
649 inline_message_id: None,
650 live_period: None,
651 heading: None,
652 horizontal_accuracy: None,
653 message_id: Some(message_id),
654 proximity_alert_radius: None,
655 reply_markup: None,
656 }
657 }
658
659 /// Creates a new `EditMessageLiveLocation` for an inline message.
660 ///
661 /// # Arguments
662 ///
663 /// * `inline_message_id` - Identifier of the inline message.
664 /// * `latitude` - Latitude of new location.
665 /// * `longitude` - Longitude of new location.
666 pub fn for_inline_message<T>(inline_message_id: T, latitude: Float, longitude: Float) -> Self
667 where
668 T: Into<String>,
669 {
670 Self {
671 latitude,
672 longitude,
673 business_connection_id: None,
674 chat_id: None,
675 heading: None,
676 horizontal_accuracy: None,
677 inline_message_id: Some(inline_message_id.into()),
678 live_period: None,
679 message_id: None,
680 proximity_alert_radius: None,
681 reply_markup: None,
682 }
683 }
684
685 /// Sets a new business connection ID.
686 ///
687 /// # Arguments
688 ///
689 /// * `value` - Unique identifier of the business connection on behalf of which the message to be edited was sent.
690 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
691 where
692 T: Into<String>,
693 {
694 self.business_connection_id = Some(value.into());
695 self
696 }
697
698 /// Sets a new horizontal accuracy.
699 ///
700 /// # Arguments
701 ///
702 /// * `value` - A radius of uncertainty for the location; in meters; 0-1500.
703 pub fn with_horizontal_accuracy(mut self, value: Float) -> Self {
704 self.horizontal_accuracy = Some(value);
705 self
706 }
707
708 /// Sets a new heading.
709 ///
710 /// # Arguments
711 ///
712 /// * `value` - A direction in which the user is moving; in degrees; 1-360.
713 pub fn with_heading(mut self, value: Integer) -> Self {
714 self.heading = Some(value);
715 self
716 }
717
718 /// Sets a new live period
719 ///
720 /// # Arguments
721 ///
722 /// * `value` - New period in seconds during which the location can be updated,
723 /// starting from the message send date.
724 /// If 0x7FFFFFFF is specified, then the location can be updated forever.
725 /// Otherwise, the new value must not exceed the current live_period by more than a day,
726 /// and the live location expiration date must remain within the next 90 days.
727 /// If not specified, then live_period remains unchanged
728 pub fn with_live_period(mut self, value: Integer) -> Self {
729 self.live_period = Some(value);
730 self
731 }
732
733 /// Sets a new proximity alert radius.
734 ///
735 /// # Arguments
736 ///
737 /// * `value` - A maximum distance for proximity alerts
738 /// about approaching another chat member; in meters; 1-100000.
739 pub fn with_proximity_alert_radius(mut self, value: Integer) -> Self {
740 self.proximity_alert_radius = Some(value);
741 self
742 }
743
744 /// Sets a new reply markup.
745 ///
746 /// # Arguments
747 ///
748 /// * `value` - Reply markup.
749 pub fn with_reply_markup<T>(mut self, value: T) -> Self
750 where
751 T: Into<InlineKeyboardMarkup>,
752 {
753 self.reply_markup = Some(value.into());
754 self
755 }
756}
757
758impl Method for EditMessageLiveLocation {
759 type Response = EditMessageResult;
760
761 fn into_payload(self) -> Payload {
762 Payload::json("editMessageLiveLocation", self)
763 }
764}
765
766/// Changes animation, audio, document, photo, or video message.
767///
768/// If a message is part of a message album, then it can be edited only
769/// to an audio for audio albums, only to a document for document albums
770/// and to a photo or a video otherwise.
771/// When an inline message is edited, a new file can't be uploaded;
772/// use a previously uploaded file via its file_id or specify a URL.
773#[derive(Debug)]
774pub struct EditMessageMedia {
775 form: Form,
776}
777
778impl EditMessageMedia {
779 /// Creates a new `EditMessageMedia` for a chat message.
780 ///
781 /// # Arguments
782 ///
783 /// * `chat_id` - Unique identifier of the target chat.
784 /// * `message_id` - Identifier of the sent message.
785 /// * `media` - New media content of the message.
786 pub fn for_chat_message<T>(chat_id: T, message_id: Integer, media: InputMedia) -> Self
787 where
788 T: Into<ChatId>,
789 {
790 let mut form: Form = media.into();
791 form.insert_field("chat_id", chat_id.into());
792 form.insert_field("message_id", message_id);
793 Self { form }
794 }
795
796 /// Creates a new `EditMessageMedia` for an inline message.
797 ///
798 /// # Arguments
799 ///
800 /// * `inline_message_id` - Identifier of the inline message.
801 /// * `media` - New media content of the message.
802 pub fn for_inline_message<T>(inline_message_id: T, media: InputMedia) -> Self
803 where
804 T: Into<String>,
805 {
806 let mut form: Form = media.into();
807 form.insert_field("inline_message_id", inline_message_id.into());
808 EditMessageMedia { form }
809 }
810
811 /// Sets a new business connection ID.
812 ///
813 /// # Arguments
814 ///
815 /// * `value` - Unique identifier of the business connection on behalf of which the message to be edited was sent.
816 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
817 where
818 T: Into<String>,
819 {
820 self.form.insert_field("business_connection_id", value.into());
821 self
822 }
823
824 /// Sets a new reply markup.
825 ///
826 /// # Arguments
827 ///
828 /// * `value` - Reply markup.
829 pub fn with_reply_markup<T>(mut self, value: T) -> Result<Self, InlineKeyboardError>
830 where
831 T: Into<InlineKeyboardMarkup>,
832 {
833 let reply_markup = value.into().serialize()?;
834 self.form.insert_field("reply_markup", reply_markup);
835 Ok(self)
836 }
837}
838
839impl Method for EditMessageMedia {
840 type Response = EditMessageResult;
841
842 fn into_payload(self) -> Payload {
843 Payload::form("editMessageMedia", self.form)
844 }
845}
846
847/// Changes the reply markup of a message.
848#[serde_with::skip_serializing_none]
849#[derive(Clone, Debug, Serialize)]
850pub struct EditMessageReplyMarkup {
851 business_connection_id: Option<String>,
852 chat_id: Option<ChatId>,
853 inline_message_id: Option<String>,
854 message_id: Option<Integer>,
855 reply_markup: Option<InlineKeyboardMarkup>,
856}
857
858impl EditMessageReplyMarkup {
859 /// Creates a new `EditMessageReplyMarkup` for a chat message.
860 ///
861 /// # Arguments
862 ///
863 /// * `chat_id` - Unique identifier of the target chat.
864 /// * `message_id` - Identifier of the sent message.
865 pub fn for_chat_message<T>(chat_id: T, message_id: Integer) -> Self
866 where
867 T: Into<ChatId>,
868 {
869 Self {
870 business_connection_id: None,
871 chat_id: Some(chat_id.into()),
872 inline_message_id: None,
873 message_id: Some(message_id),
874 reply_markup: None,
875 }
876 }
877
878 /// Creates a new `EditMessageReplyMarkup` for an inline message.
879 ///
880 /// # Arguments
881 ///
882 /// * `inline_message_id` - Identifier of the inline message.
883 pub fn for_inline_message<T>(inline_message_id: T) -> Self
884 where
885 T: Into<String>,
886 {
887 Self {
888 business_connection_id: None,
889 chat_id: None,
890 inline_message_id: Some(inline_message_id.into()),
891 message_id: None,
892 reply_markup: None,
893 }
894 }
895
896 /// Sets a new business connection ID.
897 ///
898 /// # Arguments
899 ///
900 /// * `value` - Unique identifier of the business connection on behalf of which the message to be edited was sent.
901 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
902 where
903 T: Into<String>,
904 {
905 self.business_connection_id = Some(value.into());
906 self
907 }
908
909 /// Sets a new reply markup.
910 ///
911 /// # Arguments
912 ///
913 /// * `value` - Reply markup.
914 pub fn with_reply_markup<T>(mut self, value: T) -> Self
915 where
916 T: Into<InlineKeyboardMarkup>,
917 {
918 self.reply_markup = Some(value.into());
919 self
920 }
921}
922
923impl Method for EditMessageReplyMarkup {
924 type Response = EditMessageResult;
925
926 fn into_payload(self) -> Payload {
927 Payload::json("editMessageReplyMarkup", self)
928 }
929}
930
931/// Changes a text or a game message.
932#[serde_with::skip_serializing_none]
933#[derive(Clone, Debug, Serialize)]
934pub struct EditMessageText {
935 text: String,
936 business_connection_id: Option<String>,
937 chat_id: Option<ChatId>,
938 entities: Option<TextEntities>,
939 link_preview_options: Option<LinkPreviewOptions>,
940 inline_message_id: Option<String>,
941 message_id: Option<Integer>,
942 parse_mode: Option<ParseMode>,
943 reply_markup: Option<InlineKeyboardMarkup>,
944}
945
946impl EditMessageText {
947 /// Creates a new `EditMessageText` for a chat message.
948 ///
949 /// # Arguments
950 ///
951 /// * `chat_id` - Unique identifier of the target chat.
952 /// * `message_id` - Identifier of the sent message.
953 /// * `text` - New text of the message.
954 pub fn for_chat_message<A, B>(chat_id: A, message_id: Integer, text: B) -> Self
955 where
956 A: Into<ChatId>,
957 B: Into<String>,
958 {
959 Self {
960 text: text.into(),
961 business_connection_id: None,
962 chat_id: Some(chat_id.into()),
963 link_preview_options: None,
964 entities: None,
965 inline_message_id: None,
966 message_id: Some(message_id),
967 parse_mode: None,
968 reply_markup: None,
969 }
970 }
971
972 /// Creates a new `EditMessageText` for an inline message.
973 ///
974 /// # Arguments
975 ///
976 /// * `inline_message_id` - Identifier of the inline message.
977 /// * `text` - New text of the message.
978 pub fn for_inline_message<A, B>(inline_message_id: A, text: B) -> Self
979 where
980 A: Into<String>,
981 B: Into<String>,
982 {
983 Self {
984 text: text.into(),
985 business_connection_id: None,
986 chat_id: None,
987 link_preview_options: None,
988 entities: None,
989 inline_message_id: Some(inline_message_id.into()),
990 message_id: None,
991 parse_mode: None,
992 reply_markup: None,
993 }
994 }
995
996 /// Sets a new business connection ID.
997 ///
998 /// # Arguments
999 ///
1000 /// * `value` - Unique identifier of the business connection on behalf of which the message to be edited was sent.
1001 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
1002 where
1003 T: Into<String>,
1004 {
1005 self.business_connection_id = Some(value.into());
1006 self
1007 }
1008
1009 /// Sets a new list of entities
1010 ///
1011 /// # Arguments
1012 ///
1013 /// * `value` - List of special entities that appear in the text.
1014 ///
1015 /// Parse mode will be set to [`None`] when this method is called.
1016 pub fn with_entities<T>(mut self, value: T) -> Self
1017 where
1018 T: IntoIterator<Item = TextEntity>,
1019 {
1020 self.entities = Some(value.into_iter().collect());
1021 self.parse_mode = None;
1022 self
1023 }
1024
1025 /// Sets a new link preview options.
1026 ///
1027 /// # Arguments
1028 ///
1029 /// * `value` - Link preview generation options for the message.
1030 pub fn with_link_preview_options(mut self, value: LinkPreviewOptions) -> Self {
1031 self.link_preview_options = Some(value);
1032 self
1033 }
1034
1035 /// Sets a new parse mode.
1036 ///
1037 /// # Arguments
1038 ///
1039 /// * `value` - Parse mode.
1040 ///
1041 /// Entities will be set to [`None`] when this method is called.
1042 pub fn with_parse_mode(mut self, value: ParseMode) -> Self {
1043 self.parse_mode = Some(value);
1044 self.entities = None;
1045 self
1046 }
1047
1048 /// Sets a new reply markup.
1049 ///
1050 /// # Arguments
1051 ///
1052 /// * `value` - Reply markup.
1053 pub fn with_reply_markup<T>(mut self, value: T) -> Self
1054 where
1055 T: Into<InlineKeyboardMarkup>,
1056 {
1057 self.reply_markup = Some(value.into());
1058 self
1059 }
1060}
1061
1062impl Method for EditMessageText {
1063 type Response = EditMessageResult;
1064
1065 fn into_payload(self) -> Payload {
1066 Payload::json("editMessageText", self)
1067 }
1068}
1069
1070/// Forwards a message.
1071#[serde_with::skip_serializing_none]
1072#[derive(Clone, Debug, Serialize)]
1073pub struct ForwardMessage {
1074 chat_id: ChatId,
1075 from_chat_id: ChatId,
1076 message_id: Integer,
1077 direct_messages_topic_id: Option<Integer>,
1078 disable_notification: Option<bool>,
1079 protect_content: Option<bool>,
1080 message_effect_id: Option<String>,
1081 message_thread_id: Option<Integer>,
1082 suggested_post_parameters: Option<SuggestedPostParameters>,
1083 video_start_timestamp: Option<Integer>,
1084}
1085
1086impl ForwardMessage {
1087 /// Creates a new `ForwardMessage`.
1088 ///
1089 /// # Arguments
1090 ///
1091 /// * `chat_id` - Unique identifier of the target chat.
1092 /// * `from_chat_id` - Unique identifier for the chat where the original message was sent.
1093 /// * `message_id` - Message identifier in the chat specified in `from_chat_id`.
1094 pub fn new<A, B>(chat_id: A, from_chat_id: B, message_id: Integer) -> Self
1095 where
1096 A: Into<ChatId>,
1097 B: Into<ChatId>,
1098 {
1099 Self {
1100 chat_id: chat_id.into(),
1101 from_chat_id: from_chat_id.into(),
1102 message_id,
1103 direct_messages_topic_id: None,
1104 disable_notification: None,
1105 protect_content: None,
1106 message_effect_id: None,
1107 message_thread_id: None,
1108 suggested_post_parameters: None,
1109 video_start_timestamp: None,
1110 }
1111 }
1112
1113 /// Sets a new direct messages topic ID
1114 ///
1115 /// * `value` - Identifier of the direct messages topic to which the message will be sent.
1116 ///
1117 /// Required if the message is sent to a direct messages chat.
1118 pub fn with_direct_messages_topic_id(mut self, value: Integer) -> Self {
1119 self.direct_messages_topic_id = Some(value);
1120 self
1121 }
1122
1123 /// Sets a new value for the `disable_notification` flag.
1124 ///
1125 /// # Arguments
1126 ///
1127 /// * `value` - Indicates whether to send the message silently or not;
1128 /// a user will receive a notification without sound.
1129 pub fn with_disable_notification(mut self, value: bool) -> Self {
1130 self.disable_notification = Some(value);
1131 self
1132 }
1133
1134 /// Sets a new message effect ID.
1135 ///
1136 /// # Arguments
1137 ///
1138 /// * `value` - Unique identifier of the message effect to be added to the message;
1139 /// only available when forwarding to private chats.
1140 pub fn with_message_effect_id<T>(mut self, value: T) -> Self
1141 where
1142 T: Into<String>,
1143 {
1144 self.message_effect_id = Some(value.into());
1145 self
1146 }
1147
1148 /// Sets a new message thread ID.
1149 ///
1150 /// # Arguments
1151 ///
1152 /// * `value` - Unique identifier of the target message thread;
1153 /// for forum supergroups and private chats of bots with forum topic mode enabled only.
1154 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
1155 self.message_thread_id = Some(value);
1156 self
1157 }
1158
1159 /// Sets a new value for the `protect_content` flag.
1160 ///
1161 /// # Arguments
1162 ///
1163 /// * `value` - Indicates whether to protect the contents
1164 /// of the sent message from forwarding and saving.
1165 pub fn with_protect_content(mut self, value: bool) -> Self {
1166 self.protect_content = Some(value);
1167 self
1168 }
1169
1170 /// Sets a new suggested post parameters.
1171 ///
1172 /// # Arguments
1173 ///
1174 /// * `value` - An object containing the parameters of the suggested post to send.
1175 ///
1176 /// For direct messages chats only.
1177 ///
1178 /// If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
1179 pub fn with_suggested_post_parameters(mut self, value: SuggestedPostParameters) -> Self {
1180 self.suggested_post_parameters = Some(value);
1181 self
1182 }
1183
1184 /// Sets a new video start timestamp.
1185 ///
1186 /// # Arguments
1187 ///
1188 /// * `value` - New start timestamp for the forwarded video in the message.
1189 pub fn with_video_start_timestamp(mut self, value: Integer) -> Self {
1190 self.video_start_timestamp = Some(value);
1191 self
1192 }
1193}
1194
1195impl Method for ForwardMessage {
1196 type Response = Message;
1197
1198 fn into_payload(self) -> Payload {
1199 Payload::json("forwardMessage", self)
1200 }
1201}
1202
1203/// Forwards multiple messages.
1204///
1205/// If some of the specified messages can't be found or forwarded, they are skipped.
1206/// Service messages and messages with protected content can't be forwarded.
1207/// Album grouping is kept for forwarded messages.
1208#[serde_with::skip_serializing_none]
1209#[derive(Clone, Debug, Serialize)]
1210pub struct ForwardMessages {
1211 chat_id: ChatId,
1212 from_chat_id: ChatId,
1213 message_ids: Vec<Integer>,
1214 direct_messages_topic_id: Option<Integer>,
1215 disable_notification: Option<bool>,
1216 protect_content: Option<bool>,
1217 message_thread_id: Option<Integer>,
1218}
1219
1220impl ForwardMessages {
1221 /// Creates a new `ForwardMessages`.
1222 ///
1223 /// # Arguments
1224 ///
1225 /// * `chat_id` - Unique identifier of the target chat.
1226 /// * `from_chat_id` - Unique identifier for the chat where the original message was sent.
1227 /// * `message_ids` - Identifiers of 1-100 messages in the chat `from_chat_id` to forward;
1228 /// the identifiers must be specified in a strictly increasing order.
1229 pub fn new<A, B, C>(chat_id: A, from_chat_id: B, message_ids: C) -> Self
1230 where
1231 A: Into<ChatId>,
1232 B: Into<ChatId>,
1233 C: IntoIterator<Item = Integer>,
1234 {
1235 Self {
1236 chat_id: chat_id.into(),
1237 from_chat_id: from_chat_id.into(),
1238 message_ids: message_ids.into_iter().collect(),
1239 direct_messages_topic_id: None,
1240 disable_notification: None,
1241 protect_content: None,
1242 message_thread_id: None,
1243 }
1244 }
1245
1246 /// Sets a new direct messages topic ID
1247 ///
1248 /// * `value` - Identifier of the direct messages topic to which the message will be sent.
1249 ///
1250 /// Required if the message is sent to a direct messages chat.
1251 pub fn with_direct_messages_topic_id(mut self, value: Integer) -> Self {
1252 self.direct_messages_topic_id = Some(value);
1253 self
1254 }
1255
1256 /// Sets a new value for the `disable_notification` flag.
1257 ///
1258 /// # Arguments
1259 ///
1260 /// * `value` - Indicates whether to send the message silently or not;
1261 /// a user will receive a notification without sound.
1262 pub fn with_disable_notification(mut self, value: bool) -> Self {
1263 self.disable_notification = Some(value);
1264 self
1265 }
1266
1267 /// Sets a new message thread ID.
1268 ///
1269 /// # Arguments
1270 ///
1271 /// * `value` - Unique identifier of the target message thread;
1272 /// for forum supergroups and private chats of bots with forum topic mode enabled only.
1273 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
1274 self.message_thread_id = Some(value);
1275 self
1276 }
1277
1278 /// Sets a new value for the `protect_content` flag.
1279 ///
1280 /// # Arguments
1281 ///
1282 /// * `value` - Indicates whether to protect the contents
1283 /// of the sent message from forwarding and saving.
1284 pub fn with_protect_content(mut self, value: bool) -> Self {
1285 self.protect_content = Some(value);
1286 self
1287 }
1288}
1289
1290impl Method for ForwardMessages {
1291 type Response = Vec<MessageId>;
1292
1293 fn into_payload(self) -> Payload {
1294 Payload::json("forwardMessages", self)
1295 }
1296}
1297
1298/// Sends a text message.
1299#[serde_with::skip_serializing_none]
1300#[derive(Clone, Debug, Serialize)]
1301pub struct SendMessage {
1302 chat_id: ChatId,
1303 text: String,
1304 allow_paid_broadcast: Option<bool>,
1305 business_connection_id: Option<String>,
1306 direct_messages_topic_id: Option<Integer>,
1307 disable_notification: Option<bool>,
1308 entities: Option<TextEntities>,
1309 link_preview_options: Option<LinkPreviewOptions>,
1310 message_effect_id: Option<String>,
1311 message_thread_id: Option<Integer>,
1312 parse_mode: Option<ParseMode>,
1313 protect_content: Option<bool>,
1314 reply_markup: Option<ReplyMarkup>,
1315 reply_parameters: Option<ReplyParameters>,
1316 suggested_post_parameters: Option<SuggestedPostParameters>,
1317}
1318
1319impl SendMessage {
1320 /// Creates a new `SendMessage`.
1321 ///
1322 /// # Arguments
1323 ///
1324 /// * `chat_id` - Unique identifier for the target chat.
1325 /// * `text` - Text of the message to be sent.
1326 pub fn new<A, B>(chat_id: A, text: B) -> Self
1327 where
1328 A: Into<ChatId>,
1329 B: Into<String>,
1330 {
1331 Self {
1332 chat_id: chat_id.into(),
1333 text: text.into(),
1334 allow_paid_broadcast: None,
1335 business_connection_id: None,
1336 direct_messages_topic_id: None,
1337 disable_notification: None,
1338 entities: None,
1339 link_preview_options: None,
1340 message_effect_id: None,
1341 message_thread_id: None,
1342 parse_mode: None,
1343 protect_content: None,
1344 reply_markup: None,
1345 reply_parameters: None,
1346 suggested_post_parameters: None,
1347 }
1348 }
1349
1350 /// Sets a new value for the `allow_paid_broadcast` flag.
1351 ///
1352 /// # Arguments
1353 ///
1354 /// * `value` - Whether to allow up to 1000 messages per second, ignoring broadcasting limits
1355 /// for a fee of 0.1 Telegram Stars per message.
1356 /// The relevant Stars will be withdrawn from the bot's balance.
1357 pub fn with_allow_paid_broadcast(mut self, value: bool) -> Self {
1358 self.allow_paid_broadcast = Some(value);
1359 self
1360 }
1361
1362 /// Sets a new business connection ID.
1363 ///
1364 /// # Arguments
1365 ///
1366 /// * `value` - Unique identifier of the business connection.
1367 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
1368 where
1369 T: Into<String>,
1370 {
1371 self.business_connection_id = Some(value.into());
1372 self
1373 }
1374
1375 /// Sets a new direct messages topic ID
1376 ///
1377 /// * `value` - Identifier of the direct messages topic to which the message will be sent.
1378 ///
1379 /// Required if the message is sent to a direct messages chat.
1380 pub fn with_direct_messages_topic_id(mut self, value: Integer) -> Self {
1381 self.direct_messages_topic_id = Some(value);
1382 self
1383 }
1384
1385 /// Sets a new value for the `disable_notification` flag.
1386 ///
1387 /// # Arguments
1388 ///
1389 /// * `value` - Indicates whether to send the message silently or not;
1390 /// a user will receive a notification without sound.
1391 pub fn with_disable_notification(mut self, value: bool) -> Self {
1392 self.disable_notification = Some(value);
1393 self
1394 }
1395
1396 /// Sets a new list of entities.
1397 ///
1398 /// # Arguments
1399 ///
1400 /// * `value` - List of special entities that appear in the text.
1401 ///
1402 /// Parse mode will be set to [`None`] when this method is called.
1403 pub fn with_entities<T>(mut self, value: T) -> Self
1404 where
1405 T: IntoIterator<Item = TextEntity>,
1406 {
1407 self.entities = Some(value.into_iter().collect());
1408 self.parse_mode = None;
1409 self
1410 }
1411
1412 /// Sets a new link preview options.
1413 ///
1414 /// # Arguments
1415 ///
1416 /// * `value` - Link preview generation options for the message.
1417 pub fn with_link_preview_options(mut self, value: LinkPreviewOptions) -> Self {
1418 self.link_preview_options = Some(value);
1419 self
1420 }
1421
1422 /// Sets a new message effect ID.
1423 ///
1424 /// # Arguments
1425 ///
1426 /// * `value` - Unique identifier of the message effect to be added to the message; for private chats only.
1427 pub fn with_message_effect_id<T>(mut self, value: T) -> Self
1428 where
1429 T: Into<String>,
1430 {
1431 self.message_effect_id = Some(value.into());
1432 self
1433 }
1434
1435 /// Sets a new message thread ID.
1436 ///
1437 /// # Arguments
1438 ///
1439 /// * `value` - Unique identifier of the target message thread;
1440 /// for forum supergroups and private chats of bots with forum topic mode enabled only.
1441 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
1442 self.message_thread_id = Some(value);
1443 self
1444 }
1445
1446 /// Sets a new parse mode.
1447 ///
1448 /// # Arguments
1449 ///
1450 /// * `value` - Parse mode.
1451 ///
1452 /// Entities will be set to [`None`] when this method is called.
1453 pub fn with_parse_mode(mut self, value: ParseMode) -> Self {
1454 self.parse_mode = Some(value);
1455 self.entities = None;
1456 self
1457 }
1458
1459 /// Sets a new value for the `protect_content` flag.
1460 ///
1461 /// # Arguments
1462 ///
1463 /// * `value` - Indicates whether to protect the contents
1464 /// of the sent message from forwarding and saving.
1465 pub fn with_protect_content(mut self, value: bool) -> Self {
1466 self.protect_content = Some(value);
1467 self
1468 }
1469
1470 /// Sets a new reply markup.
1471 ///
1472 /// # Arguments
1473 ///
1474 /// * `value` - Reply markup.
1475 pub fn with_reply_markup<T>(mut self, value: T) -> Self
1476 where
1477 T: Into<ReplyMarkup>,
1478 {
1479 self.reply_markup = Some(value.into());
1480 self
1481 }
1482
1483 /// Sets new reply parameters.
1484 ///
1485 /// # Arguments
1486 ///
1487 /// * `value` - Description of the message to reply to.
1488 pub fn with_reply_parameters(mut self, value: ReplyParameters) -> Self {
1489 self.reply_parameters = Some(value);
1490 self
1491 }
1492
1493 /// Sets a new suggested post parameters.
1494 ///
1495 /// # Arguments
1496 ///
1497 /// * `value` - An object containing the parameters of the suggested post to send.
1498 ///
1499 /// For direct messages chats only.
1500 ///
1501 /// If the message is sent as a reply to another suggested post, then that suggested post is automatically declined.
1502 pub fn with_suggested_post_parameters(mut self, value: SuggestedPostParameters) -> Self {
1503 self.suggested_post_parameters = Some(value);
1504 self
1505 }
1506}
1507
1508impl Method for SendMessage {
1509 type Response = Message;
1510
1511 fn into_payload(self) -> Payload {
1512 Payload::json("sendMessage", self)
1513 }
1514}
1515
1516/// Streams a partial message to a user while the message is being generated;
1517/// supported only for bots with forum topic mode enabled.
1518#[serde_with::skip_serializing_none]
1519#[derive(Clone, Debug, Serialize)]
1520pub struct SendMessageDraft {
1521 chat_id: Integer,
1522 draft_id: Integer,
1523 text: String,
1524 entities: Option<TextEntities>,
1525 message_thread_id: Option<Integer>,
1526 parse_mode: Option<ParseMode>,
1527}
1528
1529impl SendMessageDraft {
1530 /// Creates a new `SendMessageDraft`.
1531 ///
1532 /// # Arguments
1533 ///
1534 /// * `chat_id` - Unique identifier for the target private chat.
1535 /// * `draft_id` - Unique identifier of the message draft; must be non-zero.
1536 /// Changes of drafts with the same identifier are animated.
1537 /// * `text` - Text of the message to be sent, 1-4096 characters after entities parsing.
1538 pub fn new<T>(chat_id: Integer, draft_id: Integer, text: T) -> Self
1539 where
1540 T: Into<String>,
1541 {
1542 Self {
1543 chat_id,
1544 draft_id,
1545 text: text.into(),
1546 entities: None,
1547 message_thread_id: None,
1548 parse_mode: None,
1549 }
1550 }
1551
1552 /// Sets a new list of entities
1553 ///
1554 /// # Arguments
1555 ///
1556 /// * `value` - List of special entities that appear in the text.
1557 ///
1558 /// Parse mode will be set to [`None`] when this method is called.
1559 pub fn with_entities<T>(mut self, value: T) -> Self
1560 where
1561 T: IntoIterator<Item = TextEntity>,
1562 {
1563 self.entities = Some(value.into_iter().collect());
1564 self.parse_mode = None;
1565 self
1566 }
1567
1568 /// Sets a new message thread ID.
1569 ///
1570 /// # Arguments
1571 ///
1572 /// * `value` - Unique identifier for the target message thread.
1573 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
1574 self.message_thread_id = Some(value);
1575 self
1576 }
1577
1578 /// Sets a new parse mode.
1579 ///
1580 /// # Arguments
1581 ///
1582 /// * `value` - Parse mode.
1583 ///
1584 /// Entities will be set to [`None`] when this method is called.
1585 pub fn with_parse_mode(mut self, value: ParseMode) -> Self {
1586 self.entities = None;
1587 self.parse_mode = Some(value);
1588 self
1589 }
1590}
1591
1592impl Method for SendMessageDraft {
1593 type Response = bool;
1594
1595 fn into_payload(self) -> Payload {
1596 Payload::json("sendMessageDraft", self)
1597 }
1598}
1599
1600/// Stops updating a live location message before `live_period` expires.
1601#[serde_with::skip_serializing_none]
1602#[derive(Clone, Debug, Serialize)]
1603pub struct StopMessageLiveLocation {
1604 business_connection_id: Option<String>,
1605 chat_id: Option<ChatId>,
1606 inline_message_id: Option<String>,
1607 message_id: Option<Integer>,
1608 reply_markup: Option<InlineKeyboardMarkup>,
1609}
1610
1611impl StopMessageLiveLocation {
1612 /// Creates a new `StopMessageLiveLocation` for a chat message.
1613 ///
1614 /// # Arguments
1615 ///
1616 /// * `chat_id` - Unique identifier for the target chat.
1617 /// * `message_id` - Identifier of the sent message.
1618 pub fn for_chat_message<T>(chat_id: T, message_id: Integer) -> Self
1619 where
1620 T: Into<ChatId>,
1621 {
1622 Self {
1623 business_connection_id: None,
1624 chat_id: Some(chat_id.into()),
1625 inline_message_id: None,
1626 message_id: Some(message_id),
1627 reply_markup: None,
1628 }
1629 }
1630
1631 /// Creates a new `StopMessageLiveLocation` for an inline message.
1632 ///
1633 /// # Arguments
1634 ///
1635 /// * `inline_message_id` - Identifier of the inline message.
1636 pub fn for_inline_message<T>(inline_message_id: T) -> Self
1637 where
1638 T: Into<String>,
1639 {
1640 Self {
1641 business_connection_id: None,
1642 chat_id: None,
1643 inline_message_id: Some(inline_message_id.into()),
1644 message_id: None,
1645 reply_markup: None,
1646 }
1647 }
1648
1649 /// Sets a new business connection ID.
1650 ///
1651 /// # Arguments
1652 ///
1653 /// * `value` - Unique identifier of the business connection on behalf of which the message to be edited was sent.
1654 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
1655 where
1656 T: Into<String>,
1657 {
1658 self.business_connection_id = Some(value.into());
1659 self
1660 }
1661
1662 /// Sets a new reply markup.
1663 ///
1664 /// # Arguments
1665 ///
1666 /// * `value` - Reply markup.
1667 pub fn with_reply_markup<T>(mut self, value: T) -> Self
1668 where
1669 T: Into<InlineKeyboardMarkup>,
1670 {
1671 self.reply_markup = Some(value.into());
1672 self
1673 }
1674}
1675
1676impl Method for StopMessageLiveLocation {
1677 type Response = EditMessageResult;
1678
1679 fn into_payload(self) -> Payload {
1680 Payload::json("stopMessageLiveLocation", self)
1681 }
1682}