Skip to content

Commit

Permalink
Bot API 7.9 (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSonOfLars authored Aug 16, 2024
1 parent e67a260 commit 20dd7b8
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 13 deletions.
10 changes: 10 additions & 0 deletions gen_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ func (c Chat) CreateInviteLink(b *Bot, opts *CreateChatInviteLinkOpts) (*ChatInv
return b.CreateChatInviteLink(c.Id, opts)
}

// CreateSubscriptionInviteLink Helper method for Bot.CreateChatSubscriptionInviteLink.
func (c Chat) CreateSubscriptionInviteLink(b *Bot, subscriptionPeriod int64, subscriptionPrice int64, opts *CreateChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) {
return b.CreateChatSubscriptionInviteLink(c.Id, subscriptionPeriod, subscriptionPrice, opts)
}

// DeclineJoinRequest Helper method for Bot.DeclineChatJoinRequest.
func (c Chat) DeclineJoinRequest(b *Bot, userId int64, opts *DeclineChatJoinRequestOpts) (bool, error) {
return b.DeclineChatJoinRequest(c.Id, userId, opts)
Expand All @@ -53,6 +58,11 @@ func (c Chat) EditInviteLink(b *Bot, inviteLink string, opts *EditChatInviteLink
return b.EditChatInviteLink(c.Id, inviteLink, opts)
}

// EditSubscriptionInviteLink Helper method for Bot.EditChatSubscriptionInviteLink.
func (c Chat) EditSubscriptionInviteLink(b *Bot, inviteLink string, opts *EditChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) {
return b.EditChatSubscriptionInviteLink(c.Id, inviteLink, opts)
}

// ExportInviteLink Helper method for Bot.ExportChatInviteLink.
func (c Chat) ExportInviteLink(b *Bot, opts *ExportChatInviteLinkOpts) (string, error) {
return b.ExportChatInviteLink(c.Id, opts)
Expand Down
89 changes: 83 additions & 6 deletions gen_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,44 @@ func (bot *Bot) CreateChatInviteLink(chatId int64, opts *CreateChatInviteLinkOpt
return &c, json.Unmarshal(r, &c)
}

// CreateChatSubscriptionInviteLinkOpts is the set of optional fields for Bot.CreateChatSubscriptionInviteLink.
type CreateChatSubscriptionInviteLinkOpts struct {
// Invite link name; 0-32 characters
Name string
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}

// CreateChatSubscriptionInviteLink (https://core.telegram.org/bots/api#createchatsubscriptioninvitelink)
//
// Use this method to create a subscription invite link for a channel chat. The bot must have the can_invite_users administrator rights. The link can be edited using the method editChatSubscriptionInviteLink or revoked using the method revokeChatInviteLink. Returns the new invite link as a ChatInviteLink object.
// - chatId (type int64): Unique identifier for the target channel chat
// - subscriptionPeriod (type int64): The number of seconds the subscription will be active for before the next payment. Currently, it must always be 2592000 (30 days).
// - subscriptionPrice (type int64): The amount of Telegram Stars a user must pay initially and after each subsequent subscription period to be a member of the chat; 1-2500
// - opts (type CreateChatSubscriptionInviteLinkOpts): All optional parameters.
func (bot *Bot) CreateChatSubscriptionInviteLink(chatId int64, subscriptionPeriod int64, subscriptionPrice int64, opts *CreateChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["subscription_period"] = strconv.FormatInt(subscriptionPeriod, 10)
v["subscription_price"] = strconv.FormatInt(subscriptionPrice, 10)
if opts != nil {
v["name"] = opts.Name
}

var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}

r, err := bot.Request("createChatSubscriptionInviteLink", v, nil, reqOpts)
if err != nil {
return nil, err
}

var c ChatInviteLink
return &c, json.Unmarshal(r, &c)
}

// CreateForumTopicOpts is the set of optional fields for Bot.CreateForumTopic.
type CreateForumTopicOpts struct {
// Color of the topic icon in RGB format. Currently, must be one of 7322096 (0x6FB9F0), 16766590 (0xFFD67E), 13338331 (0xCB86DB), 9367192 (0x8EEE98), 16749490 (0xFF93B2), or 16478047 (0xFB6F5F)
Expand Down Expand Up @@ -1223,6 +1261,42 @@ func (bot *Bot) EditChatInviteLink(chatId int64, inviteLink string, opts *EditCh
return &c, json.Unmarshal(r, &c)
}

// EditChatSubscriptionInviteLinkOpts is the set of optional fields for Bot.EditChatSubscriptionInviteLink.
type EditChatSubscriptionInviteLinkOpts struct {
// Invite link name; 0-32 characters
Name string
// RequestOpts are an additional optional field to configure timeouts for individual requests
RequestOpts *RequestOpts
}

// EditChatSubscriptionInviteLink (https://core.telegram.org/bots/api#editchatsubscriptioninvitelink)
//
// Use this method to edit a subscription invite link created by the bot. The bot must have the can_invite_users administrator rights. Returns the edited invite link as a ChatInviteLink object.
// - chatId (type int64): Unique identifier for the target chat
// - inviteLink (type string): The invite link to edit
// - opts (type EditChatSubscriptionInviteLinkOpts): All optional parameters.
func (bot *Bot) EditChatSubscriptionInviteLink(chatId int64, inviteLink string, opts *EditChatSubscriptionInviteLinkOpts) (*ChatInviteLink, error) {
v := map[string]string{}
v["chat_id"] = strconv.FormatInt(chatId, 10)
v["invite_link"] = inviteLink
if opts != nil {
v["name"] = opts.Name
}

var reqOpts *RequestOpts
if opts != nil {
reqOpts = opts.RequestOpts
}

r, err := bot.Request("editChatSubscriptionInviteLink", v, nil, reqOpts)
if err != nil {
return nil, err
}

var c ChatInviteLink
return &c, json.Unmarshal(r, &c)
}

// EditForumTopicOpts is the set of optional fields for Bot.EditForumTopic.
type EditForumTopicOpts struct {
// New topic name, 0-128 characters. If not specified or empty, the current name of the topic will be kept
Expand All @@ -1235,7 +1309,7 @@ type EditForumTopicOpts struct {

// EditForumTopic (https://core.telegram.org/bots/api#editforumtopic)
//
// Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
// Use this method to edit name and icon of a topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights, unless it is the creator of the topic. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat
// - messageThreadId (type int64): Unique identifier for the target message thread of the forum topic
// - opts (type EditForumTopicOpts): All optional parameters.
Expand Down Expand Up @@ -1272,7 +1346,7 @@ type EditGeneralForumTopicOpts struct {

// EditGeneralForumTopic (https://core.telegram.org/bots/api#editgeneralforumtopic)
//
// Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have can_manage_topics administrator rights. Returns True on success.
// Use this method to edit the name of the 'General' topic in a forum supergroup chat. The bot must be an administrator in the chat for this to work and must have the can_manage_topics administrator rights. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat
// - name (type string): New topic name, 1-128 characters
// - opts (type EditGeneralForumTopicOpts): All optional parameters.
Expand Down Expand Up @@ -3913,6 +3987,8 @@ func (bot *Bot) SendMessage(chatId int64, text string, opts *SendMessageOpts) (*

// SendPaidMediaOpts is the set of optional fields for Bot.SendPaidMedia.
type SendPaidMediaOpts struct {
// Unique identifier of the business connection on behalf of which the message will be sent
BusinessConnectionId string
// Media caption, 0-1024 characters after entities parsing
Caption string
// Mode for parsing entities in the media caption. See formatting options for more details.
Expand All @@ -3935,8 +4011,8 @@ type SendPaidMediaOpts struct {

// SendPaidMedia (https://core.telegram.org/bots/api#sendpaidmedia)
//
// Use this method to send paid media to channel chats. On success, the sent Message is returned.
// - chatId (type int64): Unique identifier for the target chat
// Use this method to send paid media. On success, the sent Message is returned.
// - chatId (type int64): Unique identifier for the target chat. If the chat is a channel, all Telegram Star proceeds from this media will be credited to the chat's balance. Otherwise, they will be credited to the bot's balance.
// - starCount (type int64): The number of Telegram Stars that must be paid to buy access to the media
// - media (type []InputPaidMedia): A JSON-serialized array describing the media to be sent; up to 10 items
// - opts (type SendPaidMediaOpts): All optional parameters.
Expand All @@ -3961,6 +4037,7 @@ func (bot *Bot) SendPaidMedia(chatId int64, starCount int64, media []InputPaidMe
v["media"] = string(bs)
}
if opts != nil {
v["business_connection_id"] = opts.BusinessConnectionId
v["caption"] = opts.Caption
v["parse_mode"] = opts.ParseMode
if opts.CaptionEntities != nil {
Expand Down Expand Up @@ -5050,7 +5127,7 @@ func (bot *Bot) SetGameScore(userId int64, score int64, opts *SetGameScoreOpts)

// SetMessageReactionOpts is the set of optional fields for Bot.SetMessageReaction.
type SetMessageReactionOpts struct {
// A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators.
// A JSON-serialized list of reaction types to set on the message. Currently, as non-premium users, bots can set up to one reaction per message. A custom emoji reaction can be used if it is either already present on the message or explicitly allowed by chat administrators. Paid reactions can't be used by bots.
Reaction []ReactionType
// Pass True to set the reaction with a big animation
IsBig bool
Expand All @@ -5060,7 +5137,7 @@ type SetMessageReactionOpts struct {

// SetMessageReaction (https://core.telegram.org/bots/api#setmessagereaction)
//
// Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Returns True on success.
// Use this method to change the chosen reactions on a message. Service messages can't be reacted to. Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel. Bots can't use paid reactions. Returns True on success.
// - chatId (type int64): Unique identifier for the target chat
// - messageId (type int64): Identifier of the target message. If the message belongs to a media group, the reaction is set to the first non-deleted message in the group instead.
// - opts (type SetMessageReactionOpts): All optional parameters.
Expand Down
87 changes: 81 additions & 6 deletions gen_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,8 @@ type MergedChatMember struct {
CanPinMessages bool `json:"can_pin_messages,omitempty"`
// Optional. True, if the user is allowed to create, rename, close, and reopen forum topics; for supergroups only (Only for administrator, restricted)
CanManageTopics bool `json:"can_manage_topics,omitempty"`
// Optional. Date when the user's subscription will expire; Unix time (Only for member, restricted, kicked)
UntilDate int64 `json:"until_date,omitempty"`
// Optional. True, if the user is a member of the chat at the moment of the request (Only for restricted)
IsMember bool `json:"is_member,omitempty"`
// Optional. True, if the user is allowed to send text messages, contacts, giveaways, giveaway winners, invoices, locations and venues (Only for restricted)
Expand All @@ -1891,8 +1893,6 @@ type MergedChatMember struct {
CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"`
// Optional. True, if the user is allowed to add web page previews to their messages (Only for restricted)
CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"`
// Optional. Date when restrictions will be lifted for this user; Unix time. If 0, then the user is restricted forever (Only for restricted, kicked)
UntilDate int64 `json:"until_date,omitempty"`
}

// GetStatus is a helper method to easily access the common fields of an interface.
Expand Down Expand Up @@ -2192,6 +2192,8 @@ func (v ChatMemberLeft) chatMember() {}
type ChatMemberMember struct {
// Information about the user
User User `json:"user"`
// Optional. Date when the user's subscription will expire; Unix time
UntilDate int64 `json:"until_date,omitempty"`
}

// GetStatus is a helper method to easily access the common fields of an interface.
Expand All @@ -2207,8 +2209,9 @@ func (v ChatMemberMember) GetUser() User {
// MergeChatMember returns a MergedChatMember struct to simplify working with types in a non-generic world.
func (v ChatMemberMember) MergeChatMember() MergedChatMember {
return MergedChatMember{
Status: "member",
User: v.User,
Status: "member",
User: v.User,
UntilDate: v.UntilDate,
}
}

Expand Down Expand Up @@ -5883,9 +5886,9 @@ type Message struct {
MessageId int64 `json:"message_id"`
// Optional. Unique identifier of a message thread to which the message belongs; for supergroups only
MessageThreadId int64 `json:"message_thread_id,omitempty"`
// Optional. Sender of the message; empty for messages sent to channels. For backward compatibility, the field contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
// Optional. Sender of the message; may be empty for messages sent to channels. For backward compatibility, if the message was sent on behalf of a chat, the field contains a fake sender user in non-channel chats
From *User `json:"from,omitempty"`
// Optional. Sender of the message, sent on behalf of a chat. For example, the channel itself for channel posts, the supergroup itself for messages from anonymous group administrators, the linked channel for messages automatically forwarded to the discussion group. For backward compatibility, the field from contains a fake sender user in non-channel chats, if the message was sent on behalf of a chat.
// Optional. Sender of the message when sent on behalf of a chat. For example, the supergroup itself for messages sent by its anonymous administrators or a linked channel for messages automatically forwarded to the channel's discussion group. For backward compatibility, if the message was sent on behalf of a chat, the field from contains a fake sender user in non-channel chats.
SenderChat *Chat `json:"sender_chat,omitempty"`
// Optional. If the sender of the message boosted the chat, the number of boosts added by the user
SenderBoostCount int64 `json:"sender_boost_count,omitempty"`
Expand Down Expand Up @@ -7702,6 +7705,7 @@ func (v *ReactionCount) UnmarshalJSON(b []byte) error {
// This object describes the type of a reaction. Currently, it can be one of
// - ReactionTypeEmoji
// - ReactionTypeCustomEmoji
// - ReactionTypePaid
type ReactionType interface {
GetType() string
// MergeReactionType returns a MergedReactionType struct to simplify working with complex telegram types in a non-generic world.
Expand All @@ -7714,6 +7718,7 @@ type ReactionType interface {
var (
_ ReactionType = ReactionTypeEmoji{}
_ ReactionType = ReactionTypeCustomEmoji{}
_ ReactionType = ReactionTypePaid{}
)

// MergedReactionType is a helper type to simplify interactions with the various ReactionType subtypes.
Expand Down Expand Up @@ -7796,6 +7801,14 @@ func unmarshalReactionType(d json.RawMessage) (ReactionType, error) {
}
return s, nil

case "paid":
s := ReactionTypePaid{}
err := json.Unmarshal(d, &s)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal ReactionType for value 'paid': %w", err)
}
return s, nil

}
return nil, fmt.Errorf("unknown interface for ReactionType with Type %v", t.Type)
}
Expand Down Expand Up @@ -7874,6 +7887,39 @@ func (v ReactionTypeEmoji) MarshalJSON() ([]byte, error) {
// ReactionTypeEmoji.reactionType is a dummy method to avoid interface implementation.
func (v ReactionTypeEmoji) reactionType() {}

// ReactionTypePaid (https://core.telegram.org/bots/api#reactiontypepaid)
//
// The reaction is paid.
type ReactionTypePaid struct{}

// GetType is a helper method to easily access the common fields of an interface.
func (v ReactionTypePaid) GetType() string {
return "paid"
}

// MergeReactionType returns a MergedReactionType struct to simplify working with types in a non-generic world.
func (v ReactionTypePaid) MergeReactionType() MergedReactionType {
return MergedReactionType{
Type: "paid",
}
}

// MarshalJSON is a custom JSON marshaller to allow for enforcing the Type value.
func (v ReactionTypePaid) MarshalJSON() ([]byte, error) {
type alias ReactionTypePaid
a := struct {
Type string `json:"type"`
alias
}{
Type: "paid",
alias: (alias)(v),
}
return json.Marshal(a)
}

// ReactionTypePaid.reactionType is a dummy method to avoid interface implementation.
func (v ReactionTypePaid) reactionType() {}

// RefundedPayment (https://core.telegram.org/bots/api#refundedpayment)
//
// This object contains basic information about a refunded payment.
Expand Down Expand Up @@ -8439,6 +8485,8 @@ type MergedTransactionPartner struct {
User *User `json:"user,omitempty"`
// Optional. Bot-specified invoice payload (Only for user)
InvoicePayload string `json:"invoice_payload,omitempty"`
// Optional. Information about the paid media bought by the user (Only for user)
PaidMedia []PaidMedia `json:"paid_media,omitempty"`
// Optional. State of the transaction if the transaction is outgoing (Only for fragment)
WithdrawalState RevenueWithdrawalState `json:"withdrawal_state,omitempty"`
}
Expand Down Expand Up @@ -8664,6 +8712,32 @@ type TransactionPartnerUser struct {
User User `json:"user"`
// Optional. Bot-specified invoice payload
InvoicePayload string `json:"invoice_payload,omitempty"`
// Optional. Information about the paid media bought by the user
PaidMedia []PaidMedia `json:"paid_media,omitempty"`
}

// UnmarshalJSON is a custom JSON unmarshaller to use the helpers which allow for unmarshalling structs into interfaces.
func (v *TransactionPartnerUser) UnmarshalJSON(b []byte) error {
// All fields in TransactionPartnerUser, with interface fields as json.RawMessage
type tmp struct {
User User `json:"user"`
InvoicePayload string `json:"invoice_payload"`
PaidMedia json.RawMessage `json:"paid_media"`
}
t := tmp{}
err := json.Unmarshal(b, &t)
if err != nil {
return fmt.Errorf("failed to unmarshal TransactionPartnerUser JSON into tmp struct: %w", err)
}

v.User = t.User
v.InvoicePayload = t.InvoicePayload
v.PaidMedia, err = unmarshalPaidMediaArray(t.PaidMedia)
if err != nil {
return fmt.Errorf("failed to unmarshal custom JSON field PaidMedia: %w", err)
}

return nil
}

// GetType is a helper method to easily access the common fields of an interface.
Expand All @@ -8677,6 +8751,7 @@ func (v TransactionPartnerUser) MergeTransactionPartner() MergedTransactionPartn
Type: "user",
User: &v.User,
InvoicePayload: v.InvoicePayload,
PaidMedia: v.PaidMedia,
}
}

Expand Down
2 changes: 1 addition & 1 deletion spec_commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6c694460e75c07bd789ffd358eff58572caebd35
ab2e4c8ca4457b7a660620993f6bafadfef42c86

0 comments on commit 20dd7b8

Please sign in to comment.