all repos — telegram-bot-api @ ef8307cc42d0aca04fcc928dc6b7d36859ef4858

Golang bindings for the Telegram Bot API

BOT API 6.6 implementation
stdkhai k.o.zhuk@student.khai,edu
Tue, 04 Jul 2023 22:21:43 +0300
commit

ef8307cc42d0aca04fcc928dc6b7d36859ef4858

parent

3ba8237c47b151719152756b24ee5cc0b0281174

3 files changed, 343 insertions(+), 65 deletions(-)

jump to
M configs.goconfigs.go

@@ -463,7 +463,7 @@ }}

if config.Thumb != nil { files = append(files, RequestFile{ - Name: "thumb", + Name: "thumbnail", Data: config.Thumb, }) }

@@ -511,7 +511,7 @@ }}

if config.Thumb != nil { files = append(files, RequestFile{ - Name: "thumb", + Name: "thumbnail", Data: config.Thumb, }) }

@@ -551,7 +551,7 @@ }}

if config.Thumb != nil { files = append(files, RequestFile{ - Name: "thumb", + Name: "thumbnail", Data: config.Thumb, }) }

@@ -561,11 +561,18 @@ }

// StickerConfig contains information about a SendSticker request. type StickerConfig struct { + //Emoji associated with the sticker; only for just uploaded stickers + Emoji string BaseFile } func (config StickerConfig) params() (Params, error) { - return config.BaseChat.params() + params, err := config.BaseChat.params() + if err != nil { + return params, err + } + params.AddNonEmpty("emoji", config.Emoji) + return params, err } func (config StickerConfig) method() string {

@@ -627,7 +634,7 @@ }}

if config.Thumb != nil { files = append(files, RequestFile{ - Name: "thumb", + Name: "thumbnail", Data: config.Thumb, }) }

@@ -681,7 +688,7 @@ }}

if config.Thumb != nil { files = append(files, RequestFile{ - Name: "thumb", + Name: "thumbnail", Data: config.Thumb, }) }

@@ -718,7 +725,7 @@ }}

if config.Thumb != nil { files = append(files, RequestFile{ - Name: "thumb", + Name: "thumbnail", Data: config.Thumb, }) }

@@ -762,7 +769,7 @@ }}

if config.Thumb != nil { files = append(files, RequestFile{ - Name: "thumb", + Name: "thumbnail", Data: config.Thumb, }) }

@@ -2139,8 +2146,9 @@ }

// UploadStickerConfig allows you to upload a sticker for use in a set later. type UploadStickerConfig struct { - UserID int64 - PNGSticker RequestFileData + UserID int64 + Sticker RequestFile + StickerFormat string } func (config UploadStickerConfig) method() string {

@@ -2151,6 +2159,7 @@ func (config UploadStickerConfig) params() (Params, error) {

params := make(Params) params.AddNonZero64("user_id", config.UserID) + params["sticker_format"] = config.StickerFormat return params, nil }

@@ -2166,15 +2175,12 @@ // NewStickerSetConfig allows creating a new sticker set.

// // You must set either PNGSticker or TGSSticker. type NewStickerSetConfig struct { - UserID int64 - Name string - Title string - PNGSticker RequestFileData - TGSSticker RequestFileData - StickerType string - Emojis string - ContainsMasks bool // deprecated - MaskPosition *MaskPosition + UserID int64 + Name string + Title string + Stickers []InputSticker + StickerType string + NeedsRepainting bool //optional; Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only } func (config NewStickerSetConfig) method() string {

@@ -2187,11 +2193,10 @@

params.AddNonZero64("user_id", config.UserID) params["name"] = config.Name params["title"] = config.Title - params["emojis"] = config.Emojis - params.AddBool("contains_masks", config.ContainsMasks) + params.AddBool("needs_repainting", config.NeedsRepainting) params.AddNonEmpty("sticker_type", string(config.StickerType)) - err := params.AddInterface("mask_position", config.MaskPosition) + err := params.AddInterface("stickers", config.Stickers) return params, err }

