Skip to content

Commit

Permalink
Bot API 7.5 (#174)
Browse files Browse the repository at this point in the history
* feat:add new classes bot 7.5

* feat: getStarTransactions support

* feat: business_connection_id param added to all methods

* address comments

* tag with serde

* fixes

* more fixes

---------

Co-authored-by: Ayrat Badykov <[email protected]>
  • Loading branch information
pxp9 and ayrat555 authored Jul 2, 2024
1 parent f6ad0f4 commit 83220c5
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/api_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,10 @@ pub struct SendLocationParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct EditMessageLiveLocationParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub chat_id: Option<ChatId>,
Expand Down Expand Up @@ -1003,6 +1007,10 @@ pub struct EditMessageLiveLocationParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct StopMessageLiveLocationParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub chat_id: Option<ChatId>,
Expand Down Expand Up @@ -1871,6 +1879,10 @@ pub struct DeleteMyCommandsParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct EditMessageTextParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub chat_id: Option<ChatId>,
Expand Down Expand Up @@ -1905,6 +1917,10 @@ pub struct EditMessageTextParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct EditMessageCaptionParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub chat_id: Option<ChatId>,
Expand Down Expand Up @@ -1940,6 +1956,10 @@ pub struct EditMessageCaptionParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct EditMessageMediaParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub chat_id: Option<ChatId>,
Expand All @@ -1962,6 +1982,10 @@ pub struct EditMessageMediaParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct EditMessageReplyMarkupParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub chat_id: Option<ChatId>,
Expand All @@ -1981,6 +2005,10 @@ pub struct EditMessageReplyMarkupParams {

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct StopPollParams {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub business_connection_id: Option<String>,

#[builder(setter(into))]
pub chat_id: ChatId,

Expand Down Expand Up @@ -2444,6 +2472,15 @@ pub struct AnswerPreCheckoutQueryParams {
pub error_message: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct GetStarTransactionsParams {
#[builder(setter(into))]
offset: u32,

#[builder(setter(into))]
limit: u32,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Builder)]
pub struct RefundStarPaymentParams {
pub user_id: u64,
Expand Down
9 changes: 9 additions & 0 deletions src/api_traits/async_telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use crate::api_params::GetMyDefaultAdministratorRightsParams;
use crate::api_params::GetMyDescriptionParams;
use crate::api_params::GetMyNameParams;
use crate::api_params::GetMyShortDescriptionParams;
use crate::api_params::GetStarTransactionsParams;
use crate::api_params::GetStickerSetParams;
use crate::api_params::GetUpdatesParams;
use crate::api_params::GetUserChatBoostsParams;
Expand Down Expand Up @@ -136,6 +137,7 @@ use crate::objects::Message;
use crate::objects::MessageId;
use crate::objects::Poll;
use crate::objects::SentWebAppMessage;
use crate::objects::StarTransactions;
use crate::objects::StickerSet;
use crate::objects::Update;
use crate::objects::User;
Expand Down Expand Up @@ -1279,6 +1281,13 @@ pub trait AsyncTelegramApi {
self.request("answerPreCheckoutQuery", Some(params)).await
}

async fn get_star_transactions(
&self,
params: GetStarTransactionsParams,
) -> Result<MethodResponse<StarTransactions>, Self::Error> {
self.request("getStarTransactions", Some(params)).await
}

async fn refund_star_payment(
&self,
params: &RefundStarPaymentParams,
Expand Down
9 changes: 9 additions & 0 deletions src/api_traits/telegram_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ use crate::api_params::GetMyDefaultAdministratorRightsParams;
use crate::api_params::GetMyDescriptionParams;
use crate::api_params::GetMyNameParams;
use crate::api_params::GetMyShortDescriptionParams;
use crate::api_params::GetStarTransactionsParams;
use crate::api_params::GetStickerSetParams;
use crate::api_params::GetUpdatesParams;
use crate::api_params::GetUserChatBoostsParams;
Expand Down Expand Up @@ -135,6 +136,7 @@ use crate::objects::Message;
use crate::objects::MessageId;
use crate::objects::Poll;
use crate::objects::SentWebAppMessage;
use crate::objects::StarTransactions;
use crate::objects::StickerSet;
use crate::objects::Update;
use crate::objects::User;
Expand Down Expand Up @@ -1222,6 +1224,13 @@ pub trait TelegramApi {
self.request("answerPreCheckoutQuery", Some(params))
}

fn get_star_transactions(
&self,
params: GetStarTransactionsParams,
) -> Result<MethodResponse<StarTransactions>, Self::Error> {
self.request("getStarTransactions", Some(params))
}

fn refund_star_payment(
&self,
params: &RefundStarPaymentParams,
Expand Down
76 changes: 76 additions & 0 deletions src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4096,6 +4096,82 @@ pub struct InaccessibleMessage {
pub date: u64,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RevenueWithdrawalState {
Pending(RevenueWithdrawalStatePending),
Succeeded(RevenueWithdrawalStateSucceeded),
Failed(RevenueWithdrawalStateFailed),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder, Eq)]
pub struct RevenueWithdrawalStatePending {}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder, Eq)]
pub struct RevenueWithdrawalStateSucceeded {
pub date: u64,

#[builder(setter(into))]
pub url: String,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder, Eq)]
pub struct RevenueWithdrawalStateFailed {}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum TransactionPartner {
User(TransactionPartnerUser),
Fragment(TransactionPartnerFragment),
TelegramAds(TransactionPartnerTelegramAds),
Other(TransactionPartnerOther),
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct TransactionPartnerUser {
pub user: User,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub invoice_payload: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct TransactionPartnerFragment {
#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub withdrawal_state: Option<RevenueWithdrawalState>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct TransactionPartnerTelegramAds {}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct TransactionPartnerOther {}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct StarTransaction {
#[builder(setter(into))]
pub id: String,

pub amount: u32,

pub date: u64,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub source: Option<TransactionPartner>,

#[serde(skip_serializing_if = "Option::is_none")]
#[builder(setter(into, strip_option), default)]
pub receiver: Option<TransactionPartner>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Builder)]
pub struct StarTransactions {
pub transactions: Vec<StarTransaction>,
}

#[cfg(test)]
mod serde_tests {
use super::*;
Expand Down

0 comments on commit 83220c5

Please sign in to comment.