Skip to content

Commit

Permalink
7.5 (#98)
Browse files Browse the repository at this point in the history
* api v7.5

* update readme, changelog
  • Loading branch information
negasus authored Jun 24, 2024
1 parent 3c2cdfd commit 7a60411
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 27 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v1.5.0 (2024-06-24)

- support API v7.5

## v1.4.1 (2024-06-19)

- fix: getGameHighScores returns an array of high scores instead of a single object (#94)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

> [Telegram Group](https://t.me/gotelegrambotui)
> Supports Bot API version: [7.4](https://core.telegram.org/bots/api#may-28-2024) from May 28, 2024
> Supports Bot API version: [7.5](https://core.telegram.org/bots/api#june-18-2024) from June 18, 2024
It's a Go zero-dependencies telegram bot framework

Expand Down
7 changes: 7 additions & 0 deletions methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,13 @@ func (b *Bot) AnswerPreCheckoutQuery(ctx context.Context, params *AnswerPreCheck
return result, err
}

// GetStarTransactions https://core.telegram.org/bots/api#getstartransactions
func (b *Bot) GetStarTransactions(ctx context.Context, params *GetStarTransactionsParams) (*models.StarTransactions, error) {
result := models.StarTransactions{}
err := b.rawRequest(ctx, "getStarTransactions", params, &result)
return &result, err
}

// RefundStarPayment https://core.telegram.org/bots/api#refundstarpayment
func (b *Bot) RefundStarPayment(ctx context.Context, params *RefundStarPaymentParams) (bool, error) {
var result bool
Expand Down
64 changes: 38 additions & 26 deletions methods_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ type SendLocationParams struct {
}

type EditMessageLiveLocationParams struct {
ChatID any `json:"chat_id"`
BusinessConnectionID string `json:"business_connection_id,omitempty"`
ChatID any `json:"chat_id,omitempty"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
Latitude float64 `json:"latitude"`
Expand All @@ -259,10 +260,11 @@ type EditMessageLiveLocationParams struct {
}

type StopMessageLiveLocationParams struct {
ChatID any `json:"chat_id,omitempty"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
BusinessConnectionID string `json:"business_connection_id,omitempty"`
ChatID any `json:"chat_id,omitempty"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
}

// SendVenueParams https://core.telegram.org/bots/api#sendvenue
Expand Down Expand Up @@ -665,18 +667,20 @@ type GetMyDefaultAdministratorRightsParams struct {

// EditMessageTextParams https://core.telegram.org/bots/api#editmessagetext
type EditMessageTextParams struct {
ChatID any `json:"chat_id"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
Text string `json:"text"`
ParseMode models.ParseMode `json:"parse_mode,omitempty"`
Entities []models.MessageEntity `json:"entities,omitempty"`
LinkPreviewOptions *models.LinkPreviewOptions `json:"link_preview_options,omitempty"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
BusinessConnectionID string `json:"business_connection_id,omitempty"`
ChatID any `json:"chat_id,omitempty"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
Text string `json:"text"`
ParseMode models.ParseMode `json:"parse_mode,omitempty"`
Entities []models.MessageEntity `json:"entities,omitempty"`
LinkPreviewOptions *models.LinkPreviewOptions `json:"link_preview_options,omitempty"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
}

type EditMessageCaptionParams struct {
ChatID any `json:"chat_id"`
BusinessConnectionID string `json:"business_connection_id,omitempty"`
ChatID any `json:"chat_id,omitempty"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
Caption string `json:"caption,omitempty"`
Expand All @@ -688,24 +692,27 @@ type EditMessageCaptionParams struct {
}

type EditMessageMediaParams struct {
ChatID any `json:"chat_id"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
Media models.InputMedia `json:"media"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
BusinessConnectionID string `json:"business_connection_id,omitempty"`
ChatID any `json:"chat_id,omitempty"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
Media models.InputMedia `json:"media"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
}

type EditMessageReplyMarkupParams struct {
ChatID any `json:"chat_id"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
BusinessConnectionID string `json:"business_connection_id,omitempty"`
ChatID any `json:"chat_id,omitempty"`
MessageID int `json:"message_id,omitempty"`
InlineMessageID string `json:"inline_message_id,omitempty"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
}

type StopPollParams struct {
ChatID any `json:"chat_id"`
MessageID int `json:"message_id"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
BusinessConnectionID string `json:"business_connection_id,omitempty"`
ChatID any `json:"chat_id"`
MessageID int `json:"message_id"`
ReplyMarkup models.ReplyMarkup `json:"reply_markup,omitempty"`
}

// DeleteMessageParams https://core.telegram.org/bots/api#deletemessage
Expand Down Expand Up @@ -896,6 +903,11 @@ type AnswerPreCheckoutQueryParams struct {
ErrorMessage string `json:"error_message,omitempty"`
}

type GetStarTransactionsParams struct {
Offset int `json:"offset,omitempty"`
Limit int `json:"limit,omitempty"`
}

type RefundStarPaymentParams struct {
UserID int64 `json:"user_id"`
TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
Expand Down
142 changes: 142 additions & 0 deletions models/star.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
package models

import (
"encoding/json"
"fmt"
)

type TransactionPartnerType string

const (
TransactionPartnerTypeFragment TransactionPartnerType = "fragment"
TransactionPartnerTypeUser TransactionPartnerType = "user"
TransactionPartnerTypeOther TransactionPartnerType = "other"
)

// TransactionPartner https://core.telegram.org/bots/api#transactionpartner
type TransactionPartner struct {
Type TransactionPartnerType

Fragment *TransactionPartnerFragment `json:"fragment,omitempty"`
User *TransactionPartnerUser `json:"user,omitempty"`
Other *TransactionPartnerOther `json:"other,omitempty"`
}

func (m *TransactionPartner) UnmarshalJSON(data []byte) error {
v := struct {
Type TransactionPartnerType `json:"type"`
}{}
err := json.Unmarshal(data, &v)
if err != nil {
return err
}

switch v.Type {
case TransactionPartnerTypeFragment:
m.Type = TransactionPartnerTypeFragment
m.Fragment = &TransactionPartnerFragment{}
return json.Unmarshal(data, m.Fragment)
case TransactionPartnerTypeUser:
m.Type = TransactionPartnerTypeUser
m.User = &TransactionPartnerUser{}
return json.Unmarshal(data, m.User)
case TransactionPartnerTypeOther:
m.Type = TransactionPartnerTypeOther
m.Other = &TransactionPartnerOther{}
return json.Unmarshal(data, m.Other)
}

return fmt.Errorf("unsupported TransactionPartner type")
}

// TransactionPartnerFragment https://core.telegram.org/bots/api#transactionpartnerfragment
type TransactionPartnerFragment struct {
Type TransactionPartnerType `json:"type"`
WithdrawalState *RevenueWithdrawalState `json:"withdrawal_state,omitempty"`
}

// TransactionPartnerUser https://core.telegram.org/bots/api#transactionpartneruser
type TransactionPartnerUser struct {
Type TransactionPartnerType `json:"type"`
User User `json:"user"`
}

// TransactionPartnerOther https://core.telegram.org/bots/api#transactionpartnerother
type TransactionPartnerOther struct {
Type TransactionPartnerType `json:"type"`
}

type RevenueWithdrawalStateType string

const (
RevenueWithdrawalStateTypePending RevenueWithdrawalStateType = "pending"
RevenueWithdrawalStateTypeSucceeded RevenueWithdrawalStateType = "succeeded"
RevenueWithdrawalStateTypeFailed RevenueWithdrawalStateType = "failed"
)

// RevenueWithdrawalState https://core.telegram.org/bots/api#revenuewithdrawalstate
type RevenueWithdrawalState struct {
Type RevenueWithdrawalStateType `json:"type"`

Pending *RevenueWithdrawalStatePending `json:"pending,omitempty"`
Succeeded *RevenueWithdrawalStateSucceeded `json:"succeeded,omitempty"`
Failed *RevenueWithdrawalStateFailed `json:"failed,omitempty"`
}

func (m *RevenueWithdrawalState) UnmarshalJSON(data []byte) error {
v := struct {
Type RevenueWithdrawalStateType `json:"type"`
}{}
err := json.Unmarshal(data, &v)
if err != nil {
return err
}

switch v.Type {
case RevenueWithdrawalStateTypePending:
m.Type = RevenueWithdrawalStateTypePending
m.Pending = &RevenueWithdrawalStatePending{}
return json.Unmarshal(data, m.Pending)
case RevenueWithdrawalStateTypeSucceeded:
m.Type = RevenueWithdrawalStateTypeSucceeded
m.Succeeded = &RevenueWithdrawalStateSucceeded{}
return json.Unmarshal(data, m.Succeeded)
case RevenueWithdrawalStateTypeFailed:
m.Type = RevenueWithdrawalStateTypeFailed
m.Failed = &RevenueWithdrawalStateFailed{}
return json.Unmarshal(data, m.Failed)
}

return fmt.Errorf("unsupported RevenueWithdrawalState type")
}

// RevenueWithdrawalStatePending https://core.telegram.org/bots/api#revenuewithdrawalstatepending
type RevenueWithdrawalStatePending struct {
Type RevenueWithdrawalStateType `json:"type"`
}

// RevenueWithdrawalStateSucceeded https://core.telegram.org/bots/api#revenuewithdrawalstatesucceeded
type RevenueWithdrawalStateSucceeded struct {
Type RevenueWithdrawalStateType `json:"type"`
Date int `json:"date"`
URL string `json:"url"`
}

// RevenueWithdrawalStateFailed https://core.telegram.org/bots/api#revenuewithdrawalstatefailed
type RevenueWithdrawalStateFailed struct {
Type RevenueWithdrawalStateType `json:"type"`
}

// StarTransaction https://core.telegram.org/bots/api#startransaction
type StarTransaction struct {
ID string `json:"id"`
Amount int `json:"amount"`
Date int `json:"date"`
Source *TransactionPartner `json:"source,omitempty"`
Receiver *TransactionPartner `json:"receiver,omitempty"`
}

// StarTransactions https://core.telegram.org/bots/api#startransactions
type StarTransactions struct {
Transactions []StarTransaction `json:"transactions"`
}
Loading

0 comments on commit 7a60411

Please sign in to comment.