@@ -2212,12 +2217,9 @@ }

// AddStickerConfig allows you to add a sticker to a set. type AddStickerConfig struct { - UserID int64 - Name string - PNGSticker RequestFileData - TGSSticker RequestFileData - Emojis string - MaskPosition *MaskPosition + UserID int64 + Name string + Sticker InputSticker } func (config AddStickerConfig) method() string {

@@ -2229,10 +2231,7 @@ params := make(Params)

params.AddNonZero64("user_id", config.UserID) params["name"] = config.Name - params["emojis"] = config.Emojis - - err := params.AddInterface("mask_position", config.MaskPosition) - + err := params.AddInterface("sticker", config.Sticker) return params, err }

@@ -2270,6 +2269,61 @@

return params, nil } +// SetCustomEmojiStickerSetThumbnalConfig allows you to set the thumbnail of a custom emoji sticker set +type SetCustomEmojiStickerSetThumbnalConfig struct { + Name string + CustomEmojiID string +} + +func (config SetCustomEmojiStickerSetThumbnalConfig) method() string { + return "setCustomEmojiStickerSetThumbnail" +} + +func (config SetCustomEmojiStickerSetThumbnalConfig) params() (Params, error) { + params := make(Params) + + params["name"] = config.Name + params.AddNonEmpty("position", config.CustomEmojiID) + + return params, nil +} + +// SetStickerSetTitle allows you to set the title of a created sticker set +type SetStickerSetTitleConfig struct { + Name string + Title string +} + +func (config SetStickerSetTitleConfig) method() string { + return "setStickerSetTitle" +} + +func (config SetStickerSetTitleConfig) params() (Params, error) { + params := make(Params) + + params["name"] = config.Name + params["title"] = config.Title + + return params, nil +} + +// DeleteStickerSetConfig allows you to delete a sticker set that was created by the bot. +type DeleteStickerSetConfig struct { + Name string +} + +func (config DeleteStickerSetConfig) method() string { + return "deleteStickerSet" +} + +func (config DeleteStickerSetConfig) params() (Params, error) { + params := make(Params) + + params["name"] = config.Name + + return params, nil +} + // DeleteStickerConfig allows you to delete a sticker from a set. type DeleteStickerConfig struct { Sticker string

@@ -2287,6 +2341,63 @@

return params, nil } +// SetStickerEmojiListConfig allows you to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot +type SetStickerEmojiListConfig struct { + Sticker string + EmojiList []string +} + +func (config SetStickerEmojiListConfig) method() string { + return "setStickerEmojiList" +} + +func (config SetStickerEmojiListConfig) params() (Params, error) { + params := make(Params) + + params["sticker"] = config.Sticker + err := params.AddInterface("emoji_list", config.EmojiList) + + return params, err +} + +// SetStickerKeywordsConfig allows you to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot. +type SetStickerKeywordsConfig struct { + Sticker string + Keywords []string +} + +func (config SetStickerKeywordsConfig) method() string { + return "setStickerKeywords" +} + +func (config SetStickerKeywordsConfig) params() (Params, error) { + params := make(Params) + + params["sticker"] = config.Sticker + err := params.AddInterface("keywords", config.Keywords) + + return params, err +} + +// SetStickerMaskPositionConfig allows you to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot +type SetStickerMaskPositionConfig struct { + Sticker string + MaskPosition *MaskPosition +} + +func (config SetStickerMaskPositionConfig) method() string { + return "setStickerMaskPosition" +} + +func (config SetStickerMaskPositionConfig) params() (Params, error) { + params := make(Params) + + params["sticker"] = config.Sticker + err := params.AddInterface("keywords", config.MaskPosition) + + return params, err +} + // SetStickerSetThumbConfig allows you to set the thumbnail for a sticker set. type SetStickerSetThumbConfig struct { Name string

