👽 Updated code to support BotAPI v4.7
This commit is contained in:
parent
d70608c147
commit
09c0fe0ba0
6
const.go
6
const.go
|
@ -3,7 +3,7 @@ package telegram
|
||||||
import "github.com/Masterminds/semver"
|
import "github.com/Masterminds/semver"
|
||||||
|
|
||||||
// Version represents current version of Telegram API supported by this package
|
// Version represents current version of Telegram API supported by this package
|
||||||
var Version = semver.MustParse("4.6.0") //nolint: gochecknoglobals
|
var Version = semver.MustParse("4.7.0") //nolint: gochecknoglobals
|
||||||
|
|
||||||
// Action represents available and supported status actions of bot
|
// Action represents available and supported status actions of bot
|
||||||
const (
|
const (
|
||||||
|
@ -82,6 +82,7 @@ const (
|
||||||
MethodGetFile string = "getFile"
|
MethodGetFile string = "getFile"
|
||||||
MethodGetGameHighScores string = "getGameHighScores"
|
MethodGetGameHighScores string = "getGameHighScores"
|
||||||
MethodGetMe string = "getMe"
|
MethodGetMe string = "getMe"
|
||||||
|
MethodGetMyCommands string = "getMyCommands"
|
||||||
MethodGetStickerSet string = "getStickerSet"
|
MethodGetStickerSet string = "getStickerSet"
|
||||||
MethodGetUpdates string = "getUpdates"
|
MethodGetUpdates string = "getUpdates"
|
||||||
MethodGetUserProfilePhotos string = "getUserProfilePhotos"
|
MethodGetUserProfilePhotos string = "getUserProfilePhotos"
|
||||||
|
@ -95,6 +96,7 @@ const (
|
||||||
MethodSendAudio string = "sendAudio"
|
MethodSendAudio string = "sendAudio"
|
||||||
MethodSendChatAction string = "sendChatAction"
|
MethodSendChatAction string = "sendChatAction"
|
||||||
MethodSendContact string = "sendContact"
|
MethodSendContact string = "sendContact"
|
||||||
|
MethodSendDice string = "sendDice"
|
||||||
MethodSendDocument string = "sendDocument"
|
MethodSendDocument string = "sendDocument"
|
||||||
MethodSendGame string = "sendGame"
|
MethodSendGame string = "sendGame"
|
||||||
MethodSendInvoice string = "sendInvoice"
|
MethodSendInvoice string = "sendInvoice"
|
||||||
|
@ -115,8 +117,10 @@ const (
|
||||||
MethodSetChatStickerSet string = "setChatStickerSet"
|
MethodSetChatStickerSet string = "setChatStickerSet"
|
||||||
MethodSetChatTitle string = "setChatTitle"
|
MethodSetChatTitle string = "setChatTitle"
|
||||||
MethodSetGameScore string = "setGameScore"
|
MethodSetGameScore string = "setGameScore"
|
||||||
|
MethodSetMyCommands string = "setMyCommands"
|
||||||
MethodSetPassportDataErrors string = "setPassportDataErrors"
|
MethodSetPassportDataErrors string = "setPassportDataErrors"
|
||||||
MethodSetStickerPositionInSet string = "setStickerPositionInSet"
|
MethodSetStickerPositionInSet string = "setStickerPositionInSet"
|
||||||
|
MethodSetStickerSetThumb string = "setStickerSetThumb"
|
||||||
MethodSetWebhook string = "setWebhook"
|
MethodSetWebhook string = "setWebhook"
|
||||||
MethodStopMessageLiveLocation string = "stopMessageLiveLocation"
|
MethodStopMessageLiveLocation string = "stopMessageLiveLocation"
|
||||||
MethodStopPoll string = "stopPoll"
|
MethodStopPoll string = "stopPoll"
|
||||||
|
|
87
methods.go
87
methods.go
|
@ -432,7 +432,22 @@ type (
|
||||||
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SendChatAction represents data for SendChatAction method.
|
// SendDice represents data for SendDice method.
|
||||||
|
SendDice struct {
|
||||||
|
// Unique identifier for the target chat or username of the target channel (in the format @channelusername)
|
||||||
|
ChatID int64 `json:"chat_id"`
|
||||||
|
|
||||||
|
// Sends the message silently. Users will receive a notification with no sound.
|
||||||
|
DisableNotification bool `json:"disable_notification,omitempty"`
|
||||||
|
|
||||||
|
// If the message is a reply, ID of the original message
|
||||||
|
ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
|
||||||
|
|
||||||
|
// Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user.
|
||||||
|
ReplyMarkup ReplyMarkup `json:"reply_markup,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// SendChatAction represents data for SendChat method.
|
||||||
SendChatAction struct {
|
SendChatAction struct {
|
||||||
// Unique identifier for the target chat
|
// Unique identifier for the target chat
|
||||||
ChatID int64 `json:"chat_id"`
|
ChatID int64 `json:"chat_id"`
|
||||||
|
@ -672,6 +687,13 @@ type (
|
||||||
// The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
|
// The maximum amount of time in seconds that the result of the callback query may be cached client-side. Telegram apps will support caching starting in version 3.14. Defaults to 0.
|
||||||
CacheTime int `json:"cache_time,omitempty"`
|
CacheTime int `json:"cache_time,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMyCommands represents data for SetMyCommands method.
|
||||||
|
SetMyCommands struct {
|
||||||
|
// A JSON-serialized list of bot commands to be set as the list of the bot's commands. At most 100
|
||||||
|
// commands can be specified.
|
||||||
|
Commands []*BotCommand `json:"commands"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetMe testing your bot's auth token. Returns basic information about the bot in form of a User object.
|
// GetMe testing your bot's auth token. Returns basic information about the bot in form of a User object.
|
||||||
|
@ -1343,6 +1365,28 @@ func (b Bot) SendPoll(p SendPoll) (*Message, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SendDice send a dice, which will have a random value from 1 to 6. On success, the sent Message is returned. (Yes,
|
||||||
|
// we're aware of the “proper” singular of die. But it's awkward, and we decided to help it change. One dice at a
|
||||||
|
// time!)
|
||||||
|
func (b Bot) SendDice(p SendDice) (*Message, error) {
|
||||||
|
src, err := b.Do(MethodSendDice, p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := new(Response)
|
||||||
|
if err = b.marshler.Unmarshal(src, resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
result := new(Message)
|
||||||
|
if err = b.marshler.Unmarshal(resp.Result, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// SendChatAction tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success.
|
// SendChatAction tell the user that something is happening on the bot's side. The status is set for 5 seconds or less (when a message arrives from your bot, Telegram clients clear its typing status). Returns True on success.
|
||||||
//
|
//
|
||||||
// We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
|
// We only recommend using this method when a response from the bot will take a noticeable amount of time to arrive.
|
||||||
|
@ -1874,3 +1918,44 @@ func (b Bot) AnswerCallbackQuery(p AnswerCallbackQuery) (bool, error) {
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetMyCommands change the list of the bot's commands. Returns True on success.
|
||||||
|
func (b Bot) SetMyCommands(p SetMyCommands) (bool, error) {
|
||||||
|
src, err := b.Do(MethodSetMyCommands, p)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := new(Response)
|
||||||
|
if err = b.marshler.Unmarshal(src, resp); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result bool
|
||||||
|
if err = b.marshler.Unmarshal(resp.Result, &result); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetMyCommands get the current list of the bot's commands. Requires no parameters. Returns Array of BotCommand on
|
||||||
|
// success.
|
||||||
|
func (b Bot) GetMyCommands() ([]*BotCommand, error) {
|
||||||
|
src, err := b.Do(MethodGetMyCommands, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := new(Response)
|
||||||
|
if err = b.marshler.Unmarshal(src, resp); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result []*BotCommand
|
||||||
|
if err = b.marshler.Unmarshal(resp.Result, &result); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
70
stickers.go
70
stickers.go
|
@ -55,6 +55,9 @@ type (
|
||||||
|
|
||||||
// true, if the sticker set contains animated stickers
|
// true, if the sticker set contains animated stickers
|
||||||
IsAnimated bool `json:"is_animated"`
|
IsAnimated bool `json:"is_animated"`
|
||||||
|
|
||||||
|
// Sticker set thumbnail in the .WEBP or .TGS format
|
||||||
|
Thumb *PhotoSize `json:"thumb,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaskPosition describes the position on faces where a mask should be placed by default.
|
// MaskPosition describes the position on faces where a mask should be placed by default.
|
||||||
|
@ -114,8 +117,12 @@ type (
|
||||||
// Sticker set title, 1-64 characters
|
// Sticker set title, 1-64 characters
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
|
||||||
// Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. 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, or upload a new one using multipart/form-data.
|
// PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. 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, or upload a new one using multipart/form-data.
|
||||||
PNGSticker *InputFile `json:"png_sticker"`
|
PNGSticker *InputFile `json:"png_sticker,omitempty"`
|
||||||
|
|
||||||
|
// TGS animation with the sticker, uploaded using multipart/form-data.
|
||||||
|
// See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
|
||||||
|
TGSSticker *InputFile `json:"tgs_sticker,omitempty"`
|
||||||
|
|
||||||
// One or more emoji corresponding to the sticker
|
// One or more emoji corresponding to the sticker
|
||||||
Emojis string `json:"emojis"`
|
Emojis string `json:"emojis"`
|
||||||
|
@ -134,9 +141,13 @@ type (
|
||||||
// Sticker set name
|
// Sticker set name
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
||||||
// Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. 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, or upload a new one using multipart/form-data. More info on Sending Files »
|
// PNG image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. 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, or upload a new one using multipart/form-data. More info on Sending Files »
|
||||||
PNGSticker *InputFile `json:"png_sticker"`
|
PNGSticker *InputFile `json:"png_sticker"`
|
||||||
|
|
||||||
|
// TGS animation with the sticker, uploaded using multipart/form-data.
|
||||||
|
// See https://core.telegram.org/animated_stickers#technical-requirements for technical requirements
|
||||||
|
TGSSticker *InputFile `json:"tgs_sticker,omitempty"`
|
||||||
|
|
||||||
// One or more emoji corresponding to the sticker
|
// One or more emoji corresponding to the sticker
|
||||||
Emojis string `json:"emojis"`
|
Emojis string `json:"emojis"`
|
||||||
|
|
||||||
|
@ -158,6 +169,24 @@ type (
|
||||||
// File identifier of the sticker
|
// File identifier of the sticker
|
||||||
Sticker string `json:"sticker"`
|
Sticker string `json:"sticker"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetStickerSetThumb represents data for SetStickerSetThumb method.
|
||||||
|
SetStickerSetThumb struct {
|
||||||
|
// Sticker set name
|
||||||
|
Name string `json:"name"`
|
||||||
|
|
||||||
|
// User identifier of the sticker set owner
|
||||||
|
UserID int `json:"user_id"`
|
||||||
|
|
||||||
|
// A PNG image with the thumbnail, must be up to 128 kilobytes in size and have width and height
|
||||||
|
// exactly 100px, or a TGS animation with the thumbnail up to 32 kilobytes in size;
|
||||||
|
// see https://core.telegram.org/animated_stickers#technical-requirements for animated sticker
|
||||||
|
// technical requirements. 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, or
|
||||||
|
// upload a new one using multipart/form-data. More info on Sending Files ». Animated sticker set
|
||||||
|
// thumbnail can't be uploaded via HTTP URL.
|
||||||
|
Thumb *InputFile `json:"thumb,omitempty"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewSticker(chatID int64, sticker *InputFile) SendSticker {
|
func NewSticker(chatID int64, sticker *InputFile) SendSticker {
|
||||||
|
@ -368,6 +397,41 @@ func (b *Bot) DeleteStickerFromSet(sticker string) (bool, error) {
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetStickerSetThumb set the thumbnail of a sticker set. Animated thumbnails can be set for animated sticker sets
|
||||||
|
// only. Returns True on success.
|
||||||
|
func (b *Bot) SetStickerSetThumb(p SetStickerSetThumb) (bool, error) {
|
||||||
|
params := make(map[string]string)
|
||||||
|
params["name"] = p.Name
|
||||||
|
params["user_id"] = strconv.Itoa(p.UserID)
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if params["thumb"], err = b.marshler.MarshalToString(p.Thumb); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
files := make([]*InputFile, 0)
|
||||||
|
if p.Thumb.IsAttachment() {
|
||||||
|
files = append(files, p.Thumb)
|
||||||
|
}
|
||||||
|
|
||||||
|
src, err := b.Upload(MethodSetStickerSetThumb, params, files...)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
resp := new(Response)
|
||||||
|
if err = b.marshler.Unmarshal(src, resp); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var result bool
|
||||||
|
if err = b.marshler.Unmarshal(resp.Result, &result); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
// InSet checks that the current sticker in the stickers set.
|
// InSet checks that the current sticker in the stickers set.
|
||||||
func (s Sticker) InSet() bool { return s.SetName != "" }
|
func (s Sticker) InSet() bool { return s.SetName != "" }
|
||||||
|
|
||||||
|
|
22
types.go
22
types.go
|
@ -191,6 +191,9 @@ type (
|
||||||
// Message is a native poll, information about the poll
|
// Message is a native poll, information about the poll
|
||||||
Poll *Poll `json:"poll,omitempty"`
|
Poll *Poll `json:"poll,omitempty"`
|
||||||
|
|
||||||
|
// Message is a dice with random value from 1 to 6
|
||||||
|
Dice *Dice `json:"dice,omitempty"`
|
||||||
|
|
||||||
// New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
|
// New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
|
||||||
NewChatMembers []*User `json:"new_chat_members,omitempty"`
|
NewChatMembers []*User `json:"new_chat_members,omitempty"`
|
||||||
|
|
||||||
|
@ -520,6 +523,13 @@ type (
|
||||||
CorrectOptionID int `json:"correct_option_id,omitempty"`
|
CorrectOptionID int `json:"correct_option_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dice represents a dice with random value from 1 to 6. (Yes, we're aware of the “proper” singular of die.
|
||||||
|
// But it's awkward, and we decided to help it change. One dice at a time!)
|
||||||
|
Dice struct {
|
||||||
|
// Value of the dice, 1-6
|
||||||
|
Value int `json:"value"`
|
||||||
|
}
|
||||||
|
|
||||||
// UserProfilePhotos represent a user's profile pictures.
|
// UserProfilePhotos represent a user's profile pictures.
|
||||||
UserProfilePhotos struct {
|
UserProfilePhotos struct {
|
||||||
// Total number of profile pictures the target user has
|
// Total number of profile pictures the target user has
|
||||||
|
@ -772,6 +782,16 @@ type (
|
||||||
CanPinMessages bool `json:"can_pin_messages,omitempty"`
|
CanPinMessages bool `json:"can_pin_messages,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BotCommand represents a bot command.
|
||||||
|
BotCommand struct {
|
||||||
|
// Text of the command, 1-32 characters. Can contain only lowercase English letters, digits and
|
||||||
|
// underscores.
|
||||||
|
Command string `json:"command"`
|
||||||
|
|
||||||
|
// Description of the command, 3-256 characters.
|
||||||
|
Description string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
// ResponseParameters contains information about why a request was unsuccessful.
|
// ResponseParameters contains information about why a request was unsuccessful.
|
||||||
ResponseParameters struct {
|
ResponseParameters struct {
|
||||||
// The group has been migrated to a supergroup with the specified identifier.
|
// The group has been migrated to a supergroup with the specified identifier.
|
||||||
|
@ -1192,6 +1212,8 @@ func (m Message) IsEvent() bool {
|
||||||
m.IsSupergroupChatCreatedEvent() || m.IsNewChatPhotoEvent()
|
m.IsSupergroupChatCreatedEvent() || m.IsNewChatPhotoEvent()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Message) IsDice() bool { return m.Dice != nil }
|
||||||
|
|
||||||
// IsBold checks that the current entity is a bold tag.
|
// IsBold checks that the current entity is a bold tag.
|
||||||
func (e MessageEntity) IsBold() bool { return strings.EqualFold(e.Type, EntityBold) }
|
func (e MessageEntity) IsBold() bool { return strings.EqualFold(e.Type, EntityBold) }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user