Skip to content

Commit

Permalink
Add support for Bot API 4.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
yanzay committed Apr 14, 2020
1 parent cfd48f6 commit 94a4ba4
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 46 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

## Features

- Full Telegram Bot API **4.4** support
- Full Telegram Bot API **4.5** support
- **Zero** dependency
- Type-safe API client with functional options
- Capture messages by regexp
Expand Down
22 changes: 18 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
r.Set("parse_mode", "HTML")
}
OptParseModeMarkdown = func(r url.Values) {
r.Set("parse_mode", "Markdown")
r.Set("parse_mode", "MarkdownV2")
}
OptDisableNotification = func(r url.Values) {
r.Set("disable_notification", "true")
Expand Down Expand Up @@ -974,9 +974,10 @@ func (c *Client) GetUserProfilePhotos(userID int, opts ...sendOption) (*UserProf

// File object represents a file ready to be downloaded
type File struct {
FileID string `json:"file_id"`
FileSize int `json:"file_size"`
FilePath string `json:"file_path"` // use https://api.telegram.org/file/bot<token>/<file_path> to download
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
FileSize int `json:"file_size"`
FilePath string `json:"file_path"` // use https://api.telegram.org/file/bot<token>/<file_path> to download
}

/*
Expand Down Expand Up @@ -1176,6 +1177,7 @@ func (c *Client) GetChat(chatID string) (*Chat, error) {
type ChatMember struct {
User User `json:"user"`
Status string `json:"status"`
CustomTitle string `json:"custom_title"`
UntilDate int `json:"until_date"`
CanBeEdited bool `json:"can_be_edited"`
CanChangeInfo bool `json:"can_change_info"`
Expand Down Expand Up @@ -2378,6 +2380,18 @@ func (c *Client) StopPoll(chatID string, messageID string, opts ...sendOption) (
return poll, err
}

/*
SetChatAdministratorCustomTitle set a custom title for an administrator in a supergroup promoted by the bot.
*/
func (c *Client) SetChatAdministratorCustomTitle(chatID string, userID string, customTitle string) error {
req := url.Values{}
req.Set("chat_id", chatID)
req.Set("user_id", userID)
req.Set("custom_title", customTitle)
var set bool
return c.doRequest("setChatAdministratorCustomTitle", req, &set)
}

// ChatPermissions describes actions that a non-administrator user is allowed to take in a chat.
type ChatPermissions struct {
CanSendMessages bool `json:"can_send_messages,omitempty"` // True, if the user is allowed to send text messages, contacts, locations and venues
Expand Down
96 changes: 55 additions & 41 deletions updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ type User struct {

// ChatPhoto represents a chat photo
type ChatPhoto struct {
SmallFileID string `json:"small_file_id"`
BigFileID string `json:"big_file_id"`
SmallFileID string `json:"small_file_id"`
SmallFileUniqueID string `json:"small_file_unique_id"`
BigFileID string `json:"big_file_id"`
BigFileUniqueID string `json:"big_file_unique_id"`
}

// Chat represents a chat
Expand All @@ -36,6 +38,7 @@ type Chat struct {
Permissions *ChatPermissions
StickerSetName string
AllMembersAreAdministrators bool // deprecated
SlowModeDelay int
CanSetStickerSet bool
}

Expand All @@ -55,6 +58,7 @@ func (c *Chat) UnmarshalJSON(data []byte) error {
StickerSetName string `json:"sticker_set_name"`
Permissions *ChatPermissions `json:"permissions"`
AllMembersAreAdministrators bool `json:"all_members_are_administrators"`
SlowModeDelay int `json:"slow_mode_delay"`
CanSetStickerSet bool `json:"can_set_sticker_set"`
}{}
err := json.Unmarshal(data, s)
Expand All @@ -75,6 +79,7 @@ func (c *Chat) UnmarshalJSON(data []byte) error {
Permissions: s.Permissions,
StickerSetName: s.StickerSetName,
AllMembersAreAdministrators: s.AllMembersAreAdministrators,
SlowModeDelay: s.SlowModeDelay,
CanSetStickerSet: s.CanSetStickerSet,
}
return nil
Expand All @@ -92,30 +97,33 @@ type MessageEntity struct {

// Audio represents an audio file to be treated as music by the Telegram clients
type Audio struct {
FileID string `json:"file_id"`
Duration int `json:"duration"`
Performer string `json:"performer"`
Title string `json:"title"`
MIMEType string `json:"mime_type"`
FileSize int `json:"file_size"`
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Duration int `json:"duration"`
Performer string `json:"performer"`
Title string `json:"title"`
MIMEType string `json:"mime_type"`
FileSize int `json:"file_size"`
}

// PhotoSize represents one size of a photo or a file/sticker thumbnail.
type PhotoSize struct {
FileID string `json:"file_id"`
Width int `json:"width"`
Height int `json:"height"`
FileSize int `json:"file_size"`
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Width int `json:"width"`
Height int `json:"height"`
FileSize int `json:"file_size"`
}

// Document represents a general file
// (as opposed to photos, voice messages and audio files)
type Document struct {
FileID string `json:"file_id"`
Thumb *PhotoSize `json:"thumb"`
FileName string `json:"file_name"`
MIMEType string `json:"mime_type"`
FileSize int `json:"file_size"`
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Thumb *PhotoSize `json:"thumb"`
FileName string `json:"file_name"`
MIMEType string `json:"mime_type"`
FileSize int `json:"file_size"`
}

// Game represents a game. Use BotFather to create and edit games,
Expand All @@ -132,16 +140,18 @@ type Game struct {
// Animation represents an animation file
// to be displayed in the message containing a game
type Animation struct {
FileID string `json:"file_id"`
Thumb *PhotoSize `json:"thumb"`
FileName string `json:"file_name"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Thumb *PhotoSize `json:"thumb"`
FileName string `json:"file_name"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
}

// Sticker represents a sticker
type Sticker struct {
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Width int `json:"width"`
Height int `json:"height"`
IsAnimated bool `json:"is_animated"`
Expand All @@ -163,30 +173,33 @@ type MaskPosition struct {

// Video represents a video file
type Video struct {
FileID string `json:"file_id"`
Width int `json:"width"`
Height int `json:"height"`
Duration int `json:"duration"`
Thumbnail *PhotoSize `json:"thumb"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Width int `json:"width"`
Height int `json:"height"`
Duration int `json:"duration"`
Thumbnail *PhotoSize `json:"thumb"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
}

// Voice represents a voice note
type Voice struct {
FileID string `json:"file_id"`
Duration int `json:"duration"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Duration int `json:"duration"`
MimeType string `json:"mime_type"`
FileSize int `json:"file_size"`
}

// VideoNote represents a video message
type VideoNote struct {
FileID string `json:"file_id"`
Length int `json:"length"`
Duration int `json:"duration"`
Thumb *PhotoSize `json:"thumb"`
FileSize int `json:"file_size"`
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
Length int `json:"length"`
Duration int `json:"duration"`
Thumb *PhotoSize `json:"thumb"`
FileSize int `json:"file_size"`
}

// Contact represents a phone contact
Expand Down Expand Up @@ -386,9 +399,10 @@ type EncryptedPassportElement struct {

// PassportFile represents a file uploaded to Telegram Passport
type PassportFile struct {
FileID string `json:"file_id"`
FileSize int `json:"file_size"`
FileDate int `json:"file_date"`
FileID string `json:"file_id"`
FileUniqueID string `json:"file_unique_id"`
FileSize int `json:"file_size"`
FileDate int `json:"file_date"`
}

// EncryptedCredentials contains data required for decrypting and authenticating EncryptedPassportElement
Expand Down

0 comments on commit 94a4ba4

Please sign in to comment.