telegram_bot_raw_ars/requests/
edit_message_reply_markup.rs

1use crate::requests::*;
2use crate::types::*;
3
4/// Use this method to edit only the reply markup of messages sent by the bot.
5#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
6#[must_use = "requests do nothing unless sent"]
7pub struct EditMessageReplyMarkup {
8    chat_id: ChatRef,
9    message_id: MessageId,
10    #[serde(skip_serializing_if = "Option::is_none")]
11    reply_markup: Option<ReplyMarkup>,
12}
13
14impl Request for EditMessageReplyMarkup {
15    type Type = JsonRequestType<Self>;
16    type Response = JsonIdResponse<Message>;
17
18    fn serialize(&self) -> Result<HttpRequest, Error> {
19        Self::Type::serialize(RequestUrl::method("editMessageReplyMarkup"), self)
20    }
21}
22
23impl EditMessageReplyMarkup {
24    pub fn new<C, M, R>(chat: C, message_id: M, reply_markup: Option<R>) -> Self
25    where
26        C: ToChatRef,
27        M: ToMessageId,
28        R: Into<ReplyMarkup>,
29    {
30        EditMessageReplyMarkup {
31            chat_id: chat.to_chat_ref(),
32            message_id: message_id.to_message_id(),
33            reply_markup: reply_markup.map(|r| r.into()),
34        }
35    }
36}
37
38/// Edit reply markup of messages sent by the bot.
39pub trait CanEditMessageReplyMarkup {
40    fn edit_reply_markup<R>(&self, reply_markup: Option<R>) -> EditMessageReplyMarkup
41    where
42        R: Into<ReplyMarkup>;
43}
44
45impl<M> CanEditMessageReplyMarkup for M
46where
47    M: ToMessageId + ToSourceChat,
48{
49    fn edit_reply_markup<R>(&self, reply_markup: Option<R>) -> EditMessageReplyMarkup
50    where
51        R: Into<ReplyMarkup>,
52    {
53        EditMessageReplyMarkup::new(self.to_source_chat(), self.to_message_id(), reply_markup)
54    }
55}