@@ -2295,7 +2406,7 @@ Thumb RequestFileData

} func (config SetStickerSetThumbConfig) method() string { - return "setStickerSetThumb" + return "setStickerSetThumbnail" } func (config SetStickerSetThumbConfig) params() (Params, error) {

@@ -2309,7 +2420,7 @@ }

func (config SetStickerSetThumbConfig) files() []RequestFile { return []RequestFile{{ - Name: "thumb", + Name: "thumbnail", Data: config.Thumb, }} }

@@ -2702,6 +2813,86 @@ err := params.AddInterface("scope", config.Scope)

params.AddNonEmpty("language_code", config.LanguageCode) return params, err +} + +// GetMyDescriptionConfig get the current bot description for the given user language +type GetMyDescriptionConfig struct { + LanguageCode string +} + +func (config GetMyDescriptionConfig) method() string { + return "getMyDescription" +} + +func (config GetMyDescriptionConfig) params() (Params, error) { + params := make(Params) + + params.AddNonEmpty("language_code", config.LanguageCode) + + return params, nil +} + +// SetMyDescroptionConfig sets the bot's description, which is shown in the chat with the bot if the chat is empty +type SetMyDescriptionConfig struct { + // Pass an empty string to remove the dedicated description for the given language. + Description string + //If empty, the description will be applied to all users for whose language there is no dedicated description. + LanguageCode string +} + +func (config SetMyDescriptionConfig) method() string { + return "setMyDescription" +} + +func (config SetMyDescriptionConfig) params() (Params, error) { + params := make(Params) + + params.AddNonEmpty("description", config.Description) + params.AddNonEmpty("language_code", config.LanguageCode) + + return params, nil +} + +// GetMyShortDescriptionConfig get the current bot short description for the given user language +type GetMyShortDescriptionConfig struct { + LanguageCode string +} + +func (config GetMyShortDescriptionConfig) method() string { + return "getMyShortDescription" +} + +func (config GetMyShortDescriptionConfig) params() (Params, error) { + params := make(Params) + + params.AddNonEmpty("language_code", config.LanguageCode) + + return params, nil +} + +// SetMyDescroptionConfig sets the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. +type SetMyShortDescriptionConfig struct { + // New short description for the bot; 0-120 characters. + // + //Pass an empty string to remove the dedicated short description for the given language. + ShortDescription string + //A two-letter ISO 639-1 language code. + // + //If empty, the short description will be applied to all users for whose language there is no dedicated short description. + LanguageCode string +} + +func (config SetMyShortDescriptionConfig) method() string { + return "setMyDescription" +} + +func (config SetMyShortDescriptionConfig) params() (Params, error) { + params := make(Params) + + params.AddNonEmpty("short_description", config.ShortDescription) + params.AddNonEmpty("language_code", config.LanguageCode) + + return params, nil } // SetChatMenuButtonConfig changes the bot's menu button in a private chat,
M helpers.gohelpers.go

@@ -130,6 +130,29 @@ },

} } +// NewCustomEmojiStickerSetThumbnal creates a new setCustomEmojiStickerSetThumbnal request +func NewCustomEmojiStickerSetThumbnal(name, customEmojiID string) SetCustomEmojiStickerSetThumbnalConfig { + return SetCustomEmojiStickerSetThumbnalConfig{ + Name: name, + CustomEmojiID: customEmojiID, + } +} + +// NewStickerSetTitle creates a new setStickerSetTitle request +func NewStickerSetTitle(name, title string) SetStickerSetTitleConfig { + return SetStickerSetTitleConfig{ + Name: name, + Title: title, + } +} + +// NewDeleteStickerSet creates a new deleteStickerSet request +func NewDeleteStickerSet(name, title string) DeleteStickerSetConfig { + return DeleteStickerSetConfig{ + Name: name, + } +} + // NewVideo creates a new sendVideo request. func NewVideo(chatID int64, file RequestFileData) VideoConfig { return VideoConfig{

@@ -181,7 +204,7 @@ return MediaGroupConfig{

BaseChat: BaseChat{ ChatID: chatID, }, - Media: files, + Media: files, } }

