telegram_bot_raw/requests/
stop_poll.rs1use crate::requests::*;
2use crate::types::*;
3
4#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
6#[must_use = "requests do nothing unless sent"]
7pub struct StopPoll {
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 StopPoll {
15 type Type = JsonRequestType<Self>;
16 type Response = JsonIdResponse<Poll>;
17
18 fn serialize(&self) -> Result<HttpRequest, Error> {
19 Self::Type::serialize(RequestUrl::method("stopPoll"), self)
20 }
21}
22
23impl StopPoll {
24 pub fn new<C, M>(chat: C, message: M) -> Self
25 where
26 C: ToChatRef,
27 M: ToMessageId,
28 {
29 StopPoll {
30 chat_id: chat.to_chat_ref(),
31 message_id: message.to_message_id(),
32 reply_markup: None,
33 }
34 }
35
36 pub fn reply_markup<R>(&mut self, reply_markup: R) -> &mut Self
37 where
38 R: Into<ReplyMarkup>,
39 {
40 self.reply_markup = Some(reply_markup.into());
41 self
42 }
43}
44
45pub trait CanStopPoll {
47 fn stop_poll(&self) -> StopPoll;
48}
49
50impl<M> CanStopPoll for M
51where
52 M: ToMessageId + ToSourceChat,
53{
54 fn stop_poll(&self) -> StopPoll {
55 StopPoll::new(self.to_source_chat(), self.to_message_id())
56 }
57}