Merge pull request #238 from teloxide/non-exhaustive-types

Mark API types as #[non_exhaustive]
This commit is contained in:
Temirkhan Myrzamadi 2020-07-28 22:21:46 +06:00 committed by GitHub
commit d5b453e567
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 4772 additions and 36 deletions

View file

@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum AllowedUpdate {
Message,
EditedMessage,

View file

@ -8,6 +8,7 @@ use crate::types::{MimeWrapper, PhotoSize};
/// [The official docs](https://core.telegram.org/bots/api#animation).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Animation {
/// An identifier for this file.
pub file_id: String,
@ -39,6 +40,86 @@ pub struct Animation {
pub file_size: Option<u32>,
}
impl Animation {
pub fn new<S1, S2>(
file_id: S1,
file_unique_id: S2,
width: u32,
height: u32,
duration: u32,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
file_id: file_id.into(),
file_unique_id: file_unique_id.into(),
width,
height,
duration,
thumb: None,
file_name: None,
mime_type: None,
file_size: None,
}
}
pub fn file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_id = val.into();
self
}
pub fn file_unique_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_unique_id = val.into();
self
}
pub fn width(mut self, val: u32) -> Self {
self.width = val;
self
}
pub fn height(mut self, val: u32) -> Self {
self.height = val;
self
}
pub fn duration(mut self, val: u32) -> Self {
self.duration = val;
self
}
pub fn thumb(mut self, val: PhotoSize) -> Self {
self.thumb = Some(val);
self
}
pub fn file_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_name = Some(val.into());
self
}
pub fn mime_type(mut self, val: MimeWrapper) -> Self {
self.mime_type = Some(val);
self
}
pub fn file_size(mut self, val: u32) -> Self {
self.file_size = Some(val);
self
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -8,6 +8,7 @@ use crate::types::{MimeWrapper, PhotoSize};
/// [The official docs](https://core.telegram.org/bots/api#audio).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Audio {
/// An identifier for this file.
pub file_id: String,
@ -36,6 +37,77 @@ pub struct Audio {
pub thumb: Option<PhotoSize>,
}
impl Audio {
pub fn new<S1, S2>(file_id: S1, file_unique_id: S2, duration: u32) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
file_id: file_id.into(),
file_unique_id: file_unique_id.into(),
duration,
performer: None,
title: None,
mime_type: None,
file_size: None,
thumb: None,
}
}
pub fn file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_id = val.into();
self
}
pub fn file_unique_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_unique_id = val.into();
self
}
pub fn duration(mut self, val: u32) -> Self {
self.duration = val;
self
}
pub fn performer<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.performer = Some(val.into());
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = Some(val.into());
self
}
pub fn mime_type(mut self, val: MimeWrapper) -> Self {
self.mime_type = Some(val);
self
}
pub fn file_size(mut self, val: u32) -> Self {
self.file_size = Some(val);
self
}
pub fn thumb(mut self, val: PhotoSize) -> Self {
self.thumb = Some(val);
self
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -9,4 +9,5 @@ use serde::{Deserialize, Serialize};
///
/// [@Botfather]: https://t.me/botfather
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CallbackGame;

View file

@ -17,6 +17,7 @@ use crate::types::{Message, User};
/// [inline mode]: https://core.telegram.org/bots/api#inline-mode
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct CallbackQuery {
/// An unique identifier for this query.
pub id: String,
@ -49,6 +50,74 @@ pub struct CallbackQuery {
pub game_short_name: Option<String>,
}
impl CallbackQuery {
pub fn new<S1, S2>(id: S1, from: User, chat_instance: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
id: id.into(),
from,
message: None,
inline_message_id: None,
chat_instance: chat_instance.into(),
data: None,
game_short_name: None,
}
}
pub fn id<S>(mut self, id: S) -> Self
where
S: Into<String>,
{
self.id = id.into();
self
}
pub fn from(mut self, val: User) -> Self {
self.from = val;
self
}
pub fn message(mut self, val: Message) -> Self {
self.message = Some(val);
self
}
pub fn inline_message_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.inline_message_id = Some(val.into());
self
}
pub fn chat_instance<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.chat_instance = val.into();
self
}
pub fn data<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.data = Some(val.into());
self
}
pub fn game_short_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.game_short_name = Some(val.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -7,6 +7,7 @@ use crate::types::{ChatPermissions, ChatPhoto, Message};
/// [The official docs](https://core.telegram.org/bots/api#chat).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Chat {
/// A unique identifier for this chat. This number may be greater than 32
/// bits and some programming languages may have difficulty/silent defects
@ -24,9 +25,31 @@ pub struct Chat {
pub photo: Option<ChatPhoto>,
}
impl Chat {
pub fn new(id: i64, kind: ChatKind) -> Self {
Self { id, kind, photo: None }
}
pub fn id(mut self, val: i64) -> Self {
self.id = val;
self
}
pub fn kind(mut self, val: ChatKind) -> Self {
self.kind = val;
self
}
pub fn photo(mut self, val: ChatPhoto) -> Self {
self.photo = Some(val);
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum ChatKind {
Public(ChatPublic),
Private(ChatPrivate),
@ -34,6 +57,7 @@ pub enum ChatKind {
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ChatPublic {
/// A title, for supergroups, channels and group chats.
pub title: Option<String>,
@ -66,8 +90,44 @@ pub struct ChatPublic {
pub pinned_message: Option<Box<Message>>,
}
impl ChatPublic {
pub fn new(kind: PublicChatKind) -> Self {
Self { title: None, kind, description: None, invite_link: None, pinned_message: None }
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = Some(val.into());
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = Some(val.into());
self
}
pub fn invite_link<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.invite_link = Some(val.into());
self
}
pub fn pinned_message(mut self, val: Message) -> Self {
self.pinned_message = Some(Box::new(val));
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ChatPrivate {
/// A dummy field. Used to ensure that the `type` field is equal to
/// `private`.
@ -86,10 +146,41 @@ pub struct ChatPrivate {
pub last_name: Option<String>,
}
impl ChatPrivate {
pub fn new() -> Self {
Self::default()
}
pub fn username<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.username = Some(val.into());
self
}
pub fn first_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.first_name = Some(val.into());
self
}
pub fn last_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.last_name = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
#[non_exhaustive]
pub enum PublicChatKind {
Channel(PublicChatChannel),
Group(PublicChatGroup),
@ -97,14 +188,22 @@ pub enum PublicChatKind {
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PublicChatChannel {
/// A username, for private chats, supergroups and channels if available.
pub username: Option<String>,
}
impl PublicChatChannel {
pub fn new() -> Self {
Self::default()
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PublicChatGroup {
/// A default chat member permissions, for groups and supergroups. Returned
/// only from [`Bot::get_chat`].
@ -113,8 +212,15 @@ pub struct PublicChatGroup {
pub permissions: Option<ChatPermissions>,
}
impl PublicChatGroup {
pub fn new() -> Self {
Self::default()
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PublicChatSupergroup {
/// A username, for private chats, supergroups and channels if
/// available.
@ -145,6 +251,12 @@ pub struct PublicChatSupergroup {
pub slow_mode_delay: Option<i32>,
}
impl PublicChatSupergroup {
pub fn new() -> Self {
Self::default()
}
}
struct PrivateChatKindVisitor;
impl<'de> serde::de::Visitor<'de> for PrivateChatKindVisitor {

View file

@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ChatAction {
Typing,
UploadPhoto,

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
/// (in the format `@channelusername`).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Display, From)]
#[serde(untagged)]
#[non_exhaustive]
pub enum ChatId {
/// A chat identifier.
#[display(fmt = "{}", _0)]

View file

@ -7,6 +7,7 @@ use crate::types::User;
///
/// [The official docs](https://core.telegram.org/bots/api#chatmember).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ChatMember {
/// Information about the user.
pub user: User,
@ -76,6 +77,118 @@ pub struct ChatMember {
pub can_add_web_page_previews: Option<bool>,
}
impl ChatMember {
pub fn new(user: User, status: ChatMemberStatus) -> Self {
Self {
user,
status,
custom_title: None,
until_date: None,
can_be_edited: None,
can_change_info: None,
can_post_messages: None,
can_edit_messages: None,
can_delete_messages: None,
can_invite_users: None,
can_restrict_members: None,
can_pin_messages: None,
can_promote_members: None,
can_send_messages: None,
can_send_media_messages: None,
can_send_other_messages: None,
can_add_web_page_previews: None,
}
}
pub fn user(mut self, val: User) -> Self {
self.user = val;
self
}
pub fn status(mut self, val: ChatMemberStatus) -> Self {
self.status = val;
self
}
pub fn custom_title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.custom_title = Some(val.into());
self
}
pub fn until_date(mut self, val: i32) -> Self {
self.until_date = Some(val);
self
}
pub fn can_be_edited(mut self, val: bool) -> Self {
self.can_be_edited = Some(val);
self
}
pub fn can_change_info(mut self, val: bool) -> Self {
self.can_change_info = Some(val);
self
}
pub fn can_post_messages(mut self, val: bool) -> Self {
self.can_post_messages = Some(val);
self
}
pub fn can_edit_messages(mut self, val: bool) -> Self {
self.can_edit_messages = Some(val);
self
}
pub fn can_delete_messages(mut self, val: bool) -> Self {
self.can_delete_messages = Some(val);
self
}
pub fn can_invite_users(mut self, val: bool) -> Self {
self.can_invite_users = Some(val);
self
}
pub fn can_restrict_members(mut self, val: bool) -> Self {
self.can_restrict_members = Some(val);
self
}
pub fn can_pin_messages(mut self, val: bool) -> Self {
self.can_pin_messages = Some(val);
self
}
pub fn can_promote_members(mut self, val: bool) -> Self {
self.can_promote_members = Some(val);
self
}
pub fn can_send_messages(mut self, val: bool) -> Self {
self.can_send_messages = Some(val);
self
}
pub fn can_send_media_messages(mut self, val: bool) -> Self {
self.can_send_media_messages = Some(val);
self
}
pub fn can_send_other_messages(mut self, val: bool) -> Self {
self.can_send_other_messages = Some(val);
self
}
pub fn can_add_web_page_previews(mut self, val: bool) -> Self {
self.can_add_web_page_previews = Some(val);
self
}
}
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ChatMemberStatus {

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
/// A chat message or inline message.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum ChatOrInlineMessage {
Chat { chat_id: ChatId, message_id: i32 },
Inline { inline_message_id: i32 },

View file

@ -5,7 +5,8 @@ use serde::{Deserialize, Serialize};
///
/// [The official docs](https://core.telegram.org/bots/api#chatpermissions).
#[serde_with_macros::skip_serializing_none]
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ChatPermissions {
/// `true`, if the user is allowed to send text messages, contacts,
/// locations and venues.
@ -40,17 +41,8 @@ pub struct ChatPermissions {
pub can_pin_messages: Option<bool>,
}
impl Default for ChatPermissions {
fn default() -> Self {
Self {
can_send_messages: None,
can_send_media_messages: None,
can_send_polls: None,
can_send_other_messages: None,
can_add_web_page_previews: None,
can_change_info: None,
can_invite_users: None,
can_pin_messages: None,
}
impl ChatPermissions {
pub fn new() -> Self {
Self::default()
}
}

View file

@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
///
/// [The official docs](https://core.telegram.org/bots/api#chatphoto).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ChatPhoto {
/// A file identifier of small (160x160) chat photo. This file_id can be
/// used only for photo download and only for as long as the photo is
@ -25,3 +26,57 @@ pub struct ChatPhoto {
/// download or reuse the file.
pub big_file_unique_id: String,
}
impl ChatPhoto {
pub fn new<S1, S2, S3, S4>(
small_file_id: S1,
small_file_unique_id: S2,
big_file_id: S3,
big_file_unique_id: S4,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
S4: Into<String>,
{
Self {
small_file_id: small_file_id.into(),
small_file_unique_id: small_file_unique_id.into(),
big_file_id: big_file_id.into(),
big_file_unique_id: big_file_unique_id.into(),
}
}
pub fn small_file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.small_file_id = val.into();
self
}
pub fn small_file_unique_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.small_file_unique_id = val.into();
self
}
pub fn big_file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.big_file_id = val.into();
self
}
pub fn big_file_unique_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.big_file_unique_id = val.into();
self
}
}

View file

@ -10,6 +10,7 @@ use crate::types::{Location, User};
/// [result]: https://core.telegram.org/bots/api#inlinequeryresult
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ChosenInlineResult {
/// The unique identifier for the result that was chosen.
pub result_id: String,
@ -32,3 +33,53 @@ pub struct ChosenInlineResult {
/// The query that was used to obtain the result.
pub query: String,
}
impl ChosenInlineResult {
pub fn new<S1, S2>(result_id: S1, from: User, query: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
result_id: result_id.into(),
from,
location: None,
inline_message_id: None,
query: query.into(),
}
}
pub fn result_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.result_id = val.into();
self
}
pub fn from(mut self, val: User) -> Self {
self.from = val;
self
}
pub fn location<S>(mut self, val: Location) -> Self {
self.location = val.into();
self
}
pub fn inline_message_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.inline_message_id = Some(val.into());
self
}
pub fn query<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.query = val.into();
self
}
}

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#contact).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Contact {
/// A contact's phone number.
pub phone_number: String,
@ -23,3 +24,56 @@ pub struct Contact {
/// [vCard]: https://en.wikipedia.org/wiki/VCard
pub vcard: Option<String>,
}
impl Contact {
pub fn new<S1, S2>(phone_number: S1, first_name: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
phone_number: phone_number.into(),
first_name: first_name.into(),
last_name: None,
user_id: None,
vcard: None,
}
}
pub fn phone_number<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.phone_number = val.into();
self
}
pub fn first_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.first_name = val.into();
self
}
pub fn last_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.last_name = Some(val.into());
self
}
pub fn user_id(mut self, val: i32) -> Self {
self.user_id = Some(val);
self
}
pub fn vcard<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.vcard = Some(val.into());
self
}
}

View file

@ -12,6 +12,7 @@ use crate::types::{MimeWrapper, PhotoSize};
/// [audio files]: https://core.telegram.org/bots/api#audio
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Document {
/// An identifier for this file.
pub file_id: String,
@ -33,3 +34,59 @@ pub struct Document {
/// A size of a file.
pub file_size: Option<u32>,
}
impl Document {
pub fn new<S1, S2>(file_id: S1, file_unique_id: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
file_id: file_id.into(),
file_unique_id: file_unique_id.into(),
thumb: None,
file_name: None,
mime_type: None,
file_size: None,
}
}
pub fn file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_id = val.into();
self
}
pub fn file_unique_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_unique_id = val.into();
self
}
pub fn thumb(mut self, val: PhotoSize) -> Self {
self.thumb = Some(val);
self
}
pub fn file_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_name = Some(val.into());
self
}
pub fn mime_type(mut self, val: MimeWrapper) -> Self {
self.mime_type = Some(val);
self
}
pub fn file_size(mut self, val: u32) -> Self {
self.file_size = Some(val);
self
}
}

View file

@ -13,6 +13,7 @@ use serde::{Deserialize, Serialize};
/// [Telegram Passport Documentation]: https://core.telegram.org/passport#receiving-information
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedCredentials {
/// Base64-encoded encrypted JSON-serialized data with unique user's
/// payload, data hashes and secrets required for
@ -30,6 +31,41 @@ pub struct EncryptedCredentials {
pub secret: String,
}
impl EncryptedCredentials {
pub fn new<S1, S2, S3>(data: S1, hash: S2, secret: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self { data: data.into(), hash: hash.into(), secret: secret.into() }
}
pub fn data<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.data = val.into();
self
}
pub fn hash<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.hash = val.into();
self
}
pub fn secret<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.secret = val.into();
self
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -7,6 +7,7 @@ use super::PassportFile;
///
/// [The official docs](https://core.telegram.org/bots/api#encryptedpassportelement).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElement {
/// Base64-encoded element hash for using in
/// [`PassportElementErrorKind::Unspecified`].
@ -19,9 +20,32 @@ pub struct EncryptedPassportElement {
pub kind: EncryptedPassportElementKind,
}
impl EncryptedPassportElement {
pub fn new<S>(hash: S, kind: EncryptedPassportElementKind) -> Self
where
S: Into<String>,
{
Self { hash: hash.into(), kind }
}
pub fn hash<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.hash = val.into();
self
}
pub fn kind(mut self, val: EncryptedPassportElementKind) -> Self {
self.kind = val;
self
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[allow(clippy::large_enum_variant)]
#[non_exhaustive]
pub enum EncryptedPassportElementKind {
PersonalDetails(EncryptedPassportElementPersonalDetails),
Passport(EncryptedPassportElementPassport),
@ -40,6 +64,7 @@ pub enum EncryptedPassportElementKind {
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementPersonalDetails {
/// Base64-encoded encrypted Telegram Passport element data provided
/// by the user, available for `personal_details`, `passport`,
@ -52,8 +77,26 @@ pub struct EncryptedPassportElementPersonalDetails {
pub data: String,
}
impl EncryptedPassportElementPersonalDetails {
pub fn new<S>(data: S) -> Self
where
S: Into<String>,
{
Self { data: data.into() }
}
pub fn data<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.data = val.into();
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementPassport {
/// Base64-encoded encrypted Telegram Passport element data provided
/// by the user, available for `personal_details`, `passport`,
@ -96,8 +139,44 @@ pub struct EncryptedPassportElementPassport {
pub translation: Option<Vec<PassportFile>>,
}
impl EncryptedPassportElementPassport {
pub fn new<S>(data: S, front_side: PassportFile, selfie: PassportFile) -> Self
where
S: Into<String>,
{
Self { data: data.into(), front_side, selfie, translation: None }
}
pub fn data<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.data = val.into();
self
}
pub fn front_side(mut self, val: PassportFile) -> Self {
self.front_side = val;
self
}
pub fn selfie(mut self, val: PassportFile) -> Self {
self.selfie = val;
self
}
pub fn translation<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.translation = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementDriverLicense {
/// Base64-encoded encrypted Telegram Passport element data provided
/// by the user, available for `personal_details`, `passport`,
@ -149,8 +228,53 @@ pub struct EncryptedPassportElementDriverLicense {
pub translation: Option<Vec<PassportFile>>,
}
impl EncryptedPassportElementDriverLicense {
pub fn new<S>(
data: S,
front_side: PassportFile,
reverse_side: PassportFile,
selfie: PassportFile,
) -> Self
where
S: Into<String>,
{
Self { data: data.into(), front_side, reverse_side, selfie, translation: None }
}
pub fn data<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.data = val.into();
self
}
pub fn front_side(mut self, val: PassportFile) -> Self {
self.front_side = val;
self
}
pub fn reverse_side(mut self, val: PassportFile) -> Self {
self.reverse_side = val;
self
}
pub fn selfie(mut self, val: PassportFile) -> Self {
self.selfie = val;
self
}
pub fn translation<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.translation = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementIdentityCard {
/// Base64-encoded encrypted Telegram Passport element data provided
/// by the user, available for `personal_details`, `passport`,
@ -202,9 +326,53 @@ pub struct EncryptedPassportElementIdentityCard {
pub translation: Option<Vec<PassportFile>>,
}
impl EncryptedPassportElementIdentityCard {
pub fn new<S>(
data: S,
front_side: PassportFile,
reverse_side: PassportFile,
selfie: PassportFile,
) -> Self
where
S: Into<String>,
{
Self { data: data.into(), front_side, reverse_side, selfie, translation: None }
}
pub fn data<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.data = val.into();
self
}
pub fn front_side(mut self, val: PassportFile) -> Self {
self.front_side = val;
self
}
pub fn reverse_side(mut self, val: PassportFile) -> Self {
self.reverse_side = val;
self
}
pub fn selfie(mut self, val: PassportFile) -> Self {
self.selfie = val;
self
}
pub fn translation<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.translation = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementInternalPassport {
/// Base64-encoded encrypted Telegram Passport element data provided
/// by the user, available for `personal_details`, `passport`,
@ -247,8 +415,44 @@ pub struct EncryptedPassportElementInternalPassport {
pub translation: Option<Vec<PassportFile>>,
}
impl EncryptedPassportElementInternalPassport {
pub fn new<S>(data: S, front_side: PassportFile, selfie: PassportFile) -> Self
where
S: Into<String>,
{
Self { data: data.into(), front_side, selfie, translation: None }
}
pub fn data<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.data = val.into();
self
}
pub fn front_side(mut self, val: PassportFile) -> Self {
self.front_side = val;
self
}
pub fn selfie(mut self, val: PassportFile) -> Self {
self.selfie = val;
self
}
pub fn translation<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.translation = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementAddress {
/// Base64-encoded encrypted Telegram Passport element data provided
/// by the user, available for `personal_details`, `passport`,
@ -261,8 +465,26 @@ pub struct EncryptedPassportElementAddress {
pub data: String,
}
impl EncryptedPassportElementAddress {
pub fn new<S>(data: S) -> Self
where
S: Into<String>,
{
Self { data: data.into() }
}
pub fn data<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.data = val.into();
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementUtilityBill {
/// Array of encrypted files with documents provided by the user,
/// available for `utility_bill`, `bank_statement`, `rental_agreement`,
@ -287,9 +509,34 @@ pub struct EncryptedPassportElementUtilityBill {
pub translation: Option<Vec<PassportFile>>,
}
impl EncryptedPassportElementUtilityBill {
pub fn new<F>(files: F) -> Self
where
F: Into<Vec<PassportFile>>,
{
Self { files: files.into(), translation: None }
}
pub fn files<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.files = val.into();
self
}
pub fn translation<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.translation = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementBankStatement {
/// Array of encrypted files with documents provided by the user,
/// available for `utility_bill`, `bank_statement`, `rental_agreement`,
@ -314,8 +561,34 @@ pub struct EncryptedPassportElementBankStatement {
pub translation: Option<Vec<PassportFile>>,
}
impl EncryptedPassportElementBankStatement {
pub fn new<F>(files: F) -> Self
where
F: Into<Vec<PassportFile>>,
{
Self { files: files.into(), translation: None }
}
pub fn files<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.files = val.into();
self
}
pub fn translation<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.translation = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementRentalAgreement {
/// Array of encrypted files with documents provided by the user,
/// available for `utility_bill`, `bank_statement`, `rental_agreement`,
@ -340,9 +613,34 @@ pub struct EncryptedPassportElementRentalAgreement {
pub translation: Option<Vec<PassportFile>>,
}
impl EncryptedPassportElementRentalAgreement {
pub fn new<F>(files: F) -> Self
where
F: Into<Vec<PassportFile>>,
{
Self { files: files.into(), translation: None }
}
pub fn files<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.files = val.into();
self
}
pub fn translation<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.translation = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementPassportRegistration {
/// Array of encrypted files with documents provided by the user,
/// available for `utility_bill`, `bank_statement`, `rental_agreement`,
@ -367,8 +665,34 @@ pub struct EncryptedPassportElementPassportRegistration {
pub translation: Option<Vec<PassportFile>>,
}
impl EncryptedPassportElementPassportRegistration {
pub fn new<F>(files: F) -> Self
where
F: Into<Vec<PassportFile>>,
{
Self { files: files.into(), translation: None }
}
pub fn files<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.files = val.into();
self
}
pub fn translation<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.translation = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementTemporaryRegistration {
/// Array of encrypted files with documents provided by the user,
/// available for `utility_bill`, `bank_statement`, `rental_agreement`,
@ -393,18 +717,78 @@ pub struct EncryptedPassportElementTemporaryRegistration {
pub translation: Option<Vec<PassportFile>>,
}
impl EncryptedPassportElementTemporaryRegistration {
pub fn new<F>(files: F) -> Self
where
F: Into<Vec<PassportFile>>,
{
Self { files: files.into(), translation: None }
}
pub fn files<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.files = val.into();
self
}
pub fn translation<P>(mut self, val: P) -> Self
where
P: Into<Vec<PassportFile>>,
{
self.translation = Some(val.into());
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementPhoneNumber {
/// User's verified phone number, available only for `phone_number`
/// type.
pub phone_number: String,
}
impl EncryptedPassportElementPhoneNumber {
pub fn new<S>(phone_number: S) -> Self
where
S: Into<String>,
{
Self { phone_number: phone_number.into() }
}
pub fn phone_number<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.phone_number = val.into();
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct EncryptedPassportElementEmail {
/// User's verified email address, available only for `email` type.
pub email: String,
}
impl EncryptedPassportElementEmail {
pub fn new<S>(email: S) -> Self
where
S: Into<String>,
{
Self { email: email.into() }
}
pub fn email<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.email = val.into();
self
}
}

View file

@ -10,6 +10,7 @@ use serde::{Deserialize, Serialize};
///
/// [`Bot::get_file`]: crate::Bot::get_file
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct File {
/// Identifier for this file.
pub file_id: String,
@ -27,3 +28,48 @@ pub struct File {
/// to get the file.
pub file_path: String,
}
impl File {
pub fn new<S1, S2, S3>(file_id: S1, file_unique_id: S2, file_size: u32, file_path: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
file_id: file_id.into(),
file_unique_id: file_unique_id.into(),
file_size,
file_path: file_path.into(),
}
}
pub fn file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_id = val.into();
self
}
pub fn file_unique_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_unique_id = val.into();
self
}
pub fn file_size(mut self, val: u32) -> Self {
self.file_size = val;
self
}
pub fn file_path<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_id = val.into();
self
}
}

View file

@ -13,7 +13,8 @@ use crate::types::True;
///
/// [privacy mode]: https://core.telegram.org/bots#privacy-mode
#[serde_with_macros::skip_serializing_none]
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, Default, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ForceReply {
/// Shows reply interface to the user, as if they manually selected the
/// bots message and tapped Reply'.
@ -27,3 +28,14 @@ pub struct ForceReply {
/// [`Message`]: crate::types::Message
pub selective: Option<bool>,
}
impl ForceReply {
pub fn new() -> Self {
Self::default()
}
pub fn selective(mut self, val: bool) -> Self {
self.selective = Some(val);
self
}
}

View file

@ -10,6 +10,7 @@ use crate::types::{Animation, MessageEntity, PhotoSize};
/// [@Botfather]: https://t.me/botfather
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Game {
/// Title of the game.
pub title: String,
@ -40,3 +41,66 @@ pub struct Game {
/// [@Botfather]: https://t.me/botfather
pub animation: Option<Animation>,
}
impl Game {
pub fn new<S1, S2, P>(title: S1, description: S2, photo: P) -> Self
where
S1: Into<String>,
S2: Into<String>,
P: Into<Vec<PhotoSize>>,
{
Self {
title: title.into(),
description: description.into(),
photo: photo.into(),
text: None,
text_entities: None,
animation: None,
}
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = val.into();
self
}
pub fn photo<P>(mut self, val: P) -> Self
where
P: Into<Vec<PhotoSize>>,
{
self.photo = val.into();
self
}
pub fn text<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.text = Some(val.into());
self
}
pub fn text_entities<T>(mut self, val: T) -> Self
where
T: Into<Vec<MessageEntity>>,
{
self.text_entities = Some(val.into());
self
}
pub fn animation(mut self, val: Animation) -> Self {
self.animation = Some(val);
self
}
}

View file

@ -6,6 +6,7 @@ use crate::types::user::User;
///
/// [The official docs](https://core.telegram.org/bots/api#gamehighscore).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct GameHighScore {
/// Position in high score table for the game.
pub position: u32,
@ -16,3 +17,24 @@ pub struct GameHighScore {
/// Score.
pub score: u32,
}
impl GameHighScore {
pub fn new(position: u32, user: User, score: u32) -> Self {
Self { position, user, score }
}
pub fn position(mut self, val: u32) -> Self {
self.position = val;
self
}
pub fn user(mut self, val: User) -> Self {
self.user = val;
self
}
pub fn score(mut self, val: u32) -> Self {
self.score = val;
self
}
}

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
///
/// [The official docs](https://core.telegram.org/bots/api#inlinekeyboardbutton).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineKeyboardButton {
/// Label text on the button.
pub text: String,
@ -13,8 +14,31 @@ pub struct InlineKeyboardButton {
pub kind: InlineKeyboardButtonKind,
}
impl InlineKeyboardButton {
pub fn new<S>(text: S, kind: InlineKeyboardButtonKind) -> Self
where
S: Into<String>,
{
Self { text: text.into(), kind }
}
pub fn text<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.text = val.into();
self
}
pub fn kind(mut self, val: InlineKeyboardButtonKind) -> Self {
self.kind = val;
self
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum InlineKeyboardButtonKind {
/// HTTP or tg:// url to be opened when button is pressed.
Url(String),

View file

@ -12,6 +12,7 @@ use crate::types::InlineKeyboardButton;
///
/// [inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Default)]
#[non_exhaustive]
pub struct InlineKeyboardMarkup {
/// Array of button rows, each represented by an array of
/// [`InlineKeyboardButton`] objects.
@ -30,6 +31,23 @@ pub struct InlineKeyboardMarkup {
/// let keyboard = InlineKeyboardMarkup::default().append_row(vec![url_button]);
/// ```
impl InlineKeyboardMarkup {
pub fn new<I1, I2>(inline_keyboard: I1) -> Self
where
I1: Into<Vec<I2>>,
I2: Into<Vec<InlineKeyboardButton>>,
{
Self { inline_keyboard: inline_keyboard.into().into_iter().map(Into::into).collect() }
}
pub fn inline_keyboard<I1, I2>(mut self, val: I1) -> Self
where
I1: Into<Vec<I2>>,
I2: Into<Vec<InlineKeyboardButton>>,
{
self.inline_keyboard = val.into().into_iter().map(Into::into).collect();
self
}
pub fn append_row(mut self, buttons: Vec<InlineKeyboardButton>) -> Self {
self.inline_keyboard.push(buttons);
self

View file

@ -10,6 +10,7 @@ use crate::types::{Location, User};
/// [The official docs](https://core.telegram.org/bots/api#inlinequery).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQuery {
/// Unique identifier for this query.
pub id: String,
@ -26,3 +27,48 @@ pub struct InlineQuery {
/// Offset of the results to be returned, can be controlled by the bot.
pub offset: String,
}
impl InlineQuery {
pub fn new<S1, S2, S3>(id: S1, from: User, query: S2, offset: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self { id: id.into(), from, location: None, query: query.into(), offset: offset.into() }
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn from(mut self, val: User) -> Self {
self.from = val;
self
}
pub fn location(mut self, val: Location) -> Self {
self.location = Some(val);
self
}
pub fn query<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.query = val.into();
self
}
pub fn offset<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.offset = val.into();
self
}
}

View file

@ -19,6 +19,7 @@ use crate::types::{
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, From)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum InlineQueryResult {
#[serde(rename = "audio")]
CachedAudio(InlineQueryResultCachedAudio),

View file

@ -7,6 +7,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultarticle).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultArticle {
/// Unique identifier for this result, 1-64 Bytes.
pub id: String,
@ -39,3 +40,89 @@ pub struct InlineQueryResultArticle {
/// Thumbnail height.
pub thumb_height: Option<i32>,
}
impl InlineQueryResultArticle {
pub fn new<S1, S2>(id: S1, title: S2, input_message_content: InputMessageContent) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
id: id.into(),
title: title.into(),
input_message_content,
reply_markup: None,
url: None,
hide_url: None,
description: None,
thumb_url: None,
thumb_width: None,
thumb_height: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = val;
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.url = Some(val.into());
self
}
pub fn hide_url(mut self, val: bool) -> Self {
self.hide_url = Some(val);
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = Some(val.into());
self
}
pub fn thumb_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.thumb_url = Some(val.into());
self
}
pub fn thumb_width(mut self, val: i32) -> Self {
self.thumb_width = Some(val);
self
}
pub fn thumb_height(mut self, val: i32) -> Self {
self.thumb_height = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultaudio).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultAudio {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -46,3 +47,87 @@ pub struct InlineQueryResultAudio {
/// Content of the message to be sent instead of the audio.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultAudio {
pub fn new<S1, S2, S3>(id: S1, audio_url: S2, title: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
audio_url: audio_url.into(),
title: title.into(),
caption: None,
parse_mode: None,
performer: None,
audio_duration: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn audio_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.audio_url = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn performer<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.performer = Some(val.into());
self
}
pub fn audio_duration<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.audio_duration = Some(val.into());
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultcachedaudio).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultCachedAudio {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -37,3 +38,59 @@ pub struct InlineQueryResultCachedAudio {
/// Content of the message to be sent instead of the audio.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultCachedAudio {
pub fn new<S1, S2>(id: S1, audio_file_id: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
id: id.into(),
audio_file_id: audio_file_id.into(),
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn audio_file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.audio_file_id = val.into();
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultcacheddocument).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultCachedDocument {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -43,3 +44,78 @@ pub struct InlineQueryResultCachedDocument {
/// Content of the message to be sent instead of the file.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultCachedDocument {
pub fn new<S1, S2, S3>(id: S1, title: S2, document_file_id: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
title: title.into(),
document_file_id: document_file_id.into(),
description: None,
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn document_file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.document_file_id = val.into();
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = Some(val.into());
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode<S>(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultcachedgif).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultCachedGif {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -41,3 +42,68 @@ pub struct InlineQueryResultCachedGif {
/// Content of the message to be sent instead of the GIF animation.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultCachedGif {
pub fn new<S1, S2>(id: S1, gif_file_id: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
id: id.into(),
gif_file_id: gif_file_id.into(),
title: None,
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn gif_file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.gif_file_id = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = Some(val.into());
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -12,6 +12,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultcachedmpeg4gif).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultCachedMpeg4Gif {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -41,3 +42,60 @@ pub struct InlineQueryResultCachedMpeg4Gif {
/// Content of the message to be sent instead of the video animation.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultCachedMpeg4Gif {
pub fn new<S1, S2>(id: S1, mpeg4_file_id: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
id: id.into(),
mpeg4_file_id: mpeg4_file_id.into(),
title: None,
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = Some(val.into());
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode<S>(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultcachedphoto).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultCachedPhoto {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -43,3 +44,77 @@ pub struct InlineQueryResultCachedPhoto {
/// Content of the message to be sent instead of the photo.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultCachedPhoto {
pub fn new<S1, S2>(id: S1, photo_file_id: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
id: id.into(),
photo_file_id: photo_file_id.into(),
title: None,
description: None,
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn photo_file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.photo_file_id = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = Some(val.into());
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = Some(val.into());
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode<S>(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultcachedsticker).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultCachedSticker {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -26,3 +27,44 @@ pub struct InlineQueryResultCachedSticker {
/// Content of the message to be sent instead of the sticker.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultCachedSticker {
pub fn new<S1, S2>(id: S1, sticker_file_id: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
id: id.into(),
sticker_file_id: sticker_file_id.into(),
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn sticker_file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.sticker_file_id = val.into();
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultcachedvideo).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultCachedVideo {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -43,3 +44,78 @@ pub struct InlineQueryResultCachedVideo {
/// Content of the message to be sent instead of the video.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultCachedVideo {
pub fn new<S1, S2, S3>(id: S1, video_file_id: S2, title: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
video_file_id: video_file_id.into(),
title: title.into(),
description: None,
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn video_file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.video_file_id = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = Some(val.into());
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode<S>(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultcachedvideo).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultCachedVoice {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -40,3 +41,69 @@ pub struct InlineQueryResultCachedVoice {
/// Content of the message to be sent instead of the voice message.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultCachedVoice {
pub fn new<S1, S2, S3>(id: S1, voice_file_id: S2, title: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
voice_file_id: voice_file_id.into(),
title: title.into(),
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn voice_file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.voice_file_id = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode<S>(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultcachedvideo).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultContact {
/// Unique identifier for this result, 1-64 Bytes.
pub id: String,
@ -47,3 +48,93 @@ pub struct InlineQueryResultContact {
/// Thumbnail height.
pub thumb_height: Option<i32>,
}
impl InlineQueryResultContact {
pub fn new<S1, S2, S3>(id: S1, phone_number: S2, first_name: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
phone_number: phone_number.into(),
first_name: first_name.into(),
last_name: None,
vcard: None,
reply_markup: None,
input_message_content: None,
thumb_url: None,
thumb_width: None,
thumb_height: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn phone_number<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.phone_number = val.into();
self
}
pub fn first_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.first_name = val.into();
self
}
pub fn last_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.last_name = Some(val.into());
self
}
pub fn vcard<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.vcard = Some(val.into());
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
pub fn thumb_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.thumb_url = Some(val.into());
self
}
pub fn thumb_width(mut self, val: i32) -> Self {
self.thumb_width = Some(val);
self
}
pub fn thumb_height(mut self, val: i32) -> Self {
self.thumb_height = Some(val);
self
}
}

View file

@ -12,6 +12,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, MimeWrapper, Parse
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultdocument).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultDocument {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -55,3 +56,83 @@ pub struct InlineQueryResultDocument {
/// Thumbnail height.
pub thumb_height: Option<i32>,
}
impl InlineQueryResultDocument {
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode<S>(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn document_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.document_url = val.into();
self
}
pub fn mime_type(mut self, val: MimeWrapper) -> Self {
self.mime_type = val;
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = Some(val.into());
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
pub fn thumb_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.thumb_url = Some(val.into());
self
}
pub fn thumb_width(mut self, val: i32) -> Self {
self.thumb_width = Some(val);
self
}
pub fn thumb_height(mut self, val: i32) -> Self {
self.thumb_height = Some(val);
self
}
}

View file

@ -9,6 +9,7 @@ use crate::types::InlineKeyboardMarkup;
/// [game]: https://core.telegram.org/bots/api#games
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultGame {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -21,3 +22,34 @@ pub struct InlineQueryResultGame {
/// [Inline keyboard]: https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl InlineQueryResultGame {
pub fn new<S1, S2>(id: S1, game_short_name: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self { id: id.into(), game_short_name: game_short_name.into(), reply_markup: None }
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn game_short_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.game_short_name = val.into();
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultgif).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultGif {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -52,3 +53,96 @@ pub struct InlineQueryResultGif {
/// Content of the message to be sent instead of the GIF animation.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultGif {
pub fn new<S1, S2, S3>(id: S1, gif_url: S2, thumb_url: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
gif_url: gif_url.into(),
gif_width: None,
gif_height: None,
gif_duration: None,
thumb_url: thumb_url.into(),
title: None,
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn gif_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.gif_url = val.into();
self
}
pub fn gif_width(mut self, val: i32) -> Self {
self.gif_width = Some(val);
self
}
pub fn gif_height(mut self, val: i32) -> Self {
self.gif_height = Some(val);
self
}
pub fn gif_duration(mut self, val: i32) -> Self {
self.gif_duration = Some(val);
self
}
pub fn thumb_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.thumb_url = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = Some(val.into());
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultlocation).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultLocation {
/// Unique identifier for this result, 1-64 Bytes.
pub id: String,
@ -45,3 +46,83 @@ pub struct InlineQueryResultLocation {
/// Thumbnail height.
pub thumb_height: Option<i32>,
}
impl InlineQueryResultLocation {
pub fn new<S1, S2>(id: S1, title: S2, latitude: f64, longitude: f64) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
id: id.into(),
title: title.into(),
latitude,
longitude,
live_period: None,
reply_markup: None,
input_message_content: None,
thumb_url: None,
thumb_width: None,
thumb_height: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn latitude(mut self, val: f64) -> Self {
self.latitude = val;
self
}
pub fn longitude(mut self, val: f64) -> Self {
self.longitude = val;
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn live_period(mut self, val: i32) -> Self {
self.live_period = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
pub fn thumb_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.thumb_url = Some(val.into());
self
}
pub fn thumb_width(mut self, val: i32) -> Self {
self.thumb_width = Some(val);
self
}
pub fn thumb_height(mut self, val: i32) -> Self {
self.thumb_height = Some(val);
self
}
}

View file

@ -12,6 +12,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultmpeg4gif).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultMpeg4Gif {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -53,3 +54,96 @@ pub struct InlineQueryResultMpeg4Gif {
/// Content of the message to be sent instead of the video animation.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultMpeg4Gif {
pub fn new<S1, S2, S3>(id: S1, mpeg4_url: S2, thumb_url: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
mpeg4_url: mpeg4_url.into(),
thumb_url: thumb_url.into(),
mpeg4_width: None,
mpeg4_height: None,
mpeg4_duration: None,
title: None,
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn mpeg4_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.mpeg4_url = val.into();
self
}
pub fn mpeg4_width(mut self, val: i32) -> Self {
self.mpeg4_width = Some(val);
self
}
pub fn mpeg4_height(mut self, val: i32) -> Self {
self.mpeg4_height = Some(val);
self
}
pub fn mpeg4_duration(mut self, val: i32) -> Self {
self.mpeg4_duration = Some(val);
self
}
pub fn thumb_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.thumb_url = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = Some(val.into());
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode<S>(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultphoto).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultPhoto {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -53,3 +54,99 @@ pub struct InlineQueryResultPhoto {
/// Content of the message to be sent instead of the photo.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultPhoto {
pub fn new<S1, S2, S3>(id: S1, photo_url: S2, thumb_url: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
photo_url: photo_url.into(),
thumb_url: thumb_url.into(),
photo_width: None,
photo_height: None,
title: None,
description: None,
caption: None,
parse_mode: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn photo_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.photo_url = val.into();
self
}
pub fn thumb_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.thumb_url = val.into();
self
}
pub fn photo_width<S>(mut self, val: i32) -> Self {
self.photo_width = Some(val);
self
}
pub fn photo_height<S>(mut self, val: i32) -> Self {
self.photo_height = Some(val);
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = Some(val.into());
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = Some(val.into());
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode<S>(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultvenue).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultVenue {
/// Unique identifier for this result, 1-64 Bytes.
pub id: String,
@ -52,3 +53,105 @@ pub struct InlineQueryResultVenue {
/// Thumbnail height.
pub thumb_height: Option<i32>,
}
impl InlineQueryResultVenue {
pub fn new<S1, S2, S3>(id: S1, latitude: f64, longitude: f64, title: S2, address: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
latitude,
longitude,
title: title.into(),
address: address.into(),
foursquare_id: None,
foursquare_type: None,
reply_markup: None,
input_message_content: None,
thumb_url: None,
thumb_width: None,
thumb_height: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn latitude(mut self, val: f64) -> Self {
self.latitude = val;
self
}
pub fn longitude(mut self, val: f64) -> Self {
self.longitude = val;
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn address<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.address = val.into();
self
}
pub fn foursquare_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.foursquare_id = Some(val.into());
self
}
pub fn foursquare_type<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.foursquare_type = Some(val.into());
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
pub fn thumb_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.thumb_url = Some(val.into());
self
}
pub fn thumb_width(mut self, val: i32) -> Self {
self.thumb_width = Some(val);
self
}
pub fn thumb_height(mut self, val: i32) -> Self {
self.thumb_height = Some(val);
self
}
}

View file

@ -12,6 +12,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, MimeWrapper, Parse
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultvideo).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultVideo {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -64,3 +65,118 @@ pub struct InlineQueryResultVideo {
/// crate::types::InlineQueryResultVideo
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultVideo {
pub fn new<S1, S2, S3, S4>(
id: S1,
video_url: S2,
mime_type: MimeWrapper,
thumb_url: S3,
title: S4,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
S4: Into<String>,
{
Self {
id: id.into(),
video_url: video_url.into(),
mime_type,
thumb_url: thumb_url.into(),
title: title.into(),
caption: None,
parse_mode: None,
video_width: None,
video_height: None,
video_duration: None,
description: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn video_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.video_url = val.into();
self
}
pub fn mime_type(mut self, val: MimeWrapper) -> Self {
self.mime_type = val;
self
}
pub fn thumb_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.thumb_url = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn video_width(mut self, val: i32) -> Self {
self.video_width = Some(val);
self
}
pub fn video_height(mut self, val: i32) -> Self {
self.video_height = Some(val);
self
}
pub fn video_duration(mut self, val: i32) -> Self {
self.video_duration = Some(val);
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = Some(val.into());
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -12,6 +12,7 @@ use crate::types::{InlineKeyboardMarkup, InputMessageContent, ParseMode};
/// [The official docs](https://core.telegram.org/bots/api#inlinequeryresultvoice).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InlineQueryResultVoice {
/// Unique identifier for this result, 1-64 bytes.
pub id: String,
@ -44,3 +45,75 @@ pub struct InlineQueryResultVoice {
/// Content of the message to be sent instead of the voice recording.
pub input_message_content: Option<InputMessageContent>,
}
impl InlineQueryResultVoice {
pub fn new<S1, S2, S3>(id: S1, voice_url: S2, title: S3) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
id: id.into(),
voice_url: voice_url.into(),
title: title.into(),
caption: None,
parse_mode: None,
voice_duration: None,
reply_markup: None,
input_message_content: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn voice_url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.voice_url = val.into();
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn voice_duration(mut self, value: i32) -> Self {
self.voice_duration = Some(value);
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
pub fn input_message_content(mut self, val: InputMessageContent) -> Self {
self.input_message_content = Some(val);
self
}
}

View file

@ -6,6 +6,7 @@ use std::{borrow::Cow, path::PathBuf};
///
/// [The official docs](https://core.telegram.org/bots/api#inputfile).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Deserialize)]
#[non_exhaustive]
pub enum InputFile {
File(PathBuf),
Memory { file_name: String, data: Cow<'static, [u8]> },

View file

@ -2,13 +2,13 @@ use serde::{Deserialize, Serialize};
use crate::types::{InputFile, ParseMode};
// TODO: should variants use new-type?
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
/// This object represents the content of a media message to be sent.
///
/// [The official docs](https://core.telegram.org/bots/api#inputmedia).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum InputMedia {
Photo(InputMediaPhoto),
Video(InputMediaVideo),
@ -22,6 +22,7 @@ pub enum InputMedia {
/// [The official docs](https://core.telegram.org/bots/api#inputmediaphoto).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InputMediaPhoto {
/// File to send.
pub media: InputFile,
@ -38,11 +39,36 @@ pub struct InputMediaPhoto {
pub parse_mode: Option<ParseMode>,
}
impl InputMediaPhoto {
pub fn new(media: InputFile) -> Self {
Self { media, caption: None, parse_mode: None }
}
pub fn media(mut self, val: InputFile) -> Self {
self.media = val;
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
}
/// Represents a video to be sent.
///
/// [The official docs](https://core.telegram.org/bots/api#inputmediavideo).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InputMediaVideo {
// File to send.
pub media: InputFile,
@ -78,12 +104,71 @@ pub struct InputMediaVideo {
pub supports_streaming: Option<bool>,
}
impl InputMediaVideo {
pub fn new(media: InputFile) -> Self {
Self {
media,
thumb: None,
caption: None,
parse_mode: None,
width: None,
height: None,
duration: None,
supports_streaming: None,
}
}
pub fn media(mut self, val: InputFile) -> Self {
self.media = val;
self
}
pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val);
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn width(mut self, val: u16) -> Self {
self.width = Some(val);
self
}
pub fn height(mut self, val: u16) -> Self {
self.height = Some(val);
self
}
pub fn duration(mut self, val: u16) -> Self {
self.duration = Some(val);
self
}
pub fn supports_streaming(mut self, val: bool) -> Self {
self.supports_streaming = Some(val);
self
}
}
/// Represents an animation file (GIF or H.264/MPEG-4 AVC video without
/// sound) to be sent.
///
/// [The official docs](https://core.telegram.org/bots/api#inputmediaanimation).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InputMediaAnimation {
/// File to send.
pub media: InputFile,
@ -116,11 +201,64 @@ pub struct InputMediaAnimation {
pub duration: Option<u16>,
}
impl InputMediaAnimation {
pub fn new(media: InputFile) -> Self {
Self {
media,
thumb: None,
caption: None,
parse_mode: None,
width: None,
height: None,
duration: None,
}
}
pub fn media(mut self, val: InputFile) -> Self {
self.media = val;
self
}
pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val);
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn width(mut self, val: u16) -> Self {
self.width = Some(val);
self
}
pub fn height(mut self, val: u16) -> Self {
self.height = Some(val);
self
}
pub fn duration(mut self, val: u16) -> Self {
self.duration = Some(val);
self
}
}
/// Represents an audio file to be treated as music to be sent.
///
/// [The official docs](https://core.telegram.org/bots/api#inputmediaaudio).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InputMediaAudio {
/// File to send.
pub media: InputFile,
@ -141,7 +279,7 @@ pub struct InputMediaAudio {
/// [Markdown]: https://core.telegram.org/bots/api#markdown-style
/// [HTML]: https://core.telegram.org/bots/api#html-style
/// [bold, italic, fixed-width text or inline URLs]: https://core.telegram.org/bots/api#formatting-options
pub parse_mode: Option<String>,
pub parse_mode: Option<ParseMode>,
/// Duration of the audio in seconds.
pub duration: Option<u16>,
@ -153,11 +291,70 @@ pub struct InputMediaAudio {
pub title: Option<String>,
}
impl InputMediaAudio {
pub fn new(media: InputFile) -> Self {
Self {
media,
thumb: None,
caption: None,
parse_mode: None,
performer: None,
title: None,
duration: None,
}
}
pub fn media(mut self, val: InputFile) -> Self {
self.media = val;
self
}
pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val);
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn duration(mut self, val: u16) -> Self {
self.duration = Some(val);
self
}
pub fn performer<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.performer = Some(val.into());
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = Some(val.into());
self
}
}
/// Represents a general file to be sent.
///
/// [The official docs](https://core.telegram.org/bots/api#inputmediadocument).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InputMediaDocument {
/// File to send.
pub media: InputFile,
@ -181,6 +378,30 @@ pub struct InputMediaDocument {
pub parse_mode: Option<ParseMode>,
}
impl InputMediaDocument {
pub fn new(media: InputFile) -> Self {
Self { media, thumb: None, caption: None, parse_mode: None }
}
pub fn thumb(mut self, val: InputFile) -> Self {
self.thumb = Some(val);
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
}
impl InputMedia {
pub fn media(&self) -> &InputFile {
match self {

View file

@ -8,6 +8,7 @@ use crate::types::ParseMode;
/// [The official docs](https://core.telegram.org/bots/api#inputmessagecontent).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum InputMessageContent {
Text(InputMessageContentText),
Location(InputMessageContentLocation),
@ -18,6 +19,7 @@ pub enum InputMessageContent {
/// inline query.
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InputMessageContentText {
/// Text of the message to be sent, 1-4096 characters.
pub message_text: String,
@ -34,10 +36,38 @@ pub struct InputMessageContentText {
pub disable_web_page_preview: Option<bool>,
}
impl InputMessageContentText {
pub fn new<S>(message_text: S) -> Self
where
S: Into<String>,
{
Self { message_text: message_text.into(), parse_mode: None, disable_web_page_preview: None }
}
pub fn message_text<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.message_text = val.into();
self
}
pub fn parse_mode(mut self, val: ParseMode) -> Self {
self.parse_mode = Some(val);
self
}
pub fn disable_web_page_preview(mut self, val: bool) -> Self {
self.disable_web_page_preview = Some(val);
self
}
}
/// Represents the content of a location message to be sent as the result of an
/// inline query.
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InputMessageContentLocation {
/// Latitude of the location in degrees.
pub latitude: f64,
@ -50,11 +80,32 @@ pub struct InputMessageContentLocation {
pub live_period: Option<u32>,
}
impl InputMessageContentLocation {
pub fn new(latitude: f64, longitude: f64) -> Self {
Self { latitude, longitude, live_period: None }
}
pub fn latitude(mut self, val: f64) -> Self {
self.latitude = val;
self
}
pub fn longitude(mut self, val: f64) -> Self {
self.longitude = val;
self
}
pub fn live_period(mut self, val: u32) -> Self {
self.live_period = Some(val);
self
}
}
/// Represents the content of a venue message to be sent as the result of
/// an inline query.
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InputMessageContentVenue {
/// Latitude of the venue in degrees.
pub latitude: f64,
@ -77,10 +128,70 @@ pub struct InputMessageContentVenue {
pub foursquare_type: Option<String>,
}
impl InputMessageContentVenue {
pub fn new<S1, S2>(latitude: f64, longitude: f64, title: S1, address: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
latitude,
longitude,
title: title.into(),
address: address.into(),
foursquare_id: None,
foursquare_type: None,
}
}
pub fn latitude(mut self, val: f64) -> Self {
self.latitude = val;
self
}
pub fn longitude(mut self, val: f64) -> Self {
self.longitude = val;
self
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn address<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.address = val.into();
self
}
pub fn foursquare_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.foursquare_id = Some(val.into());
self
}
pub fn foursquare_type<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.foursquare_type = Some(val.into());
self
}
}
/// Represents the content of a contact message to be sent as the result of
/// an inline query.
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InputMessageContentContact {
/// Contact's phone number.
pub phone_number: String,
@ -98,6 +209,53 @@ pub struct InputMessageContentContact {
pub vcard: Option<String>,
}
impl InputMessageContentContact {
pub fn new<S1, S2>(phone_number: S1, first_name: S2) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
phone_number: phone_number.into(),
first_name: first_name.into(),
last_name: None,
vcard: None,
}
}
pub fn phone_number<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.phone_number = val.into();
self
}
pub fn first_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.first_name = val.into();
self
}
pub fn last_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.last_name = Some(val.into());
self
}
pub fn vcard<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.vcard = Some(val.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
///
/// [The official docs](https://core.telegram.org/bots/api#invoice).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Invoice {
/// Product name.
pub title: String,
@ -27,3 +28,63 @@ pub struct Invoice {
/// [`currencies.json`]: https://core.telegram.org/bots/payments/currencies.json
pub total_amount: i32,
}
impl Invoice {
pub fn new<S1, S2, S3, S4>(
title: S1,
description: S2,
start_parameter: S3,
currency: S4,
total_amount: i32,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
S4: Into<String>,
{
Self {
title: title.into(),
description: description.into(),
start_parameter: start_parameter.into(),
currency: currency.into(),
total_amount,
}
}
pub fn title<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.title = val.into();
self
}
pub fn description<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.description = val.into();
self
}
pub fn start_parameter<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.start_parameter = val.into();
self
}
pub fn currency<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.currency = val.into();
self
}
pub fn total_amount(mut self, val: i32) -> Self {
self.total_amount = val;
self
}
}

View file

@ -10,6 +10,7 @@ use crate::types::{KeyboardButtonPollType, True};
/// [The official docs](https://core.telegram.org/bots/api#keyboardbutton).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct KeyboardButton {
/// Text of the button. If none of the optional fields are used, it will
/// be sent as a message when the button is pressed.
@ -25,8 +26,6 @@ pub struct KeyboardButton {
}
impl KeyboardButton {
/// Creates `KeyboardButton` with the provided `text` and all the other
/// fields set to `None`.
pub fn new<T>(text: T) -> Self
where
T: Into<String>,
@ -45,6 +44,7 @@ impl KeyboardButton {
// Serialize + Deserialize are implemented by hand
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[non_exhaustive]
pub enum ButtonRequest {
Location,
Contact,
@ -54,6 +54,7 @@ pub enum ButtonRequest {
/// Helper struct for (de)serializing [`ButtonRequest`](ButtonRequest)
#[serde_with_macros::skip_serializing_none]
#[derive(Serialize, Deserialize)]
#[non_exhaustive]
struct RawRequest {
/// If `true`, the user's phone number will be sent as a contact
/// when the button is pressed. Available in private chats only.

View file

@ -1,6 +1,24 @@
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct KeyboardButtonPollType {
poll_type: String,
}
impl KeyboardButtonPollType {
pub fn new<S>(poll_type: S) -> Self
where
S: Into<String>,
{
Self { poll_type: poll_type.into() }
}
pub fn poll_type<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.poll_type = val.into();
self
}
}

View file

@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
///
/// [The official docs](https://core.telegram.org/bots/api#labeledprice).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct LabeledPrice {
/// Portion label.
pub label: String,
@ -19,6 +20,28 @@ pub struct LabeledPrice {
pub amount: i32,
}
impl LabeledPrice {
pub fn new<S>(label: S, amount: i32) -> Self
where
S: Into<String>,
{
Self { label: label.into(), amount }
}
pub fn label<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.label = val.into();
self
}
pub fn amount(mut self, val: i32) -> Self {
self.amount = val;
self
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
/// This object represents a point on the map.
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Location {
/// Longitude as defined by sender.
pub longitude: f64,
@ -9,3 +10,19 @@ pub struct Location {
/// Latitude as defined by sender.
pub latitude: f64,
}
impl Location {
pub fn new(longitude: f64, latitude: f64) -> Self {
Self { longitude, latitude }
}
pub fn latitude(mut self, val: f64) -> Self {
self.latitude = val;
self
}
pub fn longitude(mut self, val: f64) -> Self {
self.longitude = val;
self
}
}

View file

@ -14,9 +14,41 @@ use serde::{Deserialize, Serialize};
/// [Telegram Login Widget]: https://core.telegram.org/widgets/login
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct LoginUrl {
pub url: String,
pub forward_text: Option<String>,
pub bot_username: Option<String>,
pub request_write_access: Option<bool>,
}
impl LoginUrl {
pub fn url<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.url = val.into();
self
}
pub fn forward_text<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.forward_text = Some(val.into());
self
}
pub fn bot_username<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.bot_username = Some(val.into());
self
}
pub fn request_write_access<S>(mut self, val: bool) -> Self {
self.request_write_access = Some(val);
self
}
}

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
///
/// [The official docs](https://core.telegram.org/bots/api#maskposition).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MaskPosition {
/// The part of the face relative to which the mask should be placed. One
/// of `forehead`, `eyes`, `mouth`, or `chin`.
@ -23,3 +24,35 @@ pub struct MaskPosition {
/// Mask scaling coefficient. For example, `2.0` means double size.
pub scale: f64,
}
impl MaskPosition {
pub fn new<S>(point: S, x_shift: f64, y_shift: f64, scale: f64) -> Self
where
S: Into<String>,
{
Self { point: point.into(), x_shift, y_shift, scale }
}
pub fn point<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.point = val.into();
self
}
pub fn x_shift(mut self, val: f64) -> Self {
self.x_shift = val;
self
}
pub fn y_shift(mut self, val: f64) -> Self {
self.y_shift = val;
self
}
pub fn scale(mut self, val: f64) -> Self {
self.scale = val;
self
}
}

View file

@ -13,6 +13,7 @@ use crate::types::{
///
/// [The official docs](https://core.telegram.org/bots/api#message).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Message {
/// Unique message identifier inside this chat.
#[serde(rename = "message_id")]
@ -28,8 +29,35 @@ pub struct Message {
pub kind: MessageKind,
}
impl Message {
pub fn new(id: i32, date: i32, chat: Chat, kind: MessageKind) -> Self {
Self { id, date, chat, kind }
}
pub fn id(mut self, val: i32) -> Self {
self.id = val;
self
}
pub fn date(mut self, val: i32) -> Self {
self.date = val;
self
}
pub fn chat(mut self, val: Chat) -> Self {
self.chat = val;
self
}
pub fn kind(mut self, val: MessageKind) -> Self {
self.kind = val;
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum MessageKind {
Common(MessageCommon),
NewChatMembers(MessageNewChatMembers),
@ -50,6 +78,7 @@ pub enum MessageKind {
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageCommon {
/// Sender, empty for messages sent to channels.
pub from: Option<User>,
@ -68,7 +97,39 @@ pub struct MessageCommon {
pub reply_markup: Option<InlineKeyboardMarkup>,
}
impl MessageCommon {
pub fn new(forward_kind: ForwardKind, media_kind: MediaKind) -> Self {
Self { from: None, forward_kind, edit_date: None, media_kind, reply_markup: None }
}
pub fn from(mut self, val: User) -> Self {
self.from = Some(val);
self
}
pub fn forward_kind(mut self, val: ForwardKind) -> Self {
self.forward_kind = val;
self
}
pub fn edit_date(mut self, val: i32) -> Self {
self.edit_date = Some(val);
self
}
pub fn media_kind(mut self, val: MediaKind) -> Self {
self.media_kind = val;
self
}
pub fn reply_markup(mut self, val: InlineKeyboardMarkup) -> Self {
self.reply_markup = Some(val);
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageNewChatMembers {
/// New members that were added to the group or supergroup and
/// information about them (the bot itself may be one of these
@ -76,38 +137,124 @@ pub struct MessageNewChatMembers {
pub new_chat_members: Vec<User>,
}
impl MessageNewChatMembers {
pub fn new<N>(new_chat_members: N) -> Self
where
N: Into<Vec<User>>,
{
Self { new_chat_members: new_chat_members.into() }
}
pub fn new_chat_members<N>(mut self, val: N) -> Self
where
N: Into<Vec<User>>,
{
self.new_chat_members = val.into();
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageLeftChatMember {
/// A member was removed from the group, information about them (this
/// member may be the bot itself).
pub left_chat_member: User,
}
impl MessageLeftChatMember {
pub fn new<N>(left_chat_member: N) -> Self
where
N: Into<User>,
{
Self { left_chat_member: left_chat_member.into() }
}
pub fn left_chat_member<N>(mut self, val: N) -> Self
where
N: Into<User>,
{
self.left_chat_member = val.into();
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageNewChatTitle {
/// A chat title was changed to this value.
pub new_chat_title: String,
}
impl MessageNewChatTitle {
pub fn new<N>(new_chat_title: N) -> Self
where
N: Into<String>,
{
Self { new_chat_title: new_chat_title.into() }
}
pub fn new_chat_title<N>(mut self, val: N) -> Self
where
N: Into<String>,
{
self.new_chat_title = val.into();
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageNewChatPhoto {
/// A chat photo was change to this value.
pub new_chat_photo: Vec<PhotoSize>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
impl MessageNewChatPhoto {
pub fn new<N>(new_chat_photo: N) -> Self
where
N: Into<Vec<PhotoSize>>,
{
Self { new_chat_photo: new_chat_photo.into() }
}
pub fn new_chat_photo<N>(mut self, val: N) -> Self
where
N: Into<Vec<PhotoSize>>,
{
self.new_chat_photo = val.into();
self
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageDeleteChatPhoto {
/// Service message: the chat photo was deleted.
pub delete_chat_photo: True,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
impl MessageDeleteChatPhoto {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageGroupChatCreated {
/// Service message: the group has been created.
pub group_chat_created: True,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
impl MessageGroupChatCreated {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageSupergroupChatCreated {
/// Service message: the supergroup has been created. This field cant
/// be received in a message coming through updates, because bot cant
@ -117,7 +264,14 @@ pub struct MessageSupergroupChatCreated {
pub supergroup_chat_created: True,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
impl MessageSupergroupChatCreated {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageChannelChatCreated {
/// Service message: the channel has been created. This field cant be
/// received in a message coming through updates, because bot cant be
@ -127,7 +281,14 @@ pub struct MessageChannelChatCreated {
pub channel_chat_created: True,
}
impl MessageChannelChatCreated {
pub fn new() -> Self {
Self::default()
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageMigrate {
/// The group has been migrated to a supergroup with the specified
/// identifier. This number may be greater than 32 bits and some
@ -146,7 +307,24 @@ pub struct MessageMigrate {
pub migrate_from_chat_id: i64,
}
impl MessageMigrate {
pub fn new(migrate_to_chat_id: i64, migrate_from_chat_id: i64) -> Self {
Self { migrate_to_chat_id, migrate_from_chat_id }
}
pub fn migrate_to_chat_id(mut self, val: i64) -> Self {
self.migrate_to_chat_id = val;
self
}
pub fn migrate_from_chat_id(mut self, val: i64) -> Self {
self.migrate_from_chat_id = val;
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessagePinned {
/// Specified message was pinned. Note that the Message object in this
/// field will not contain further `reply_to_message` fields even if it
@ -155,7 +333,19 @@ pub struct MessagePinned {
pub pinned: Box<Message>,
}
impl MessagePinned {
pub fn new(pinned: Message) -> Self {
Self { pinned: Box::new(pinned) }
}
pub fn pinned(mut self, val: Message) -> Self {
self.pinned = Box::new(val);
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageInvoice {
/// Message is an invoice for a [payment], information about the
/// invoice. [More about payments »].
@ -165,7 +355,19 @@ pub struct MessageInvoice {
pub invoice: Invoice,
}
impl MessageInvoice {
pub fn new(invoice: Invoice) -> Self {
Self { invoice }
}
pub fn invoice(mut self, val: Invoice) -> Self {
self.invoice = val;
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageSuccessfulPayment {
/// Message is a service message about a successful payment,
/// information about the payment. [More about payments »].
@ -174,7 +376,19 @@ pub struct MessageSuccessfulPayment {
pub successful_payment: SuccessfulPayment,
}
impl MessageSuccessfulPayment {
pub fn new(successful_payment: SuccessfulPayment) -> Self {
Self { successful_payment }
}
pub fn successful_payment(mut self, val: SuccessfulPayment) -> Self {
self.successful_payment = val;
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageConnectedWebsite {
/// The domain name of the website on which the user has logged in.
/// [More about Telegram Login »].
@ -183,13 +397,43 @@ pub struct MessageConnectedWebsite {
pub connected_website: String,
}
impl MessageConnectedWebsite {
pub fn new<S>(connected_website: S) -> Self
where
S: Into<String>,
{
Self { connected_website: connected_website.into() }
}
pub fn connected_website<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.connected_website = val.into();
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessagePassportData {
/// Telegram Passport data.
pub passport_data: PassportData,
}
impl MessagePassportData {
pub fn new(passport_data: PassportData) -> Self {
Self { passport_data }
}
pub fn passport_data(mut self, val: PassportData) -> Self {
self.passport_data = val;
self
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum ForwardedFrom {
#[serde(rename = "forward_from")]
User(User),
@ -199,6 +443,7 @@ pub enum ForwardedFrom {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum ForwardKind {
Channel(ForwardChannel),
NonChannel(ForwardNonChannel),
@ -206,6 +451,7 @@ pub enum ForwardKind {
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ForwardChannel {
#[serde(rename = "forward_date")]
pub date: i32,
@ -220,7 +466,37 @@ pub struct ForwardChannel {
pub signature: Option<String>,
}
impl ForwardChannel {
pub fn new(date: i32, chat: Chat, message_id: i32) -> Self {
Self { date, chat, message_id, signature: None }
}
pub fn date(mut self, val: i32) -> Self {
self.date = val;
self
}
pub fn chat(mut self, val: Chat) -> Self {
self.chat = val;
self
}
pub fn message_id(mut self, val: i32) -> Self {
self.message_id = val;
self
}
pub fn signature<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.signature = Some(val.into());
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ForwardNonChannel {
#[serde(rename = "forward_date")]
pub date: i32,
@ -229,13 +505,42 @@ pub struct ForwardNonChannel {
pub from: ForwardedFrom,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
impl ForwardNonChannel {
pub fn new(date: i32, from: ForwardedFrom) -> Self {
Self { date, from }
}
pub fn date(mut self, val: i32) -> Self {
self.date = val;
self
}
pub fn from(mut self, val: ForwardedFrom) -> Self {
self.from = val;
self
}
}
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ForwardOrigin {
pub reply_to_message: Option<Box<Message>>,
}
impl ForwardOrigin {
pub fn new() -> Self {
Self::default()
}
pub fn reply_to_message(mut self, val: Message) -> Self {
self.reply_to_message = Some(Box::new(val));
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum MediaKind {
Animation(MediaAnimation),
Audio(MediaAudio),
@ -254,6 +559,7 @@ pub enum MediaKind {
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaAnimation {
/// Message is an animation, information about the animation. For
/// backward compatibility, when this field is set, the document field
@ -274,8 +580,39 @@ pub struct MediaAnimation {
pub caption_entities: Vec<MessageEntity>,
}
impl MediaAnimation {
pub fn new<CE>(animation: Animation, caption_entities: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
Self { animation, document: (), caption: None, caption_entities: caption_entities.into() }
}
pub fn animation(mut self, val: Animation) -> Self {
self.animation = val;
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn caption_entities<CE>(mut self, val: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
self.caption_entities = val.into();
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaAudio {
/// Message is an audio file, information about the file.
pub audio: Audio,
@ -289,14 +626,57 @@ pub struct MediaAudio {
pub caption_entities: Vec<MessageEntity>,
}
impl MediaAudio {
pub fn new<CE>(audio: Audio, caption_entities: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
Self { audio, caption: None, caption_entities: caption_entities.into() }
}
pub fn audio(mut self, val: Audio) -> Self {
self.audio = val;
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn caption_entities<CE>(mut self, val: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
self.caption_entities = val.into();
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaContact {
/// Message is a shared contact, information about the contact.
contact: Contact,
}
impl MediaContact {
pub fn new(contact: Contact) -> Self {
Self { contact }
}
pub fn contact(mut self, val: Contact) -> Self {
self.contact = val;
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaDocument {
/// Message is a general file, information about the file.
pub document: Document,
@ -310,7 +690,38 @@ pub struct MediaDocument {
pub caption_entities: Vec<MessageEntity>,
}
impl MediaDocument {
pub fn new<CE>(document: Document, caption_entities: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
Self { document, caption: None, caption_entities: caption_entities.into() }
}
pub fn document(mut self, val: Document) -> Self {
self.document = val;
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn caption_entities<CE>(mut self, val: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
self.caption_entities = val.into();
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaGame {
/// Message is a game, information about the game. [More
/// about games »].
@ -319,14 +730,38 @@ pub struct MediaGame {
pub game: Game,
}
impl MediaGame {
pub fn new(game: Game) -> Self {
Self { game }
}
pub fn game(mut self, val: Game) -> Self {
self.game = val;
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaLocation {
/// Message is a shared location, information about the location.
pub location: Location,
}
impl MediaLocation {
pub fn new(location: Location) -> Self {
Self { location }
}
pub fn location(mut self, val: Location) -> Self {
self.location = val;
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaPhoto {
/// Message is a photo, available sizes of the photo.
pub photo: Vec<PhotoSize>,
@ -344,19 +779,91 @@ pub struct MediaPhoto {
pub media_group_id: Option<String>,
}
impl MediaPhoto {
pub fn new<P, CE>(photo: P, caption_entities: CE) -> Self
where
P: Into<Vec<PhotoSize>>,
CE: Into<Vec<MessageEntity>>,
{
Self {
photo: photo.into(),
caption: None,
caption_entities: caption_entities.into(),
media_group_id: None,
}
}
pub fn photo<P>(mut self, val: P) -> Self
where
P: Into<Vec<PhotoSize>>,
{
self.photo = val.into();
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn caption_entities<CE>(mut self, val: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
self.caption_entities = val.into();
self
}
pub fn media_group_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.media_group_id = Some(val.into());
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaPoll {
/// Message is a native poll, information about the poll.
pub poll: Poll,
}
impl MediaPoll {
pub fn new(poll: Poll) -> Self {
Self { poll }
}
pub fn poll(mut self, val: Poll) -> Self {
self.poll = val;
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaSticker {
/// Message is a sticker, information about the sticker.
pub sticker: Sticker,
}
impl MediaSticker {
pub fn new(sticker: Sticker) -> Self {
Self { sticker }
}
pub fn poll(mut self, val: Sticker) -> Self {
self.sticker = val;
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaText {
/// For text messages, the actual UTF-8 text of the message, 0-4096
/// characters.
@ -368,8 +875,35 @@ pub struct MediaText {
pub entities: Vec<MessageEntity>,
}
impl MediaText {
pub fn new<S, E>(text: S, entities: E) -> Self
where
S: Into<String>,
E: Into<Vec<MessageEntity>>,
{
Self { text: text.into(), entities: entities.into() }
}
pub fn text<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.text = val.into();
self
}
pub fn entities<CE>(mut self, val: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
self.entities = val.into();
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaVideo {
/// Message is a video, information about the video.
pub video: Video,
@ -387,7 +921,51 @@ pub struct MediaVideo {
pub media_group_id: Option<String>,
}
impl MediaVideo {
pub fn new<CE>(video: Video, caption_entities: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
Self {
video,
caption: None,
caption_entities: caption_entities.into(),
media_group_id: None,
}
}
pub fn video(mut self, val: Video) -> Self {
self.video = val;
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn caption_entities<CE>(mut self, val: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
self.caption_entities = val.into();
self
}
pub fn media_group_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.media_group_id = Some(val.into());
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaVideoNote {
/// Message is a [video note], information about the video message.
///
@ -395,8 +973,20 @@ pub struct MediaVideoNote {
pub video_note: VideoNote,
}
impl MediaVideoNote {
pub fn new(video_note: VideoNote) -> Self {
Self { video_note }
}
pub fn video_note(mut self, val: VideoNote) -> Self {
self.video_note = val;
self
}
}
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaVoice {
/// Message is a voice message, information about the file.
pub voice: Voice,
@ -410,12 +1000,54 @@ pub struct MediaVoice {
pub caption_entities: Vec<MessageEntity>,
}
impl MediaVoice {
pub fn new<CE>(voice: Voice, caption_entities: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
Self { voice, caption: None, caption_entities: caption_entities.into() }
}
pub fn voice(mut self, val: Voice) -> Self {
self.voice = val;
self
}
pub fn caption<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.caption = Some(val.into());
self
}
pub fn caption_entities<CE>(mut self, val: CE) -> Self
where
CE: Into<Vec<MessageEntity>>,
{
self.caption_entities = val.into();
self
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MediaVenue {
/// Message is a venue, information about the venue.
pub venue: Venue,
}
impl MediaVenue {
pub fn new(venue: Venue) -> Self {
Self { venue }
}
pub fn venue(mut self, val: Venue) -> Self {
self.venue = val;
self
}
}
mod getters {
use std::ops::Deref;

View file

@ -8,6 +8,7 @@ use crate::types::{Message, User};
///
/// [The official docs](https://core.telegram.org/bots/api#messageentity).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct MessageEntity {
#[serde(flatten)]
pub kind: MessageEntityKind,
@ -19,9 +20,31 @@ pub struct MessageEntity {
pub length: usize,
}
impl MessageEntity {
pub fn new(kind: MessageEntityKind, offset: usize, length: usize) -> Self {
Self { kind, offset, length }
}
pub fn kind(mut self, val: MessageEntityKind) -> Self {
self.kind = val;
self
}
pub fn offset(mut self, val: usize) -> Self {
self.offset = val;
self
}
pub fn length(mut self, val: usize) -> Self {
self.length = val;
self
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
#[non_exhaustive]
pub enum MessageEntityKind {
Mention,
Hashtag,

View file

@ -6,6 +6,7 @@ use crate::types::ShippingAddress;
///
/// [The official docs](https://core.telegram.org/bots/api#orderinfo).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct OrderInfo {
/// User's name.
pub name: String,
@ -19,3 +20,53 @@ pub struct OrderInfo {
/// User's shipping address.
pub shipping_address: ShippingAddress,
}
impl OrderInfo {
pub fn new<S1, S2, S3>(
name: S1,
phone_number: S2,
email: S3,
shipping_address: ShippingAddress,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
S3: Into<String>,
{
Self {
name: name.into(),
phone_number: phone_number.into(),
email: email.into(),
shipping_address,
}
}
pub fn name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.name = val.into();
self
}
pub fn phone_number<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.phone_number = val.into();
self
}
pub fn email<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.email = val.into();
self
}
pub fn shipping_address(mut self, val: ShippingAddress) -> Self {
self.shipping_address = val;
self
}
}

View file

@ -126,6 +126,7 @@ use serde::{Deserialize, Serialize};
/// [`HTML`]: ParseMode::HTML
/// [`Markdown`]: ParseMode::Markdown
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum ParseMode {
MarkdownV2,
HTML,

View file

@ -7,6 +7,7 @@ use super::{EncryptedCredentials, EncryptedPassportElement};
///
/// [The official docs](https://core.telegram.org/bots/api#passportdata).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportData {
/// Array with information about documents and other Telegram Passport
/// elements that was shared with the bot.
@ -15,3 +16,25 @@ pub struct PassportData {
/// Encrypted credentials required to decrypt the data.
pub credentials: EncryptedCredentials,
}
impl PassportData {
pub fn new<E>(data: E, credentials: EncryptedCredentials) -> Self
where
E: Into<Vec<EncryptedPassportElement>>,
{
Self { data: data.into(), credentials }
}
pub fn data<E>(mut self, val: E) -> Self
where
E: Into<Vec<EncryptedPassportElement>>,
{
self.data = val.into();
self
}
pub fn credentials(mut self, val: EncryptedCredentials) -> Self {
self.credentials = val;
self
}
}

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerror).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementError {
/// Error message.
message: String,
@ -13,9 +14,31 @@ pub struct PassportElementError {
kind: PassportElementErrorKind,
}
// TODO: use different types?
impl PassportElementError {
pub fn new<S>(message: S, kind: PassportElementErrorKind) -> Self
where
S: Into<String>,
{
Self { message: message.into(), kind }
}
pub fn message<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.message = val.into();
self
}
pub fn kind(mut self, val: PassportElementErrorKind) -> Self {
self.kind = val;
self
}
}
#[serde(tag = "source")]
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub enum PassportElementErrorKind {
#[serde(rename = "data")]
DataField(PassportElementErrorDataField),
@ -52,6 +75,7 @@ pub enum PassportElementErrorKind {
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrordatafield).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementErrorDataField {
/// The section of the user's Telegram Passport which has the error.
pub r#type: PassportElementErrorDataFieldType,
@ -63,6 +87,41 @@ pub struct PassportElementErrorDataField {
pub data_hash: String,
}
impl PassportElementErrorDataField {
pub fn new<S1, S2>(
r#type: PassportElementErrorDataFieldType,
field_name: S1,
data_hash: S2,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self { r#type, field_name: field_name.into(), data_hash: data_hash.into() }
}
pub fn r#type(mut self, val: PassportElementErrorDataFieldType) -> Self {
self.r#type = val;
self
}
pub fn field_name<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.field_name = val.into();
self
}
pub fn data_hash<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.data_hash = val.into();
self
}
}
/// Represents an issue with the front side of a document.
///
/// The error is considered resolved when the file with the front side of the
@ -70,6 +129,7 @@ pub struct PassportElementErrorDataField {
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrorfrontside).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementErrorFrontSide {
/// The section of the user's Telegram Passport which has the issue.
pub r#type: PassportElementErrorFrontSideType,
@ -79,6 +139,28 @@ pub struct PassportElementErrorFrontSide {
pub file_hash: String,
}
impl PassportElementErrorFrontSide {
pub fn new<S>(r#type: PassportElementErrorFrontSideType, file_hash: S) -> Self
where
S: Into<String>,
{
Self { r#type, file_hash: file_hash.into() }
}
pub fn r#type(mut self, val: PassportElementErrorFrontSideType) -> Self {
self.r#type = val;
self
}
pub fn file_hash<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_hash = val.into();
self
}
}
/// Represents an issue with the reverse side of a document.
///
/// The error is considered resolved when the file with reverse side of the
@ -86,6 +168,7 @@ pub struct PassportElementErrorFrontSide {
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrorreverseside).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementErrorReverseSide {
/// The section of the user's Telegram Passport which has the issue.
pub r#type: PassportElementErrorReverseSideType,
@ -95,12 +178,35 @@ pub struct PassportElementErrorReverseSide {
pub file_hash: String,
}
impl PassportElementErrorReverseSide {
pub fn new<S>(r#type: PassportElementErrorReverseSideType, file_hash: S) -> Self
where
S: Into<String>,
{
Self { r#type, file_hash: file_hash.into() }
}
pub fn r#type(mut self, val: PassportElementErrorReverseSideType) -> Self {
self.r#type = val;
self
}
pub fn file_hash<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_hash = val.into();
self
}
}
//// Represents an issue with the selfie with a document.
//
/// The error is considered resolved when the file with the selfie changes.
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrorselfie).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementErrorSelfie {
/// The section of the user's Telegram Passport which has the issue.
pub r#type: PassportElementErrorSelfieType,
@ -109,6 +215,28 @@ pub struct PassportElementErrorSelfie {
pub file_hash: String,
}
impl PassportElementErrorSelfie {
pub fn new<S>(r#type: PassportElementErrorSelfieType, file_hash: S) -> Self
where
S: Into<String>,
{
Self { r#type, file_hash: file_hash.into() }
}
pub fn r#type(mut self, val: PassportElementErrorSelfieType) -> Self {
self.r#type = val;
self
}
pub fn file_hash<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_hash = val.into();
self
}
}
/// Represents an issue with a document scan.
///
/// The error is considered resolved when the file with the document scan
@ -116,6 +244,7 @@ pub struct PassportElementErrorSelfie {
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrorfile).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementErrorFile {
/// The section of the user's Telegram Passport which has the issue.
pub r#type: PassportElementErrorFileType,
@ -124,6 +253,28 @@ pub struct PassportElementErrorFile {
pub file_hash: String,
}
impl PassportElementErrorFile {
pub fn new<S>(r#type: PassportElementErrorFileType, file_hash: S) -> Self
where
S: Into<String>,
{
Self { r#type, file_hash: file_hash.into() }
}
pub fn r#type(mut self, val: PassportElementErrorFileType) -> Self {
self.r#type = val;
self
}
pub fn file_hash<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_hash = val.into();
self
}
}
/// Represents an issue with a list of scans.
///
/// The error is considered resolved when the list of files containing the scans
@ -131,6 +282,7 @@ pub struct PassportElementErrorFile {
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrorfiles).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementErrorFiles {
/// The section of the user's Telegram Passport which has the issue.
pub r#type: PassportElementErrorFilesType,
@ -139,6 +291,28 @@ pub struct PassportElementErrorFiles {
pub file_hashes: Vec<String>,
}
impl PassportElementErrorFiles {
pub fn new<S>(r#type: PassportElementErrorFilesType, file_hashes: S) -> Self
where
S: Into<Vec<String>>,
{
Self { r#type, file_hashes: file_hashes.into() }
}
pub fn r#type(mut self, val: PassportElementErrorFilesType) -> Self {
self.r#type = val;
self
}
pub fn file_hashes<S>(mut self, val: S) -> Self
where
S: Into<Vec<String>>,
{
self.file_hashes = val.into();
self
}
}
/// Represents an issue with one of the files that constitute the
/// translation of a document.
///
@ -146,6 +320,7 @@ pub struct PassportElementErrorFiles {
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrortranslationfile).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementErrorTranslationFile {
/// Type of element of the user's Telegram Passport which has the
/// issue.
@ -155,6 +330,28 @@ pub struct PassportElementErrorTranslationFile {
pub file_hash: String,
}
impl PassportElementErrorTranslationFile {
pub fn new<S>(r#type: PassportElementErrorTranslationFileType, file_hash: S) -> Self
where
S: Into<String>,
{
Self { r#type, file_hash: file_hash.into() }
}
pub fn r#type(mut self, val: PassportElementErrorTranslationFileType) -> Self {
self.r#type = val;
self
}
pub fn file_hash<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_hash = val.into();
self
}
}
/// Represents an issue with the translated version of a document.
///
/// The error is considered resolved when a file with the document translation
@ -162,6 +359,7 @@ pub struct PassportElementErrorTranslationFile {
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrortranslationfiles).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementErrorTranslationFiles {
/// Type of element of the user's Telegram Passport which has the issue
pub r#type: PassportElementErrorTranslationFilesType,
@ -170,12 +368,35 @@ pub struct PassportElementErrorTranslationFiles {
pub file_hashes: Vec<String>,
}
impl PassportElementErrorTranslationFiles {
pub fn new<S>(r#type: PassportElementErrorTranslationFilesType, file_hashes: S) -> Self
where
S: Into<Vec<String>>,
{
Self { r#type, file_hashes: file_hashes.into() }
}
pub fn r#type(mut self, val: PassportElementErrorTranslationFilesType) -> Self {
self.r#type = val;
self
}
pub fn file_hashes<S>(mut self, val: S) -> Self
where
S: Into<Vec<String>>,
{
self.file_hashes = val.into();
self
}
}
/// Represents an issue in an unspecified place.
///
/// The error is considered resolved when new data is added.
///
/// [The official docs](https://core.telegram.org/bots/api#passportelementerrorunspecified).
#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportElementErrorUnspecified {
/// Type of element of the user's Telegram Passport which has the
/// issue.
@ -185,8 +406,31 @@ pub struct PassportElementErrorUnspecified {
pub element_hash: String,
}
impl PassportElementErrorUnspecified {
pub fn new<S>(r#type: PassportElementErrorUnspecifiedType, file_hash: S) -> Self
where
S: Into<String>,
{
Self { r#type, element_hash: file_hash.into() }
}
pub fn r#type(mut self, val: PassportElementErrorUnspecifiedType) -> Self {
self.r#type = val;
self
}
pub fn element_hash<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.element_hash = val.into();
self
}
}
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PassportElementErrorDataFieldType {
PersonalDetails,
Passport,
@ -198,6 +442,7 @@ pub enum PassportElementErrorDataFieldType {
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PassportElementErrorFrontSideType {
Passport,
DriverLicense,
@ -207,6 +452,7 @@ pub enum PassportElementErrorFrontSideType {
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PassportElementErrorReverseSideType {
DriverLicense,
IdentityCard,
@ -214,6 +460,7 @@ pub enum PassportElementErrorReverseSideType {
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PassportElementErrorSelfieType {
Passport,
DriverLicense,
@ -223,6 +470,7 @@ pub enum PassportElementErrorSelfieType {
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PassportElementErrorFileType {
UtilityBill,
BankStatement,
@ -233,6 +481,7 @@ pub enum PassportElementErrorFileType {
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PassportElementErrorFilesType {
UtilityBill,
BankStatement,
@ -243,6 +492,7 @@ pub enum PassportElementErrorFilesType {
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PassportElementErrorTranslationFileType {
Passport,
DriverLicense,
@ -257,6 +507,7 @@ pub enum PassportElementErrorTranslationFileType {
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PassportElementErrorTranslationFilesType {
Passport,
DriverLicense,
@ -271,6 +522,7 @@ pub enum PassportElementErrorTranslationFilesType {
#[derive(Clone, Copy, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum PassportElementErrorUnspecifiedType {
DataField,
FrontSide,

View file

@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize};
///
/// [The official docs](https://core.telegram.org/bots/api#passportfile).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PassportFile {
/// Identifier for this file.
pub file_id: String,
@ -22,3 +23,44 @@ pub struct PassportFile {
/// Unix time when the file was uploaded.
pub file_date: u64,
}
impl PassportFile {
pub fn new<S1, S2>(file_id: S1, file_unique_id: S2, file_size: u64, file_date: u64) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
file_id: file_id.into(),
file_unique_id: file_unique_id.into(),
file_size,
file_date,
}
}
pub fn file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_id = val.into();
self
}
pub fn file_unique_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_unique_id = val.into();
self
}
pub fn file_size(mut self, val: u64) -> Self {
self.file_size = val;
self
}
pub fn file_date(mut self, val: u64) -> Self {
self.file_date = val;
self
}
}

View file

@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
/// [sticker]: crate::types::Sticker
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PhotoSize {
/// Identifier for this file.
pub file_id: String,
@ -25,6 +26,53 @@ pub struct PhotoSize {
pub file_size: Option<u32>,
}
impl PhotoSize {
pub fn new<S1, S2>(file_id: S1, file_unique_id: S2, width: i32, height: i32) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
file_id: file_id.into(),
file_unique_id: file_unique_id.into(),
width,
height,
file_size: None,
}
}
pub fn file_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_id = val.into();
self
}
pub fn file_unique_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.file_unique_id = val.into();
self
}
pub fn width(mut self, val: i32) -> Self {
self.width = val;
self
}
pub fn height(mut self, val: i32) -> Self {
self.height = val;
self
}
pub fn file_size(mut self, val: u32) -> Self {
self.file_size = Some(val);
self
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#poll).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Poll {
/// Unique poll identifier.
pub id: String,
@ -38,10 +39,98 @@ pub struct Poll {
pub correct_option_id: Option<i32>,
}
impl Poll {
#[allow(clippy::too_many_arguments)]
pub fn new<S1, S2, O>(
id: S1,
question: S2,
options: O,
is_closed: bool,
total_voter_count: i32,
is_anonymous: bool,
poll_type: PollType,
allows_multiple_answers: bool,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
O: Into<Vec<PollOption>>,
{
Self {
id: id.into(),
question: question.into(),
options: options.into(),
is_closed,
total_voter_count,
is_anonymous,
poll_type,
allows_multiple_answers,
correct_option_id: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn question<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.question = val.into();
self
}
pub fn options<P>(mut self, val: P) -> Self
where
P: Into<Vec<PollOption>>,
{
self.options = val.into();
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_closed(mut self, val: bool) -> Self {
self.is_closed = val;
self
}
pub fn total_voter_count(mut self, val: i32) -> Self {
self.total_voter_count = val;
self
}
#[allow(clippy::wrong_self_convention)]
pub fn is_anonymous(mut self, val: bool) -> Self {
self.is_anonymous = val;
self
}
pub fn poll_type(mut self, val: PollType) -> Self {
self.poll_type = val;
self
}
pub fn allows_multiple_answers(mut self, val: bool) -> Self {
self.allows_multiple_answers = val;
self
}
pub fn correct_option_id(mut self, val: i32) -> Self {
self.correct_option_id = Some(val);
self
}
}
/// This object contains information about one answer option in a poll.
///
/// [The official docs](https://core.telegram.org/bots/api#polloption).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PollOption {
/// Option text, 1-100 characters.
pub text: String,
@ -50,6 +139,28 @@ pub struct PollOption {
pub voter_count: i32,
}
impl PollOption {
pub fn new<S>(text: S, voter_count: i32) -> Self
where
S: Into<String>,
{
Self { text: text.into(), voter_count }
}
pub fn text<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.text = val.into();
self
}
pub fn voter_count(mut self, val: i32) -> Self {
self.voter_count = val;
self
}
}
#[cfg(test)]
mod tests {
use super::*;

View file

@ -2,6 +2,7 @@ use crate::types::User;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PollAnswer {
/// Unique poll identifier.
pub poll_id: String,
@ -14,3 +15,34 @@ pub struct PollAnswer {
/// May be empty if the user retracted their vote.
pub option_ids: Vec<i32>,
}
impl PollAnswer {
pub fn new<S, O>(poll_id: S, user: User, option_ids: O) -> Self
where
S: Into<String>,
O: Into<Vec<i32>>,
{
Self { poll_id: poll_id.into(), user, option_ids: option_ids.into() }
}
pub fn poll_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.poll_id = val.into();
self
}
pub fn user(mut self, val: User) -> Self {
self.user = val;
self
}
pub fn option_ids<S>(mut self, val: S) -> Self
where
S: Into<Vec<i32>>,
{
self.option_ids = val.into();
self
}
}

View file

@ -2,6 +2,7 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
#[non_exhaustive]
pub enum PollType {
Quiz,
Regular,

View file

@ -7,6 +7,7 @@ use crate::types::{Currency, OrderInfo, User};
/// [The official docs](https://core.telegram.org/bots/api#precheckoutquery).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PreCheckoutQuery {
/// Unique query identifier.
pub id: String,
@ -37,3 +38,71 @@ pub struct PreCheckoutQuery {
/// Order info provided by the user.
pub order_info: Option<OrderInfo>,
}
impl PreCheckoutQuery {
pub fn new<S1, S2>(
id: S1,
from: User,
currency: Currency,
total_amount: i32,
invoice_payload: S2,
) -> Self
where
S1: Into<String>,
S2: Into<String>,
{
Self {
id: id.into(),
from,
currency,
total_amount,
invoice_payload: invoice_payload.into(),
shipping_option_id: None,
order_info: None,
}
}
pub fn id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.id = val.into();
self
}
pub fn from(mut self, val: User) -> Self {
self.from = val;
self
}
pub fn currency<S>(mut self, val: Currency) -> Self {
self.currency = val;
self
}
pub fn total_amount(mut self, val: i32) -> Self {
self.total_amount = val;
self
}
pub fn invoice_payload<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.invoice_payload = val.into();
self
}
pub fn shipping_option_id<S>(mut self, val: S) -> Self
where
S: Into<String>,
{
self.shipping_option_id = Some(val.into());
self
}
pub fn order_info(mut self, val: OrderInfo) -> Self {
self.order_info = Some(val);
self
}
}

View file

@ -11,6 +11,7 @@ use crate::types::KeyboardButton;
/// [Introduction to bots]: https://core.telegram.org/bots#keyboards
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Default)]
#[non_exhaustive]
pub struct ReplyKeyboardMarkup {
/// Array of button rows, each represented by an Array of
/// [`KeyboardButton`] objects

View file

@ -14,6 +14,7 @@ use crate::types::True;
/// [`ReplyKeyboardMarkup`]: crate::types::ReplyKeyboardMarkup
#[serde_with_macros::skip_serializing_none]
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ReplyKeyboardRemove {
/// Requests clients to remove the custom keyboard (user will not be able
/// to summon this keyboard; if you want to hide the keyboard from sight

View file

@ -5,6 +5,7 @@ use crate::types::{ForceReply, InlineKeyboardMarkup, ReplyKeyboardMarkup, ReplyK
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, From)]
#[serde(untagged)]
#[non_exhaustive]
pub enum ReplyMarkup {
InlineKeyboardMarkup(InlineKeyboardMarkup),
ReplyKeyboardMarkup(ReplyKeyboardMarkup),

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#responseparameters).
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum ResponseParameters {
/// The group has been migrated to a supergroup with the specified
/// identifier. This number may be greater than 32 bits and some

View file

@ -5,6 +5,7 @@ use crate::types::{ChatId, InlineKeyboardMarkup, LabeledPrice};
// TODO: missing docs
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SendInvoice {
pub chat_id: ChatId,
pub title: String,

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
///
/// [The official docs](https://core.telegram.org/bots/api#shippingaddress).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShippingAddress {
/// ISO 3166-1 alpha-2 country code.
pub country_code: CountryCode,

View file

@ -6,6 +6,7 @@ use crate::types::LabeledPrice;
///
/// [The official docs](https://core.telegram.org/bots/api#shippingoption).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShippingOption {
/// Shipping option identifier.
pub id: String,

View file

@ -6,6 +6,7 @@ use crate::types::{ShippingAddress, User};
///
/// [The official docs](https://core.telegram.org/bots/api#shippingquery).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ShippingQuery {
/// Unique query identifier.
pub id: String,

View file

@ -7,6 +7,7 @@ use crate::types::{MaskPosition, PhotoSize};
/// [The official docs](https://core.telegram.org/bots/api#sticker).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Sticker {
/// Identifier for this file.
pub file_id: String,

View file

@ -6,6 +6,7 @@ use crate::types::Sticker;
///
/// [The official docs](https://core.telegram.org/bots/api#stickerset).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct StickerSet {
/// Sticker set name.
pub name: String,

View file

@ -7,6 +7,7 @@ use crate::types::{Currency, OrderInfo};
/// [The official docs](https://core.telegram.org/bots/api#successfulpayment).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct SuccessfulPayment {
/// Three-letter ISO 4217 [currency] code.
///

View file

@ -14,6 +14,7 @@ use serde_json::Value;
///
/// [object]: https://core.telegram.org/bots/api#available-types
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Update {
/// The updates unique identifier. Update identifiers start from a certain
/// positive number and increase sequentially. This ID becomes especially
@ -54,6 +55,7 @@ impl Update {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
#[non_exhaustive]
pub enum UpdateKind {
/// New incoming message of any kind — text, photo, sticker, etc.
Message(Message),

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#user).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct User {
/// Unique identifier for this user or bot.
pub id: i32,
@ -48,6 +49,7 @@ impl User {
///
/// [`Bot::get_me`]: crate::Bot::get_me
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Me {
#[serde(flatten)]
pub user: User,

View file

@ -6,6 +6,7 @@ use crate::types::PhotoSize;
///
/// [The official docs](https://core.telegram.org/bots/api#userprofilephotos).
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct UserProfilePhotos {
/// Total number of profile pictures the target user has.
pub total_count: u32,

View file

@ -5,6 +5,7 @@ use crate::types::Location;
/// This object represents a venue.
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Venue {
/// Venue location.
pub location: Location,

View file

@ -7,6 +7,7 @@ use crate::types::{MimeWrapper, PhotoSize};
/// [The official docs](https://core.telegram.org/bots/api#video).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Video {
/// Identifier for this file.
pub file_id: String,

View file

@ -11,6 +11,7 @@ use crate::types::PhotoSize;
/// [v4.0]: https://telegram.org/blog/video-messages-and-telescope
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct VideoNote {
/// Identifier for this file.
pub file_id: String,

View file

@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#voice).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Voice {
/// Identifier for this file.
pub file_id: String,

View file

@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
/// [The official docs](https://core.telegram.org/bots/api#webhookinfo).
#[serde_with_macros::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct WebhookInfo {
/// Webhook URL, may be empty if webhook is not set up.
pub url: String,