all repos — telegram-bot-api @ 24d4f79474ff891d3ee1b2e3756a094556c78464

Golang bindings for the Telegram Bot API

Updates for Bot API 5.1.
Syfaro syfaro@huefox.com
Tue, 09 Mar 2021 12:27:17 -0500
commit

24d4f79474ff891d3ee1b2e3756a094556c78464

parent

4064ced03f921894c1c8ee0b40476903f7d10b40

3 files changed, 209 insertions(+), 16 deletions(-)

jump to
M configs.goconfigs.go

@@ -1067,7 +1067,8 @@

// KickChatMemberConfig contains extra fields to kick user type KickChatMemberConfig struct { ChatMemberConfig - UntilDate int64 + UntilDate int64 + RevokeMessages bool } func (config KickChatMemberConfig) method() string {

@@ -1080,6 +1081,7 @@

params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddNonZero("user_id", config.UserID) params.AddNonZero64("until_date", config.UntilDate) + params.AddBool("revoke_messages", config.RevokeMessages) return params, nil }

@@ -1110,15 +1112,17 @@

// PromoteChatMemberConfig contains fields to promote members of chat type PromoteChatMemberConfig struct { ChatMemberConfig - IsAnonymous bool - CanChangeInfo bool - CanPostMessages bool - CanEditMessages bool - CanDeleteMessages bool - CanInviteUsers bool - CanRestrictMembers bool - CanPinMessages bool - CanPromoteMembers bool + IsAnonymous bool + CanManageChat bool + CanChangeInfo bool + CanPostMessages bool + CanEditMessages bool + CanDeleteMessages bool + CanManageVoiceChats bool + CanInviteUsers bool + CanRestrictMembers bool + CanPinMessages bool + CanPromoteMembers bool } func (config PromoteChatMemberConfig) method() string {

@@ -1132,10 +1136,12 @@ params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)

params.AddNonZero("user_id", config.UserID) params.AddBool("is_anonymous", config.IsAnonymous) + params.AddBool("can_manage_chat", config.CanManageChat) params.AddBool("can_change_info", config.CanChangeInfo) params.AddBool("can_post_messages", config.CanPostMessages) params.AddBool("can_edit_messages", config.CanEditMessages) 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_restrict_members", config.CanRestrictMembers) params.AddBool("can_pin_messages", config.CanPinMessages)

@@ -1242,6 +1248,77 @@ func (config ChatInviteLinkConfig) params() (Params, error) {

params := make(Params) params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + + 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 }

@@ -1885,8 +1962,9 @@ // DiceConfig contains information about a sendDice request.

type DiceConfig struct { BaseChat // Emoji on which the dice throw animation is based. - // Currently, must be one of “🎲”, “🎯”, or “🏀”. - // Dice can have values 1-6 for “🎲” and “🎯”, and values 1-5 for “🏀”. + // Currently, must be one of 🎲, 🎯, 🏀, ⚽, 🎳, or 🎰. + // Dice can have values 1-6 for 🎲, 🎯, and 🎳, values 1-5 for 🏀 and ⚽, + // and values 1-64 for 🎰. // Defaults to “🎲” Emoji string }
M types.gotypes.go

@@ -96,6 +96,18 @@ // receive new votes only in polls that were sent by the bot itself.

// // optional 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.

@@ -463,6 +475,11 @@ // if someone replies to a very first message in a channel;

// // optional 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. // This number may be greater than 32 bits and some programming languages // may have difficulty/silent defects in interpreting it.

@@ -508,6 +525,19 @@ // triggered another user's proximity alert while sharing Live Location

// // optional 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. // login_url buttons are represented as ordinary url buttons. //

@@ -1037,6 +1067,33 @@ // Distance is the distance between the users

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. type UserProfilePhotos struct { // TotalCount total number of profile pictures the target user has

@@ -1336,6 +1393,29 @@ // used to download or reuse the file.

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. type ChatMember struct { // User information about the user

@@ -1369,6 +1449,14 @@ // True, if the bot is allowed to edit administrator privileges of that user.

// // optional 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. // True, if the administrator can post in the channel; // channels only.

@@ -1386,6 +1474,11 @@ // True, if the administrator can delete messages of other users.

// // optional 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. // True, if the administrator can restrict, ban or unban chat members. //

@@ -1454,6 +1547,25 @@ func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }

// WasKicked returns if the ChatMember was kicked from the chat. 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 // allowed to take in a chat. All fields are optional.
M types_test.gotypes_test.go

@@ -282,17 +282,20 @@ var (

_ Chattable = AnimationConfig{} _ Chattable = AudioConfig{} _ Chattable = CallbackConfig{} - _ Chattable = ChatAdministratorsConfig{} _ Chattable = ChatActionConfig{} + _ Chattable = ChatAdministratorsConfig{} _ Chattable = ChatInfoConfig{} _ Chattable = ChatInviteLinkConfig{} _ Chattable = CloseConfig{} - _ Chattable = CopyMessageConfig{} _ Chattable = ContactConfig{} + _ Chattable = CopyMessageConfig{} + _ Chattable = CreateChatInviteLinkConfig{} _ Chattable = DeleteChatPhotoConfig{} _ Chattable = DeleteChatStickerSetConfig{} _ Chattable = DeleteMessageConfig{} + _ Chattable = DeleteWebhookConfig{} _ Chattable = DocumentConfig{} + _ Chattable = EditChatInviteLinkConfig{} _ Chattable = EditMessageCaptionConfig{} _ Chattable = EditMessageLiveLocationConfig{} _ Chattable = EditMessageMediaConfig{}

@@ -315,8 +318,8 @@ _ Chattable = PhotoConfig{}

_ Chattable = PinChatMessageConfig{} _ Chattable = PreCheckoutConfig{} _ Chattable = PromoteChatMemberConfig{} - _ Chattable = DeleteWebhookConfig{} _ Chattable = RestrictChatMemberConfig{} + _ Chattable = RevokeChatInviteLinkConfig{} _ Chattable = SendPollConfig{} _ Chattable = SetChatDescriptionConfig{} _ Chattable = SetChatPhotoConfig{}

@@ -324,8 +327,8 @@ _ Chattable = SetChatTitleConfig{}

_ Chattable = SetGameScoreConfig{} _ Chattable = ShippingConfig{} _ Chattable = StickerConfig{} - _ Chattable = StopPollConfig{} _ Chattable = StopMessageLiveLocationConfig{} + _ Chattable = StopPollConfig{} _ Chattable = UnbanChatMemberConfig{} _ Chattable = UnpinChatMessageConfig{} _ Chattable = UpdateConfig{}