Skip to content

Commit

Permalink
Bot API 7.7 + payment message filters (#174)
Browse files Browse the repository at this point in the history
* regenerate library to latest spec

* Add new successful+refunded payment msg filters
  • Loading branch information
PaulSonOfLars authored Jul 7, 2024
1 parent 5562b4a commit a9b43ef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
20 changes: 20 additions & 0 deletions ext/handlers/filters/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,23 @@ func TopicAction(msg *gotgbot.Message) bool {
return TopicEdited(msg) || TopicCreated(msg) ||
TopicClosed(msg) || TopicReopened(msg)
}

func SuccessfulPayment(msg *gotgbot.Message) bool {
return msg.SuccessfulPayment != nil
}

func SuccessfulPaymentInvoicePrefix(pref string) func(msg *gotgbot.Message) bool {
return func(msg *gotgbot.Message) bool {
return msg.SuccessfulPayment != nil && strings.HasPrefix(msg.SuccessfulPayment.InvoicePayload, pref)
}
}

func RefundedPayment(msg *gotgbot.Message) bool {
return msg.RefundedPayment != nil
}

func RefundedPaymentInvoicePrefix(pref string) func(msg *gotgbot.Message) bool {
return func(msg *gotgbot.Message) bool {
return msg.RefundedPayment != nil && strings.HasPrefix(msg.RefundedPayment.InvoicePayload, pref)
}
}
20 changes: 20 additions & 0 deletions gen_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5999,6 +5999,8 @@ type Message struct {
Invoice *Invoice `json:"invoice,omitempty"`
// Optional. Message is a service message about a successful payment, information about the payment. More about payments: https://core.telegram.org/bots/api#payments
SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"`
// Optional. Message is a service message about a refunded payment, information about the payment. More about payments: https://core.telegram.org/bots/api#payments
RefundedPayment *RefundedPayment `json:"refunded_payment,omitempty"`
// Optional. Service message: users were shared with the bot
UsersShared *UsersShared `json:"users_shared,omitempty"`
// Optional. Service message: a chat was shared with the bot
Expand Down Expand Up @@ -6113,6 +6115,7 @@ func (v *Message) UnmarshalJSON(b []byte) error {
PinnedMessage json.RawMessage `json:"pinned_message"`
Invoice *Invoice `json:"invoice"`
SuccessfulPayment *SuccessfulPayment `json:"successful_payment"`
RefundedPayment *RefundedPayment `json:"refunded_payment"`
UsersShared *UsersShared `json:"users_shared"`
ChatShared *ChatShared `json:"chat_shared"`
ConnectedWebsite string `json:"connected_website"`
Expand Down Expand Up @@ -6210,6 +6213,7 @@ func (v *Message) UnmarshalJSON(b []byte) error {
}
v.Invoice = t.Invoice
v.SuccessfulPayment = t.SuccessfulPayment
v.RefundedPayment = t.RefundedPayment
v.UsersShared = t.UsersShared
v.ChatShared = t.ChatShared
v.ConnectedWebsite = t.ConnectedWebsite
Expand Down Expand Up @@ -7870,6 +7874,22 @@ func (v ReactionTypeEmoji) MarshalJSON() ([]byte, error) {
// ReactionTypeEmoji.reactionType is a dummy method to avoid interface implementation.
func (v ReactionTypeEmoji) reactionType() {}

// RefundedPayment (https://core.telegram.org/bots/api#refundedpayment)
//
// This object contains basic information about a refunded payment.
type RefundedPayment struct {
// Three-letter ISO 4217 currency code, or "XTR" for payments in Telegram Stars. Currently, always "XTR"
Currency string `json:"currency"`
// Total refunded price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45, total_amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
TotalAmount int64 `json:"total_amount"`
// Bot-specified invoice payload
InvoicePayload string `json:"invoice_payload"`
// Telegram payment identifier
TelegramPaymentChargeId string `json:"telegram_payment_charge_id"`
// Optional. Provider payment identifier
ProviderPaymentChargeId string `json:"provider_payment_charge_id,omitempty"`
}

// ReplyKeyboardMarkup (https://core.telegram.org/bots/api#replykeyboardmarkup)
//
// This object represents a custom keyboard with reply options (see Introduction to bots for details and examples). Not supported in channels and for messages sent on behalf of a Telegram Business account.
Expand Down
2 changes: 1 addition & 1 deletion spec_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8e38e5d9e38a849748b5f37709dbec72b00b6a33
9bcc9ae799d55ec5d08556cfbdfaab49ce0c357d

0 comments on commit a9b43ef

Please sign in to comment.