mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
added new type keyboard_button_poll_type.rs
This commit is contained in:
parent
fb3f0558c2
commit
357e2640f4
4 changed files with 28 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
use serde::{de::Error, Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
use crate::types::True;
|
||||
use crate::types::{True, KeyboardButtonPollType};
|
||||
|
||||
/// This object represents one button of the reply keyboard. For filter text
|
||||
/// buttons String can be used instead of this object to specify text of the
|
||||
|
@ -24,10 +24,11 @@ pub struct KeyboardButton {
|
|||
}
|
||||
|
||||
// Serialize + Deserialize are implemented by hand
|
||||
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq)]
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum ButtonRequest {
|
||||
Location,
|
||||
Contact,
|
||||
KeyboardButtonPollType(KeyboardButtonPollType)
|
||||
}
|
||||
|
||||
/// Helper struct for (de)serializing [`ButtonRequest`](ButtonRequest)
|
||||
|
@ -43,6 +44,10 @@ struct RawRequest {
|
|||
/// button is pressed. Available in private chats only
|
||||
#[serde(rename = "request_location")]
|
||||
location: Option<True>,
|
||||
|
||||
/// Optional. If specified, the user will be asked to create a poll and send it to the bot when the button is pressed. Available in private chats only
|
||||
#[serde(rename = "request_poll")]
|
||||
poll: Option<KeyboardButtonPollType>,
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ButtonRequest {
|
||||
|
@ -55,6 +60,7 @@ impl<'de> Deserialize<'de> for ButtonRequest {
|
|||
RawRequest {
|
||||
contact: Some(_),
|
||||
location: Some(_),
|
||||
poll: Some(_),
|
||||
} => Err(D::Error::custom(
|
||||
"`request_contact` and `request_location` fields are mutually \
|
||||
exclusive, but both were provided",
|
||||
|
@ -65,6 +71,9 @@ impl<'de> Deserialize<'de> for ButtonRequest {
|
|||
RawRequest {
|
||||
location: Some(_), ..
|
||||
} => Ok(Self::Location),
|
||||
RawRequest {
|
||||
poll: Some(poll_type), ..
|
||||
} => Ok(Self::KeyboardButtonPollType(poll_type)),
|
||||
_ => Err(D::Error::custom(
|
||||
"Either one of `request_contact` and `request_location` \
|
||||
fields is required",
|
||||
|
@ -82,13 +91,21 @@ impl Serialize for ButtonRequest {
|
|||
Self::Contact => RawRequest {
|
||||
contact: Some(True),
|
||||
location: None,
|
||||
poll: None,
|
||||
}
|
||||
.serialize(serializer),
|
||||
Self::Location => RawRequest {
|
||||
contact: None,
|
||||
location: Some(True),
|
||||
poll: None,
|
||||
}
|
||||
.serialize(serializer),
|
||||
Self::KeyboardButtonPollType(poll_type) => RawRequest {
|
||||
contact: None,
|
||||
location: None,
|
||||
poll: Some(poll_type.clone())
|
||||
}
|
||||
.serialize(serializer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
6
src/types/keyboard_button_poll_type.rs
Normal file
6
src/types/keyboard_button_poll_type.rs
Normal file
|
@ -0,0 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
pub struct KeyboardButtonPollType {
|
||||
poll_type: String
|
||||
}
|
|
@ -50,6 +50,7 @@ pub use input_media::*;
|
|||
pub use input_message_content::*;
|
||||
pub use invoice::*;
|
||||
pub use keyboard_button::*;
|
||||
pub use keyboard_button_poll_type::*;
|
||||
pub use label_price::*;
|
||||
pub use location::*;
|
||||
pub use login_url::*;
|
||||
|
@ -113,6 +114,7 @@ mod input_media;
|
|||
mod input_message_content;
|
||||
mod invoice;
|
||||
mod keyboard_button;
|
||||
mod keyboard_button_poll_type;
|
||||
mod label_price;
|
||||
mod location;
|
||||
mod login_url;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum PollType {
|
||||
Quiz,
|
||||
|
|
Loading…
Reference in a new issue