Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bot API 7.3 #158

Merged
merged 5 commits into from
May 18, 2024
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
18 changes: 18 additions & 0 deletions custom_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ func (im InaccessibleMessage) ToMessage() *Message {
}
}

// ToChat is a helper function to turn a ChatFullInfo struct into a Chat.
func (c ChatFullInfo) ToChat() Chat {
return Chat{
Id: c.Id,
Type: c.Type,
Title: c.Title,
Username: c.Username,
FirstName: c.FirstName,
LastName: c.LastName,
IsForum: c.IsForum,
}
}

// SendMessage is a helper function to easily call Bot.SendMessage in a chat.
func (c Chat) SendMessage(b *Bot, text string, opts *SendMessageOpts) (*Message, error) {
return b.SendMessage(c.Id, text, opts)
Expand All @@ -98,6 +111,11 @@ func (f File) URL(b *Bot, opts *RequestOpts) string {
return b.FileURL(b.Token, f.FilePath, opts)
}

// IsJoinRequest returns true if ChatMemberUpdated originated from a join request; either from a direct join, or from an invitelink.
func (cm ChatMemberUpdated) IsJoinRequest() bool {
return cm.ViaJoinRequest || (cm.InviteLink != nil && cm.InviteLink.CreatesJoinRequest)
}

// unmarshalMaybeInaccessibleMessage is a JSON unmarshal helper to marshal the right structs into a
// MaybeInaccessibleMessage interface based on the Date field.
// This method is manually maintained due to special-case handling on the Date field rather than a specific type field.
Expand Down
2 changes: 1 addition & 1 deletion gen_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (c Chat) ExportInviteLink(b *Bot, opts *ExportChatInviteLinkOpts) (string,
}

// Get Helper method for Bot.GetChat.
func (c Chat) Get(b *Bot, opts *GetChatOpts) (*Chat, error) {
func (c Chat) Get(b *Bot, opts *GetChatOpts) (*ChatFullInfo, error) {
return b.GetChat(c.Id, opts)
}

Expand Down
Loading
Loading