mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 19:33:53 +01:00
Update types to TBA 5.2
This commit is contained in:
parent
c5ab1ac89a
commit
653c804037
8 changed files with 307 additions and 5 deletions
|
@ -37,6 +37,7 @@ tokio-util = "0.6.0"
|
|||
pin-project = "1.0.3"
|
||||
bytes = "1.0.0"
|
||||
reqwest = { version = "0.11.0", features = ["json", "stream", "multipart"], default-features = false }
|
||||
url = { version = "2", features = ["serde"] }
|
||||
log = "0.4"
|
||||
|
||||
serde = { version = "1.0.114", features = ["derive"] }
|
||||
|
|
|
@ -15,6 +15,7 @@ pub use chat_member::*;
|
|||
pub use chat_member_updated::*;
|
||||
pub use chat_permissions::*;
|
||||
pub use chat_photo::*;
|
||||
pub use chat_type::*;
|
||||
pub use chosen_inline_result::*;
|
||||
pub use contact::*;
|
||||
pub use dice::*;
|
||||
|
@ -99,6 +100,7 @@ pub use video_note::*;
|
|||
pub use voice::*;
|
||||
pub use voice_chat_ended::*;
|
||||
pub use voice_chat_participants_invited::*;
|
||||
pub use voice_chat_scheduled::*;
|
||||
pub use voice_chat_started::*;
|
||||
pub use webhook_info::*;
|
||||
|
||||
|
@ -117,6 +119,7 @@ mod chat_member;
|
|||
mod chat_member_updated;
|
||||
mod chat_permissions;
|
||||
mod chat_photo;
|
||||
mod chat_type;
|
||||
mod chosen_inline_result;
|
||||
mod contact;
|
||||
mod dice;
|
||||
|
@ -174,6 +177,7 @@ mod video_note;
|
|||
mod voice;
|
||||
mod voice_chat_ended;
|
||||
mod voice_chat_participants_invited;
|
||||
mod voice_chat_scheduled;
|
||||
mod voice_chat_started;
|
||||
mod webhook_info;
|
||||
|
||||
|
|
|
@ -7,8 +7,8 @@ pub enum ChatAction {
|
|||
UploadPhoto,
|
||||
RecordVideo,
|
||||
UploadVideo,
|
||||
RecordAudio,
|
||||
UploadAudio,
|
||||
RecordVoice,
|
||||
UploadVoice,
|
||||
UploadDocument,
|
||||
FindLocation,
|
||||
RecordVideoNote,
|
||||
|
|
13
src/types/chat_type.rs
Normal file
13
src/types/chat_type.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Type of the chat, from which the inline query was sent.
|
||||
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ChatType {
|
||||
/// Private chat with the inline query sender.
|
||||
Sender,
|
||||
Private,
|
||||
Group,
|
||||
Supergroup,
|
||||
Channel,
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::{Location, User};
|
||||
use crate::types::{ChatType, Location, User};
|
||||
|
||||
/// This object represents an incoming inline query.
|
||||
///
|
||||
|
@ -25,8 +25,16 @@ pub struct InlineQuery {
|
|||
|
||||
/// Offset of the results to be returned, can be controlled by the bot.
|
||||
pub offset: String,
|
||||
|
||||
/// Type of the chat, from which the inline query was sent.
|
||||
///
|
||||
/// The chat type should be always known for requests sent from official
|
||||
/// clients and most third-party clients, unless the request was sent
|
||||
/// from a secret chat.
|
||||
pub chat_type: Option<ChatType>,
|
||||
}
|
||||
|
||||
// TODO(waffle): remove
|
||||
impl InlineQuery {
|
||||
pub fn new<S1, S2, S3>(id: S1, from: User, query: S2, offset: S3) -> Self
|
||||
where
|
||||
|
@ -40,6 +48,7 @@ impl InlineQuery {
|
|||
location: None,
|
||||
query: query.into(),
|
||||
offset: offset.into(),
|
||||
chat_type: None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use reqwest::Url;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::types::{MessageEntity, ParseMode};
|
||||
use crate::types::{Currency, LabeledPrice, MessageEntity, ParseMode};
|
||||
|
||||
/// This object represents the content of a message to be sent as a result of an
|
||||
/// inline query.
|
||||
|
@ -13,6 +14,7 @@ pub enum InputMessageContent {
|
|||
Location(InputMessageContentLocation),
|
||||
Venue(InputMessageContentVenue),
|
||||
Contact(InputMessageContentContact),
|
||||
Invoice(InputMessageContentInvoice),
|
||||
}
|
||||
/// Represents the content of a text message to be sent as the result of an
|
||||
/// inline query.
|
||||
|
@ -297,6 +299,262 @@ impl InputMessageContentContact {
|
|||
}
|
||||
}
|
||||
|
||||
/// Represents the [content] of an invoice message to be sent as the result of
|
||||
/// an inline query.
|
||||
///
|
||||
/// [content]: InputMessageContent
|
||||
#[serde_with_macros::skip_serializing_none]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct InputMessageContentInvoice {
|
||||
/// Product name, 1-32 characters
|
||||
pub title: String,
|
||||
|
||||
/// Product description, 1-255 characters
|
||||
pub description: String,
|
||||
|
||||
/// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
|
||||
/// the user, use for your internal processes.
|
||||
pub payload: String,
|
||||
|
||||
/// Payment provider token, obtained via [@Botfather]
|
||||
///
|
||||
/// [@Botfather]: https://t.me/Botfather
|
||||
pub provider_token: String,
|
||||
|
||||
/// Three-letter ISO 4217 currency code, see [more on currencies]
|
||||
///
|
||||
/// [more on currencies]: https://core.telegram.org/bots/payments#supported-currencies
|
||||
pub currency: Currency,
|
||||
|
||||
/// Price breakdown, list of components (e.g. product price, tax, discount,
|
||||
/// delivery cost, delivery tax, bonus, etc.)
|
||||
pub prices: Vec<LabeledPrice>,
|
||||
|
||||
/// ----The maximum accepted amount for tips in the smallest units of the
|
||||
/// currency (integer, not float/double). For example, for a maximum tip of
|
||||
/// US$ 1.45 pass max_tip_amount = 145. See the exp parameter in
|
||||
/// currencies.json, it shows the number of digits past the decimal point
|
||||
/// for each currency (2 for the majority of currencies). Defaults to 0
|
||||
pub max_tip_amount: Option<u32>,
|
||||
|
||||
/// List of suggested amounts of tip in the smallest units of the currency
|
||||
/// (integer, not float/double). At most 4 suggested tip amounts can be
|
||||
/// specified. The suggested tip amounts must be positive, passed in a
|
||||
/// strictly increased order and must not exceed max_tip_amount.
|
||||
pub suggested_tip_amounts: Option<Vec<u32>>,
|
||||
|
||||
/// ----A JSON-serialized object for data about the invoice, which will be
|
||||
/// shared with the payment provider. A detailed description of the required
|
||||
/// fields should be provided by the payment provider.
|
||||
pub provider_data: Option<String>,
|
||||
|
||||
/// URL of the product photo for the invoice. Can be a photo of the goods or
|
||||
/// a marketing image for a service. People like it better when they see
|
||||
/// what they are paying for.
|
||||
pub photo_url: Option<Url>,
|
||||
|
||||
/// Photo size
|
||||
pub photo_size: Option<u32>,
|
||||
|
||||
/// Photo width
|
||||
pub photo_width: Option<u32>,
|
||||
|
||||
/// Photo height
|
||||
pub photo_height: Option<u32>,
|
||||
|
||||
/// Pass `true`, if you require the user's full name to complete the order
|
||||
pub need_name: Option<bool>,
|
||||
|
||||
/// Pass `true`, if you require the user's phone number to complete the
|
||||
/// order
|
||||
pub need_phone_number: Option<bool>,
|
||||
|
||||
/// Pass `true`, if you require the user's email address to complete the
|
||||
/// order
|
||||
pub need_email: Option<bool>,
|
||||
|
||||
/// Pass `true`, if you require the user's shipping address to complete the
|
||||
/// order
|
||||
pub need_shipping_address: Option<bool>,
|
||||
|
||||
/// Pass True, if user's phone number should be sent to provider
|
||||
pub send_phone_number_to_provider: Option<bool>,
|
||||
|
||||
/// Pass True, if user's email address should be sent to provider
|
||||
pub send_email_to_provider: Option<bool>,
|
||||
|
||||
/// Pass True, if the final price depends on the shipping method
|
||||
pub is_flexible: Option<bool>,
|
||||
}
|
||||
|
||||
impl InputMessageContentInvoice {
|
||||
pub fn new<T, D, PA, PT, PR>(
|
||||
title: T,
|
||||
description: D,
|
||||
payload: PA,
|
||||
provider_token: PT,
|
||||
currency: Currency,
|
||||
prices: PR,
|
||||
) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
D: Into<String>,
|
||||
PA: Into<String>,
|
||||
PT: Into<String>,
|
||||
PR: IntoIterator<Item = LabeledPrice>,
|
||||
{
|
||||
let title = title.into();
|
||||
let description = description.into();
|
||||
let payload = payload.into();
|
||||
let provider_token = provider_token.into();
|
||||
let prices = prices.into_iter().collect();
|
||||
|
||||
Self {
|
||||
title,
|
||||
description,
|
||||
payload,
|
||||
provider_token,
|
||||
currency,
|
||||
prices,
|
||||
max_tip_amount: None,
|
||||
suggested_tip_amounts: None,
|
||||
provider_data: None,
|
||||
photo_url: None,
|
||||
photo_size: None,
|
||||
photo_width: None,
|
||||
photo_height: None,
|
||||
need_name: None,
|
||||
need_phone_number: None,
|
||||
need_email: None,
|
||||
need_shipping_address: None,
|
||||
send_phone_number_to_provider: None,
|
||||
send_email_to_provider: None,
|
||||
is_flexible: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn title<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.title = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn description<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.description = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn payload<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.payload = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn provider_token<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.provider_token = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn currency(mut self, val: Currency) -> Self {
|
||||
self.currency = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn prices<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: IntoIterator<Item = LabeledPrice>,
|
||||
{
|
||||
self.prices = val.into_iter().collect();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn max_tip_amount(mut self, val: u32) -> Self {
|
||||
self.max_tip_amount = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn suggested_tip_amounts<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: IntoIterator<Item = u32>,
|
||||
{
|
||||
self.suggested_tip_amounts = Some(val.into_iter().collect());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn provider_data<T>(mut self, val: T) -> Self
|
||||
where
|
||||
T: Into<String>,
|
||||
{
|
||||
self.provider_data = Some(val.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_url(mut self, val: Url) -> Self {
|
||||
self.photo_url = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_size(mut self, val: u32) -> Self {
|
||||
self.photo_size = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_width(mut self, val: u32) -> Self {
|
||||
self.photo_width = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn photo_height(mut self, val: u32) -> Self {
|
||||
self.photo_height = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_name(mut self, val: bool) -> Self {
|
||||
self.need_name = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_phone_number(mut self, val: bool) -> Self {
|
||||
self.need_phone_number = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_email(mut self, val: bool) -> Self {
|
||||
self.need_email = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn need_shipping_address(mut self, val: bool) -> Self {
|
||||
self.need_shipping_address = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn send_phone_number_to_provider(mut self, val: bool) -> Self {
|
||||
self.send_phone_number_to_provider = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn send_email_to_provider(mut self, val: bool) -> Self {
|
||||
self.send_email_to_provider = Some(val);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn is_flexible(mut self, val: bool) -> Self {
|
||||
self.is_flexible = Some(val);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::types::{
|
|||
Invoice, Location, MessageAutoDeleteTimerChanged, MessageEntity, PassportData, PhotoSize, Poll,
|
||||
ProximityAlertTriggered, PublicChatChannel, PublicChatSupergroup, Sticker, SuccessfulPayment,
|
||||
True, User, Venue, Video, VideoNote, Voice, VoiceChatEnded, VoiceChatParticipantsInvited,
|
||||
VoiceChatStarted,
|
||||
VoiceChatScheduled, VoiceChatStarted,
|
||||
};
|
||||
|
||||
/// This object represents a message.
|
||||
|
@ -54,6 +54,7 @@ pub enum MessageKind {
|
|||
PassportData(MessagePassportData),
|
||||
Dice(MessageDice),
|
||||
ProximityAlertTriggered(MessageProximityAlertTriggered),
|
||||
VoiceChatScheduled(MessageVoiceChatScheduled),
|
||||
VoiceChatStarted(MessageVoiceChatStarted),
|
||||
VoiceChatEnded(MessageVoiceChatEnded),
|
||||
VoiceChatParticipantsInvited(MessageVoiceChatParticipantsInvited),
|
||||
|
@ -456,6 +457,12 @@ pub struct MessageProximityAlertTriggered {
|
|||
pub proximity_alert_triggered: ProximityAlertTriggered,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct MessageVoiceChatScheduled {
|
||||
/// Service message: voice chat scheduled
|
||||
pub voice_chat_scheduled: VoiceChatScheduled,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct MessageVoiceChatStarted {
|
||||
/// Service message: voice chat started.
|
||||
|
|
10
src/types/voice_chat_scheduled.rs
Normal file
10
src/types/voice_chat_scheduled.rs
Normal file
|
@ -0,0 +1,10 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// This object represents a service message about a voice chat scheduled in the
|
||||
/// chat.
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
pub struct VoiceChatScheduled {
|
||||
/// Point in time (Unix timestamp) when the voice chat is supposed to be
|
||||
/// started by a chat administrator.
|
||||
pub start_date: u64,
|
||||
}
|
Loading…
Reference in a new issue