telegram_bot_raw/requests/
send_venue.rs1use std::borrow::Cow;
2use std::ops::Not;
3
4use crate::requests::*;
5use crate::types::*;
6
7#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
9#[must_use = "requests do nothing unless sent"]
10pub struct SendVenue<'t, 'a, 'f> {
11 chat_id: ChatRef,
12 latitude: Float,
13 longitude: Float,
14 title: Cow<'t, str>,
15 address: Cow<'a, str>,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 foursquare_id: Option<Cow<'f, str>>,
18 #[serde(skip_serializing_if = "Not::not")]
19 disable_notification: bool,
20 #[serde(skip_serializing_if = "Option::is_none")]
21 reply_to_message_id: Option<MessageId>,
22 #[serde(skip_serializing_if = "Option::is_none")]
23 reply_markup: Option<ReplyMarkup>,
24}
25
26impl<'t, 'a, 'f> Request for SendVenue<'t, 'a, 'f> {
27 type Type = JsonRequestType<Self>;
28 type Response = JsonIdResponse<Message>;
29
30 fn serialize(&self) -> Result<HttpRequest, Error> {
31 Self::Type::serialize(RequestUrl::method("sendVenue"), self)
32 }
33}
34
35impl<'t, 'a, 'f> SendVenue<'t, 'a, 'f> {
36 pub fn new<C, T, A>(chat: C, latitude: Float, longitude: Float, title: T, address: A) -> Self
37 where
38 C: ToChatRef,
39 T: Into<Cow<'t, str>>,
40 A: Into<Cow<'a, str>>,
41 {
42 SendVenue {
43 chat_id: chat.to_chat_ref(),
44 latitude: latitude,
45 longitude: longitude,
46 title: title.into(),
47 address: address.into(),
48 disable_notification: false,
49 foursquare_id: None,
50 reply_to_message_id: None,
51 reply_markup: None,
52 }
53 }
54
55 pub fn disable_notification(&mut self) -> &mut Self {
56 self.disable_notification = true;
57 self
58 }
59
60 pub fn foursquare_id<F>(&mut self, id: F) -> &mut Self
61 where
62 F: Into<Cow<'f, str>>,
63 {
64 self.foursquare_id = Some(id.into());
65 self
66 }
67
68 pub fn reply_to<R>(&mut self, to: R) -> &mut Self
69 where
70 R: ToMessageId,
71 {
72 self.reply_to_message_id = Some(to.to_message_id());
73 self
74 }
75
76 pub fn reply_markup<R>(&mut self, reply_markup: R) -> &mut Self
77 where
78 R: Into<ReplyMarkup>,
79 {
80 self.reply_markup = Some(reply_markup.into());
81 self
82 }
83}
84
85pub trait CanSendVenue<'t, 'a, 'f> {
87 fn venue<T, A>(
88 &self,
89 latitude: Float,
90 longitude: Float,
91 title: T,
92 address: A,
93 ) -> SendVenue<'t, 'a, 'f>
94 where
95 T: Into<Cow<'t, str>>,
96 A: Into<Cow<'a, str>>;
97}
98
99impl<'t, 'a, 'f, C> CanSendVenue<'t, 'a, 'f> for C
100where
101 C: ToChatRef,
102{
103 fn venue<T, A>(
104 &self,
105 latitude: Float,
106 longitude: Float,
107 title: T,
108 address: A,
109 ) -> SendVenue<'t, 'a, 'f>
110 where
111 T: Into<Cow<'t, str>>,
112 A: Into<Cow<'a, str>>,
113 {
114 SendVenue::new(self, latitude, longitude, title, address)
115 }
116}
117
118pub trait CanReplySendVenue {
120 fn venue_reply<'t, 'a, 'f, T, A>(
121 &self,
122 latitude: Float,
123 longitude: Float,
124 title: T,
125 address: A,
126 ) -> SendVenue<'t, 'a, 'f>
127 where
128 T: Into<Cow<'t, str>>,
129 A: Into<Cow<'a, str>>;
130}
131
132impl<M> CanReplySendVenue for M
133where
134 M: ToMessageId + ToSourceChat,
135{
136 fn venue_reply<'t, 'a, 'f, T, A>(
137 &self,
138 latitude: Float,
139 longitude: Float,
140 title: T,
141 address: A,
142 ) -> SendVenue<'t, 'a, 'f>
143 where
144 T: Into<Cow<'t, str>>,
145 A: Into<Cow<'a, str>>,
146 {
147 let mut rq = self
148 .to_source_chat()
149 .venue(latitude, longitude, title, address);
150 rq.reply_to(self.to_message_id());
151 rq
152 }
153}
154
155impl<'b> ToRequest<'b> for Venue {
156 type Request = SendVenue<'b, 'b, 'b>;
157
158 fn to_request<C>(&'b self, chat: C) -> Self::Request
159 where
160 C: ToChatRef,
161 {
162 let mut rq = chat.venue(
163 self.location.latitude,
164 self.location.longitude,
165 self.title.as_str(),
166 self.address.as_str(),
167 );
168 if let Some(ref foursquare_id) = self.foursquare_id {
169 rq.foursquare_id(foursquare_id.as_str());
170 }
171 rq
172 }
173}
174
175impl<'b> ToReplyRequest<'b> for Venue {
176 type Request = SendVenue<'b, 'b, 'b>;
177
178 fn to_reply_request<M>(&'b self, message: M) -> Self::Request
179 where
180 M: ToMessageId + ToSourceChat,
181 {
182 let mut rq = message.venue_reply(
183 self.location.latitude,
184 self.location.longitude,
185 self.title.as_str(),
186 self.address.as_str(),
187 );
188 if let Some(ref foursquare_id) = self.foursquare_id {
189 rq.foursquare_id(foursquare_id.as_str());
190 }
191 rq
192 }
193}