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