telegram_bot_raw/requests/
edit_message_caption.rs

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