@@ -905,6 +928,36 @@ return BotCommandScope{

Type: "chat_member", ChatID: chatID, UserID: userID, + } +} + +// NewSetMyDescription allows you to change the bot's description, which is shown in the chat with the bot if the chat is empty. +func NewSetMyDescription(description, languageCode string) SetMyDescriptionConfig { + return SetMyDescriptionConfig{ + Description: description, + LanguageCode: languageCode, + } +} + +// NewGetMyDescription returns the current bot description for the given user language +func NewGetMyDescription(languageCode string) GetMyDescriptionConfig { + return GetMyDescriptionConfig{ + LanguageCode: languageCode, + } +} + +// NewSetMyShortDescription allows you change the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot. +func NewSetMyShortDescription(shortDescription, languageCode string) SetMyShortDescriptionConfig { + return SetMyShortDescriptionConfig{ + ShortDescription: shortDescription, + LanguageCode: languageCode, + } +} + +// NewGetMyShortDescription returns the current bot short description for the given user language. +func NewGetMyShortDescription(languageCode string) GetMyShortDescriptionConfig { + return GetMyShortDescriptionConfig{ + LanguageCode: languageCode, } }
M types.gotypes.go

@@ -953,7 +953,7 @@ Duration int `json:"duration"`

// Thumbnail animation thumbnail as defined by sender // // optional - Thumbnail *PhotoSize `json:"thumb,omitempty"` + Thumbnail *PhotoSize `json:"thumbnail,omitempty"` // FileName original animation filename as defined by sender // // optional

@@ -1002,7 +1002,7 @@ FileSize int64 `json:"file_size,omitempty"`

// Thumbnail is the album cover to which the music file belongs // // optional - Thumbnail *PhotoSize `json:"thumb,omitempty"` + Thumbnail *PhotoSize `json:"thumbnail,omitempty"` } // Document represents a general file.

@@ -1017,7 +1017,7 @@ FileUniqueID string `json:"file_unique_id"`

// Thumbnail document thumbnail as defined by sender // // optional - Thumbnail *PhotoSize `json:"thumb,omitempty"` + Thumbnail *PhotoSize `json:"thumbnail,omitempty"` // FileName original filename as defined by sender // // optional

@@ -1050,7 +1050,7 @@ Duration int `json:"duration"`

// Thumbnail video thumbnail // // optional - Thumbnail *PhotoSize `json:"thumb,omitempty"` + Thumbnail *PhotoSize `json:"thumbnail,omitempty"` // FileName is the original filename as defined by sender // // optional

@@ -1080,7 +1080,7 @@ Duration int `json:"duration"`

// Thumbnail video thumbnail // // optional - Thumbnail *PhotoSize `json:"thumb,omitempty"` + Thumbnail *PhotoSize `json:"thumbnail,omitempty"` // FileSize file size // // optional

@@ -2212,6 +2212,16 @@ ChatID int64 `json:"chat_id,omitempty"`

UserID int64 `json:"user_id,omitempty"` } +// BotDescription represents the bot's description. +type BotDescription struct { + Description string `json:"description"` +} + +// BotShortDescription represents the bot's short description +type BotShortDescription struct { + ShortDescription string `json:"short_description"` +} + // MenuButton describes the bot's menu button in a private chat. type MenuButton struct { // Type is the type of menu button, must be one of:

@@ -2284,7 +2294,7 @@ // Thumbnail of the file sent; can be ignored if thumbnail generation for

// the file is supported server-side. // // optional - Thumb RequestFileData `json:"thumb,omitempty"` + Thumb RequestFileData `json:"thumbnail,omitempty"` // Width video width // // optional

@@ -2314,7 +2324,7 @@ // Thumbnail of the file sent; can be ignored if thumbnail generation for

// the file is supported server-side. // // optional - Thumb RequestFileData `json:"thumb,omitempty"` + Thumb RequestFileData `json:"thumbnail,omitempty"` // Width video width // // optional

@@ -2340,7 +2350,7 @@ // Thumbnail of the file sent; can be ignored if thumbnail generation for

