From a8cbe6b4efd516b437a352dcd951e3e18a25d6d8 Mon Sep 17 00:00:00 2001 From: Apolisk Date: Fri, 21 Jun 2024 12:31:52 +0300 Subject: [PATCH 1/2] BotAPI7.5 --- bot.go | 20 ++++++++++++++++++++ media.go | 4 ++++ stars.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 stars.go diff --git a/bot.go b/bot.go index 3062705a..8db0deee 100644 --- a/bot.go +++ b/bot.go @@ -1252,6 +1252,26 @@ func (b *Bot) MyShortDescription(language string) (*BotInfo, error) { return b.botInfo(language, "getMyShortDescription") } +func (b *Bot) GetStarTransactions(offset, limit int) (*StarTransaction, error) { + params := map[string]int{ + "offset": offset, + "limit": limit, + } + + data, err := b.Raw("getStarTransactions", params) + if err != nil { + return nil, err + } + + var resp struct { + Result *StarTransaction + } + if err := json.Unmarshal(data, &resp); err != nil { + return nil, wrapError(err) + } + return resp.Result, nil +} + func (b *Bot) botInfo(language, key string) (*BotInfo, error) { params := map[string]string{ "language_code": language, diff --git a/media.go b/media.go index bdce5557..f4d952c0 100644 --- a/media.go +++ b/media.go @@ -341,6 +341,10 @@ type Location struct { // Period in seconds for which the location will be updated // (see Live Locations, should be between 60 and 86400.) LivePeriod int `json:"live_period,omitempty"` + + // (Optional) Unique identifier of the business connection + // on behalf of which the message to be edited was sent + BusinessConnectionID string `json:"business_connection_id"` } // Venue object represents a venue location with name, address and diff --git a/stars.go b/stars.go new file mode 100644 index 00000000..67c06d9e --- /dev/null +++ b/stars.go @@ -0,0 +1,50 @@ +package telebot + +type RevenueWithdrawalState struct { + // Type of the state, always “pending” + Type string `json:"type"` + + // Date the withdrawal was completed in Unix time + Date int `json:"date,omitempty"` + + // An HTTPS URL that can be used to see transaction details + URL string `json:"url,omitempty"` +} + +type TransactionPartner struct { + // Type of the state, always “fragment” + Type string `json:"type"` + + // (Optional) State of the transaction if the transaction is outgoing$$ + WithdrawalState RevenueWithdrawalState `json:"withdrawal_state,omitempty"` + + // Information about the user + User User `json:"user,omitempty"` +} + +type StarTransaction struct { + // Unique identifier of the transaction. Coincides with the identifer of the + // original transaction for refund transactions. Coincides with + // SuccessfulPayment.telegram_payment_charge_id for successful incoming + // payments from users. + ID string `json:"id"` + + // Number of Telegram Stars transferred by the transaction + Amount int `json:"amount"` + + // Date the transaction was created in Unix time + Date int `json:"date"` + + // (Optional) Source of an incoming transaction (e.g., a user purchasing goods + //or services, Fragment refunding a failed withdrawal). Only for incoming transactions + Source TransactionPartner `json:"source"` + + // (Optional) Receiver of an outgoing transaction (e.g., a user for a purchase + //refund, Fragment for a withdrawal). Only for outgoing transactions + Receiver TransactionPartner `json:"receiver"` +} + +type StarTransactions struct { + // The list of transactions + Transactions []StarTransaction `json:"transactions"` +} From 0bc9e8ab4b3f4b9615b6c0670556d21071c70ac6 Mon Sep 17 00:00:00 2001 From: Apolisk Date: Fri, 21 Jun 2024 13:54:31 +0300 Subject: [PATCH 2/2] bot, stars: refactor --- bot.go | 8 +++++--- stars.go | 56 +++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 44 insertions(+), 20 deletions(-) diff --git a/bot.go b/bot.go index 8db0deee..0a546b12 100644 --- a/bot.go +++ b/bot.go @@ -1252,7 +1252,7 @@ func (b *Bot) MyShortDescription(language string) (*BotInfo, error) { return b.botInfo(language, "getMyShortDescription") } -func (b *Bot) GetStarTransactions(offset, limit int) (*StarTransaction, error) { +func (b *Bot) GetStarTransactions(offset, limit int) ([]StarTransaction, error) { params := map[string]int{ "offset": offset, "limit": limit, @@ -1264,12 +1264,14 @@ func (b *Bot) GetStarTransactions(offset, limit int) (*StarTransaction, error) { } var resp struct { - Result *StarTransaction + Result struct { + Transactions []StarTransaction `json:"transactions"` + } } if err := json.Unmarshal(data, &resp); err != nil { return nil, wrapError(err) } - return resp.Result, nil + return resp.Result.Transactions, nil } func (b *Bot) botInfo(language, key string) (*BotInfo, error) { diff --git a/stars.go b/stars.go index 67c06d9e..fb196d00 100644 --- a/stars.go +++ b/stars.go @@ -1,25 +1,47 @@ package telebot -type RevenueWithdrawalState struct { - // Type of the state, always “pending” - Type string `json:"type"` +import "time" - // Date the withdrawal was completed in Unix time - Date int `json:"date,omitempty"` +type TransactionType = string - // An HTTPS URL that can be used to see transaction details - URL string `json:"url,omitempty"` -} +const ( + TransactionTypeFragment TransactionType = "fragment" + TransactionTypeUser TransactionType = "user" + TransactionTypeOther TransactionType = "other" + TransactionPartnerTelegramAds TransactionType = "telegram_ads" +) + +type RevenueState = string + +const ( + RevenueStatePending RevenueState = "pending" + RevenueStateSucceeded RevenueState = "succeeded" + RevenueStateFailed RevenueState = "failed" +) type TransactionPartner struct { - // Type of the state, always “fragment” - Type string `json:"type"` + // Type of the state + Type TransactionType `json:"type"` // (Optional) State of the transaction if the transaction is outgoing$$ WithdrawalState RevenueWithdrawalState `json:"withdrawal_state,omitempty"` // Information about the user - User User `json:"user,omitempty"` + Partner *User `json:"user,omitempty"` + + // (Optional) Bot-specified invoice payload + InvoicePayload string `json:"invoice_payload"` +} + +type RevenueWithdrawalState struct { + // Type of the state + Type RevenueState `json:"type"` + + // Date the withdrawal was completed in Unix time + Date int `json:"date,omitempty"` + + // An HTTPS URL that can be used to see transaction details + URL string `json:"url,omitempty"` } type StarTransaction struct { @@ -33,18 +55,18 @@ type StarTransaction struct { Amount int `json:"amount"` // Date the transaction was created in Unix time - Date int `json:"date"` + Unixtime int64 `json:"date"` // (Optional) Source of an incoming transaction (e.g., a user purchasing goods - //or services, Fragment refunding a failed withdrawal). Only for incoming transactions + // or services, Fragment refunding a failed withdrawal). Only for incoming transactions Source TransactionPartner `json:"source"` // (Optional) Receiver of an outgoing transaction (e.g., a user for a purchase - //refund, Fragment for a withdrawal). Only for outgoing transactions + // refund, Fragment for a withdrawal). Only for outgoing transactions Receiver TransactionPartner `json:"receiver"` } -type StarTransactions struct { - // The list of transactions - Transactions []StarTransaction `json:"transactions"` +// Date returns the local datetime. +func (c *StarTransaction) Date() time.Time { + return time.Unix(c.Unixtime, 0) }