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