telegram_bot_async_raw/requests/
edit_message_caption.rs

1use std::borrow::Cow;
2
3use crate::{requests::*, types::*};
4
5/// Use this method to edit captions of messages sent by the bot.
6#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
7#[must_use = "requests do nothing unless sent"]
8pub struct EditMessageCaption<'s> {
9    chat_id: ChatRef,
10    message_id: MessageId,
11    caption: Cow<'s, str>,
12    #[serde(skip_serializing_if = "Option::is_none")]
13    reply_markup: Option<ReplyMarkup>,
14}
15
16impl<'s> Request for EditMessageCaption<'s> {
17    type Type = JsonRequestType<Self>;
18    type Response = JsonIdResponse<Message>;
19
20    fn serialize(&self) -> Result<HttpRequest, Error> {
21        Self::Type::serialize(RequestUrl::method("editMessageCaption"), self)
22    }
23}
24
25impl<'s> EditMessageCaption<'s> {
26    pub fn new<C, M, T>(chat: C, message_id: M, caption: T) -> Self
27    where
28        C: ToChatRef,
29        M: ToMessageId,
30        T: Into<Cow<'s, str>>,
31    {
32        EditMessageCaption {
33            chat_id: chat.to_chat_ref(),
34            message_id: message_id.to_message_id(),
35            caption: caption.into(),
36            reply_markup: None,
37        }
38    }
39
40    pub fn reply_markup<R>(mut self, reply_markup: R) -> Self
41    where
42        R: Into<ReplyMarkup>,
43    {
44        self.reply_markup = Some(reply_markup.into());
45        self
46    }
47}
48
49/// Edit captions of messages sent by the bot.
50pub trait CanEditMessageCaption {
51    fn edit_caption<'s, T>(&self, caption: T) -> EditMessageCaption<'s>
52    where
53        T: Into<Cow<'s, str>>;
54}
55
56impl<M> CanEditMessageCaption for M
57where
58    M: ToMessageId + ToSourceChat,
59{
60    fn edit_caption<'s, T>(&self, caption: T) -> EditMessageCaption<'s>
61    where
62        T: Into<Cow<'s, str>>,
63    {
64        EditMessageCaption::new(self.to_source_chat(), self.to_message_id(), caption)
65    }
66}