// the file is supported server-side. // // optional - Thumb RequestFileData `json:"thumb,omitempty"` + Thumb RequestFileData `json:"thumbnail,omitempty"` // Duration of the audio in seconds // // optional

@@ -2362,7 +2372,7 @@ // Thumbnail of the file sent; can be ignored if thumbnail generation for

// the file is supported server-side. // // optional - Thumb RequestFileData `json:"thumb,omitempty"` + Thumb RequestFileData `json:"thumbnail,omitempty"` // DisableContentTypeDetection disables automatic server-side content type // detection for files uploaded using multipart/form-data. Always true, if // the document is sent as part of an album

@@ -2406,7 +2416,7 @@ IsVideo bool `json:"is_video,omitempty"`

// Thumbnail sticker thumbnail in the .WEBP or .JPG format // // optional - Thumbnail *PhotoSize `json:"thumb,omitempty"` + Thumbnail *PhotoSize `json:"thumbnail,omitempty"` // Emoji associated with the sticker // // optional

@@ -2428,6 +2438,10 @@ // CustomEmojiID for custom emoji stickers, unique identifier of the custom emoji

// // optional CustomEmojiID string `json:"custom_emoji_id,omitempty"` + // NeedsRepainting True, if the sticker must be repainted to a text color in messages, the color of the Telegram Premium badge in emoji status, white color on chat photos, or another appropriate color in other places + // + //optional + NeedsRepainting bool `json:"needs_reainting,omitempty"` // FileSize // // optional

@@ -2468,7 +2482,7 @@ ContainsMasks bool `json:"contains_masks"`

// Stickers list of all set stickers Stickers []Sticker `json:"stickers"` // Thumb is the sticker set thumbnail in the .WEBP or .TGS format - Thumbnail *PhotoSize `json:"thumb"` + Thumbnail *PhotoSize `json:"thumbnail"` } // IsRegular returns if the StickerSet is regular

@@ -2504,6 +2518,22 @@ // Mask scaling coefficient. For example, 2.0 means double size.

Scale float64 `json:"scale"` } +// InputSticker describes a sticker to be added to a sticker set. +type InputSticker struct { + // The added sticker. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, upload a new one using multipart/form-data, or pass “attach://<file_attach_name>” to upload a new one using multipart/form-data under <file_attach_name> name. Animated and video stickers can't be uploaded via HTTP URL. + Sticker RequestFile `json:"sticker"` + // List of 1-20 emoji associated with the sticker + EmojiList []string `json:"emoji_list"` + // Position where the mask should be placed on faces. For “mask” stickers only. + // + // optional + MaskPosition *MaskPosition `json:"mask_position"` + // List of 0-20 search keywords for the sticker with total length of up to 64 characters. For “regular” and “custom_emoji” stickers only. + // + // optional + Keywords []string `json:"keywords"` +} + // Game represents a game. Use BotFather to create and edit games, their short // names will act as unique identifiers. type Game struct {

@@ -2923,15 +2953,15 @@ Description string `json:"description,omitempty"`

// ThumbURL url of the thumbnail for the result // // optional - ThumbURL string `json:"thumb_url,omitempty"` + ThumbURL string `json:"thumbnail_url,omitempty"` // ThumbWidth thumbnail width // // optional - ThumbWidth int `json:"thumb_width,omitempty"` + ThumbWidth int `json:"thumbnail_width,omitempty"` // ThumbHeight thumbnail height // // optional - ThumbHeight int `json:"thumb_height,omitempty"` + ThumbHeight int `json:"thumbnail_height,omitempty"` } // InlineQueryResultAudio is an inline query response audio.

@@ -2987,9 +3017,9 @@ LastName string `json:"last_name"`

VCard string `json:"vcard"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` - ThumbURL string `json:"thumb_url"` - ThumbWidth int `json:"thumb_width"` - ThumbHeight int `json:"thumb_height"` + ThumbURL string `json:"thumbnail_url"` + ThumbWidth int `json:"thumbnail_width"` + ThumbHeight int `json:"thumbnail_height"` } // InlineQueryResultGame is an inline query response game.

