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