Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1395,8 +1396,10 @@ func (config ChatInviteLinkConfig) params() (Params, error) {
// RevokeChatInviteLinkConfig.
type CreateChatInviteLinkConfig struct {
ChatConfig
ExpireDate int
MemberLimit int
Name string
ExpireDate int
MemberLimit int
CreatesJoinRequest bool
}

func (CreateChatInviteLinkConfig) method() string {
Expand All @@ -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
}
Expand All @@ -1418,9 +1423,11 @@ func (config CreateChatInviteLinkConfig) params() (Params, error) {
// must have the appropriate admin rights.
type EditChatInviteLinkConfig struct {
ChatConfig
InviteLink string
ExpireDate int
MemberLimit int
InviteLink string
Name string
ExpireDate int
MemberLimit int
CreatesJoinRequest bool
}

func (EditChatInviteLinkConfig) method() string {
Expand All @@ -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
}
Expand All @@ -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
Expand Down
38 changes: 38 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
//
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down