@@ -3037,15 +3067,15 @@ InputMessageContent interface{} `json:"input_message_content,omitempty"`

// ThumbURL url of the thumbnail (jpeg only) for the file // // optional - ThumbURL string `json:"thumb_url,omitempty"` + ThumbURL string `json:"thumbnail_url,omitempty"` // ThumbWidth thumbnail width // // optional - ThumbWidth int `json:"thumb_width,omitempty"` + ThumbWidth int `json:"thumbnail_width,omitempty"` // ThumbHeight thumbnail height // // optional - ThumbHeight int `json:"thumb_height,omitempty"` + ThumbHeight int `json:"thumbnail_height,omitempty"` } // InlineQueryResultGIF is an inline query response GIF.

@@ -3057,7 +3087,9 @@ ID string `json:"id"`

// URL a valid URL for the GIF file. File size must not exceed 1MB. URL string `json:"gif_url"` // ThumbURL url of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result. - ThumbURL string `json:"thumb_url"` + ThumbURL string `json:"thumbnail_url"` + // MIME type of the thumbnail, must be one of “image/jpeg”, “image/gif”, or “video/mp4”. Defaults to “image/jpeg” + ThumbMimeType string `json:"thumbnail_mime_type,omitempty"` // Width of the GIF // // optional

@@ -3143,15 +3175,15 @@ InputMessageContent interface{} `json:"input_message_content,omitempty"`

// ThumbURL url of the thumbnail for the result // // optional - ThumbURL string `json:"thumb_url,omitempty"` + ThumbURL string `json:"thumbnail_url,omitempty"` // ThumbWidth thumbnail width // // optional - ThumbWidth int `json:"thumb_width,omitempty"` + ThumbWidth int `json:"thumbnail_width,omitempty"` // ThumbHeight thumbnail height // // optional - ThumbHeight int `json:"thumb_height,omitempty"` + ThumbHeight int `json:"thumbnail_height,omitempty"` } // InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.

@@ -3175,7 +3207,9 @@ //

// optional Duration int `json:"mpeg4_duration,omitempty"` // ThumbURL url of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result. - ThumbURL string `json:"thumb_url"` + ThumbURL string `json:"thumbnail_url"` + // MIME type of the thumbnail, must be one of “image/jpeg”, “image/gif”, or “video/mp4”. Defaults to “image/jpeg” + ThumbMimeType string `json:"thumbnail_mime_type,omitempty"` // Title for the result // // optional

@@ -3227,7 +3261,7 @@ Height int `json:"photo_height,omitempty"`

// ThumbURL url of the thumbnail for the photo. // // optional - ThumbURL string `json:"thumb_url,omitempty"` + ThumbURL string `json:"thumbnail_url,omitempty"` // Title for the result // // optional

@@ -3303,15 +3337,15 @@ InputMessageContent interface{} `json:"input_message_content,omitempty"`

// ThumbURL url of the thumbnail for the result // // optional - ThumbURL string `json:"thumb_url,omitempty"` + ThumbURL string `json:"thumbnail_url,omitempty"` // ThumbWidth thumbnail width // // optional - ThumbWidth int `json:"thumb_width,omitempty"` + ThumbWidth int `json:"thumbnail_width,omitempty"` // ThumbHeight thumbnail height // // optional - ThumbHeight int `json:"thumb_height,omitempty"` + ThumbHeight int `json:"thumbnail_height,omitempty"` } // InlineQueryResultVideo is an inline query response video.

@@ -3327,7 +3361,7 @@ MimeType string `json:"mime_type"`

// // ThumbURL url of the thumbnail (jpeg only) for the video // optional - ThumbURL string `json:"thumb_url,omitempty"` + ThumbURL string `json:"thumbnail_url,omitempty"` // Title for the result Title string `json:"title"` // Caption of the video to be sent, 0-1024 characters after entities parsing