Updates for Bot API 5.1.

bot-api-6.1
Syfaro 2021-03-09 12:27:17 -05:00
parent 4064ced03f
commit 24d4f79474
3 changed files with 209 additions and 16 deletions

View File

@ -1067,7 +1067,8 @@ func (config UnbanChatMemberConfig) params() (Params, error) {
// KickChatMemberConfig contains extra fields to kick user // KickChatMemberConfig contains extra fields to kick user
type KickChatMemberConfig struct { type KickChatMemberConfig struct {
ChatMemberConfig ChatMemberConfig
UntilDate int64 UntilDate int64
RevokeMessages bool
} }
func (config KickChatMemberConfig) method() string { func (config KickChatMemberConfig) method() string {
@ -1080,6 +1081,7 @@ func (config KickChatMemberConfig) params() (Params, error) {
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("user_id", config.UserID) params.AddNonZero("user_id", config.UserID)
params.AddNonZero64("until_date", config.UntilDate) params.AddNonZero64("until_date", config.UntilDate)
params.AddBool("revoke_messages", config.RevokeMessages)
return params, nil return params, nil
} }
@ -1110,15 +1112,17 @@ func (config RestrictChatMemberConfig) params() (Params, error) {
// PromoteChatMemberConfig contains fields to promote members of chat // PromoteChatMemberConfig contains fields to promote members of chat
type PromoteChatMemberConfig struct { type PromoteChatMemberConfig struct {
ChatMemberConfig ChatMemberConfig
IsAnonymous bool IsAnonymous bool
CanChangeInfo bool CanManageChat bool
CanPostMessages bool CanChangeInfo bool
CanEditMessages bool CanPostMessages bool
CanDeleteMessages bool CanEditMessages bool
CanInviteUsers bool CanDeleteMessages bool
CanRestrictMembers bool CanManageVoiceChats bool
CanPinMessages bool CanInviteUsers bool
CanPromoteMembers bool CanRestrictMembers bool
CanPinMessages bool
CanPromoteMembers bool
} }
func (config PromoteChatMemberConfig) method() string { func (config PromoteChatMemberConfig) method() string {
@ -1132,10 +1136,12 @@ func (config PromoteChatMemberConfig) params() (Params, error) {
params.AddNonZero("user_id", config.UserID) params.AddNonZero("user_id", config.UserID)
params.AddBool("is_anonymous", config.IsAnonymous) params.AddBool("is_anonymous", config.IsAnonymous)
params.AddBool("can_manage_chat", config.CanManageChat)
params.AddBool("can_change_info", config.CanChangeInfo) params.AddBool("can_change_info", config.CanChangeInfo)
params.AddBool("can_post_messages", config.CanPostMessages) params.AddBool("can_post_messages", config.CanPostMessages)
params.AddBool("can_edit_messages", config.CanEditMessages) params.AddBool("can_edit_messages", config.CanEditMessages)
params.AddBool("can_delete_messages", config.CanDeleteMessages) params.AddBool("can_delete_messages", config.CanDeleteMessages)
params.AddBool("can_manage_voice_chats", config.CanManageVoiceChats)
params.AddBool("can_invite_users", config.CanInviteUsers) params.AddBool("can_invite_users", config.CanInviteUsers)
params.AddBool("can_restrict_members", config.CanRestrictMembers) params.AddBool("can_restrict_members", config.CanRestrictMembers)
params.AddBool("can_pin_messages", config.CanPinMessages) params.AddBool("can_pin_messages", config.CanPinMessages)
@ -1246,6 +1252,77 @@ func (config ChatInviteLinkConfig) params() (Params, error) {
return params, nil return params, nil
} }
// CreateChatInviteLinkConfig allows you to create an additional invite link for
// a chat. The bot must be an administrator in the chat for this to work and
// must have the appropriate admin rights. The link can be revoked using the
// RevokeChatInviteLinkConfig.
type CreateChatInviteLinkConfig struct {
ChatConfig
ExpireDate int
MemberLimit int
}
func (CreateChatInviteLinkConfig) method() string {
return "createChatInviteLink"
}
func (config CreateChatInviteLinkConfig) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("expire_date", config.ExpireDate)
params.AddNonZero("member_limit", config.MemberLimit)
return params, nil
}
// EditChatInviteLinkConfig allows you to edit a non-primary invite link created
// by the bot. The bot must be an administrator in the chat for this to work and
// must have the appropriate admin rights.
type EditChatInviteLinkConfig struct {
ChatConfig
InviteLink string
ExpireDate int
MemberLimit int
}
func (EditChatInviteLinkConfig) method() string {
return "editChatInviteLink"
}
func (config EditChatInviteLinkConfig) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params["invite_link"] = config.InviteLink
params.AddNonZero("expire_date", config.ExpireDate)
params.AddNonZero("member_limit", config.MemberLimit)
return params, nil
}
// RevokeChatInviteLinkConfig allows you to revoke an invite link created by the
// bot. If the primary link is revoked, a new link is automatically generated.
// The bot must be an administrator in the chat for this to work and must have
// the appropriate admin rights.
type RevokeChatInviteLinkConfig struct {
ChatConfig
InviteLink string
}
func (RevokeChatInviteLinkConfig) method() string {
return "revokeChatInviteLink"
}
func (config RevokeChatInviteLinkConfig) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params["invite_link"] = config.InviteLink
return params, nil
}
// LeaveChatConfig allows you to leave a chat. // LeaveChatConfig allows you to leave a chat.
type LeaveChatConfig struct { type LeaveChatConfig struct {
ChatID int64 ChatID int64
@ -1885,8 +1962,9 @@ func (config SetMyCommandsConfig) params() (Params, error) {
type DiceConfig struct { type DiceConfig struct {
BaseChat BaseChat
// Emoji on which the dice throw animation is based. // Emoji on which the dice throw animation is based.
// Currently, must be one of “🎲”, “🎯”, or “🏀”. // Currently, must be one of 🎲, 🎯, 🏀, ⚽, 🎳, or 🎰.
// Dice can have values 1-6 for “🎲” and “🎯”, and values 1-5 for “🏀”. // Dice can have values 1-6 for 🎲, 🎯, and 🎳, values 1-5 for 🏀 and ⚽,
// and values 1-64 for 🎰.
// Defaults to “🎲” // Defaults to “🎲”
Emoji string Emoji string
} }

112
types.go
View File

@ -96,6 +96,18 @@ type Update struct {
// //
// optional // optional
PollAnswer *PollAnswer `json:"poll_answer,omitempty"` PollAnswer *PollAnswer `json:"poll_answer,omitempty"`
// MyChatMember is the bot's chat member status was updated in a chat. For
// private chats, this update is received only when the bot is blocked or
// unblocked by the user.
//
// optional
MyChatMember *ChatMemberUpdated `json:"my_chat_member"`
// ChatMember is a chat member's status was updated in a chat. The bot must
// be an administrator in the chat and must explicitly specify "chat_member"
// in the list of allowed_updates to receive these updates.
//
// optional
ChatMember *ChatMemberUpdated `json:"chat_member"`
} }
// UpdatesChannel is the channel for getting updates. // UpdatesChannel is the channel for getting updates.
@ -463,6 +475,11 @@ type Message struct {
// //
// optional // optional
ChannelChatCreated bool `json:"channel_chat_created,omitempty"` ChannelChatCreated bool `json:"channel_chat_created,omitempty"`
// MessageAutoDeleteTimerChanged is a service message: auto-delete timer
// settings changed in the chat.
//
// optional
MessageAutoDeleteTimerChanged *MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed"`
// MigrateToChatID is the group has been migrated to a supergroup with the specified identifier. // MigrateToChatID is the group has been migrated to a supergroup with the specified identifier.
// This number may be greater than 32 bits and some programming languages // This number may be greater than 32 bits and some programming languages
// may have difficulty/silent defects in interpreting it. // may have difficulty/silent defects in interpreting it.
@ -508,6 +525,19 @@ type Message struct {
// //
// optional // optional
ProximityAlertTriggered *ProximityAlertTriggered `json:"proximity_alert_triggered"` ProximityAlertTriggered *ProximityAlertTriggered `json:"proximity_alert_triggered"`
// VoiceChatStarted is a service message: voice chat started.
//
// optional
VoiceChatStarted *VoiceChatStarted `json:"voice_chat_started"`
// VoiceChatEnded is a service message: voice chat ended.
//
// optional
VoiceChatEnded *VoiceChatEnded `json:"voice_chat_ended"`
// VoiceChatParticipantsInvited is a service message: new participants
// invited to a voice chat.
//
// optional
VoiceChatParticipantsInvited *VoiceChatParticipantsInvited `json:"voice_chat_participants_invited"`
// ReplyMarkup is the Inline keyboard attached to the message. // ReplyMarkup is the Inline keyboard attached to the message.
// login_url buttons are represented as ordinary url buttons. // login_url buttons are represented as ordinary url buttons.
// //
@ -1037,6 +1067,33 @@ type ProximityAlertTriggered struct {
Distance int `json:"distance"` Distance int `json:"distance"`
} }
// MessageAutoDeleteTimerChanged represents a service message about a change in
// auto-delete timer settings.
type MessageAutoDeleteTimerChanged struct {
// New auto-delete time for messages in the chat.
MessageAutoDeleteTime int `json:"message_auto_delete_time"`
}
// VoiceChatStarted represents a service message about a voice chat started in
// the chat.
type VoiceChatStarted struct{}
// VoiceChatEnded represents a service message about a voice chat ended in the
// chat.
type VoiceChatEnded struct {
// Voice chat duration; in seconds.
Duration int `json:"duration"`
}
// VoiceChatParticipantsInvited represents a service message about new members
// invited to a voice chat.
type VoiceChatParticipantsInvited struct {
// New members that were invited to the voice chat.
//
// optional
Users []User `json:"users"`
}
// UserProfilePhotos contains a set of user profile photos. // UserProfilePhotos contains a set of user profile photos.
type UserProfilePhotos struct { type UserProfilePhotos struct {
// TotalCount total number of profile pictures the target user has // TotalCount total number of profile pictures the target user has
@ -1336,6 +1393,29 @@ type ChatPhoto struct {
BigFileUniqueID string `json:"big_file_unique_id"` BigFileUniqueID string `json:"big_file_unique_id"`
} }
// ChatInviteLink represents an invite link for a chat.
type ChatInviteLink struct {
// InviteLink is the invite link. If the link was created by another chat
// administrator, then the second part of the link will be replaced with “…”.
InviteLink string `json:"invite_link"`
// Creator of the link.
Creator User `json:"creator"`
// IsPrimary is true, if the link is primary.
IsPrimary bool `json:"is_primary"`
// IsRevoked is true, if the link is revoked.
IsRevoked bool `json:"is_revoked"`
// ExpireDate is the point in time (Unix timestamp) when the link will
// expire or has been expired.
//
// optional
ExpireDate int `json:"expire_date"`
// MemberLimit is the maximum number of users that can be members of the
// chat simultaneously after joining the chat via this invite link; 1-99999.
//
// optional
MemberLimit int `json:"member_limit"`
}
// ChatMember contains information about one member of a chat. // ChatMember contains information about one member of a chat.
type ChatMember struct { type ChatMember struct {
// User information about the user // User information about the user
@ -1369,6 +1449,14 @@ type ChatMember struct {
// //
// optional // optional
CanBeEdited bool `json:"can_be_edited,omitempty"` CanBeEdited bool `json:"can_be_edited,omitempty"`
// CanManageChat administrators only.
// True, if the administrator can access the chat event log, chat
// statistics, message statistics in channels, see channel members, see
// anonymous administrators in supergoups and ignore slow mode. Implied by
// any other administrator privilege.
//
// optional
CanManageChat bool `json:"can_manage_chat"`
// CanPostMessages administrators only. // CanPostMessages administrators only.
// True, if the administrator can post in the channel; // True, if the administrator can post in the channel;
// channels only. // channels only.
@ -1386,6 +1474,11 @@ type ChatMember struct {
// //
// optional // optional
CanDeleteMessages bool `json:"can_delete_messages,omitempty"` CanDeleteMessages bool `json:"can_delete_messages,omitempty"`
// CanManageVoiceChats administrators only.
// True, if the administrator can manage voice chats.
//
// optional
CanManageVoiceChats bool `json:"can_manage_voice_chats"`
// CanRestrictMembers administrators only. // CanRestrictMembers administrators only.
// True, if the administrator can restrict, ban or unban chat members. // True, if the administrator can restrict, ban or unban chat members.
// //
@ -1455,6 +1548,25 @@ func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
// WasKicked returns if the ChatMember was kicked from the chat. // WasKicked returns if the ChatMember was kicked from the chat.
func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" } func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
// ChatMemberUpdated represents changes in the status of a chat member.
type ChatMemberUpdated struct {
// Chat the user belongs to.
Chat Chat `json:"chat"`
// From is the performer of the action, which resulted in the change.
From User `json:"from"`
// Date the change was done in Unix time.
Date int `json:"date"`
// Previous information about the chat member.
OldChatMember ChatMember `json:"old_chat_member"`
// New information about the chat member.
NewChatMember ChatMember `json:"new_chat_member"`
// InviteLink is the link which was used by the user to join the chat;
// for joining by invite link events only.
//
// optional
InviteLink *ChatInviteLink `json:"invite_link"`
}
// ChatPermissions describes actions that a non-administrator user is // ChatPermissions describes actions that a non-administrator user is
// allowed to take in a chat. All fields are optional. // allowed to take in a chat. All fields are optional.
type ChatPermissions struct { type ChatPermissions struct {

View File

@ -282,17 +282,20 @@ var (
_ Chattable = AnimationConfig{} _ Chattable = AnimationConfig{}
_ Chattable = AudioConfig{} _ Chattable = AudioConfig{}
_ Chattable = CallbackConfig{} _ Chattable = CallbackConfig{}
_ Chattable = ChatAdministratorsConfig{}
_ Chattable = ChatActionConfig{} _ Chattable = ChatActionConfig{}
_ Chattable = ChatAdministratorsConfig{}
_ Chattable = ChatInfoConfig{} _ Chattable = ChatInfoConfig{}
_ Chattable = ChatInviteLinkConfig{} _ Chattable = ChatInviteLinkConfig{}
_ Chattable = CloseConfig{} _ Chattable = CloseConfig{}
_ Chattable = CopyMessageConfig{}
_ Chattable = ContactConfig{} _ Chattable = ContactConfig{}
_ Chattable = CopyMessageConfig{}
_ Chattable = CreateChatInviteLinkConfig{}
_ Chattable = DeleteChatPhotoConfig{} _ Chattable = DeleteChatPhotoConfig{}
_ Chattable = DeleteChatStickerSetConfig{} _ Chattable = DeleteChatStickerSetConfig{}
_ Chattable = DeleteMessageConfig{} _ Chattable = DeleteMessageConfig{}
_ Chattable = DeleteWebhookConfig{}
_ Chattable = DocumentConfig{} _ Chattable = DocumentConfig{}
_ Chattable = EditChatInviteLinkConfig{}
_ Chattable = EditMessageCaptionConfig{} _ Chattable = EditMessageCaptionConfig{}
_ Chattable = EditMessageLiveLocationConfig{} _ Chattable = EditMessageLiveLocationConfig{}
_ Chattable = EditMessageMediaConfig{} _ Chattable = EditMessageMediaConfig{}
@ -315,8 +318,8 @@ var (
_ Chattable = PinChatMessageConfig{} _ Chattable = PinChatMessageConfig{}
_ Chattable = PreCheckoutConfig{} _ Chattable = PreCheckoutConfig{}
_ Chattable = PromoteChatMemberConfig{} _ Chattable = PromoteChatMemberConfig{}
_ Chattable = DeleteWebhookConfig{}
_ Chattable = RestrictChatMemberConfig{} _ Chattable = RestrictChatMemberConfig{}
_ Chattable = RevokeChatInviteLinkConfig{}
_ Chattable = SendPollConfig{} _ Chattable = SendPollConfig{}
_ Chattable = SetChatDescriptionConfig{} _ Chattable = SetChatDescriptionConfig{}
_ Chattable = SetChatPhotoConfig{} _ Chattable = SetChatPhotoConfig{}
@ -324,8 +327,8 @@ var (
_ Chattable = SetGameScoreConfig{} _ Chattable = SetGameScoreConfig{}
_ Chattable = ShippingConfig{} _ Chattable = ShippingConfig{}
_ Chattable = StickerConfig{} _ Chattable = StickerConfig{}
_ Chattable = StopPollConfig{}
_ Chattable = StopMessageLiveLocationConfig{} _ Chattable = StopMessageLiveLocationConfig{}
_ Chattable = StopPollConfig{}
_ Chattable = UnbanChatMemberConfig{} _ Chattable = UnbanChatMemberConfig{}
_ Chattable = UnpinChatMessageConfig{} _ Chattable = UnpinChatMessageConfig{}
_ Chattable = UpdateConfig{} _ Chattable = UpdateConfig{}