telegram_bot_async_raw/requests/
edit_message_reply_markup.rs

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