Updates for Bot API 5.4.

bot-api-6.1
Syfaro 2021-11-08 14:17:17 -05:00
parent 309d612d70
commit 04f547ba7c
2 changed files with 90 additions and 5 deletions

View File

@ -29,6 +29,7 @@ const (
// Deprecated: use ChatUploadVoice instead.
ChatUploadAudio = "upload_audio"
ChatUploadDocument = "upload_document"
ChatChooseSticker = "choose_sticker"
ChatFindLocation = "find_location"
ChatRecordVideoNote = "record_video_note"
ChatUploadVideoNote = "upload_video_note"
@ -1395,8 +1396,10 @@ func (config ChatInviteLinkConfig) params() (Params, error) {
// RevokeChatInviteLinkConfig.
type CreateChatInviteLinkConfig struct {
ChatConfig
Name string
ExpireDate int
MemberLimit int
CreatesJoinRequest bool
}
func (CreateChatInviteLinkConfig) method() string {
@ -1406,9 +1409,11 @@ func (CreateChatInviteLinkConfig) method() string {
func (config CreateChatInviteLinkConfig) params() (Params, error) {
params := make(Params)
params.AddNonEmpty("name", config.Name)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("expire_date", config.ExpireDate)
params.AddNonZero("member_limit", config.MemberLimit)
params.AddBool("creates_join_request", config.CreatesJoinRequest)
return params, nil
}
@ -1419,8 +1424,10 @@ func (config CreateChatInviteLinkConfig) params() (Params, error) {
type EditChatInviteLinkConfig struct {
ChatConfig
InviteLink string
Name string
ExpireDate int
MemberLimit int
CreatesJoinRequest bool
}
func (EditChatInviteLinkConfig) method() string {
@ -1431,9 +1438,11 @@ func (config EditChatInviteLinkConfig) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonEmpty("name", config.Name)
params["invite_link"] = config.InviteLink
params.AddNonZero("expire_date", config.ExpireDate)
params.AddNonZero("member_limit", config.MemberLimit)
params.AddBool("creates_join_request", config.CreatesJoinRequest)
return params, nil
}
@ -1460,6 +1469,44 @@ func (config RevokeChatInviteLinkConfig) params() (Params, error) {
return params, nil
}
// ApproveChatJoinRequestConfig allows you to approve a chat join request.
type ApproveChatJoinRequestConfig struct {
ChatConfig
UserID int64
}
func (ApproveChatJoinRequestConfig) method() string {
return "approveChatJoinRequest"
}
func (config ApproveChatJoinRequestConfig) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("user_id", int(config.UserID))
return params, nil
}
// DeclineChatJoinRequest allows you to decline a chat join request.
type DeclineChatJoinRequest struct {
ChatConfig
UserID int64
}
func (DeclineChatJoinRequest) method() string {
return "declineChatJoinRequest"
}
func (config DeclineChatJoinRequest) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
params.AddNonZero("user_id", int(config.UserID))
return params, nil
}
// LeaveChatConfig allows you to leave a chat.
type LeaveChatConfig struct {
ChatID int64

View File

@ -108,6 +108,12 @@ type Update struct {
//
// optional
ChatMember *ChatMemberUpdated `json:"chat_member"`
// ChatJoinRequest is a request to join the chat has been sent. The bot must
// have the can_invite_users administrator right in the chat to receive
// these updates.
//
// optional
ChatJoinRequest *ChatJoinRequest `json:"chat_join_request"`
}
// UpdatesChannel is the channel for getting updates.
@ -1421,10 +1427,19 @@ type ChatInviteLink struct {
InviteLink string `json:"invite_link"`
// Creator of the link.
Creator User `json:"creator"`
// CreatesJoinRequest is true if users joining the chat via the link need to
// be approved by chat administrators.
//
// optional
CreatesJoinRequest bool `json:"creates_join_request"`
// 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"`
// Name is the name of the invite link.
//
// optional
Name string `json:"name"`
// ExpireDate is the point in time (Unix timestamp) when the link will
// expire or has been expired.
//
@ -1435,6 +1450,11 @@ type ChatInviteLink struct {
//
// optional
MemberLimit int `json:"member_limit"`
// PendingJoinRequestCount is the number of pending join requests created
// using this link.
//
// optional
PendingJoinRequestCount int `json:"pending_join_request_count"`
}
// ChatMember contains information about one member of a chat.
@ -1588,6 +1608,24 @@ type ChatMemberUpdated struct {
InviteLink *ChatInviteLink `json:"invite_link"`
}
// ChatJoinRequest represents a join request sent to a chat.
type ChatJoinRequest struct {
// Chat to which the request was sent.
Chat Chat `json:"chat"`
// User that sent the join request.
From User `json:"user"`
// Date the request was sent in Unix time.
Date int `json:"date"`
// Bio of the user.
//
// optional
Bio string `json:"bio"`
// InviteLink is the link that was used by the user to send the join request.
//
// 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.
type ChatPermissions struct {