tgbot/types/venue/mod.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{
4 api::{Method, Payload},
5 types::{ChatId, Float, Integer, Location, Message, ReplyMarkup, ReplyParameters},
6};
7
8#[cfg(test)]
9mod tests;
10
11/// Represents a venue.
12#[serde_with::skip_serializing_none]
13#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
14pub struct Venue {
15 /// Address of the venue.
16 pub address: String,
17 /// Location of the venue.
18 pub location: Location,
19 /// Name of the venue.
20 pub title: String,
21 /// Foursquare identifier.
22 pub foursquare_id: Option<String>,
23 /// Foursquare type.
24 ///
25 /// Example: “arts_entertainment/default”,
26 /// “arts_entertainment/aquarium” or “food/ice-cream”.
27 pub foursquare_type: Option<String>,
28 /// Google Places identifier.
29 pub google_place_id: Option<String>,
30 /// Google Places type.
31 ///
32 /// <https://developers.google.com/places/web-service/supported_types>
33 pub google_place_type: Option<String>,
34}
35
36impl Venue {
37 /// Creates a new `Venue`.
38 ///
39 /// # Arguments
40 ///
41 /// * `title` - Title of the venue.
42 /// * `address` - Address of the venue.
43 /// * `location` - Location of the venue.
44 pub fn new<A, B>(title: A, address: B, location: Location) -> Self
45 where
46 A: Into<String>,
47 B: Into<String>,
48 {
49 Self {
50 address: address.into(),
51 location,
52 title: title.into(),
53 foursquare_id: None,
54 foursquare_type: None,
55 google_place_id: None,
56 google_place_type: None,
57 }
58 }
59
60 /// Sets a new foursquare ID.
61 ///
62 /// # Arguments
63 ///
64 /// * `value` - Foursquare identifier of the venue.
65 pub fn with_foursquare_id<T>(mut self, value: T) -> Self
66 where
67 T: Into<String>,
68 {
69 self.foursquare_id = Some(value.into());
70 self
71 }
72
73 /// Sets a new foursquare type.
74 ///
75 /// # Arguments
76 ///
77 /// * `value` - Foursquare type of the venue.
78 ///
79 /// For example, “arts_entertainment/default”,
80 /// “arts_entertainment/aquarium” or “food/ice-cream”.
81 pub fn with_foursquare_type<T>(mut self, value: T) -> Self
82 where
83 T: Into<String>,
84 {
85 self.foursquare_type = Some(value.into());
86 self
87 }
88
89 /// Sets a new Google Places ID.
90 ///
91 /// # Arguments
92 ///
93 /// * `value` - Google Places identifier of the venue.
94 pub fn with_google_place_id<T>(mut self, value: T) -> Self
95 where
96 T: Into<String>,
97 {
98 self.google_place_id = Some(value.into());
99 self
100 }
101
102 /// Sets a new Google Places type.
103 ///
104 /// # Arguments
105 ///
106 /// * `value` - Google Places type of the venue.
107 ///
108 /// <https://developers.google.com/places/web-service/supported_types>
109 pub fn with_google_place_type<T>(mut self, value: T) -> Self
110 where
111 T: Into<String>,
112 {
113 self.google_place_type = Some(value.into());
114 self
115 }
116}
117
118/// Sends information about a venue.
119#[serde_with::skip_serializing_none]
120#[derive(Clone, Debug, Serialize)]
121pub struct SendVenue {
122 chat_id: ChatId,
123 latitude: Float,
124 longitude: Float,
125 title: String,
126 address: String,
127 allow_paid_broadcast: Option<bool>,
128 business_connection_id: Option<String>,
129 disable_notification: Option<bool>,
130 foursquare_id: Option<String>,
131 foursquare_type: Option<String>,
132 google_place_id: Option<String>,
133 google_place_type: Option<String>,
134 message_effect_id: Option<String>,
135 message_thread_id: Option<Integer>,
136 protect_content: Option<bool>,
137 reply_markup: Option<ReplyMarkup>,
138 reply_parameters: Option<ReplyParameters>,
139}
140
141impl SendVenue {
142 /// Creates a new `SendVenue`.
143 ///
144 /// # Arguments
145 ///
146 /// * `chat_id` - Unique identifier of the target chat.
147 /// * `latitude` - Latitude of the venue.
148 /// * `longitude` - Longitude of the venue.
149 /// * `title` - Name of the venue.
150 /// * `address` - Address of the venue.
151 pub fn new<A, B, C>(chat_id: A, latitude: Float, longitude: Float, title: B, address: C) -> Self
152 where
153 A: Into<ChatId>,
154 B: Into<String>,
155 C: Into<String>,
156 {
157 Self {
158 chat_id: chat_id.into(),
159 latitude,
160 longitude,
161 title: title.into(),
162 address: address.into(),
163 allow_paid_broadcast: None,
164 business_connection_id: None,
165 disable_notification: None,
166 foursquare_id: None,
167 foursquare_type: None,
168 google_place_id: None,
169 google_place_type: None,
170 message_effect_id: None,
171 message_thread_id: None,
172 protect_content: None,
173 reply_markup: None,
174 reply_parameters: None,
175 }
176 }
177
178 /// Sets a new value for the `allow_paid_broadcast` flag.
179 ///
180 /// # Arguments
181 ///
182 /// * `value` - Whether to allow up to 1000 messages per second, ignoring broadcasting limits
183 /// for a fee of 0.1 Telegram Stars per message.
184 /// The relevant Stars will be withdrawn from the bot's balance.
185 pub fn with_allow_paid_broadcast(mut self, value: bool) -> Self {
186 self.allow_paid_broadcast = Some(value);
187 self
188 }
189
190 /// Sets a new business connection ID.
191 ///
192 /// # Arguments
193 ///
194 /// * `value` - Unique identifier of the business connection.
195 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
196 where
197 T: Into<String>,
198 {
199 self.business_connection_id = Some(value.into());
200 self
201 }
202
203 /// Sets a new value for the `disable_notification` flag.
204 ///
205 /// # Arguments
206 ///
207 /// * `value` - Indicates whether to send the message silently or not;
208 /// a user will receive a notification without sound.
209 pub fn with_disable_notification(mut self, value: bool) -> Self {
210 self.disable_notification = Some(value);
211 self
212 }
213
214 /// Sets a new foursquare ID.
215 ///
216 /// # Arguments
217 ///
218 /// * `value` - Foursquare identifier of the venue.
219 pub fn with_foursquare_id<T>(mut self, value: T) -> Self
220 where
221 T: Into<String>,
222 {
223 self.foursquare_id = Some(value.into());
224 self
225 }
226
227 /// Sets a new foursquare type.
228 ///
229 /// # Arguments
230 ///
231 /// * `value` - Foursquare type of the venue.
232 ///
233 /// For example, “arts_entertainment/default”,
234 /// “arts_entertainment/aquarium” or “food/ice-cream”.
235 pub fn with_foursquare_type<T>(mut self, value: T) -> Self
236 where
237 T: Into<String>,
238 {
239 self.foursquare_type = Some(value.into());
240 self
241 }
242
243 /// Sets a new Google Places ID.
244 ///
245 /// # Arguments
246 ///
247 /// * `value` - Google Places identifier of the venue.
248 pub fn with_google_place_id<T>(mut self, value: T) -> Self
249 where
250 T: Into<String>,
251 {
252 self.google_place_id = Some(value.into());
253 self
254 }
255
256 /// Sets a new Google Places type.
257 ///
258 /// # Arguments
259 ///
260 /// * `value` - Google Places type of the venue.
261 ///
262 /// <https://developers.google.com/places/web-service/supported_types>
263 pub fn with_google_place_type<T>(mut self, value: T) -> Self
264 where
265 T: Into<String>,
266 {
267 self.google_place_type = Some(value.into());
268 self
269 }
270
271 /// Sets a new message effect ID.
272 ///
273 /// # Arguments
274 ///
275 /// * `value` - Unique identifier of the message effect to be added to the message; for private chats only.
276 pub fn with_message_effect_id<T>(mut self, value: T) -> Self
277 where
278 T: Into<String>,
279 {
280 self.message_effect_id = Some(value.into());
281 self
282 }
283
284 /// Sets a new message thread ID.
285 ///
286 /// # Arguments
287 ///
288 /// * `value` - Unique identifier of the target message thread;
289 /// supergroups only.
290 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
291 self.message_thread_id = Some(value);
292 self
293 }
294
295 /// Sets a new value for the `protect_content` flag.
296 ///
297 /// # Arguments
298 ///
299 /// * `value` - Indicates whether to protect the contents
300 /// of the sent message from forwarding and saving.
301 pub fn with_protect_content(mut self, value: bool) -> Self {
302 self.protect_content = Some(value);
303 self
304 }
305
306 /// Sets a new reply markup.
307 ///
308 /// # Arguments
309 ///
310 /// * `value` - Reply markup.
311 pub fn with_reply_markup<T>(mut self, value: T) -> Self
312 where
313 T: Into<ReplyMarkup>,
314 {
315 self.reply_markup = Some(value.into());
316 self
317 }
318
319 /// Sets new reply parameters.
320 ///
321 /// # Arguments
322 ///
323 /// * `value` - Description of the message to reply to.
324 pub fn with_reply_parameters(mut self, value: ReplyParameters) -> Self {
325 self.reply_parameters = Some(value);
326 self
327 }
328}
329
330impl Method for SendVenue {
331 type Response = Message;
332
333 fn into_payload(self) -> Payload {
334 Payload::json("sendVenue", self)
335 }
336}