telegram_bot_raw/requests/
edit_message_live_location.rs

1use crate::requests::*;
2use crate::types::*;
3
4/// Use this method to edit live location messages sent by the bot.
5/// A location can be edited until its live_period expires or editing
6/// is explicitly disabled by a call to stopMessageLiveLocation.
7#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
8#[must_use = "requests do nothing unless sent"]
9pub struct EditMessageLiveLocation {
10    chat_id: ChatRef,
11    message_id: MessageId,
12    latitude: Float,
13    longitude: Float,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    reply_markup: Option<ReplyMarkup>,
16}
17
18impl Request for EditMessageLiveLocation {
19    type Type = JsonRequestType<Self>;
20    type Response = JsonIdResponse<Message>;
21
22    fn serialize(&self) -> Result<HttpRequest, Error> {
23        Self::Type::serialize(RequestUrl::method("editMessageLiveLocation"), self)
24    }
25}
26
27impl EditMessageLiveLocation {
28    pub fn new<C, M>(chat: C, message_id: M, latitude: Float, longitude: Float) -> Self
29    where
30        C: ToChatRef,
31        M: ToMessageId,
32    {
33        EditMessageLiveLocation {
34            chat_id: chat.to_chat_ref(),
35            message_id: message_id.to_message_id(),
36            latitude: latitude,
37            longitude: longitude,
38            reply_markup: None,
39        }
40    }
41
42    pub fn reply_markup<R>(&mut self, reply_markup: R) -> &mut Self
43    where
44        R: Into<ReplyMarkup>,
45    {
46        self.reply_markup = Some(reply_markup.into());
47        self
48    }
49}
50
51/// Edit live location messages sent by the bot.
52pub trait CanEditMessageLiveLocation {
53    fn edit_live_location(&self, latitude: Float, longitude: Float) -> EditMessageLiveLocation;
54}
55
56impl<M> CanEditMessageLiveLocation for M
57where
58    M: ToMessageId + ToSourceChat,
59{
60    fn edit_live_location(&self, latitude: Float, longitude: Float) -> EditMessageLiveLocation {
61        EditMessageLiveLocation::new(
62            self.to_source_chat(),
63            self.to_message_id(),
64            latitude,
65            longitude,
66        )
67    }
68}