Skip to content

Commit

Permalink
Merge pull request #52 from Desiders/add-support-bot-api-8.1
Browse files Browse the repository at this point in the history
Add support Bot API 8.1
  • Loading branch information
Desiders authored Dec 31, 2024
2 parents 1239721 + 4de1d04 commit 341c413
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
4 changes: 4 additions & 0 deletions telers/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
//!
//! Each variant has an implementation of [`Into`] trait to convert from the variant to the [`Message`].
pub mod affiliate_info;
pub mod animation;
pub mod audio;
pub mod background_fill;
Expand Down Expand Up @@ -251,6 +252,7 @@ pub mod successful_payment;
pub mod switch_inline_query_chosen_chat;
pub mod text_quote;
pub mod transaction_partner;
pub mod transaction_partner_affiliate_program;
pub mod transaction_partner_fragment;
pub mod transaction_partner_other;
pub mod transaction_partner_telegram_ads;
Expand All @@ -275,6 +277,7 @@ pub mod web_app_user;
pub mod webhook_info;
pub mod write_access_allowed;

pub use affiliate_info::AffiliateInfo;
pub use animation::Animation;
pub use audio::Audio;
pub use background_fill::BackgroundFill;
Expand Down Expand Up @@ -564,6 +567,7 @@ pub use successful_payment::SuccessfulPayment;
pub use switch_inline_query_chosen_chat::SwitchInlineQueryChosenChat;
pub use text_quote::TextQuote;
pub use transaction_partner::TransactionPartner;
pub use transaction_partner_affiliate_program::TransactionPartnerAffiliateProgram;
pub use transaction_partner_fragment::TransactionPartnerFragment;
pub use transaction_partner_other::TransactionPartnerOther;
pub use transaction_partner_telegram_ads::TransactionPartnerTelegramAds;
Expand Down
22 changes: 22 additions & 0 deletions telers/src/types/affiliate_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use super::{Chat, User};

use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

/// Contains information about the affiliate that received a commission via this transaction
/// # Documentation
/// <https://core.telegram.org/bots/api#affiliateinfo>
#[skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct AffiliateInfo {
/// The bot or the user that received an affiliate commission if it was received by a bot or a user
pub affiliate_user: Option<User>,
/// The chat that received an affiliate commission if it was received by a chat
pub affiliate_chat: Option<Chat>,
/// The number of Telegram Stars received by the affiliate for each 1000 Telegram Stars received by the bot from referred users
pub commission_per_mille: i64,
/// Integer amount of Telegram Stars received by the affiliate from the transaction, rounded to 0; can be negative for refunds
pub amount: i64,
/// The number of 1/1000000000 shares of Telegram Stars received by the affiliate; from -999999999 to 999999999; can be negative for refunds
pub nanostar_amount: Option<i64>,
}
16 changes: 16 additions & 0 deletions telers/src/types/star_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub struct Source {
pub id: Box<str>,
/// Number of Telegram Stars transferred by the transaction
pub amount: i64,
/// The number of 1/1000000000 shares of Telegram Stars transferred by the transaction; from 0 to 999999999
pub nanostar_amount: Option<i64>,
/// Date the transaction was created in Unix time
pub date: i64,
/// Source of an incoming transaction (e.g., a user purchasing goods or services, Fragment refunding a failed withdrawal)
Expand All @@ -30,6 +32,8 @@ pub struct Receiver {
pub id: Box<str>,
/// Number of Telegram Stars transferred by the transaction
pub amount: i64,
/// The number of 1/1000000000 shares of Telegram Stars transferred by the transaction; from 0 to 999999999
pub nanostar_amount: Option<i64>,
/// Date the transaction was created in Unix time
pub date: i64,
/// Receiver of an outgoing transaction (e.g., a user for a purchase refund, Fragment for a withdrawal)
Expand All @@ -53,6 +57,18 @@ impl StarTransaction {
}
}

#[must_use]
pub const fn nanostar_amount(&self) -> Option<i64> {
match self {
StarTransaction::Source(Source {
nanostar_amount, ..
})
| StarTransaction::Receiver(Receiver {
nanostar_amount, ..
}) => *nanostar_amount,
}
}

#[must_use]
pub const fn date(&self) -> i64 {
match self {
Expand Down
12 changes: 10 additions & 2 deletions telers/src/types/transaction_partner.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use super::{
TransactionPartnerFragment, TransactionPartnerOther, TransactionPartnerTelegramAds,
TransactionPartnerTelegramApi, TransactionPartnerUser,
TransactionPartnerAffiliateProgram, TransactionPartnerFragment, TransactionPartnerOther,
TransactionPartnerTelegramAds, TransactionPartnerTelegramApi, TransactionPartnerUser,
};

use serde::{Deserialize, Serialize};

/// This object describes the source of a transaction, or its recipient for outgoing transactions. Currently, it can be one of
/// - [`TransactionPartnerUser`]
/// - [`TransactionPartnerAffiliateProgram`]
/// - [`TransactionPartnerFragment`]
/// - [`TransactionPartnerTelegramAds`]
/// - [`TransactionPartnerTelegramApi`]
Expand All @@ -17,6 +18,7 @@ use serde::{Deserialize, Serialize};
#[serde(tag = "type", rename_all = "snake_case")]
pub enum TransactionPartner {
User(TransactionPartnerUser),
AffiliateProgram(TransactionPartnerAffiliateProgram),
Fragment(TransactionPartnerFragment),
TelegramAds(TransactionPartnerTelegramAds),
TelegramApi(TransactionPartnerTelegramApi),
Expand All @@ -29,6 +31,12 @@ impl From<TransactionPartnerUser> for TransactionPartner {
}
}

impl From<TransactionPartnerAffiliateProgram> for TransactionPartner {
fn from(partner: TransactionPartnerAffiliateProgram) -> Self {
Self::AffiliateProgram(partner)
}
}

impl From<TransactionPartnerFragment> for TransactionPartner {
fn from(partner: TransactionPartnerFragment) -> Self {
Self::Fragment(partner)
Expand Down
16 changes: 16 additions & 0 deletions telers/src/types/transaction_partner_affiliate_program.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use super::User;

use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

/// Describes the affiliate program that issued the affiliate commission received via this transaction.
/// # Documentation
/// <https://core.telegram.org/bots/api#transactionpartneraffiliateprogram>
#[skip_serializing_none]
#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)]
pub struct TransactionPartnerAffiliateProgram {
/// Information about the bot that sponsored the affiliate program
pub sponsor_user: Option<User>,
/// The number of Telegram Stars received by the bot for each 1000 Telegram Stars received by the affiliate program sponsor from referred users
pub commission_per_mille: i64,
}
4 changes: 3 additions & 1 deletion telers/src/types/transaction_partner_user.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{Gift, PaidMedia, User};
use super::{AffiliateInfo, Gift, PaidMedia, User};

use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;
Expand All @@ -11,6 +11,8 @@ use serde_with::skip_serializing_none;
pub struct TransactionPartnerUser {
/// Information about the user
pub user: User,
/// Information about the affiliate that received a commission via this transaction
pub affiliate: Option<AffiliateInfo>,
/// Bot-specified invoice payload
pub invoice_payload: Option<Box<str>>,
/// The duration of the paid subscription
Expand Down

0 comments on commit 341c413

Please sign in to comment.