Skip to content

Commit

Permalink
implement bot api 7.5 (#700)
Browse files Browse the repository at this point in the history
* BotAPI7.5

* bot, stars: refactor
  • Loading branch information
Apolisk authored Aug 9, 2024
1 parent a5ca447 commit c0f26a7
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,28 @@ 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 struct {
Transactions []StarTransaction `json:"transactions"`
}
}
if err := json.Unmarshal(data, &resp); err != nil {
return nil, wrapError(err)
}
return resp.Result.Transactions, nil
}

func (b *Bot) botInfo(language, key string) (*BotInfo, error) {
params := map[string]string{
"language_code": language,
Expand Down
4 changes: 4 additions & 0 deletions media.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,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
Expand Down
72 changes: 72 additions & 0 deletions stars.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package telebot

import "time"

type TransactionType = string

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
Type TransactionType `json:"type"`

// (Optional) State of the transaction if the transaction is outgoing$$
WithdrawalState RevenueWithdrawalState `json:"withdrawal_state,omitempty"`

// Information about the user
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 {
// 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
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
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"`
}

// Date returns the local datetime.
func (c *StarTransaction) Date() time.Time {
return time.Unix(c.Unixtime, 0)
}

0 comments on commit c0f26a7

Please sign in to comment.