1
0
Fork 0

🎨 Format of the code

This commit is contained in:
Maxim Lebedev 2020-01-10 10:23:55 +05:00
parent afee6b4fd4
commit a440bb0dad
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
13 changed files with 374 additions and 876 deletions

54
bot.go
View File

@ -46,7 +46,7 @@ func (b *Bot) SetClient(newClient *http.Client) {
b.client = newClient b.client = newClient
} }
func (b *Bot) Do(method string, payload interface{}) ([]byte, error) { func (b Bot) Do(method string, payload interface{}) ([]byte, error) {
u := http.AcquireURI() u := http.AcquireURI()
defer http.ReleaseURI(u) defer http.ReleaseURI(u)
u.SetScheme("https") u.SetScheme("https")
@ -75,7 +75,7 @@ func (b *Bot) Do(method string, payload interface{}) ([]byte, error) {
return resp.Body(), nil return resp.Body(), nil
} }
func (b *Bot) Upload(method string, payload map[string]string, files ...*InputFile) ([]byte, error) { func (b Bot) Upload(method string, payload map[string]string, files ...*InputFile) ([]byte, error) {
if len(files) == 0 { if len(files) == 0 {
return b.Do(method, payload) return b.Do(method, payload)
} }
@ -134,22 +134,22 @@ func (b *Bot) Upload(method string, payload map[string]string, files ...*InputFi
} }
// IsMessageFromMe checks that the input message is a message from the current bot. // IsMessageFromMe checks that the input message is a message from the current bot.
func (b *Bot) IsMessageFromMe(m *Message) bool { func (b Bot) IsMessageFromMe(m Message) bool {
return b != nil && b.User != nil && m != nil && m.From != nil && m.From.ID == b.ID return b.User != nil && m.From != nil && m.From.ID == b.ID
} }
// IsForwardFromMe checks that the input message is a forwarded message from the current bot. // IsForwardFromMe checks that the input message is a forwarded message from the current bot.
func (b *Bot) IsForwardFromMe(m *Message) bool { func (b Bot) IsForwardFromMe(m Message) bool {
return b != nil && b.User != nil && m.IsForward() && m.ForwardFrom.ID == b.ID return b.User != nil && m.IsForward() && m.ForwardFrom.ID == b.ID
} }
// IsReplyToMe checks that the input message is a reply to the current bot. // IsReplyToMe checks that the input message is a reply to the current bot.
func (b *Bot) IsReplyToMe(m *Message) bool { func (b Bot) IsReplyToMe(m Message) bool {
return m.Chat.IsPrivate() || (m.IsReply() && b.IsMessageFromMe(m.ReplyToMessage)) return m.Chat.IsPrivate() || (m.IsReply() && b.IsMessageFromMe(*m.ReplyToMessage))
} }
// IsCommandToMe checks that the input message is a command for the current bot. // IsCommandToMe checks that the input message is a command for the current bot.
func (b *Bot) IsCommandToMe(m *Message) bool { func (b Bot) IsCommandToMe(m Message) bool {
if !m.IsCommand() { if !m.IsCommand() {
return false return false
} }
@ -167,8 +167,8 @@ func (b *Bot) IsCommandToMe(m *Message) bool {
} }
// IsMessageMentionsMe checks that the input message mentions the current bot. // IsMessageMentionsMe checks that the input message mentions the current bot.
func (b *Bot) IsMessageMentionsMe(m *Message) bool { func (b Bot) IsMessageMentionsMe(m Message) bool {
if b == nil || b.User == nil || m == nil { if b.User == nil {
return false return false
} }
@ -195,30 +195,22 @@ func (b *Bot) IsMessageMentionsMe(m *Message) bool {
} }
// IsForwardMentionsMe checks that the input forwarded message mentions the current bot. // IsForwardMentionsMe checks that the input forwarded message mentions the current bot.
func (b *Bot) IsForwardMentionsMe(m *Message) bool { return m.IsForward() && b.IsMessageMentionsMe(m) } func (b Bot) IsForwardMentionsMe(m Message) bool { return m.IsForward() && b.IsMessageMentionsMe(m) }
// IsReplyMentionsMe checks that the input message mentions the current b. // IsReplyMentionsMe checks that the input message mentions the current b.
func (b *Bot) IsReplyMentionsMe(m *Message) bool { func (b Bot) IsReplyMentionsMe(m Message) bool {
return m.IsReply() && b.IsMessageMentionsMe(m.ReplyToMessage) return m.IsReply() && b.IsMessageMentionsMe(*m.ReplyToMessage)
} }
// IsMessageToMe checks that the input message is addressed to the current b. // IsMessageToMe checks that the input message is addressed to the current b.
func (b *Bot) IsMessageToMe(m *Message) bool { func (b Bot) IsMessageToMe(m Message) bool {
if m == nil || m.Chat == nil { return m.Chat != nil && (m.Chat.IsPrivate() || b.IsCommandToMe(m) || b.IsReplyToMe(m) ||
return false b.IsMessageMentionsMe(m))
}
if m.Chat.IsPrivate() || b.IsCommandToMe(m) || b.IsReplyToMe(m) || b.IsMessageMentionsMe(m) {
return true
}
return false
} }
// NewFileURL creates a url.URL to file with path getted from GetFile method. // NewFileURL creates a fasthttp.URI to file with path getted from GetFile method.
func (b *Bot) NewFileURL(filePath string) *http.URI { func (b Bot) NewFileURL(filePath string) *http.URI {
if b == nil || b.AccessToken == "" || if b.AccessToken == "" || filePath == "" {
filePath == "" {
return nil return nil
} }
@ -230,9 +222,9 @@ func (b *Bot) NewFileURL(filePath string) *http.URI {
return result return result
} }
// NewRedirectURL creates new url.URL for redirecting from one chat to another. // NewRedirectURL creates new fasthttp.URI for redirecting from one chat to another.
func (b *Bot) NewRedirectURL(param string, group bool) *http.URI { func (b Bot) NewRedirectURL(param string, group bool) *http.URI {
if b == nil || b.User == nil || b.User.Username == "" { if b.User == nil || b.User.Username == "" {
return nil return nil
} }

View File

@ -1,8 +1,7 @@
package telegram package telegram
type ( type (
// Game represents a game. Use BotFather to create and edit games, their short names will act as unique // Game represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers.
// identifiers.
Game struct { Game struct {
// Title of the game // Title of the game
Title string `json:"title"` Title string `json:"title"`
@ -10,9 +9,7 @@ type (
// Description of the game // Description of the game
Description string `json:"description"` Description string `json:"description"`
// Brief description of the game or high scores included in the game message. Can be automatically // Brief description of the game or high scores included in the game message. Can be automatically edited to include current high scores for the game when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.
// edited to include current high scores for the game when the bot calls setGameScore, or manually
// edited using editMessageText. 0-4096 characters.
Text string `json:"text,omitempty"` Text string `json:"text,omitempty"`
// Photo that will be displayed in the game message in chats. // Photo that will be displayed in the game message in chats.
@ -45,8 +42,7 @@ type (
// Unique identifier for the target chat // Unique identifier for the target chat
ChatID int64 `json:"chat_id"` ChatID int64 `json:"chat_id"`
// Short name of the game, serves as the unique identifier for the game. Set up your games via // Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.
// Botfather.
GameShortName string `json:"game_short_name"` GameShortName string `json:"game_short_name"`
// Sends the message silently. Users will receive a notification with no sound. // Sends the message silently. Users will receive a notification with no sound.
@ -55,8 +51,7 @@ type (
// If the message is a reply, ID of the original message. // If the message is a reply, ID of the original message.
ReplyToMessageID int `json:"reply_to_message_id,omitempty"` ReplyToMessageID int `json:"reply_to_message_id,omitempty"`
// A JSON-serialized object for an inline keyboard. If empty, one Play game_title button will be // A JSON-serialized object for an inline keyboard. If empty, one Play game_title button will be shown. If not empty, the first button must launch the game.
// shown. If not empty, the first button must launch the game.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
} }
@ -71,8 +66,7 @@ type (
// Required if inline_message_id is not specified. Identifier of the sent message // Required if inline_message_id is not specified. Identifier of the sent message
MessageID int `json:"message_id,omitempty"` MessageID int `json:"message_id,omitempty"`
// Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or // Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
// banning cheaters
Force bool `json:"force,omitempty"` Force bool `json:"force,omitempty"`
// Pass True, if the game message should not be automatically edited to include the current scoreboard // Pass True, if the game message should not be automatically edited to include the current scoreboard
@ -102,7 +96,7 @@ type (
) )
// SendGame send a game. On success, the sent Message is returned. // SendGame send a game. On success, the sent Message is returned.
func (b *Bot) SendGame(p SendGame) (*Message, error) { func (b Bot) SendGame(p SendGame) (*Message, error) {
src, err := b.Do(MethodSendGame, p) src, err := b.Do(MethodSendGame, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -121,10 +115,8 @@ func (b *Bot) SendGame(p SendGame) (*Message, error) {
return result, nil return result, nil
} }
// SetGameScore set the score of the specified user in a game. On success, if the message was sent by the bot, returns // SetGameScore set the score of the specified user in a game. On success, if the message was sent by the bot, returns the edited Message, otherwise returns True. Returns an error, if the new score is not greater than the user's current score in the chat and force is False.
// the edited Message, otherwise returns True. Returns an error, if the new score is not greater than the user's func (b Bot) SetGameScore(p SetGameScore) (*Message, error) {
// current score in the chat and force is False.
func (b *Bot) SetGameScore(p SetGameScore) (*Message, error) {
src, err := b.Do(MethodSetGameScore, p) src, err := b.Do(MethodSetGameScore, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -143,9 +135,8 @@ func (b *Bot) SetGameScore(p SetGameScore) (*Message, error) {
return result, nil return result, nil
} }
// GetGameHighScores get data for high score tables. Will return the score of the specified user and several of his // GetGameHighScores get data for high score tables. Will return the score of the specified user and several of his neighbors in a game. On success, returns an Array of GameHighScore objects.
// neighbors in a game. On success, returns an Array of GameHighScore objects. func (b Bot) GetGameHighScores(p GetGameHighScores) ([]*GameHighScore, error) {
func (b *Bot) GetGameHighScores(p GetGameHighScores) ([]*GameHighScore, error) {
src, err := b.Do(MethodGetGameHighScores, p) src, err := b.Do(MethodGetGameHighScores, p)
if err != nil { if err != nil {
return nil, err return nil, err

199
inline.go
View File

@ -60,10 +60,7 @@ type (
ThumbHeight int `json:"thumb_height,omitempty"` ThumbHeight int `json:"thumb_height,omitempty"`
} }
// InlineQueryResultPhoto represents a link to a photo. By default, this // InlineQueryResultPhoto represents a link to a photo. By default, this photo will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo.
// photo will be sent by the user with optional caption. Alternatively, you
// can use input_message_content to send a message with the specified content
// instead of the photo.
InlineQueryResultPhoto struct { InlineQueryResultPhoto struct {
// Type of the result, must be photo // Type of the result, must be photo
Type string `json:"type"` Type string `json:"type"`
@ -71,8 +68,7 @@ type (
// Unique identifier for this result, 1-64 bytes // Unique identifier for this result, 1-64 bytes
ID string `json:"id"` ID string `json:"id"`
// A valid URL of the photo. Photo must be in jpeg format. Photo size // A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB
// must not exceed 5MB
PhotoURL string `json:"photo_url"` PhotoURL string `json:"photo_url"`
// URL of the thumbnail for the photo // URL of the thumbnail for the photo
@ -87,8 +83,7 @@ type (
// Caption of the photo to be sent, 0-200 characters // Caption of the photo to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Width of the photo // Width of the photo
@ -104,10 +99,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultGif represents a link to an animated GIF file. By // InlineQueryResultGif represents a link to an animated GIF file. By default, this animated GIF file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.
// default, this animated GIF file will be sent by the user with optional
// caption. Alternatively, you can use input_message_content to send a
// message with the specified content instead of the animation.
InlineQueryResultGif struct { InlineQueryResultGif struct {
// Type of the result, must be gif // Type of the result, must be gif
Type string `json:"type"` Type string `json:"type"`
@ -127,8 +119,7 @@ type (
// Caption of the GIF file to be sent, 0-200 characters // Caption of the GIF file to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Width of the GIF // Width of the GIF
@ -147,11 +138,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultMpeg4Gif represents a link to a video animation // InlineQueryResultMpeg4Gif represents a link to a video animation (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4 file will be sent by the user with optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.
// (H.264/MPEG-4 AVC video without sound). By default, this animated MPEG-4
// file will be sent by the user with optional caption. Alternatively, you
// can use input_message_content to send a message with the specified content
// instead of the animation.
InlineQueryResultMpeg4Gif struct { InlineQueryResultMpeg4Gif struct {
// Type of the result, must be mpeg4_gif // Type of the result, must be mpeg4_gif
Type string `json:"type"` Type string `json:"type"`
@ -187,14 +174,9 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultVideo represents a link to a page containing an embedded // InlineQueryResultVideo represents a link to a page containing an embedded video player or a video file. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video.
// video player or a video file. By default, this video file will be sent by
// the user with an optional caption. Alternatively, you can use
// input_message_content to send a message with the specified content
// instead of the video.
// //
// If an InlineQueryResultVideo message contains an embedded video (e.g., // If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you must replace its content using input_message_content.
// YouTube), you must replace its content using input_message_content.
InlineQueryResultVideo struct { InlineQueryResultVideo struct {
// Type of the result, must be video // Type of the result, must be video
Type string `json:"type"` Type string `json:"type"`
@ -217,8 +199,7 @@ type (
// Caption of the video to be sent, 0-200 characters // Caption of the video to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Short description of the result // Short description of the result
@ -236,16 +217,11 @@ type (
// Inline keyboard attached to the message // Inline keyboard attached to the message
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
// Content of the message to be sent instead of the video. This field is // Content of the message to be sent instead of the video. This field is required if InlineQueryResultVideo is used to send an HTML-page as a result (e.g., a YouTube video).
// required if InlineQueryResultVideo is used to send an HTML-page as a
// result (e.g., a YouTube video).
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultAudio represents a link to an mp3 audio file. By default, // InlineQueryResultAudio represents a link to an mp3 audio file. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio.
// this audio file will be sent by the user. Alternatively, you can use
// input_message_content to send a message with the specified content
// instead of the audio.
InlineQueryResultAudio struct { InlineQueryResultAudio struct {
// Type of the result, must be audio // Type of the result, must be audio
Type string `json:"type"` Type string `json:"type"`
@ -262,8 +238,7 @@ type (
// Caption, 0-200 characters // Caption, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Performer // Performer
@ -279,10 +254,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultVoice represents a link to a voice recording in an .ogg // InlineQueryResultVoice represents a link to a voice recording in an .ogg container encoded with OPUS. By default, this voice recording will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the the voice message.
// container encoded with OPUS. By default, this voice recording will be
// sent by the user. Alternatively, you can use input_message_content to
// send a message with the specified content instead of the the voice message.
InlineQueryResultVoice struct { InlineQueryResultVoice struct {
// Type of the result, must be voice // Type of the result, must be voice
Type string `json:"type"` Type string `json:"type"`
@ -299,8 +271,7 @@ type (
// Caption, 0-200 characters // Caption, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Recording duration in seconds // Recording duration in seconds
@ -313,11 +284,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultDocument represents a link to a file. By default, this // InlineQueryResultDocument represents a link to a file. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file. Currently, only .PDF and .ZIP files can be sent using this method.
// file will be sent by the user with an optional caption. Alternatively,
// you can use input_message_content to send a message with the specified
// content instead of the file. Currently, only .PDF and .ZIP files can be
// sent using this method.
InlineQueryResultDocument struct { InlineQueryResultDocument struct {
// Type of the result, must be document // Type of the result, must be document
Type string `json:"type"` Type string `json:"type"`
@ -331,15 +298,13 @@ type (
// Caption of the document to be sent, 0-200 characters // Caption of the document to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// A valid URL for the file // A valid URL for the file
DocumentURL string `json:"document_url"` DocumentURL string `json:"document_url"`
// Mime type of the content of the file, either "application/pdf" or // Mime type of the content of the file, either "application/pdf" or "application/zip"
// "application/zip"
MimeType string `json:"mime_type"` MimeType string `json:"mime_type"`
// Short description of the result // Short description of the result
@ -361,10 +326,7 @@ type (
ThumbHeight int `json:"thumb_height,omitempty"` ThumbHeight int `json:"thumb_height,omitempty"`
} }
// InlineQueryResultLocation represents a location on a map. By default, the // InlineQueryResultLocation represents a location on a map. By default, the location will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the location.
// location will be sent by the user. Alternatively, you can use
// input_message_content to send a message with the specified content
// instead of the location.
InlineQueryResultLocation struct { InlineQueryResultLocation struct {
// Type of the result, must be location // Type of the result, must be location
Type string `json:"type"` Type string `json:"type"`
@ -397,9 +359,7 @@ type (
ThumbHeight int `json:"thumb_height,omitempty"` ThumbHeight int `json:"thumb_height,omitempty"`
} }
// InlineQueryResultVenue represents a venue. By default, the venue will be // InlineQueryResultVenue represents a venue. By default, the venue will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the venue.
// sent by the user. Alternatively, you can use input_message_content to
// send a message with the specified content instead of the venue.
InlineQueryResultVenue struct { InlineQueryResultVenue struct {
// Type of the result, must be venue // Type of the result, must be venue
Type string `json:"type"` Type string `json:"type"`
@ -416,9 +376,7 @@ type (
// Foursquare identifier of the venue if known // Foursquare identifier of the venue if known
FoursquareID string `json:"foursquare_id,omitempty"` FoursquareID string `json:"foursquare_id,omitempty"`
// Foursquare type of the venue, if known. (For example, // Foursquare type of the venue, if known. (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".)
// "arts_entertainment/default", "arts_entertainment/aquarium" or
// "food/icecream".)
FoursquareType string `json:"foursquare_type,omitempty"` FoursquareType string `json:"foursquare_type,omitempty"`
// Url of the thumbnail for the result // Url of the thumbnail for the result
@ -443,10 +401,7 @@ type (
ThumbHeight int `json:"thumb_height,omitempty"` ThumbHeight int `json:"thumb_height,omitempty"`
} }
// InlineQueryResultContact represents a contact with a phone number. By // InlineQueryResultContact represents a contact with a phone number. By default, this contact will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the contact.
// default, this contact will be sent by the user. Alternatively, you can
// use input_message_content to send a message with the specified content
// instead of the contact.
InlineQueryResultContact struct { InlineQueryResultContact struct {
// Type of the result, must be contact // Type of the result, must be contact
Type string `json:"type"` Type string `json:"type"`
@ -497,10 +452,7 @@ type (
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
} }
// InlineQueryResultCachedPhoto represents a link to a photo stored on the // InlineQueryResultCachedPhoto represents a link to a photo stored on the Telegram servers. By default, this photo will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the photo.
// Telegram servers. By default, this photo will be sent by the user with an
// optional caption. Alternatively, you can use input_message_content to
// send a message with the specified content instead of the photo.
InlineQueryResultCachedPhoto struct { InlineQueryResultCachedPhoto struct {
// Type of the result, must be photo // Type of the result, must be photo
Type string `json:"type"` Type string `json:"type"`
@ -520,8 +472,7 @@ type (
// Caption of the photo to be sent, 0-200 characters // Caption of the photo to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message // Inline keyboard attached to the message
@ -531,11 +482,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultCachedGif represents a link to an animated GIF file // InlineQueryResultCachedGif represents a link to an animated GIF file stored on the Telegram servers. By default, this animated GIF file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with specified content instead of the animation.
// stored on the Telegram servers. By default, this animated GIF file will
// be sent by the user with an optional caption. Alternatively, you can use
// input_message_content to send a message with specified content instead of
// the animation.
InlineQueryResultCachedGif struct { InlineQueryResultCachedGif struct {
// Type of the result, must be gif // Type of the result, must be gif
Type string `json:"type"` Type string `json:"type"`
@ -552,8 +499,7 @@ type (
// Caption of the GIF file to be sent, 0-200 characters // Caption of the GIF file to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message // Inline keyboard attached to the message
@ -563,11 +509,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultCachedMpeg4Gif represents a link to a video animation // InlineQueryResultCachedMpeg4Gif represents a link to a video animation (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By default, this animated MPEG-4 file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the animation.
// (H.264/MPEG-4 AVC video without sound) stored on the Telegram servers. By
// default, this animated MPEG-4 file will be sent by the user with an
// optional caption. Alternatively, you can use input_message_content to
// send a message with the specified content instead of the animation.
InlineQueryResultCachedMpeg4Gif struct { InlineQueryResultCachedMpeg4Gif struct {
// Type of the result, must be mpeg4_gif // Type of the result, must be mpeg4_gif
Type string `json:"type"` Type string `json:"type"`
@ -584,8 +526,7 @@ type (
// Caption of the MPEG-4 file to be sent, 0-200 characters // Caption of the MPEG-4 file to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message // Inline keyboard attached to the message
@ -595,10 +536,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultCachedSticker represents a link to a sticker stored on // InlineQueryResultCachedSticker represents a link to a sticker stored on the Telegram servers. By default, this sticker will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the sticker.
// the Telegram servers. By default, this sticker will be sent by the user.
// Alternatively, you can use input_message_content to send a message with
// the specified content instead of the sticker.
InlineQueryResultCachedSticker struct { InlineQueryResultCachedSticker struct {
// Type of the result, must be sticker // Type of the result, must be sticker
Type string `json:"type"` Type string `json:"type"`
@ -616,10 +554,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultCachedDocument represents a link to a file stored on the // InlineQueryResultCachedDocument represents a link to a file stored on the Telegram servers. By default, this file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the file.
// Telegram servers. By default, this file will be sent by the user with an
// optional caption. Alternatively, you can use input_message_content to
// send a message with the specified content instead of the file.
InlineQueryResultCachedDocument struct { InlineQueryResultCachedDocument struct {
// Type of the result, must be document // Type of the result, must be document
Type string `json:"type"` Type string `json:"type"`
@ -639,8 +574,7 @@ type (
// Caption of the document to be sent, 0-200 characters // Caption of the document to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message // Inline keyboard attached to the message
@ -650,11 +584,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultCachedVideo represents a link to a video file stored on // InlineQueryResultCachedVideo represents a link to a video file stored on the Telegram servers. By default, this video file will be sent by the user with an optional caption. Alternatively, you can use input_message_content to send a message with the specified content instead of the video.
// the Telegram servers. By default, this video file will be sent by the
// user with an optional caption. Alternatively, you can use
// input_message_content to send a message with the specified content
// instead of the video.
InlineQueryResultCachedVideo struct { InlineQueryResultCachedVideo struct {
// Type of the result, must be video // Type of the result, must be video
Type string `json:"type"` Type string `json:"type"`
@ -674,8 +604,7 @@ type (
// Caption of the video to be sent, 0-200 characters // Caption of the video to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message // Inline keyboard attached to the message
@ -685,10 +614,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultCachedVoice represents a link to a voice message stored // InlineQueryResultCachedVoice represents a link to a voice message stored on the Telegram servers. By default, this voice message will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the voice message.
// on the Telegram servers. By default, this voice message will be sent by
// the user. Alternatively, you can use input_message_content to send a
// message with the specified content instead of the voice message.
InlineQueryResultCachedVoice struct { InlineQueryResultCachedVoice struct {
// Type of the result, must be voice // Type of the result, must be voice
Type string `json:"type"` Type string `json:"type"`
@ -705,8 +631,7 @@ type (
// Caption, 0-200 characters // Caption, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message // Inline keyboard attached to the message
@ -716,10 +641,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"` InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
} }
// InlineQueryResultCachedAudio represents a link to an mp3 audio file // InlineQueryResultCachedAudio represents a link to an mp3 audio file stored on the Telegram servers. By default, this audio file will be sent by the user. Alternatively, you can use input_message_content to send a message with the specified content instead of the audio.
// stored on the Telegram servers. By default, this audio file will be sent
// by the user. Alternatively, you can use input_message_content to send a
// message with the specified content instead of the audio.
InlineQueryResultCachedAudio struct { InlineQueryResultCachedAudio struct {
// Type of the result, must be audio // Type of the result, must be audio
Type string `json:"type"` Type string `json:"type"`
@ -733,8 +655,7 @@ type (
// Caption, 0-200 characters // Caption, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message // Inline keyboard attached to the message
@ -749,22 +670,19 @@ type (
isInputMessageContent() isInputMessageContent()
} }
// InputTextMessageContent represents the content of a text message to be // InputTextMessageContent represents the content of a text message to be sent as the result of an inline query.
// sent as the result of an inline query.
InputTextMessageContent struct { InputTextMessageContent struct {
// Text of the message to be sent, 1-4096 characters // Text of the message to be sent, 1-4096 characters
MessageText string `json:"message_text"` MessageText string `json:"message_text"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
// fixed-width text or inline URLs in your bot's message.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Disables link previews for links in the sent message // Disables link previews for links in the sent message
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"` DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
} }
// InputLocationMessageContent represents the content of a location message // InputLocationMessageContent represents the content of a location message to be sent as the result of an inline query.
// to be sent as the result of an inline query.
InputLocationMessageContent struct { InputLocationMessageContent struct {
// Latitude of the location in degrees // Latitude of the location in degrees
Latitude float32 `json:"latitude"` Latitude float32 `json:"latitude"`
@ -776,8 +694,7 @@ type (
LivePeriod int `json:"live_period,omitempty"` LivePeriod int `json:"live_period,omitempty"`
} }
// InputVenueMessageContent represents the content of a venue message to be // InputVenueMessageContent represents the content of a venue message to be sent as the result of an inline query.
// sent as the result of an inline query.
InputVenueMessageContent struct { InputVenueMessageContent struct {
// Latitude of the location in degrees // Latitude of the location in degrees
Latitude float32 `json:"latitude"` Latitude float32 `json:"latitude"`
@ -794,14 +711,11 @@ type (
// Foursquare identifier of the venue, if known // Foursquare identifier of the venue, if known
FoursquareID string `json:"foursquare_id,omitempty"` FoursquareID string `json:"foursquare_id,omitempty"`
// Foursquare type of the venue, if known. (For example, // Foursquare type of the venue, if known. (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".)
// "arts_entertainment/default", "arts_entertainment/aquarium" or
// "food/icecream".)
FoursquareType string `json:"foursquare_type,omitempty"` FoursquareType string `json:"foursquare_type,omitempty"`
} }
// InputContactMessageContent represents the content of a contact message to // InputContactMessageContent represents the content of a contact message to be sent as the result of an inline query.
// be sent as the result of an inline query.
InputContactMessageContent struct { InputContactMessageContent struct {
// Contact's phone number // Contact's phone number
PhoneNumber string `json:"phone_number"` PhoneNumber string `json:"phone_number"`
@ -816,15 +730,12 @@ type (
VCard string `json:"vcard,omitempty"` VCard string `json:"vcard,omitempty"`
} }
// ChosenInlineResult represents a result of an inline query that was chosen // ChosenInlineResult represents a result of an inline query that was chosen by the user and sent to their chat partner.
// by the user and sent to their chat partner.
ChosenInlineResult struct { ChosenInlineResult struct {
// The unique identifier for the result that was chosen // The unique identifier for the result that was chosen
ResultID string `json:"result_id"` ResultID string `json:"result_id"`
// Identifier of the sent inline message. Available only if there is an // Identifier of the sent inline message. Available only if there is an inline keyboard attached to the message. Will be also received in callback queries and can be used to edit the message.
// inline keyboard attached to the message. Will be also received in
// callback queries and can be used to edit the message.
InlineMessageID string `json:"inline_message_id,omitempty"` InlineMessageID string `json:"inline_message_id,omitempty"`
// The query that was used to obtain the result // The query that was used to obtain the result
@ -842,32 +753,22 @@ type (
// Unique identifier for the answered query // Unique identifier for the answered query
InlineQueryID string `json:"inline_query_id"` InlineQueryID string `json:"inline_query_id"`
// Pass the offset that a client should send in the next query with the same // Pass the offset that a client should send in the next query with the same text to receive more results. Pass an empty string if there are no more results or if you dont support pagination. Offset length cant exceed 64 bytes.
// text to receive more results. Pass an empty string if there are no more
// results or if you dont support pagination. Offset length cant exceed 64
// bytes.
NextOffset string `json:"next_offset,omitempty"` NextOffset string `json:"next_offset,omitempty"`
// If passed, clients will display a button with specified text that switches // If passed, clients will display a button with specified text that switches the user to a private chat with the bot and sends the bot a start message with the parameter switch_pm_parameter
// the user to a private chat with the bot and sends the bot a start message
// with the parameter switch_pm_parameter
SwitchPrivateMessageText string `json:"switch_pm_text,omitempty"` SwitchPrivateMessageText string `json:"switch_pm_text,omitempty"`
// Deep-linking parameter for the /start message sent to the bot when user // Deep-linking parameter for the /start message sent to the bot when user presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and - are allowed.
// presses the switch button. 1-64 characters, only A-Z, a-z, 0-9, _ and -
// are allowed.
SwitchPrivateMessageParameter string `json:"switch_pm_parameter,omitempty"` SwitchPrivateMessageParameter string `json:"switch_pm_parameter,omitempty"`
// A JSON-serialized array of results for the inline query // A JSON-serialized array of results for the inline query
Results []InlineQueryResult `json:"results"` Results []InlineQueryResult `json:"results"`
// The maximum amount of time in seconds that the result of the inline query // The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
// may be cached on the server. Defaults to 300.
CacheTime int `json:"cache_time,omitempty"` CacheTime int `json:"cache_time,omitempty"`
// Pass True, if results may be cached on the server side only for the user // Pass True, if results may be cached on the server side only for the user that sent the query. By default, results may be returned to any user who sends the same query
// that sent the query. By default, results may be returned to any user who
// sends the same query
IsPersonal bool `json:"is_personal,omitempty"` IsPersonal bool `json:"is_personal,omitempty"`
} }
@ -879,7 +780,7 @@ type (
// AnswerInlineQuery send answers to an inline query. On success, True is returned. // AnswerInlineQuery send answers to an inline query. On success, True is returned.
// //
// No more than 50 results per query are allowed. // No more than 50 results per query are allowed.
func (b *Bot) AnswerInlineQuery(p AnswerInlineQuery) (bool, error) { func (b Bot) AnswerInlineQuery(p AnswerInlineQuery) (bool, error) {
src, err := b.Do(MethodAnswerInlineQuery, p) src, err := b.Do(MethodAnswerInlineQuery, p)
if err != nil { if err != nil {
return false, err return false, err

View File

@ -1,3 +1,2 @@
// Package login contains methods for obtaining structure of the user data and // Package login contains methods for obtaining structure of the user data and its validation.
// its validation. package login // import "gitlab.com/toby3d/telegram/login"
package login

View File

@ -44,12 +44,12 @@ func NewWidget(accessToken string) *Widget {
// received by comparing the received hash parameter with the hexadecimal // received by comparing the received hash parameter with the hexadecimal
// representation of the HMAC-SHA-256 signature of the data-check-string with the // representation of the HMAC-SHA-256 signature of the data-check-string with the
// SHA256 hash of the bot's token used as a secret key. // SHA256 hash of the bot's token used as a secret key.
func (w *Widget) CheckAuthorization(u User) (bool, error) { func (w Widget) CheckAuthorization(u User) (bool, error) {
hash, err := w.GenerateHash(u) hash, err := w.GenerateHash(u)
return hash == u.Hash, err return hash == u.Hash, err
} }
func (w *Widget) GenerateHash(u User) (string, error) { func (w Widget) GenerateHash(u User) (string, error) {
a := http.AcquireArgs() a := http.AcquireArgs()
defer http.ReleaseArgs(a) defer http.ReleaseArgs(a)

View File

@ -1,12 +1,10 @@
package login package login
import ( import "time"
"time"
)
// FullName return user first name only or full name if last name is present. // FullName return user first name only or full name if last name is present.
func (u *User) FullName() string { func (u User) FullName() string {
if u == nil || u.FirstName == "" { if u.FirstName == "" {
return "" return ""
} }
@ -19,8 +17,8 @@ func (u *User) FullName() string {
} }
// AuthTime convert AuthDate field into time.Time. // AuthTime convert AuthDate field into time.Time.
func (u *User) AuthTime() time.Time { func (u User) AuthTime() time.Time {
if u == nil || u.AuthDate == 0 { if u.AuthDate == 0 {
return time.Time{} return time.Time{}
} }
@ -28,16 +26,10 @@ func (u *User) AuthTime() time.Time {
} }
// HasLastName checks what the current user has a LastName. // HasLastName checks what the current user has a LastName.
func (u *User) HasLastName() bool { func (u User) HasLastName() bool { return u.LastName != "" }
return u != nil && u.LastName != ""
}
// HasUsername checks what the current user has a username. // HasUsername checks what the current user has a username.
func (u *User) HasUsername() bool { func (u User) HasUsername() bool { return u.Username != "" }
return u != nil && u.Username != ""
}
// HasPhoto checks what the current user has a photo. // HasPhoto checks what the current user has a photo.
func (u *User) HasPhoto() bool { func (u User) HasPhoto() bool { return u.PhotoURL != "" }
return u != nil && u.PhotoURL != ""
}

View File

@ -660,7 +660,7 @@ type (
) )
// 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.
func (b *Bot) GetMe() (*User, error) { func (b Bot) GetMe() (*User, error) {
src, err := b.Do(MethodGetMe, nil) src, err := b.Do(MethodGetMe, nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -680,7 +680,7 @@ func (b *Bot) GetMe() (*User, error) {
} }
// SendMessage send text messages. On success, the sent Message is returned. // SendMessage send text messages. On success, the sent Message is returned.
func (b *Bot) SendMessage(p SendMessage) (*Message, error) { func (b Bot) SendMessage(p SendMessage) (*Message, error) {
src, err := b.Do(MethodSendMessage, p) src, err := b.Do(MethodSendMessage, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -700,7 +700,7 @@ func (b *Bot) SendMessage(p SendMessage) (*Message, error) {
} }
// ForwardMessage forward messages of any kind. On success, the sent Message is returned. // ForwardMessage forward messages of any kind. On success, the sent Message is returned.
func (b *Bot) ForwardMessage(p ForwardMessage) (*Message, error) { func (b Bot) ForwardMessage(p ForwardMessage) (*Message, error) {
src, err := b.Do(MethodForwardMessage, p) src, err := b.Do(MethodForwardMessage, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -720,7 +720,7 @@ func (b *Bot) ForwardMessage(p ForwardMessage) (*Message, error) {
} }
// SendPhoto send photos. On success, the sent Message is returned. // SendPhoto send photos. On success, the sent Message is returned.
func (b *Bot) SendPhoto(p SendPhoto) (*Message, error) { func (b Bot) SendPhoto(p SendPhoto) (*Message, error) {
params := make(map[string]string) params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10) params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
params["caption"] = p.Caption params["caption"] = p.Caption
@ -764,7 +764,7 @@ func (b *Bot) SendPhoto(p SendPhoto) (*Message, error) {
// SendAudio send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future. // SendAudio send audio files, if you want Telegram clients to display them in the music player. Your audio must be in the .MP3 or .M4A format. On success, the sent Message is returned. Bots can currently send audio files of up to 50 MB in size, this limit may be changed in the future.
// //
// For sending voice messages, use the sendVoice method instead. // For sending voice messages, use the sendVoice method instead.
func (b *Bot) SendAudio(p SendAudio) (*Message, error) { func (b Bot) SendAudio(p SendAudio) (*Message, error) {
params := make(map[string]string) params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10) params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
params["caption"] = p.Caption params["caption"] = p.Caption
@ -816,7 +816,7 @@ func (b *Bot) SendAudio(p SendAudio) (*Message, error) {
} }
// SendDocument send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future. // SendDocument send general files. On success, the sent Message is returned. Bots can currently send files of any type of up to 50 MB in size, this limit may be changed in the future.
func (b *Bot) SendDocument(p SendDocument) (*Message, error) { func (b Bot) SendDocument(p SendDocument) (*Message, error) {
params := make(map[string]string) params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10) params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
params["caption"] = p.Caption params["caption"] = p.Caption
@ -857,7 +857,7 @@ func (b *Bot) SendDocument(p SendDocument) (*Message, error) {
} }
// SendVideo send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. // SendVideo send video files, Telegram clients support mp4 videos (other formats may be sent as Document). On success, the sent Message is returned. Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future.
func (b *Bot) SendVideo(p SendVideo) (*Message, error) { func (b Bot) SendVideo(p SendVideo) (*Message, error) {
params := make(map[string]string) params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10) params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
params["duration"] = strconv.Itoa(p.Duration) params["duration"] = strconv.Itoa(p.Duration)
@ -910,7 +910,7 @@ func (b *Bot) SendVideo(p SendVideo) (*Message, error) {
} }
// SendAnimation send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future. // SendAnimation send animation files (GIF or H.264/MPEG-4 AVC video without sound). On success, the sent Message is returned. Bots can currently send animation files of up to 50 MB in size, this limit may be changed in the future.
func (b *Bot) SendAnimation(p SendAnimation) (*Message, error) { func (b Bot) SendAnimation(p SendAnimation) (*Message, error) {
params := make(map[string]string) params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10) params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
params["duration"] = strconv.Itoa(p.Duration) params["duration"] = strconv.Itoa(p.Duration)
@ -962,7 +962,7 @@ func (b *Bot) SendAnimation(p SendAnimation) (*Message, error) {
} }
// SendVoice send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future. // SendVoice send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS (other formats may be sent as Audio or Document). On success, the sent Message is returned. Bots can currently send voice messages of up to 50 MB in size, this limit may be changed in the future.
func (b *Bot) SendVoice(p SendVoice) (*Message, error) { func (b Bot) SendVoice(p SendVoice) (*Message, error) {
params := make(map[string]string) params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10) params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
params["duration"] = strconv.Itoa(p.Duration) params["duration"] = strconv.Itoa(p.Duration)
@ -1004,7 +1004,7 @@ func (b *Bot) SendVoice(p SendVoice) (*Message, error) {
} }
// SendVideoNote send video messages. On success, the sent Message is returned. // SendVideoNote send video messages. On success, the sent Message is returned.
func (b *Bot) SendVideoNote(p SendVideoNote) (*Message, error) { func (b Bot) SendVideoNote(p SendVideoNote) (*Message, error) {
params := make(map[string]string) params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10) params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
params["duration"] = strconv.Itoa(p.Duration) params["duration"] = strconv.Itoa(p.Duration)
@ -1053,7 +1053,7 @@ func (b *Bot) SendVideoNote(p SendVideoNote) (*Message, error) {
} }
// SendMediaGroup send a group of photos or videos as an album. On success, an array of the sent Messages is returned. // SendMediaGroup send a group of photos or videos as an album. On success, an array of the sent Messages is returned.
func (b *Bot) SendMediaGroup(p SendMediaGroup) ([]*Message, error) { func (b Bot) SendMediaGroup(p SendMediaGroup) ([]*Message, error) {
media := make([]string, len(p.Media), 10) media := make([]string, len(p.Media), 10)
files := make([]*InputFile, 0) files := make([]*InputFile, 0)
@ -1097,7 +1097,7 @@ func (b *Bot) SendMediaGroup(p SendMediaGroup) ([]*Message, error) {
} }
// SendLocation send point on the map. On success, the sent Message is returned. // SendLocation send point on the map. On success, the sent Message is returned.
func (b *Bot) SendLocation(p SendLocation) (*Message, error) { func (b Bot) SendLocation(p SendLocation) (*Message, error) {
src, err := b.Do(MethodSendLocation, p) src, err := b.Do(MethodSendLocation, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1117,7 +1117,7 @@ func (b *Bot) SendLocation(p SendLocation) (*Message, error) {
} }
// EditMessageLiveLocation edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. // EditMessageLiveLocation edit live location messages. A location can be edited until its live_period expires or editing is explicitly disabled by a call to stopMessageLiveLocation. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
func (b *Bot) EditMessageLiveLocation(p *EditMessageLiveLocation) (*Message, bool, error) { func (b Bot) EditMessageLiveLocation(p EditMessageLiveLocation) (*Message, bool, error) {
src, err := b.Do(MethodEditMessageLiveLocation, p) src, err := b.Do(MethodEditMessageLiveLocation, p)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
@ -1137,7 +1137,7 @@ func (b *Bot) EditMessageLiveLocation(p *EditMessageLiveLocation) (*Message, boo
} }
// StopMessageLiveLocation stop updating a live location message before live_period expires. On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned. // StopMessageLiveLocation stop updating a live location message before live_period expires. On success, if the message was sent by the bot, the sent Message is returned, otherwise True is returned.
func (b *Bot) StopMessageLiveLocation(p StopMessageLiveLocation) (*Message, bool, error) { func (b Bot) StopMessageLiveLocation(p StopMessageLiveLocation) (*Message, bool, error) {
src, err := b.Do(MethodStopMessageLiveLocation, p) src, err := b.Do(MethodStopMessageLiveLocation, p)
if err != nil { if err != nil {
return nil, false, err return nil, false, err
@ -1157,7 +1157,7 @@ func (b *Bot) StopMessageLiveLocation(p StopMessageLiveLocation) (*Message, bool
} }
// SendVenue send information about a venue. On success, the sent Message is returned. // SendVenue send information about a venue. On success, the sent Message is returned.
func (b *Bot) SendVenue(p SendVenue) (*Message, error) { func (b Bot) SendVenue(p SendVenue) (*Message, error) {
src, err := b.Do(MethodSendVenue, p) src, err := b.Do(MethodSendVenue, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1177,7 +1177,7 @@ func (b *Bot) SendVenue(p SendVenue) (*Message, error) {
} }
// SendContact send phone contacts. On success, the sent Message is returned. // SendContact send phone contacts. On success, the sent Message is returned.
func (b *Bot) SendContact(p SendContact) (*Message, error) { func (b Bot) SendContact(p SendContact) (*Message, error) {
src, err := b.Do(MethodSendContact, p) src, err := b.Do(MethodSendContact, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1197,7 +1197,7 @@ func (b *Bot) SendContact(p SendContact) (*Message, error) {
} }
// SendPoll send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is returned. // SendPoll send a native poll. A native poll can't be sent to a private chat. On success, the sent Message is returned.
func (b *Bot) SendPoll(p SendPoll) (*Message, error) { func (b Bot) SendPoll(p SendPoll) (*Message, error) {
src, err := b.Do(MethodSendPoll, p) src, err := b.Do(MethodSendPoll, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1219,10 +1219,8 @@ func (b *Bot) SendPoll(p SendPoll) (*Message, error) {
// 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.
func (b *Bot) SendChatAction(chatID int64, action string) (bool, error) { func (b Bot) SendChatAction(cid int64, action string) (bool, error) {
src, err := b.Do(MethodSendChatAction, SendChatAction{ src, err := b.Do(MethodSendChatAction, SendChatAction{ChatID: cid, Action: action})
ChatID: chatID, Action: action,
})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -1241,7 +1239,7 @@ func (b *Bot) SendChatAction(chatID int64, action string) (bool, error) {
} }
// GetUserProfilePhotos get a list of profile pictures for a user. Returns a UserProfilePhotos object. // GetUserProfilePhotos get a list of profile pictures for a user. Returns a UserProfilePhotos object.
func (b *Bot) GetUserProfilePhotos(p GetUserProfilePhotos) (*UserProfilePhotos, error) { func (b Bot) GetUserProfilePhotos(p GetUserProfilePhotos) (*UserProfilePhotos, error) {
src, err := b.Do(MethodGetUserProfilePhotos, p) src, err := b.Do(MethodGetUserProfilePhotos, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -1263,8 +1261,8 @@ func (b *Bot) GetUserProfilePhotos(p GetUserProfilePhotos) (*UserProfilePhotos,
// GetFile get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again. // GetFile get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to 20MB in size. On success, a File object is returned. The file can then be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>, where <file_path> is taken from the response. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile again.
// //
// Note: This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received. // Note: This function may not preserve the original file name and MIME type. You should save the file's MIME type and name (if available) when the File object is received.
func (b *Bot) GetFile(fileID string) (*File, error) { func (b Bot) GetFile(fid string) (*File, error) {
src, err := b.Do(MethodGetFile, GetFile{FileID: fileID}) src, err := b.Do(MethodGetFile, GetFile{FileID: fid})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1285,7 +1283,7 @@ func (b *Bot) GetFile(fileID string) (*File, error) {
// KickChatMember kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. // KickChatMember kick a user from a group, a supergroup or a channel. In the case of supergroups and channels, the user will not be able to return to the group on their own using invite links, etc., unless unbanned first. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
// //
// Note: In regular groups (non-supergroups), this method will only work if the 'All Members Are Admins' setting is off in the target group. Otherwise members may only be removed by the group's creator or by the member that added them. // Note: In regular groups (non-supergroups), this method will only work if the 'All Members Are Admins' setting is off in the target group. Otherwise members may only be removed by the group's creator or by the member that added them.
func (b *Bot) KickChatMember(p KickChatMember) (bool, error) { func (b Bot) KickChatMember(p KickChatMember) (bool, error) {
src, err := b.Do(MethodKickChatMember, p) src, err := b.Do(MethodKickChatMember, p)
if err != nil { if err != nil {
return false, err return false, err
@ -1305,10 +1303,8 @@ func (b *Bot) KickChatMember(p KickChatMember) (bool, error) {
} }
// UnbanChatMember unban a previously kicked user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. Returns True on success. // UnbanChatMember unban a previously kicked user in a supergroup or channel. The user will not return to the group or channel automatically, but will be able to join via link, etc. The bot must be an administrator for this to work. Returns True on success.
func (b *Bot) UnbanChatMember(chatID int64, userID int) (bool, error) { func (b Bot) UnbanChatMember(cid int64, uid int) (bool, error) {
src, err := b.Do(MethodUnbanChatMember, UnbanChatMember{ src, err := b.Do(MethodUnbanChatMember, UnbanChatMember{ChatID: cid, UserID: uid})
ChatID: chatID, UserID: userID,
})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -1327,7 +1323,7 @@ func (b *Bot) UnbanChatMember(chatID int64, userID int) (bool, error) {
} }
// restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all permissions to lift restrictions from a user. Returns True on success. // restrict a user in a supergroup. The bot must be an administrator in the supergroup for this to work and must have the appropriate admin rights. Pass True for all permissions to lift restrictions from a user. Returns True on success.
func (b *Bot) RestrictChatMember(p RestrictChatMember) (bool, error) { func (b Bot) RestrictChatMember(p RestrictChatMember) (bool, error) {
src, err := b.Do(MethodRestrictChatMember, p) src, err := b.Do(MethodRestrictChatMember, p)
if err != nil { if err != nil {
return false, err return false, err
@ -1347,7 +1343,7 @@ func (b *Bot) RestrictChatMember(p RestrictChatMember) (bool, error) {
} }
// PromoteChatMember promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean to demote a user. Returns True on success. // PromoteChatMember promote or demote a user in a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Pass False for all boolean to demote a user. Returns True on success.
func (b *Bot) PromoteChatMember(p PromoteChatMember) (bool, error) { func (b Bot) PromoteChatMember(p PromoteChatMember) (bool, error) {
src, err := b.Do(MethodPromoteChatMember, p) src, err := b.Do(MethodPromoteChatMember, p)
if err != nil { if err != nil {
return false, err return false, err
@ -1367,7 +1363,7 @@ func (b *Bot) PromoteChatMember(p PromoteChatMember) (bool, error) {
} }
// SetChatAdministratorCustomTitle method to set a custom title for an administrator in a supergroup promoted by the b. Returns True on success. // SetChatAdministratorCustomTitle method to set a custom title for an administrator in a supergroup promoted by the b. Returns True on success.
func (b *Bot) SetChatAdministratorCustomTitle(p SetChatAdministratorCustomTitle) (bool, error) { func (b Bot) SetChatAdministratorCustomTitle(p SetChatAdministratorCustomTitle) (bool, error) {
src, err := b.Do(MethodSetChatAdministratorCustomTitle, p) src, err := b.Do(MethodSetChatAdministratorCustomTitle, p)
if err != nil { if err != nil {
return false, err return false, err
@ -1387,7 +1383,7 @@ func (b *Bot) SetChatAdministratorCustomTitle(p SetChatAdministratorCustomTitle)
} }
// SetChatPermissions set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success. // SetChatPermissions set default chat permissions for all members. The bot must be an administrator in the group or a supergroup for this to work and must have the can_restrict_members admin rights. Returns True on success.
func (b *Bot) SetChatPermissions(p SetChatPermissions) (bool, error) { func (b Bot) SetChatPermissions(p SetChatPermissions) (bool, error) {
src, err := b.Do(MethodSetChatPermissions, p) src, err := b.Do(MethodSetChatPermissions, p)
if err != nil { if err != nil {
return false, err return false, err
@ -1407,8 +1403,8 @@ func (b *Bot) SetChatPermissions(p SetChatPermissions) (bool, error) {
} }
// ExportChatInviteLink export an invite link to a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns exported invite link as String on success. // ExportChatInviteLink export an invite link to a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns exported invite link as String on success.
func (b *Bot) ExportChatInviteLink(chatID int64) (string, error) { func (b Bot) ExportChatInviteLink(cid int64) (string, error) {
src, err := b.Do(MethodExportChatInviteLink, ExportChatInviteLink{ChatID: chatID}) src, err := b.Do(MethodExportChatInviteLink, ExportChatInviteLink{ChatID: cid})
if err != nil { if err != nil {
return "", err return "", err
} }
@ -1427,18 +1423,18 @@ func (b *Bot) ExportChatInviteLink(chatID int64) (string, error) {
} }
// SetChatPhoto set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. // SetChatPhoto set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
func (b *Bot) SetChatPhoto(chatID int64, chatPhoto *InputFile) (bool, error) { func (b Bot) SetChatPhoto(cid int64, photo *InputFile) (bool, error) {
params := make(map[string]string) params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(chatID, 10) params["chat_id"] = strconv.FormatInt(cid, 10)
var err error var err error
if params["photo"], err = b.marshler.MarshalToString(chatPhoto); err != nil { if params["photo"], err = b.marshler.MarshalToString(photo); err != nil {
return false, err return false, err
} }
files := make([]*InputFile, 0) files := make([]*InputFile, 0)
if chatPhoto.IsAttachment() { if photo.IsAttachment() {
files = append(files, chatPhoto) files = append(files, photo)
} }
src, err := b.Upload(MethodSetChatPhoto, params, files...) src, err := b.Upload(MethodSetChatPhoto, params, files...)
@ -1460,8 +1456,8 @@ func (b *Bot) SetChatPhoto(chatID int64, chatPhoto *InputFile) (bool, error) {
} }
// DeleteChatPhoto delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. // DeleteChatPhoto delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
func (b *Bot) DeleteChatPhoto(chatID int64) (bool, error) { func (b Bot) DeleteChatPhoto(cid int64) (bool, error) {
src, err := b.Do(MethodDeleteChatPhoto, DeleteChatPhoto{ChatID: chatID}) src, err := b.Do(MethodDeleteChatPhoto, DeleteChatPhoto{ChatID: cid})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -1480,10 +1476,8 @@ func (b *Bot) DeleteChatPhoto(chatID int64) (bool, error) {
} }
// SetChatTitle change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. // SetChatTitle change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
func (b *Bot) SetChatTitle(chatID int64, title string) (bool, error) { func (b Bot) SetChatTitle(cid int64, title string) (bool, error) {
src, err := b.Do(MethodSetChatTitle, SetChatTitle{ src, err := b.Do(MethodSetChatTitle, SetChatTitle{ChatID: cid, Title: title})
ChatID: chatID, Title: title,
})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -1502,10 +1496,8 @@ func (b *Bot) SetChatTitle(chatID int64, title string) (bool, error) {
} }
// SetChatDescription change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. // SetChatDescription change the description of a group, a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success.
func (b *Bot) SetChatDescription(chatID int64, description string) (bool, error) { func (b Bot) SetChatDescription(cid int64, txt string) (bool, error) {
src, err := b.Do(MethodSetChatDescription, SetChatDescription{ src, err := b.Do(MethodSetChatDescription, SetChatDescription{ChatID: cid, Description: txt})
ChatID: chatID, Description: description,
})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -1524,7 +1516,7 @@ func (b *Bot) SetChatDescription(chatID int64, description string) (bool, error)
} }
// PinChatMessage pin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the can_pin_messages admin right in the supergroup or can_edit_messages admin right in the channel. Returns True on success. // PinChatMessage pin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the can_pin_messages admin right in the supergroup or can_edit_messages admin right in the channel. Returns True on success.
func (b *Bot) PinChatMessage(p *PinChatMessage) (bool, error) { func (b Bot) PinChatMessage(p PinChatMessage) (bool, error) {
src, err := b.Do(MethodPinChatMessage, p) src, err := b.Do(MethodPinChatMessage, p)
if err != nil { if err != nil {
return false, err return false, err
@ -1544,8 +1536,8 @@ func (b *Bot) PinChatMessage(p *PinChatMessage) (bool, error) {
} }
// UnpinChatMessage unpin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the can_pin_messages admin right in the supergroup or can_edit_messages admin right in the channel. Returns True on success. // UnpinChatMessage unpin a message in a group, a supergroup, or a channel. The bot must be an administrator in the chat for this to work and must have the can_pin_messages admin right in the supergroup or can_edit_messages admin right in the channel. Returns True on success.
func (b *Bot) UnpinChatMessage(chatID int64) (bool, error) { func (b Bot) UnpinChatMessage(cid int64) (bool, error) {
src, err := b.Do(MethodUnpinChatMessage, UnpinChatMessage{ChatID: chatID}) src, err := b.Do(MethodUnpinChatMessage, UnpinChatMessage{ChatID: cid})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -1564,8 +1556,8 @@ func (b *Bot) UnpinChatMessage(chatID int64) (bool, error) {
} }
// LeaveChat leave a group, supergroup or channel. Returns True on success. // LeaveChat leave a group, supergroup or channel. Returns True on success.
func (b *Bot) LeaveChat(chatID int64) (bool, error) { func (b Bot) LeaveChat(cid int64) (bool, error) {
src, err := b.Do(MethodLeaveChat, LeaveChat{ChatID: chatID}) src, err := b.Do(MethodLeaveChat, LeaveChat{ChatID: cid})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -1584,8 +1576,8 @@ func (b *Bot) LeaveChat(chatID int64) (bool, error) {
} }
// GetChat get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success. // GetChat get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). Returns a Chat object on success.
func (b *Bot) GetChat(chatID int64) (*Chat, error) { func (b Bot) GetChat(cid int64) (*Chat, error) {
src, err := b.Do(MethodGetChat, GetChat{ChatID: chatID}) src, err := b.Do(MethodGetChat, GetChat{ChatID: cid})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1604,8 +1596,8 @@ func (b *Bot) GetChat(chatID int64) (*Chat, error) {
} }
// GetChatAdministrators get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned. // GetChatAdministrators get a list of administrators in a chat. On success, returns an Array of ChatMember objects that contains information about all chat administrators except other bots. If the chat is a group or a supergroup and no administrators were appointed, only the creator will be returned.
func (b *Bot) GetChatAdministrators(chatID int64) ([]*ChatMember, error) { func (b Bot) GetChatAdministrators(cid int64) ([]*ChatMember, error) {
src, err := b.Do(MethodGetChatAdministrators, GetChatAdministrators{ChatID: chatID}) src, err := b.Do(MethodGetChatAdministrators, GetChatAdministrators{ChatID: cid})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1624,8 +1616,8 @@ func (b *Bot) GetChatAdministrators(chatID int64) ([]*ChatMember, error) {
} }
// GetChatMembersCount get the number of members in a chat. Returns Int on success. // GetChatMembersCount get the number of members in a chat. Returns Int on success.
func (b *Bot) GetChatMembersCount(chatID int64) (int, error) { func (b Bot) GetChatMembersCount(cid int64) (int, error) {
src, err := b.Do(MethodGetChatMembersCount, GetChatMembersCount{ChatID: chatID}) src, err := b.Do(MethodGetChatMembersCount, GetChatMembersCount{ChatID: cid})
if err != nil { if err != nil {
return 0, err return 0, err
} }
@ -1644,10 +1636,8 @@ func (b *Bot) GetChatMembersCount(chatID int64) (int, error) {
} }
// GetChatMember get information about a member of a chat. Returns a ChatMember object on success. // GetChatMember get information about a member of a chat. Returns a ChatMember object on success.
func (b *Bot) GetChatMember(chatID int64, userID int) (*ChatMember, error) { func (b Bot) GetChatMember(cid int64, uid int) (*ChatMember, error) {
src, err := b.Do(MethodGetChatMember, GetChatMember{ src, err := b.Do(MethodGetChatMember, GetChatMember{ChatID: cid, UserID: uid})
ChatID: chatID, UserID: userID,
})
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -1666,10 +1656,8 @@ func (b *Bot) GetChatMember(chatID int64, userID int) (*ChatMember, error) {
} }
// SetChatStickerSet set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success. // SetChatStickerSet set a new group sticker set for a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
func (b *Bot) SetChatStickerSet(chatID int64, stickerSetName string) (bool, error) { func (b Bot) SetChatStickerSet(cid int64, name string) (bool, error) {
src, err := b.Do(MethodSetChatStickerSet, SetChatStickerSet{ src, err := b.Do(MethodSetChatStickerSet, SetChatStickerSet{ChatID: cid, StickerSetName: name})
ChatID: chatID, StickerSetName: stickerSetName,
})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -1688,8 +1676,8 @@ func (b *Bot) SetChatStickerSet(chatID int64, stickerSetName string) (bool, erro
} }
// DeleteChatStickerSet delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success. // DeleteChatStickerSet delete a group sticker set from a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Use the field can_set_sticker_set optionally returned in getChat requests to check if the bot can use this method. Returns True on success.
func (b *Bot) DeleteChatStickerSet(chatID int64) (bool, error) { func (b Bot) DeleteChatStickerSet(cid int64) (bool, error) {
src, err := b.Do(MethodDeleteChatStickerSet, DeleteChatStickerSet{ChatID: chatID}) src, err := b.Do(MethodDeleteChatStickerSet, DeleteChatStickerSet{ChatID: cid})
if err != nil { if err != nil {
return false, err return false, err
} }
@ -1708,7 +1696,7 @@ func (b *Bot) DeleteChatStickerSet(chatID int64) (bool, error) {
} }
// AnswerCallbackQuery send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned. // AnswerCallbackQuery send answers to callback queries sent from inline keyboards. The answer will be displayed to the user as a notification at the top of the chat screen or as an alert. On success, True is returned.
func (b *Bot) AnswerCallbackQuery(p AnswerCallbackQuery) (bool, error) { func (b Bot) AnswerCallbackQuery(p AnswerCallbackQuery) (bool, error) {
src, err := b.Do(MethodAnswerCallbackQuery, p) src, err := b.Do(MethodAnswerCallbackQuery, p)
if err != nil { if err != nil {
return false, err return false, err

View File

@ -14,20 +14,16 @@ import "errors"
*/ */
type ( type (
// PassportData contains information about Telegram Passport data shared with // PassportData contains information about Telegram Passport data shared with the bot by the user.
// the bot by the user.
PassportData struct { PassportData struct {
// Array with information about documents and other Telegram Passport // Array with information about documents and other Telegram Passport elements that was shared with the bot
// elements that was shared with the bot
Data []*EncryptedPassportElement `json:"data"` Data []*EncryptedPassportElement `json:"data"`
// Encrypted credentials required to decrypt the data // Encrypted credentials required to decrypt the data
Credentials *EncryptedCredentials `json:"credentials"` Credentials *EncryptedCredentials `json:"credentials"`
} }
// PassportFile represents a file uploaded to Telegram Passport. Currently all // PassportFile represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB.
// Telegram Passport files are in JPEG format when decrypted and don't exceed
// 10MB.
PassportFile struct { PassportFile struct {
// Identifier for this file, which can be used to download or reuse the file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
@ -42,17 +38,12 @@ type (
FileDate int `json:"file_date"` FileDate int `json:"file_date"`
} }
// EncryptedPassportElement contains information about documents or other // EncryptedPassportElement contains information about documents or other Telegram Passport elements shared with the bot by the user.
// Telegram Passport elements shared with the bot by the user.
EncryptedPassportElement struct { EncryptedPassportElement struct {
// Element type. // Element type.
Type string `json:"type"` Type string `json:"type"`
// Base64-encoded encrypted Telegram Passport element data provided by // Base64-encoded encrypted Telegram Passport element data provided by the user, available for "personal_details", "passport", "driver_license", "identity_card", "identity_passport" and "address" types. Can be decrypted and verified using the accompanying EncryptedCredentials.
// the user, available for "personal_details", "passport",
// "driver_license", "identity_card", "identity_passport" and "address"
// types. Can be decrypted and verified using the accompanying
// EncryptedCredentials.
Data string `json:"data,omitempty"` Data string `json:"data,omitempty"`
// User's verified phone number, available only for "phone_number" type // User's verified phone number, available only for "phone_number" type
@ -61,78 +52,50 @@ type (
// User's verified email address, available only for "email" type // User's verified email address, available only for "email" type
Email string `json:"email,omitempty"` Email string `json:"email,omitempty"`
// Array of encrypted files with documents provided by the user, // Array of encrypted files with documents provided by the user, available for "utility_bill", "bank_statement", "rental_agreement", "passport_registration" and "temporary_registration" types. Files can be decrypted and verified using the accompanying EncryptedCredentials.
// available for "utility_bill", "bank_statement", "rental_agreement",
// "passport_registration" and "temporary_registration" types. Files can
// be decrypted and verified using the accompanying EncryptedCredentials.
Files []*PassportFile `json:"files,omitempty"` Files []*PassportFile `json:"files,omitempty"`
// Encrypted file with the front side of the document, provided by the // Encrypted file with the front side of the document, provided by the user. Available for "passport", "driver_license", "identity_card" and "internal_passport". The file can be decrypted and verified using the accompanying EncryptedCredentials.
// user. Available for "passport", "driver_license", "identity_card" and
// "internal_passport". The file can be decrypted and verified using the
// accompanying EncryptedCredentials.
FrontSide *PassportFile `json:"front_side,omitempty"` FrontSide *PassportFile `json:"front_side,omitempty"`
// Encrypted file with the reverse side of the document, provided by the // Encrypted file with the reverse side of the document, provided by the user. Available for "driver_license" and "identity_card". The file can be decrypted and verified using the accompanying EncryptedCredentials.
// user. Available for "driver_license" and "identity_card". The file can
// be decrypted and verified using the accompanying EncryptedCredentials.
ReverseSide *PassportFile `json:"reverse_side,omitempty"` ReverseSide *PassportFile `json:"reverse_side,omitempty"`
// Encrypted file with the selfie of the user holding a document, // Encrypted file with the selfie of the user holding a document, provided by the user; available for "passport", "driver_license", "identity_card" and "internal_passport". The file can be decrypted and verified using the accompanying EncryptedCredentials.
// provided by the user; available for "passport", "driver_license",
// "identity_card" and "internal_passport". The file can be decrypted
// and verified using the accompanying EncryptedCredentials.
Selfie *PassportFile `json:"selfie,omitempty"` Selfie *PassportFile `json:"selfie,omitempty"`
// Array of encrypted files with translated versions of documents // Array of encrypted files with translated versions of documents provided by the user. Available if requested for “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration” and “temporary_registration” types. Files can be decrypted and verified using the accompanying EncryptedCredentials.
// provided by the user. Available if requested for “passport”,
// “driver_license”, “identity_card”, “internal_passport”,
// “utility_bill”, “bank_statement”, “rental_agreement”,
// “passport_registration” and “temporary_registration” types.
// Files can be decrypted and verified using the accompanying
// EncryptedCredentials.
Translation []*PassportFile `json:"translation,omitempty"` Translation []*PassportFile `json:"translation,omitempty"`
// Base64-encoded element hash for using in PassportElementErrorUnspecified // Base64-encoded element hash for using in PassportElementErrorUnspecified
Hash string `json:"hash"` Hash string `json:"hash"`
} }
// EncryptedCredentials contains data required for decrypting and // EncryptedCredentials contains data required for decrypting and authenticating EncryptedPassportElement. See the Telegram Passport Documentation for a complete description of the data decryption and authentication processes.
// authenticating EncryptedPassportElement. See the Telegram Passport
// Documentation for a complete description of the data decryption and
// authentication processes.
EncryptedCredentials struct { EncryptedCredentials struct {
// Base64-encoded encrypted JSON-serialized data with unique user's // Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required for EncryptedPassportElement decryption and authentication
// payload, data hashes and secrets required for EncryptedPassportElement
// decryption and authentication
Data string `json:"data"` Data string `json:"data"`
// Base64-encoded data hash for data authentication // Base64-encoded data hash for data authentication
Hash string `json:"hash"` Hash string `json:"hash"`
// Base64-encoded secret, encrypted with the bot's public RSA key, // Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption
// required for data decryption
Secret string `json:"secret"` Secret string `json:"secret"`
} }
// PassportElementError represents an error in the Telegram Passport element // PassportElementError represents an error in the Telegram Passport element which was submitted that should be resolved by the user.
// which was submitted that should be resolved by the user.
PassportElementError interface { PassportElementError interface {
PassportElementErrorMessage() string PassportElementErrorMessage() string
PassportElementErrorSource() string PassportElementErrorSource() string
PassportElementErrorType() string PassportElementErrorType() string
} }
// PassportElementErrorDataField represents an issue in one of the data // PassportElementErrorDataField represents an issue in one of the data fields that was provided by the user. The error is considered resolved when the field's value changes.
// fields that was provided by the user. The error is considered resolved
// when the field's value changes.
PassportElementErrorDataField struct { PassportElementErrorDataField struct {
// Error source, must be data // Error source, must be data
Source string `json:"source"` Source string `json:"source"`
// The section of the user's Telegram Passport which has the error, one // The section of the user's Telegram Passport which has the error, one of "personal_details", "passport", "driver_license", "identity_card", "internal_passport", "address"
// of "personal_details", "passport", "driver_license", "identity_card",
// "internal_passport", "address"
Type string `json:"type"` Type string `json:"type"`
// Name of the data field which has the error // Name of the data field which has the error
@ -145,15 +108,12 @@ type (
Message string `json:"message"` Message string `json:"message"`
} }
// PassportElementErrorFrontSide represents an issue with the front side of // PassportElementErrorFrontSide represents an issue with the front side of a document. The error is considered resolved when the file with the front side of the document changes.
// a document. The error is considered resolved when the file with the front
// side of the document changes.
PassportElementErrorFrontSide struct { PassportElementErrorFrontSide struct {
// Error source, must be front_side // Error source, must be front_side
Source string `json:"source"` Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one // The section of the user's Telegram Passport which has the issue, one of "passport", "driver_license", "identity_card", "internal_passport"
// of "passport", "driver_license", "identity_card", "internal_passport"
Type string `json:"type"` Type string `json:"type"`
// Base64-encoded hash of the file with the front side of the document // Base64-encoded hash of the file with the front side of the document
@ -163,15 +123,12 @@ type (
Message string `json:"message"` Message string `json:"message"`
} }
// PassportElementErrorReverseSide represents an issue with the reverse side // PassportElementErrorReverseSide represents an issue with the reverse side of a document. The error is considered resolved when the file with reverse side of the document changes.
// of a document. The error is considered resolved when the file with reverse
// side of the document changes.
PassportElementErrorReverseSide struct { PassportElementErrorReverseSide struct {
// Error source, must be reverse_side // Error source, must be reverse_side
Source string `json:"source"` Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one // The section of the user's Telegram Passport which has the issue, one of "driver_license", "identity_card"
// of "driver_license", "identity_card"
Type string `json:"type"` Type string `json:"type"`
// Base64-encoded hash of the file with the reverse side of the document // Base64-encoded hash of the file with the reverse side of the document
@ -181,15 +138,12 @@ type (
Message string `json:"message"` Message string `json:"message"`
} }
// PassportElementErrorSelfie represents an issue with the selfie with a // PassportElementErrorSelfie represents an issue with the selfie with a document. The error is considered resolved when the file with the selfie changes.
// document. The error is considered resolved when the file with the selfie
// changes.
PassportElementErrorSelfie struct { PassportElementErrorSelfie struct {
// Error source, must be selfie // Error source, must be selfie
Source string `json:"source"` Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one // The section of the user's Telegram Passport which has the issue, one of "passport", "driver_license", "identity_card", "internal_passport"
// of "passport", "driver_license", "identity_card", "internal_passport"
Type string `json:"type"` Type string `json:"type"`
// Base64-encoded hash of the file with the selfie // Base64-encoded hash of the file with the selfie
@ -199,15 +153,12 @@ type (
Message string `json:"message"` Message string `json:"message"`
} }
// PassportElementErrorFile represents an issue with a document scan. The // PassportElementErrorFile represents an issue with a document scan. The error is considered resolved when the file with the document scan changes.
// error is considered resolved when the file with the document scan changes.
PassportElementErrorFile struct { PassportElementErrorFile struct {
// Error source, must be file // Error source, must be file
Source string `json:"source"` Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one // The section of the user's Telegram Passport which has the issue, one of "utility_bill", "bank_statement", "rental_agreement", "passport_registration", "temporary_registration"
// of "utility_bill", "bank_statement", "rental_agreement",
// "passport_registration", "temporary_registration"
Type string `json:"type"` Type string `json:"type"`
// Base64-encoded file hash // Base64-encoded file hash
@ -217,16 +168,12 @@ type (
Message string `json:"message"` Message string `json:"message"`
} }
// PassportElementErrorFiles represents an issue with a list of scans. The // PassportElementErrorFiles represents an issue with a list of scans. The error is considered resolved when the list of files containing the scans changes.
// error is considered resolved when the list of files containing the scans
// changes.
PassportElementErrorFiles struct { PassportElementErrorFiles struct {
// Error source, must be files // Error source, must be files
Source string `json:"source"` Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one // The section of the user's Telegram Passport which has the issue, one of "utility_bill", "bank_statement", "rental_agreement", "passport_registration", "temporary_registration"
// of "utility_bill", "bank_statement", "rental_agreement",
// "passport_registration", "temporary_registration"
Type string `json:"type"` Type string `json:"type"`
// List of base64-encoded file hashes // List of base64-encoded file hashes
@ -236,17 +183,12 @@ type (
Message string `json:"message"` Message string `json:"message"`
} }
// PassportElementErrorTranslationFile represents an issue with one of the // PassportElementErrorTranslationFile represents an issue with one of the files that constitute the translation of a document. The error is considered resolved when the file changes.
// files that constitute the translation of a document. The error is
// considered resolved when the file changes.
PassportElementErrorTranslationFile struct { PassportElementErrorTranslationFile struct {
// Error source, must be translation_file // Error source, must be translation_file
Source string `json:"source"` Source string `json:"source"`
// Type of element of the user's Telegram Passport which has the issue, // Type of element of the user's Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”
// one of “passport”, “driver_license”, “identity_card”,
// “internal_passport”, “utility_bill”, “bank_statement”,
// “rental_agreement”, “passport_registration”, “temporary_registration”
Type string `json:"type"` Type string `json:"type"`
// Base64-encoded file hash // Base64-encoded file hash
@ -256,17 +198,12 @@ type (
Message string `json:"message"` Message string `json:"message"`
} }
// PassportElementErrorTranslationFiles represents an issue with the translated // PassportElementErrorTranslationFiles represents an issue with the translated version of a document. The error is considered resolved when a file with the document translation change.
// version of a document. The error is considered resolved when a file with the
// document translation change.
PassportElementErrorTranslationFiles struct { PassportElementErrorTranslationFiles struct {
// Error source, must be translation_files // Error source, must be translation_files
Source string `json:"source"` Source string `json:"source"`
// Type of element of the user's Telegram Passport which has the issue, // Type of element of the user's Telegram Passport which has the issue, one of “passport”, “driver_license”, “identity_card”, “internal_passport”, “utility_bill”, “bank_statement”, “rental_agreement”, “passport_registration”, “temporary_registration”
// one of “passport”, “driver_license”, “identity_card”,
// “internal_passport”, “utility_bill”, “bank_statement”,
// “rental_agreement”, “passport_registration”, “temporary_registration”
Type string `json:"type"` Type string `json:"type"`
// List of base64-encoded file hashes // List of base64-encoded file hashes
@ -276,8 +213,7 @@ type (
Message string `json:"message"` Message string `json:"message"`
} }
// PassportElementErrorUnspecified represents an issue in an unspecified place. // PassportElementErrorUnspecified represents an issue in an unspecified place. The error is considered resolved when new data is added.
// The error is considered resolved when new data is added.
PassportElementErrorUnspecified struct { PassportElementErrorUnspecified struct {
// Error source, must be unspecified // Error source, must be unspecified
Source string `json:"source"` Source string `json:"source"`
@ -302,14 +238,10 @@ type (
// AuthParameters represent a Telegram Passport auth parameters for SDK. // AuthParameters represent a Telegram Passport auth parameters for SDK.
Auth struct { Auth struct {
// Unique identifier for the b. You can get it from bot token. // Unique identifier for the b. You can get it from bot token. For example, for the bot token 1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy, the bot id is 1234567.
// For example, for the bot token
// 1234567:4TT8bAc8GHUspu3ERYn-KGcvsvGB9u_n4ddy, the bot id is
// 1234567.
BotID int `json:"bot_id"` BotID int `json:"bot_id"`
// A JSON-serialized object describing the data you want to // A JSON-serialized object describing the data you want to request
// request
Scope *PassportScope `json:"scope"` Scope *PassportScope `json:"scope"`
// Public key of the bot // Public key of the bot
@ -317,19 +249,13 @@ type (
// Bot-specified nonce. // Bot-specified nonce.
// //
// Important: For security purposes it should be a // Important: For security purposes it should be a cryptographically secure unique identifier of the request. In particular, it should be long enough and it should be generated using a cryptographically secure pseudorandom number generator. You should never accept credentials with the same nonce twice.
// cryptographically secure unique identifier of the request. In
// particular, it should be long enough and it should be
// generated using a cryptographically secure pseudorandom number
// generator. You should never accept credentials with the same
// nonce twice.
Nonce string `json:"nonce"` Nonce string `json:"nonce"`
} }
// PassportScope represents the data to be requested. // PassportScope represents the data to be requested.
PassportScope struct { PassportScope struct {
// List of requested elements, each type may be used only once // List of requested elements, each type may be used only once in the entire array of PassportScopeElement objects
// in the entire array of PassportScopeElement objects
Data []*PassportScopeElement `json:"data"` Data []*PassportScopeElement `json:"data"`
// Scope version, must be 1 // Scope version, must be 1
@ -347,34 +273,25 @@ type (
// List of elements one of which must be provided; // List of elements one of which must be provided;
OneOf []*PassportScopeElementOne `json:"one_of"` OneOf []*PassportScopeElementOne `json:"one_of"`
// Use this parameter if you want to request a selfie with the // Use this parameter if you want to request a selfie with the document from this list that the user chooses to upload.
// document from this list that the user chooses to upload.
Selfie bool `json:"selfie,omitempty"` Selfie bool `json:"selfie,omitempty"`
// Use this parameter if you want to request a translation of // Use this parameter if you want to request a translation of the document from this list that the user chooses to upload. Note: We suggest to only request translations after you have received a valid document that requires one.
// the document from this list that the user chooses to upload.
// Note: We suggest to only request translations after you have
// received a valid document that requires one.
Translation bool `json:"translation,omitempty"` Translation bool `json:"translation,omitempty"`
} }
// PassportScopeElementOne represents one particular element that must // PassportScopeElementOne represents one particular element that must be provided. If no options are needed, String can be used instead of this object to specify the type of the element.
// be provided. If no options are needed, String can be used instead of
// this object to specify the type of the element.
PassportScopeElementOne struct { PassportScopeElementOne struct {
// Element type. // Element type.
Type string `json:"type"` Type string `json:"type"`
// Use this parameter if you want to request a selfie with the // Use this parameter if you want to request a selfie with the document as well.
// document as well.
Selfie bool `json:"selfie,omitempty"` Selfie bool `json:"selfie,omitempty"`
// Use this parameter if you want to request a translation of // Use this parameter if you want to request a translation of the document as well.
// the document as well.
Translation bool `json:"translation,omitempty"` Translation bool `json:"translation,omitempty"`
// Use this parameter to request the first, last and middle name // Use this parameter to request the first, last and middle name of the user in the language of the user's country of residence.
// of the user in the language of the user's country of residence.
NativeNames bool `json:"native_names,omitempty"` NativeNames bool `json:"native_names,omitempty"`
} }
@ -532,8 +449,7 @@ type (
Nonce string `json:"nonce"` Nonce string `json:"nonce"`
} }
// SecureData represents the credentials required to decrypt encrypted // SecureData represents the credentials required to decrypt encrypted data. All fields are optional and depend on fields that were requested.
// data. All fields are optional and depend on fields that were requested.
SecureData struct { SecureData struct {
// Credentials for encrypted personal details // Credentials for encrypted personal details
PersonalDetails *SecureValue `json:"personal_details,omitempty"` PersonalDetails *SecureValue `json:"personal_details,omitempty"`
@ -569,9 +485,7 @@ type (
TemporaryRegistration *SecureValue `json:"temporary_registration,omitempty"` TemporaryRegistration *SecureValue `json:"temporary_registration,omitempty"`
} }
// SecureValue represents the credentials required to decrypt encrypted // SecureValue represents the credentials required to decrypt encrypted values. All fields are optional and depend on the type of fields that were requested.
// values. All fields are optional and depend on the type of fields that
// were requested.
SecureValue struct { SecureValue struct {
// Credentials for encrypted Telegram Passport data. // Credentials for encrypted Telegram Passport data.
Data *DataCredentials `json:"data,omitempty"` Data *DataCredentials `json:"data,omitempty"`
@ -592,8 +506,7 @@ type (
Files []*FileCredentials `json:"files,omitempty"` Files []*FileCredentials `json:"files,omitempty"`
} }
// DataCredentials can be used to decrypt encrypted data from the data // DataCredentials can be used to decrypt encrypted data from the data field in EncryptedPassportElement.
// field in EncryptedPassportElement.
DataCredentials struct { DataCredentials struct {
// Checksum of encrypted data // Checksum of encrypted data
DataHash string `json:"data_hash"` DataHash string `json:"data_hash"`
@ -602,9 +515,7 @@ type (
Secret string `json:"secret"` Secret string `json:"secret"`
} }
// FileCredentials can be used to decrypt encrypted files from the // FileCredentials can be used to decrypt encrypted files from the front_side, reverse_side, selfie, files and translation fields in EncryptedPassportElement.
// front_side, reverse_side, selfie, files and translation fields in
// EncryptedPassportElement.
FileCredentials struct { FileCredentials struct {
// Checksum of encrypted file // Checksum of encrypted file
FileHash string `json:"file_hash"` FileHash string `json:"file_hash"`
@ -616,17 +527,10 @@ type (
var ErrNotEqual = errors.New("credentials hash and credentials data hash is not equal") var ErrNotEqual = errors.New("credentials hash and credentials data hash is not equal")
// SetPassportDataErrors informs a user that some of the Telegram Passport // SetPassportDataErrors informs a user that some of the Telegram Passport elements they provided contains errors. The user will not be able to re-submit their Passport to you until the errors are fixed (the contents of the field for which you returned the error must change). Returns True on success.
// elements they provided contains errors. The user will not be able to re-submit
// their Passport to you until the errors are fixed (the contents of the field
// for which you returned the error must change). Returns True on success.
// //
// Use this if the data submitted by the user doesn't satisfy the standards your // Use this if the data submitted by the user doesn't satisfy the standards your service requires for any reason. For example, if a birthday date seems invalid, a submitted document is blurry, a scan shows evidence of tampering, etc. Supply some details in the error message to make sure the user knows how to correct the issues.
// service requires for any reason. For example, if a birthday date seems func (b Bot) SetPassportDataErrors(uid int, errors ...PassportElementError) (bool, error) {
// invalid, a submitted document is blurry, a scan shows evidence of tampering,
// etc. Supply some details in the error message to make sure the user knows how
// to correct the issues.
func (b *Bot) SetPassportDataErrors(uid int, errors ...PassportElementError) (bool, error) {
src, err := b.Do(MethodSetPassportDataErrors, SetPassportDataErrors{ src, err := b.Do(MethodSetPassportDataErrors, SetPassportDataErrors{
UserID: uid, Errors: errors, UserID: uid, Errors: errors,
}) })

View File

@ -6,11 +6,7 @@ type (
// Portion label // Portion label
Label string `json:"label"` Label string `json:"label"`
// Price of the product in the smallest units of the currency (integer, // Price of the product in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
// not float/double). For example, for a price of US$ 1.45 pass amount =
// 145. See the exp parameter in currencies.json, it shows the number of
// digits past the decimal point for each currency (2 for the majority
// of currencies).
Amount int `json:"amount"` Amount int `json:"amount"`
} }
@ -29,11 +25,7 @@ type (
// Three-letter ISO 4217 currency code // Three-letter ISO 4217 currency code
Currency string `json:"currency"` Currency string `json:"currency"`
// Total price in the smallest units of the currency (integer, not // Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
// float/double). For example, for a price of US$ 1.45 pass amount = 145.
// See the exp parameter in currencies.json, it shows the number of
// digits past the decimal point for each currency (2 for the majority
// of currencies).
TotalAmount int `json:"total_amount"` TotalAmount int `json:"total_amount"`
} }
@ -102,11 +94,7 @@ type (
// Provider payment identifier // Provider payment identifier
ProviderPaymentChargeID string `json:"provider_payment_charge_id"` ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
// Total price in the smallest units of the currency (integer, not // Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
// float/double). For example, for a price of US$ 1.45 pass amount = 145.
// See the exp parameter in currencies.json, it shows the number of
// digits past the decimal point for each currency (2 for the majority
// of currencies).
TotalAmount int `json:"total_amount"` TotalAmount int `json:"total_amount"`
// Order info provided by the user // Order info provided by the user
@ -145,11 +133,7 @@ type (
// User who sent the query // User who sent the query
From *User `json:"from"` From *User `json:"from"`
// Total price in the smallest units of the currency (integer, not // Total price in the smallest units of the currency (integer, not float/double). For example, for a price of US$ 1.45 pass amount = 145. See the exp parameter in currencies.json, it shows the number of digits past the decimal point for each currency (2 for the majority of currencies).
// float/double). For example, for a price of US$ 1.45 pass amount = 145.
// See the exp parameter in currencies.json, it shows the number of
// digits past the decimal point for each currency (2 for the majority of
// currencies).
TotalAmount int `json:"total_amount"` TotalAmount int `json:"total_amount"`
// Order info provided by the user // Order info provided by the user
@ -167,32 +151,25 @@ type (
// Product description, 1-255 characters // Product description, 1-255 characters
Description string `json:"description"` Description string `json:"description"`
// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to // Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
// the user, use for your internal processes.
Payload string `json:"payload"` Payload string `json:"payload"`
// Payments provider token, obtained via Botfather // Payments provider token, obtained via Botfather
ProviderToken string `json:"provider_token"` ProviderToken string `json:"provider_token"`
// Unique deep-linking parameter that can be used to generate this invoice // Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
// when used as a start parameter
StartParameter string `json:"start_parameter"` StartParameter string `json:"start_parameter"`
// Three-letter ISO 4217 currency code, see more on currencies // Three-letter ISO 4217 currency code, see more on currencies
Currency string `json:"currency"` Currency string `json:"currency"`
// JSON-encoded data about the invoice, which will be shared with the payment // JSON-encoded data about the invoice, which will be shared with the payment provider. A detailed description of required fields should be provided by the payment provider.
// provider. A detailed description of required fields should be provided by
// the payment provider.
ProviderData string `json:"provider_data,omitempty"` ProviderData string `json:"provider_data,omitempty"`
// URL of the product photo for the invoice. Can be a photo of the goods or a // URL of the product photo for the invoice. Can be a photo of the goods or a marketing image for a service. People like it better when they see what they are paying for.
// marketing image for a service. People like it better when they see what
// they are paying for.
PhotoURL string `json:"photo_url,omitempty"` PhotoURL string `json:"photo_url,omitempty"`
// Price breakdown, a list of components (e.g. product price, tax, discount, // Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
// delivery cost, delivery tax, bonus, etc.)
Prices []*LabeledPrice `json:"prices"` Prices []*LabeledPrice `json:"prices"`
// Photo size // Photo size
@ -216,20 +193,16 @@ type (
// Pass True, if you require the user's email to complete the order // Pass True, if you require the user's email to complete the order
NeedEmail bool `json:"need_email,omitempty"` NeedEmail bool `json:"need_email,omitempty"`
// Pass True, if you require the user's shipping address to complete the // Pass True, if you require the user's shipping address to complete the order
// order
NeedShippingAddress bool `json:"need_shipping_address,omitempty"` NeedShippingAddress bool `json:"need_shipping_address,omitempty"`
// Pass True, if the final price depends on the shipping method // Pass True, if the final price depends on the shipping method
IsFlexible bool `json:"is_flexible,omitempty"` IsFlexible bool `json:"is_flexible,omitempty"`
// Sends the message silently. Users will receive a notification with no // Sends the message silently. Users will receive a notification with no sound.
// sound.
DisableNotification bool `json:"disable_notification,omitempty"` DisableNotification bool `json:"disable_notification,omitempty"`
// A JSON-serialized object for an inline keyboard. If empty, one 'Pay total // A JSON-serialized object for an inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button.
// price' button will be shown. If not empty, the first button must be a Pay
// button.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
} }
@ -238,44 +211,31 @@ type (
// Unique identifier for the query to be answered // Unique identifier for the query to be answered
ShippingQueryID string `json:"shipping_query_id"` ShippingQueryID string `json:"shipping_query_id"`
// Required if ok is False. Error message in human readable form that // Required if ok is False. Error message in human readable form that explains why it is impossible to complete the order (e.g. "Sorry, delivery to your desired address is unavailable'). Telegram will display this message to the user.
// explains why it is impossible to complete the order (e.g. "Sorry, delivery
// to your desired address is unavailable'). Telegram will display this
// message to the user.
ErrorMessage string `json:"error_message,omitempty"` ErrorMessage string `json:"error_message,omitempty"`
// Specify True if delivery to the specified address is possible and False // Specify True if delivery to the specified address is possible and False if there are any problems (for example, if delivery to the specified address is not possible)
// if there are any problems (for example, if delivery to the specified
// address is not possible)
Ok bool `json:"ok"` Ok bool `json:"ok"`
// Required if ok is True. A JSON-serialized array of available shipping // Required if ok is True. A JSON-serialized array of available shipping options.
// options.
ShippingOptions []*ShippingOption `json:"shipping_options,omitempty"` ShippingOptions []*ShippingOption `json:"shipping_options,omitempty"`
} }
// AnswerPreCheckoutQueryParameters represents data for AnswerPreCheckoutQuery // AnswerPreCheckoutQueryParameters represents data for AnswerPreCheckoutQuery method.
// method.
AnswerPreCheckoutQuery struct { AnswerPreCheckoutQuery struct {
// Unique identifier for the query to be answered // Unique identifier for the query to be answered
PreCheckoutQueryID string `json:"pre_checkout_query_id"` PreCheckoutQueryID string `json:"pre_checkout_query_id"`
// Required if ok is False. Error message in human readable form that // Required if ok is False. Error message in human readable form that explains the reason for failure to proceed with the checkout (e.g. "Sorry, somebody just bought the last of our amazing black T-shirts while you were busy filling out your payment details. Please choose a different color or garment!"). Telegram will display this message to the user.
// explains the reason for failure to proceed with the checkout (e.g. "Sorry,
// somebody just bought the last of our amazing black T-shirts while you were
// busy filling out your payment details. Please choose a different color or
// garment!"). Telegram will display this message to the user.
ErrorMessage string `json:"error_message,omitempty"` ErrorMessage string `json:"error_message,omitempty"`
// Specify True if everything is alright (goods are available, etc.) and the // Specify True if everything is alright (goods are available, etc.) and the bot is ready to proceed with the order. Use False if there are any problems.
// bot is ready to proceed with the order. Use False if there are any
// problems.
Ok bool `json:"ok"` Ok bool `json:"ok"`
} }
) )
// SendInvoice send invoices. On success, the sent Message is returned. // SendInvoice send invoices. On success, the sent Message is returned.
func (b *Bot) SendInvoice(p SendInvoice) (*Message, error) { func (b Bot) SendInvoice(p SendInvoice) (*Message, error) {
src, err := b.Do(MethodSendInvoice, p) src, err := b.Do(MethodSendInvoice, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -296,10 +256,8 @@ func (b *Bot) SendInvoice(p SendInvoice) (*Message, error) {
// AnswerShippingQuery reply to shipping queries. // AnswerShippingQuery reply to shipping queries.
// //
// If you sent an invoice requesting a shipping address and the parameter // If you sent an invoice requesting a shipping address and the parameter is_flexible was specified, the Bot API will send an Update with a shipping_query field to the b. On success, True is returned.
// is_flexible was specified, the Bot API will send an Update with a func (b Bot) AnswerShippingQuery(p AnswerShippingQuery) (bool, error) {
// shipping_query field to the b. On success, True is returned.
func (b *Bot) AnswerShippingQuery(p AnswerShippingQuery) (bool, error) {
src, err := b.Do(MethodAnswerShippingQuery, p) src, err := b.Do(MethodAnswerShippingQuery, p)
if err != nil { if err != nil {
return false, err return false, err
@ -320,14 +278,10 @@ func (b *Bot) AnswerShippingQuery(p AnswerShippingQuery) (bool, error) {
// AnswerPreCheckoutQuery respond to such pre-checkout queries. // AnswerPreCheckoutQuery respond to such pre-checkout queries.
// //
// Once the user has confirmed their payment and shipping details, the Bot API // Once the user has confirmed their payment and shipping details, the Bot API sends the final confirmation in the form of an Update with the field pre_checkout_query. Use this method to respond to such pre-checkout queries. On success, True is returned.
// sends the final confirmation in the form of an Update with the field
// pre_checkout_query. Use this method to respond to such pre-checkout queries.
// On success, True is returned.
// //
// Note: The Bot API must receive an answer within 10 seconds after the // Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
// pre-checkout query was sent. func (b Bot) AnswerPreCheckoutQuery(p AnswerShippingQuery) (bool, error) {
func (b *Bot) AnswerPreCheckoutQuery(p AnswerShippingQuery) (bool, error) {
src, err := b.Do(MethodAnswerPreCheckoutQuery, p) src, err := b.Do(MethodAnswerPreCheckoutQuery, p)
if err != nil { if err != nil {
return false, err return false, err

View File

@ -97,9 +97,7 @@ type (
// User identifier of sticker file owner // User identifier of sticker file owner
UserID int `json:"user_id"` UserID int `json:"user_id"`
// Png image with the sticker, must be up to 512 kilobytes in size, // 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.
// dimensions must not exceed 512px, and either width or height
// must be exactly 512px.
PNGSticker *InputFile `json:"png_sticker"` PNGSticker *InputFile `json:"png_sticker"`
} }
@ -107,22 +105,13 @@ type (
// User identifier of created sticker set owner // User identifier of created sticker set owner
UserID int `json:"user_id"` UserID int `json:"user_id"`
// Short name of sticker set, to be used in t.me/addstickers/ URLs // Short name of sticker set, to be used in t.me/addstickers/ URLs (e.g., animals). Can contain only english letters, digits and underscores. Must begin with a letter, can't contain consecutive underscores and must end in “_by_<bot username>”. <bot_username> is case insensitive. 1-64 characters.
// (e.g., animals). Can contain only english letters, digits and
// underscores. Must begin with a letter, can't contain consecutive
// underscores and must end in “_by_<bot username>”. <bot_username>
// is case insensitive. 1-64 characters.
Name string `json:"name"` Name string `json:"name"`
// 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, // 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.
// 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"`
// One or more emoji corresponding to the sticker // One or more emoji corresponding to the sticker
@ -131,8 +120,7 @@ type (
// Pass True, if a set of mask stickers should be created // Pass True, if a set of mask stickers should be created
ContainsMasks bool `json:"contains_masks,omitempty"` ContainsMasks bool `json:"contains_masks,omitempty"`
// A JSON-serialized object for position where the mask should be // A JSON-serialized object for position where the mask should be placed on faces
// placed on faces
MaskPosition *MaskPosition `json:"mask_position,omitempty"` MaskPosition *MaskPosition `json:"mask_position,omitempty"`
} }
@ -170,7 +158,7 @@ type (
) )
// SendSticker send .webp stickers. On success, the sent Message is returned. // SendSticker send .webp stickers. On success, the sent Message is returned.
func (b *Bot) SendSticker(p SendSticker) (*Message, error) { func (b Bot) SendSticker(p SendSticker) (*Message, error) {
src, err := b.Do(MethodSendSticker, p) src, err := b.Do(MethodSendSticker, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -190,7 +178,7 @@ func (b *Bot) SendSticker(p SendSticker) (*Message, error) {
} }
// GetStickerSet get a sticker set. On success, a StickerSet object is returned. // GetStickerSet get a sticker set. On success, a StickerSet object is returned.
func (b *Bot) GetStickerSet(name string) (*StickerSet, error) { func (b Bot) GetStickerSet(name string) (*StickerSet, error) {
src, err := b.Do(MethodGetStickerSet, GetStickerSet{Name: name}) src, err := b.Do(MethodGetStickerSet, GetStickerSet{Name: name})
if err != nil { if err != nil {
return nil, err return nil, err
@ -210,16 +198,16 @@ func (b *Bot) GetStickerSet(name string) (*StickerSet, error) {
} }
// UploadStickerFile upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success. // UploadStickerFile upload a .png file with a sticker for later use in createNewStickerSet and addStickerToSet methods (can be used multiple times). Returns the uploaded File on success.
func (b *Bot) UploadStickerFile(userID int, pngSticker *InputFile) (*File, error) { func (b Bot) UploadStickerFile(uid int, sticker *InputFile) (*File, error) {
params := make(map[string]string) params := make(map[string]string)
params["user_id"] = strconv.Itoa(userID) params["user_id"] = strconv.Itoa(uid)
var err error var err error
if params["png_sticker"], err = b.marshler.MarshalToString(pngSticker); err != nil { if params["png_sticker"], err = b.marshler.MarshalToString(sticker); err != nil {
return nil, err return nil, err
} }
src, err := b.Upload(MethodUploadStickerFile, params, pngSticker) src, err := b.Upload(MethodUploadStickerFile, params, sticker)
if err != nil { if err != nil {
return nil, err return nil, err
} }

328
types.go
View File

@ -47,8 +47,7 @@ type (
// Unique identifier for this chat. // Unique identifier for this chat.
ID int64 `json:"id"` ID int64 `json:"id"`
// Type of chat, can be either "private", "group", "supergroup" or // Type of chat, can be either "private", "group", "supergroup" or "channel"
// "channel"
Type string `json:"type"` Type string `json:"type"`
// Title, for supergroups, channels and group chats // Title, for supergroups, channels and group chats
@ -69,8 +68,7 @@ type (
// Description, for groups, supergroups and channel chats. Returned only in getChat. // Description, for groups, supergroups and channel chats. Returned only in getChat.
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
// Chat invite link, for supergroups and channel chats. Returned only in // Chat invite link, for supergroups and channel chats. Returned only in getChat.
// getChat.
InviteLink string `json:"invite_link,omitempty"` InviteLink string `json:"invite_link,omitempty"`
// Pinned message, for groups, supergroups and channels. Returned only in getChat. // Pinned message, for groups, supergroups and channels. Returned only in getChat.
@ -85,8 +83,7 @@ type (
// For supergroups, name of Group sticker set. Returned only in getChat. // For supergroups, name of Group sticker set. Returned only in getChat.
StickerSetName string `json:"sticker_set_name,omitempty"` StickerSetName string `json:"sticker_set_name,omitempty"`
// True, if the bot can change group the sticker set. Returned only in // True, if the bot can change group the sticker set. Returned only in getChat.
// getChat.
CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"`
} }
@ -107,29 +104,22 @@ type (
// For forwarded messages, sender of the original message // For forwarded messages, sender of the original message
ForwardFrom *User `json:"forward_from,omitempty"` ForwardFrom *User `json:"forward_from,omitempty"`
// For messages forwarded from channels, information about the original // For messages forwarded from channels, information about the original channel
// channel
ForwardFromChat *Chat `json:"forward_from_chat,omitempty"` ForwardFromChat *Chat `json:"forward_from_chat,omitempty"`
// For messages forwarded from channels, identifier of the original // For messages forwarded from channels, identifier of the original message in the channel
// message in the channel
ForwardFromMessageID int `json:"forward_from_message_id,omitempty"` ForwardFromMessageID int `json:"forward_from_message_id,omitempty"`
// For messages forwarded from channels, signature of the post author if // For messages forwarded from channels, signature of the post author if present
// present
ForwardSignature string `json:"forward_signature,omitempty"` ForwardSignature string `json:"forward_signature,omitempty"`
// Sender's name for messages forwarded from users who disallow adding a // Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages
// link to their account in forwarded messages
ForwardSenderName string `json:"forward_sender_name,omitempty"` ForwardSenderName string `json:"forward_sender_name,omitempty"`
// For forwarded messages, date the original message was sent in Unix // For forwarded messages, date the original message was sent in Unix time
// time
ForwardDate int64 `json:"forward_date,omitempty"` ForwardDate int64 `json:"forward_date,omitempty"`
// For replies, the original message. Note that the Message object in // For replies, the original message. Note that the Message object in this field will not contain further reply_to_message fields even if it itself is a reply.
// this field will not contain further reply_to_message fields even if it
// itself is a reply.
ReplyToMessage *Message `json:"reply_to_message,omitempty"` ReplyToMessage *Message `json:"reply_to_message,omitempty"`
// Date the message was last edited in Unix time // Date the message was last edited in Unix time
@ -141,16 +131,13 @@ type (
// Signature of the post author for messages in channels // Signature of the post author for messages in channels
AuthorSignature string `json:"author_signature,omitempty"` AuthorSignature string `json:"author_signature,omitempty"`
// For text messages, the actual UTF-8 text of the message, 0-4096 // For text messages, the actual UTF-8 text of the message, 0-4096 characters.
// characters.
Text string `json:"text,omitempty"` Text string `json:"text,omitempty"`
// For text messages, special entities like usernames, URLs, bot // For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
// commands, etc. that appear in the text
Entities []*MessageEntity `json:"entities,omitempty"` Entities []*MessageEntity `json:"entities,omitempty"`
// For messages with a caption, special entities like usernames, URLs, // For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption
// bot commands, etc. that appear in the caption
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"` CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
// Message is an audio file, information about the file // Message is an audio file, information about the file
@ -159,9 +146,7 @@ type (
// Message is a general file, information about the file // Message is a general file, information about the file
Document *Document `json:"document,omitempty"` Document *Document `json:"document,omitempty"`
// Message is an animation, information about the animation. For backward // Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set
// compatibility, when this field is set, the document field will also be
// set
Animation *Animation `json:"animation,omitempty"` Animation *Animation `json:"animation,omitempty"`
// Message is a game, information about the game. // Message is a game, information about the game.
@ -197,12 +182,10 @@ 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"`
// New members that were added to the group or supergroup and information // New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
// 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"`
// A member was removed from the group, information about them (this // A member was removed from the group, information about them (this member may be the bot itself)
// member may be the bot itself)
LeftChatMember *User `json:"left_chat_member,omitempty"` LeftChatMember *User `json:"left_chat_member,omitempty"`
// A chat title was changed to this value // A chat title was changed to this value
@ -217,38 +200,25 @@ type (
// Service message: the group has been created // Service message: the group has been created
GroupChatCreated bool `json:"group_chat_created,omitempty"` GroupChatCreated bool `json:"group_chat_created,omitempty"`
// Service message: the supergroup has been created. This field cant be // Service message: the supergroup has been created. This field cant be received in a message coming through updates, because bot cant be a member of a supergroup when it is created. It can only be found in reply_to_message if someone replies to a very first message in a directly created supergroup.
// received in a message coming through updates, because bot cant be a
// member of a supergroup when it is created. It can only be found in
// reply_to_message if someone replies to a very first message in a
// directly created supergroup.
SupergroupChatCreated bool `json:"supergroup_chat_created,omitempty"` SupergroupChatCreated bool `json:"supergroup_chat_created,omitempty"`
// Service message: the channel has been created. This field cant be // Service message: the channel has been created. This field cant be received in a message coming through updates, because bot cant be a member of a channel when it is created. It can only be found in reply_to_message if someone replies to a very first message in a channel.
// received in a message coming through updates, because bot cant be a
// member of a channel when it is created. It can only be found in
// reply_to_message if someone replies to a very first message in a
// channel.
ChannelChatCreated bool `json:"channel_chat_created,omitempty"` ChannelChatCreated bool `json:"channel_chat_created,omitempty"`
// The group has been migrated to a supergroup with the specified // The group has been migrated to a supergroup with the specified identifier.
// identifier.
MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"`
// The supergroup has been migrated from a group with the specified // The supergroup has been migrated from a group with the specified identifier.
// identifier.
MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"` MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"`
// Specified message was pinned. Note that the Message object in this // Specified message was pinned. Note that the Message object in this field will not contain further reply_to_message fields even if it is itself a reply.
// field will not contain further reply_to_message fields even if it is
// itself a reply.
PinnedMessage *Message `json:"pinned_message,omitempty"` PinnedMessage *Message `json:"pinned_message,omitempty"`
// Message is an invoice for a payment, information about the invoice. // Message is an invoice for a payment, information about the invoice.
Invoice *Invoice `json:"invoice,omitempty"` Invoice *Invoice `json:"invoice,omitempty"`
// Message is a service message about a successful payment, information // Message is a service message about a successful payment, information about the payment.
// about the payment.
SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"` SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"`
// The domain name of the website on which the user has logged in. // The domain name of the website on which the user has logged in.
@ -261,17 +231,12 @@ type (
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
} }
// MessageEntity represents one special entity in a text message. For // MessageEntity represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.
// example, hashtags, usernames, URLs, etc.
MessageEntity struct { MessageEntity struct {
// Type of the entity. Can be mention (@username), hashtag, bot_command, // Type of the entity. Can be mention (@username), hashtag, bot_command, url, email, bold (bold text), italic (italic text), code (monowidth string), pre (monowidth block), text_link (for clickable text URLs), text_mention (for users without usernames)
// url, email, bold (bold text), italic (italic text), code (monowidth
// string), pre (monowidth block), text_link (for clickable text URLs),
// text_mention (for users without usernames)
Type string `json:"type"` Type string `json:"type"`
// For "text_link" only, url that will be opened after user taps on the // For "text_link" only, url that will be opened after user taps on the text
// text
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
// Offset in UTF-16 code units to the start of the entity // Offset in UTF-16 code units to the start of the entity
@ -289,8 +254,7 @@ type (
// Identifier for this file, which can be used to download or reuse the file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
// Unique identifier for this file, which is supposed to be the same over time and for different bots. // Unique identifier for this file, which is supposed to be the same over time and for different bots. Can't be used to download or reuse the file.
// Can't be used to download or reuse the file.
FileUniqueID string `json:"file_unique_id"` FileUniqueID string `json:"file_unique_id"`
// Photo width // Photo width
@ -303,8 +267,7 @@ type (
FileSize int `json:"file_size,omitempty"` FileSize int `json:"file_size,omitempty"`
} }
// Audio represents an audio file to be treated as music by the Telegram // Audio represents an audio file to be treated as music by the Telegram clients.
// clients.
Audio struct { Audio struct {
// Identifier for this file, which can be used to download or reuse the file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
@ -331,8 +294,7 @@ type (
Thumb *PhotoSize `json:"thumb,omitempty"` Thumb *PhotoSize `json:"thumb,omitempty"`
} }
// Document represents a general file (as opposed to photos, voice messages // Document represents a general file (as opposed to photos, voice messages and audio files).
// and audio files).
Document struct { Document struct {
// Identifier for this file, which can be used to download or reuse the file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
@ -380,9 +342,7 @@ type (
FileSize int `json:"file_size,omitempty"` FileSize int `json:"file_size,omitempty"`
} }
// Animation provide an animation for your game so that it looks stylish in // Animation provide an animation for your game so that it looks stylish in chats (check out Lumberjack for an example). This object represents an animation file to be displayed in the message containing a game.
// chats (check out Lumberjack for an example). This object represents an
// animation file to be displayed in the message containing a game.
Animation struct { Animation struct {
// Unique file identifier // Unique file identifier
FileID string `json:"file_id"` FileID string `json:"file_id"`
@ -430,8 +390,7 @@ type (
FileSize int `json:"file_size,omitempty"` FileSize int `json:"file_size,omitempty"`
} }
// VideoNote represents a video message (available in Telegram apps as of // VideoNote represents a video message (available in Telegram apps as of v.4.0).
// v.4.0).
VideoNote struct { VideoNote struct {
// Identifier for this file, which can be used to download or reuse the file // Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"` FileID string `json:"file_id"`
@ -530,10 +489,7 @@ type (
Photos [][]*PhotoSize `json:"photos"` Photos [][]*PhotoSize `json:"photos"`
} }
// File represents a file ready to be downloaded. The file can be downloaded // File represents a file ready to be downloaded. The file can be downloaded via the link https://api.telegram.org/file/bot<token>/<file_path>. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile.
// via the link https://api.telegram.org/file/bot<token>/<file_path>. It is
// guaranteed that the link will be valid for at least 1 hour. When the link
// expires, a new one can be requested by calling getFile.
// //
// Maximum file size to download is 20 MB // Maximum file size to download is 20 MB
File struct { File struct {
@ -546,91 +502,57 @@ type (
// File size, if known // File size, if known
FileSize int `json:"file_size,omitempty"` FileSize int `json:"file_size,omitempty"`
// File path. Use https://api.telegram.org/file/bot<token>/<file_path> to // File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file.
// get the file.
FilePath string `json:"file_path,omitempty"` FilePath string `json:"file_path,omitempty"`
} }
// ReplyKeyboardMarkup represents a custom keyboard with reply options (see // ReplyKeyboardMarkup represents a custom keyboard with reply options (see Introduction to bots for details and examples).
// Introduction to bots for details and examples).
ReplyKeyboardMarkup struct { ReplyKeyboardMarkup struct {
// Array of button rows, each represented by an Array of KeyboardButton // Array of button rows, each represented by an Array of KeyboardButton objects
// objects
Keyboard [][]*KeyboardButton `json:"keyboard"` Keyboard [][]*KeyboardButton `json:"keyboard"`
// Requests clients to resize the keyboard vertically for optimal fit // Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.
// (e.g., make the keyboard smaller if there are just two rows of
// buttons). Defaults to false, in which case the custom keyboard is
// always of the same height as the app's standard keyboard.
ResizeKeyboard bool `json:"resize_keyboard,omitempty"` ResizeKeyboard bool `json:"resize_keyboard,omitempty"`
// Requests clients to hide the keyboard as soon as it's been used. The // Requests clients to hide the keyboard as soon as it's been used. The keyboard will still be available, but clients will automatically display the usual letter-keyboard in the chat the user can press a special button in the input field to see the custom keyboard again. Defaults to false.
// keyboard will still be available, but clients will automatically
// display the usual letter-keyboard in the chat the user can press a
// special button in the input field to see the custom keyboard again.
// Defaults to false.
OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"` OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"`
// Use this parameter if you want to show the keyboard to specific users // Use this parameter if you want to show the keyboard to specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
// only. Targets: 1) users that are @mentioned in the text of the Message
// object; 2) if the bot's message is a reply (has reply_to_message_id),
// sender of the original message.
// //
// Example: A user requests to change the bots language, bot replies to // Example: A user requests to change the bots language, bot replies to the request with a keyboard to select the new language. Other users in the group dont see the keyboard.
// the request with a keyboard to select the new language. Other users in
// the group dont see the keyboard.
Selective bool `json:"selective,omitempty"` Selective bool `json:"selective,omitempty"`
} }
// KeyboardButton represents one button of the reply keyboard. For simple // KeyboardButton represents one button of the reply keyboard. For simple text buttons String can be used instead of this object to specify text of the button. Optional fields are mutually exclusive.
// text buttons String can be used instead of this object to specify text of
// the button. Optional fields are mutually exclusive.
KeyboardButton struct { KeyboardButton struct {
// Text of the button. If none of the optional fields are used, it will // Text of the button. If none of the optional fields are used, it will be sent to the bot as a message when the button is pressed
// be sent to the bot as a message when the button is pressed
Text string `json:"text"` Text string `json:"text"`
// If True, the user's phone number will be sent as a contact when the // If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
// button is pressed. Available in private chats only
RequestContact bool `json:"request_contact,omitempty"` RequestContact bool `json:"request_contact,omitempty"`
// If True, the user's current location will be sent when the button is // If True, the user's current location will be sent when the button is pressed. Available in private chats only
// pressed. Available in private chats only
RequestLocation bool `json:"request_location,omitempty"` RequestLocation bool `json:"request_location,omitempty"`
} }
// ReplyKeyboardRemove will remove the current custom keyboard and display // ReplyKeyboardRemove will remove the current custom keyboard and display the default letter-keyboard. By default, custom keyboards are displayed until a new keyboard is sent by a b. An exception is made for one-time keyboards that are hidden immediately after the user presses a button (see ReplyKeyboardMarkup).
// the default letter-keyboard. By default, custom keyboards are displayed
// until a new keyboard is sent by a b. An exception is made for one-time
// keyboards that are hidden immediately after the user presses a button
// (see ReplyKeyboardMarkup).
ReplyKeyboardRemove struct { ReplyKeyboardRemove struct {
// Requests clients to remove the custom keyboard (user will not be able // Requests clients to remove the custom keyboard (user will not be able to summon this keyboard; if you want to hide the keyboard from sight but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)
// to summon this keyboard; if you want to hide the keyboard from sight
// but keep it accessible, use one_time_keyboard in ReplyKeyboardMarkup)
RemoveKeyboard bool `json:"remove_keyboard"` RemoveKeyboard bool `json:"remove_keyboard"`
// Use this parameter if you want to remove the keyboard for specific // Use this parameter if you want to remove the keyboard for specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
// users only. Targets: 1) users that are @mentioned in the text of the
// Message object; 2) if the bot's message is a reply (has
// reply_to_message_id), sender of the original message.
// //
// Example: A user votes in a poll, bot returns confirmation message in // Example: A user votes in a poll, bot returns confirmation message in reply to the vote and removes the keyboard for that user, while still showing the keyboard with poll options to users who haven't voted yet.
// reply to the vote and removes the keyboard for that user, while still
// showing the keyboard with poll options to users who haven't voted yet.
Selective bool `json:"selective,omitempty"` Selective bool `json:"selective,omitempty"`
} }
// InlineKeyboardMarkup represents an inline keyboard that appears right next // InlineKeyboardMarkup represents an inline keyboard that appears right next to the message it belongs to.
// to the message it belongs to.
InlineKeyboardMarkup struct { InlineKeyboardMarkup struct {
// Array of button rows, each represented by an Array of // Array of button rows, each represented by an Array of InlineKeyboardButton objects
// InlineKeyboardButton objects
InlineKeyboard [][]*InlineKeyboardButton `json:"inline_keyboard"` InlineKeyboard [][]*InlineKeyboardButton `json:"inline_keyboard"`
} }
// InlineKeyboardButton represents one button of an inline keyboard. You // InlineKeyboardButton represents one button of an inline keyboard. You must use exactly one of the optional fields.
// must use exactly one of the optional fields.
InlineKeyboardButton struct { InlineKeyboardButton struct {
// Label text on the button // Label text on the button
Text string `json:"text"` Text string `json:"text"`
@ -638,126 +560,82 @@ type (
// HTTP url to be opened when button is pressed // HTTP url to be opened when button is pressed
URL string `json:"url,omitempty"` URL string `json:"url,omitempty"`
// An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram // An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.
// Login Widget.
LoginURL *LoginURL `json:"login_url,omitempty"` LoginURL *LoginURL `json:"login_url,omitempty"`
// Data to be sent in a callback query to the bot when button is pressed, // Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
// 1-64 bytes
CallbackData string `json:"callback_data,omitempty"` CallbackData string `json:"callback_data,omitempty"`
// If set, pressing the button will prompt the user to select one of // If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bots username and the specified inline query in the input field. Can be empty, in which case just the bots username will be inserted.
// their chats, open that chat and insert the bots username and the
// specified inline query in the input field. Can be empty, in which
// case just the bots username will be inserted.
// //
// Note: This offers an easy way for users to start using your bot in // Note: This offers an easy way for users to start using your bot in inline mode when they are currently in a private chat with it. Especially useful when combined with switch_pm… actions in this case the user will be automatically returned to the chat they switched from, skipping the chat selection screen.
// inline mode when they are currently in a private chat with it.
// Especially useful when combined with switch_pm… actions in this case
// the user will be automatically returned to the chat they switched
// from, skipping the chat selection screen.
SwitchInlineQuery string `json:"switch_inline_query,omitempty"` SwitchInlineQuery string `json:"switch_inline_query,omitempty"`
// If set, pressing the button will insert the bots username and the // If set, pressing the button will insert the bots username and the specified inline query in the current chat's input field. Can be empty, in which case only the bots username will be inserted.
// specified inline query in the current chat's input field. Can be
// empty, in which case only the bots username will be inserted.
// //
// This offers a quick way for the user to open your bot in inline mode // This offers a quick way for the user to open your bot in inline mode in the same chat good for selecting something from multiple options.
// in the same chat good for selecting something from multiple options.
SwitchInlineQueryCurrentChat string `json:"switch_inline_query_current_chat,omitempty"` SwitchInlineQueryCurrentChat string `json:"switch_inline_query_current_chat,omitempty"`
// Description of the game that will be launched when the user presses // Description of the game that will be launched when the user presses the button.
// the button.
// //
// NOTE: This type of button must always be the first button in the // NOTE: This type of button must always be the first button in the first row.
// first row.
CallbackGame *CallbackGame `json:"callback_game,omitempty"` CallbackGame *CallbackGame `json:"callback_game,omitempty"`
// Specify True, to send a Pay button. // Specify True, to send a Pay button.
// //
// NOTE: This type of button must always be the first button in the // NOTE: This type of button must always be the first button in the first row.
// first row.
Pay bool `json:"pay,omitempty"` Pay bool `json:"pay,omitempty"`
} }
// LoginURL represents a parameter of the inline keyboard button used to automatically authorize a user. // LoginURL represents a parameter of the inline keyboard button used to automatically authorize a user.
LoginURL struct { LoginURL struct {
// An HTTP URL to be opened with user authorization data added to the query string when the button is // An HTTP URL to be opened with user authorization data added to the query string when the button is pressed. If the user refuses to provide authorization data, the original URL without information about the user will be opened. The data added is the same as described in Receiving authorization data.
// pressed. If the user refuses to provide authorization data, the original URL without information
// about the user will be opened. The data added is the same as described in Receiving authorization
// data.
// //
// NOTE: You must always check the hash of the received data to verify the authentication and the // NOTE: You must always check the hash of the received data to verify the authentication and the integrity of the data as described in Checking authorization.
// integrity of the data as described in Checking authorization.
URL string `json:"url"` URL string `json:"url"`
// New text of the button in forwarded messages. // New text of the button in forwarded messages.
ForwardText string `json:"forward_text,omitempty"` ForwardText string `json:"forward_text,omitempty"`
// Username of a bot, which will be used for user authorization. See Setting up a bot for more // Username of a bot, which will be used for user authorization. See Setting up a bot for more details. If not specified, the current bot's username will be assumed. The url's domain must be the same as the domain linked with the b. See Linking your domain to the bot for more details.
// details. If not specified, the current bot's username will be assumed. The url's domain must be the
// same as the domain linked with the b. See Linking your domain to the bot for more details.
BotUsername string `json:"bot_username,omitempty"` BotUsername string `json:"bot_username,omitempty"`
// Pass true to request the permission for your bot to send messages to the user. // Pass true to request the permission for your bot to send messages to the user.
RequestWriteAccess bool `json:"request_write_access,omitempty"` RequestWriteAccess bool `json:"request_write_access,omitempty"`
} }
// CallbackQuery represents an incoming callback query from a callback button // CallbackQuery represents an incoming callback query from a callback button in an inline keyboard. If the button that originated the query was attached to a message sent by the bot, the field message will be present. If the button was attached to a message sent via the bot (in inline mode), the field inline_message_id will be present. Exactly one of the fields data or game_short_name will be present.
// in an inline keyboard. If the button that originated the query was
// attached to a message sent by the bot, the field message will be present.
// If the button was attached to a message sent via the bot (in inline mode),
// the field inline_message_id will be present. Exactly one of the fields
// data or game_short_name will be present.
// //
// NOTE: After the user presses a callback button, Telegram clients will // NOTE: After the user presses a callback button, Telegram clients will display a progress bar until you call answerCallbackQuery. It is, therefore, necessary to react by calling answerCallbackQuery even if no notification to the user is needed (e.g., without specifying any of the optional ).
// display a progress bar until you call answerCallbackQuery. It is,
// therefore, necessary to react by calling answerCallbackQuery even if no
// notification to the user is needed (e.g., without specifying any of the
// optional ).
CallbackQuery struct { CallbackQuery struct {
// Unique identifier for this query // Unique identifier for this query
ID string `json:"id"` ID string `json:"id"`
// Identifier of the message sent via the bot in inline mode, that // Identifier of the message sent via the bot in inline mode, that originated the query.
// originated the query.
InlineMessageID string `json:"inline_message_id,omitempty"` InlineMessageID string `json:"inline_message_id,omitempty"`
// Global identifier, uniquely corresponding to the chat to which the // Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
// message with the callback button was sent. Useful for high scores in
// games.
ChatInstance string `json:"chat_instance"` ChatInstance string `json:"chat_instance"`
// Data associated with the callback button. Be aware that a bad client // Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.
// can send arbitrary data in this field.
Data string `json:"data,omitempty"` Data string `json:"data,omitempty"`
// Short name of a Game to be returned, serves as the unique identifier // Short name of a Game to be returned, serves as the unique identifier for the game
// for the game
GameShortName string `json:"game_short_name,omitempty"` GameShortName string `json:"game_short_name,omitempty"`
// Sender // Sender
From *User `json:"from"` From *User `json:"from"`
// Message with the callback button that originated the query. Note that // Message with the callback button that originated the query. Note that message content and message date will not be available if the message is too old
// message content and message date will not be available if the message
// is too old
Message *Message `json:"message,omitempty"` Message *Message `json:"message,omitempty"`
} }
// ForceReply display a reply interface to the user (act as if the user has // ForceReply display a reply interface to the user (act as if the user has selected the bots message and tapped Reply'). This can be extremely useful if you want to create user-friendly step-by-step interfaces without having to sacrifice privacy mode.
// selected the bots message and tapped Reply'). This can be extremely
// useful if you want to create user-friendly step-by-step interfaces without
// having to sacrifice privacy mode.
ForceReply struct { ForceReply struct {
// Shows reply interface to the user, as if they manually selected the // Shows reply interface to the user, as if they manually selected the bots message and tapped Reply'
// bots message and tapped Reply'
ForceReply bool `json:"force_reply"` ForceReply bool `json:"force_reply"`
// Use this parameter if you want to force reply from specific users // Use this parameter if you want to force reply from specific users only. Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's message is a reply (has reply_to_message_id), sender of the original message.
// only. Targets: 1) users that are @mentioned in the text of the Message
// object; 2) if the bot's message is a reply (has reply_to_message_id),
// sender of the original message.
Selective bool `json:"selective,omitempty"` Selective bool `json:"selective,omitempty"`
} }
@ -781,8 +659,7 @@ type (
// Information about the user // Information about the user
User *User `json:"user"` User *User `json:"user"`
// The member's status in the chat. Can be "creator", "administrator", "member", "restricted", "left" // The member's status in the chat. Can be "creator", "administrator", "member", "restricted", "left" or "kicked"
// or "kicked"
Status string `json:"status"` Status string `json:"status"`
// Owner and administrators only. Custom title for this user // Owner and administrators only. Custom title for this user
@ -807,10 +684,7 @@ type (
// unban chat members // unban chat members
CanRestrictMembers bool `json:"can_restrict_members,omitempty"` CanRestrictMembers bool `json:"can_restrict_members,omitempty"`
// Administrators only. True, if the administrator can add new // Administrators only. True, if the administrator can add new administrators with a subset of his own privileges or demote administrators that he has promoted, directly or indirectly (promoted by administrators that were appointed by the user)
// administrators with a subset of his own privileges or demote
// administrators that he has promoted, directly or indirectly (promoted
// by administrators that were appointed by the user)
CanPromoteMembers bool `json:"can_promote_members,omitempty"` CanPromoteMembers bool `json:"can_promote_members,omitempty"`
// Restricted only. True, if the user is a member of the chat at the moment of the request // Restricted only. True, if the user is a member of the chat at the moment of the request
@ -824,22 +698,19 @@ type (
// True, if the user is allowed to send text messages, contacts, locations and venues // True, if the user is allowed to send text messages, contacts, locations and venues
CanSendMessages bool `json:"can_send_messages,omitempty"` CanSendMessages bool `json:"can_send_messages,omitempty"`
// True, if the user is allowed to send audios, documents, photos, videos, video notes and voice // True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
// notes, implies can_send_messages
CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"` CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"`
// True, if the user is allowed to send polls, implies can_send_messages // True, if the user is allowed to send polls, implies can_send_messages
CanSendPolls bool `json:"can_send_polls,omitempty"` CanSendPolls bool `json:"can_send_polls,omitempty"`
// True, if the user is allowed to send animations, games, stickers and use inline bots, implies // True, if the user is allowed to send animations, games, stickers and use inline bots, implies can_send_media_messages
// can_send_media_messages
CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"`
// True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages // True, if the user is allowed to add web page previews to their messages, implies can_send_media_messages
CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"`
// True, if the user is allowed to change the chat title, photo and other settings. Ignored in public // True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups
// supergroups
CanChangeInfo bool `json:"can_change_info,omitempty"` CanChangeInfo bool `json:"can_change_info,omitempty"`
// True, if the user is allowed to invite new users to the chat // True, if the user is allowed to invite new users to the chat
@ -849,15 +720,12 @@ type (
CanPinMessages bool `json:"can_pin_messages,omitempty"` CanPinMessages bool `json:"can_pin_messages,omitempty"`
} }
// ResponseParameters contains information about why a request was // ResponseParameters contains information about why a request was unsuccessful.
// unsuccessful.
ResponseParameters struct { ResponseParameters struct {
// The group has been migrated to a supergroup with the specified // The group has been migrated to a supergroup with the specified identifier.
// identifier.
MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"`
// In case of exceeding flood control, the number of seconds left to wait // In case of exceeding flood control, the number of seconds left to wait before the request can be repeated
// before the request can be repeated
RetryAfter int `json:"retry_after,omitempty"` RetryAfter int `json:"retry_after,omitempty"`
} }
@ -876,18 +744,13 @@ type (
// Type of the result, must be photo // Type of the result, must be photo
Type string `json:"type"` Type string `json:"type"`
// File to send. Pass a file_id to send a file that exists on the // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://<file_attach_name>" to upload a new one using multipart/form-data under <file_attach_name> name.
// Telegram servers (recommended), pass an HTTP URL for Telegram to get
// a file from the Internet, or pass "attach://<file_attach_name>" to
// upload a new one using multipart/form-data under <file_attach_name>
// name.
Media *InputFile `json:"media"` Media *InputFile `json:"media"`
// Caption of the photo to be sent, 0-200 characters // Caption of the photo to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
} }
@ -896,18 +759,13 @@ type (
// Type of the result, must be video // Type of the result, must be video
Type string `json:"type"` Type string `json:"type"`
// File to send. Pass a file_id to send a file that exists on the // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://<file_attach_name>" to upload a new one using multipart/form-data under <file_attach_name> name.
// Telegram servers (recommended), pass an HTTP URL for Telegram to get
// a file from the Internet, or pass "attach://<file_attach_name>" to
// upload a new one using multipart/form-data under <file_attach_name>
// name.
Media *InputFile `json:"media"` Media *InputFile `json:"media"`
// Caption of the video to be sent, 0-200 characters // Caption of the video to be sent, 0-200 characters
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Video width // Video width
@ -929,20 +787,10 @@ type (
// Type of the result, must be animation // Type of the result, must be animation
Type string `json:"type"` Type string `json:"type"`
// File to send. Pass a file_id to send a file that exists on the // File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP URL for Telegram to get a file from the Internet, or pass "attach://<file_attach_name>" to upload a new one using multipart/form-data under <file_attach_name name.
// Telegram servers (recommended), pass an HTTP URL for Telegram to get
// a file from the Internet, or pass "attach://<file_attach_name>" to
// upload a new one using multipart/form-data under <file_attach_name
// name.
Media *InputFile `json:"media"` Media *InputFile `json:"media"`
// Thumbnail of the file sent. The thumbnail should be in JPEG format and // Thumbnail of the file sent. The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnails width and height should not exceed 90. Ignored if the file is not uploaded using multipart/form-data. Thumbnails cant be reused and can be only uploaded as a new file, so you can pass "attach://<file_attach_name>" if the thumbnail was uploaded using multipart/form-data under <file_attach_name>.
// less than 200 kB in size. A thumbnails width and height should not
// exceed 90. Ignored if the file is not uploaded using
// multipart/form-data. Thumbnails cant be reused and can be only
// uploaded as a new file, so you can pass "attach://<file_attach_name>"
// if the thumbnail was uploaded using multipart/form-data under
// <file_attach_name>.
Thumb *InputFile `json:"thumb,omitempty"` Thumb *InputFile `json:"thumb,omitempty"`
// Caption of the animation to be sent, 0-200 characters // Caption of the animation to be sent, 0-200 characters
@ -1525,13 +1373,13 @@ func (m *InputMediaVideo) GetMedia() *InputFile { return m.Media }
func (InputMediaVideo) isAlbumMedia() {} func (InputMediaVideo) isAlbumMedia() {}
func (f *InputFile) IsFileID() bool { return f.ID != "" } func (f InputFile) IsFileID() bool { return f.ID != "" }
func (f *InputFile) IsURI() bool { return f.URI != nil } func (f InputFile) IsURI() bool { return f.URI != nil }
func (f *InputFile) IsAttachment() bool { return f.Attachment != nil } func (f InputFile) IsAttachment() bool { return f.Attachment != nil }
func (f *InputFile) MarshalJSON() ([]byte, error) { func (f InputFile) MarshalJSON() ([]byte, error) {
switch { switch {
case f.IsFileID(): case f.IsFileID():
return []byte(f.ID), nil return []byte(f.ID), nil

View File

@ -11,11 +11,7 @@ type (
// //
// At most one of the optional parameters can be present in any given update. // At most one of the optional parameters can be present in any given update.
Update struct { Update struct {
// The updates unique identifier. Update identifiers start from a // The updates unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if youre using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order.
// certain positive number and increase sequentially. This ID becomes
// especially handy if youre using Webhooks, since it allows you to
// ignore repeated updates or to restore the correct update sequence,
// should they get out of order.
UpdateID int `json:"update_id"` UpdateID int `json:"update_id"`
// New incoming message of any kind — text, photo, sticker, etc. // New incoming message of any kind — text, photo, sticker, etc.
@ -33,8 +29,7 @@ type (
// New incoming inline query // New incoming inline query
InlineQuery *InlineQuery `json:"inline_query,omitempty"` InlineQuery *InlineQuery `json:"inline_query,omitempty"`
// The result of an inline query that was chosen by a user and sent to // The result of an inline query that was chosen by a user and sent to their chat partner.
// their chat partner.
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"` ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
// New incoming callback query // New incoming callback query
@ -43,8 +38,7 @@ type (
// New incoming shipping query. Only for invoices with flexible price // New incoming shipping query. Only for invoices with flexible price
ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"` ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"`
// New incoming pre-checkout query. Contains full information about // New incoming pre-checkout query. Contains full information about checkout
// checkout
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"` PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"`
// New poll state. Bots receive only updates about polls, which are sent or stopped by the bot // New poll state. Bots receive only updates about polls, which are sent or stopped by the bot
@ -56,88 +50,62 @@ type (
// Webhook URL, may be empty if webhook is not set up // Webhook URL, may be empty if webhook is not set up
URL string `json:"url"` URL string `json:"url"`
// Error message in human-readable format for the most recent error that // Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook
// happened when trying to deliver an update via webhook
LastErrorMessage string `json:"last_error_message,omitempty"` LastErrorMessage string `json:"last_error_message,omitempty"`
// True, if a custom certificate was provided for webhook certificate // True, if a custom certificate was provided for webhook certificate checks
// checks
HasCustomCertificate bool `json:"has_custom_certificate"` HasCustomCertificate bool `json:"has_custom_certificate"`
// Number of updates awaiting delivery // Number of updates awaiting delivery
PendingUpdateCount int `json:"pending_update_count"` PendingUpdateCount int `json:"pending_update_count"`
// Maximum allowed number of simultaneous HTTPS connections to the // Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery
// webhook for update delivery
MaxConnections int `json:"max_connections,omitempty"` MaxConnections int `json:"max_connections,omitempty"`
// Unix time for the most recent error that happened when trying to // Unix time for the most recent error that happened when trying to deliver an update via webhook
// deliver an update via webhook
LastErrorDate int64 `json:"last_error_date,omitempty"` LastErrorDate int64 `json:"last_error_date,omitempty"`
// A list of update types the bot is subscribed to. Defaults to all // A list of update types the bot is subscribed to. Defaults to all update types
// update types
AllowedUpdates []string `json:"allowed_updates,omitempty"` AllowedUpdates []string `json:"allowed_updates,omitempty"`
} }
// GetUpdatesParameters represents data for GetUpdates method. // GetUpdatesParameters represents data for GetUpdates method.
GetUpdates struct { GetUpdates struct {
// Identifier of the first update to be returned. Must be greater by one than the highest among the // Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will forgotten.
// identifiers of previously received updates. By default, updates starting with the earliest unconfirmed
// update are returned. An update is considered confirmed as soon as getUpdates is called with an offset
// higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset
// update from the end of the updates queue. All previous updates will forgotten.
Offset int `json:"offset,omitempty"` Offset int `json:"offset,omitempty"`
// Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100. // Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100.
Limit int `json:"limit,omitempty"` Limit int `json:"limit,omitempty"`
// Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short // Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only.
// polling should be used for testing purposes only.
Timeout int `json:"timeout,omitempty"` Timeout int `json:"timeout,omitempty"`
// List the types of updates you want your bot to receive. For example, specify ["message", // List the types of updates you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used.
// "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete
// list of available update types. Specify an empty list to receive all updates regardless of type (default).
// If not specified, the previous setting will be used.
// //
// Please note that this parameter doesn't affect updates created before the call to the getUpdates, so // Please note that this parameter doesn't affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time.
// unwanted updates may be received for a short period of time.
AllowedUpdates []string `json:"allowed_updates,omitempty"` AllowedUpdates []string `json:"allowed_updates,omitempty"`
} }
// SetWebhookParameters represents data for SetWebhook method. // SetWebhookParameters represents data for SetWebhook method.
SetWebhook struct { SetWebhook struct {
// HTTPS url to send updates to. Use an empty string to remove webhook // HTTPS url to send updates to. Use an empty string to remove webhook integration
// integration
URL string `json:"url"` URL string `json:"url"`
// Upload your public key certificate so that the root certificate in use can // Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details.
// be checked. See our self-signed guide for details.
Certificate InputFile `json:"certificate,omitempty"` Certificate InputFile `json:"certificate,omitempty"`
// Maximum allowed number of simultaneous HTTPS connections to the webhook // Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bots server, and higher values to increase your bots throughput.
// for update delivery, 1-100. Defaults to 40. Use lower values to limit the
// load on your bots server, and higher values to increase your bots
// throughput.
MaxConnections int `json:"max_connections,omitempty"` MaxConnections int `json:"max_connections,omitempty"`
// List the types of updates you want your bot to receive. For example, // List the types of updates you want your bot to receive. For example, specify [“message”, “edited_channel_post”, “callback_query”] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all updates regardless of type (default). If not specified, the previous setting will be used.
// specify [“message”, “edited_channel_post”, “callback_query”] to only
// receive updates of these types. See Update for a complete list of
// available update types. Specify an empty list to receive all updates
// regardless of type (default). If not specified, the previous setting will
// be used.
// //
// Please note that this parameter doesn't affect updates created before the // Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time.
// call to the setWebhook, so unwanted updates may be received for a short
// period of time.
AllowedUpdates []string `json:"allowed_updates,omitempty"` AllowedUpdates []string `json:"allowed_updates,omitempty"`
} }
) )
// GetUpdates receive incoming updates using long polling. An Array of Update objects is returned. // GetUpdates receive incoming updates using long polling. An Array of Update objects is returned.
func (b *Bot) GetUpdates(p *GetUpdates) ([]*Update, error) { func (b Bot) GetUpdates(p *GetUpdates) ([]*Update, error) {
src, err := b.Do(MethodGetUpdates, p) src, err := b.Do(MethodGetUpdates, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -159,7 +127,7 @@ func (b *Bot) GetUpdates(p *GetUpdates) ([]*Update, error) {
// SetWebhook specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns true. // SetWebhook specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns true.
// //
// If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bots token, you can be pretty sure its us. // If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bots token, you can be pretty sure its us.
func (b *Bot) SetWebhook(p SetWebhook) (bool, error) { func (b Bot) SetWebhook(p SetWebhook) (bool, error) {
// TODO(toby3d) // TODO(toby3d)
// if p.Certificate != nil { // if p.Certificate != nil {
// src, err = b.Upload(MethodSetWebhook, "certificate", "cert.pem", params.Certificate, args) // src, err = b.Upload(MethodSetWebhook, "certificate", "cert.pem", params.Certificate, args)
@ -183,7 +151,7 @@ func (b *Bot) SetWebhook(p SetWebhook) (bool, error) {
} }
// DeleteWebhook remove webhook integration if you decide to switch back to getUpdates. Returns True on success. Requires no parameters. // DeleteWebhook remove webhook integration if you decide to switch back to getUpdates. Returns True on success. Requires no parameters.
func (b *Bot) DeleteWebhook() (bool, error) { func (b Bot) DeleteWebhook() (bool, error) {
src, err := b.Do(MethodDeleteWebhook, nil) src, err := b.Do(MethodDeleteWebhook, nil)
if err != nil { if err != nil {
return false, err return false, err
@ -203,7 +171,7 @@ func (b *Bot) DeleteWebhook() (bool, error) {
} }
// GetWebhookInfo get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty. // GetWebhookInfo get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.
func (b *Bot) GetWebhookInfo() (*WebhookInfo, error) { func (b Bot) GetWebhookInfo() (*WebhookInfo, error) {
src, err := b.Do(MethodGetWebhookInfo, nil) src, err := b.Do(MethodGetWebhookInfo, nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -280,17 +248,17 @@ func (u Update) Type() string {
} }
} }
func (wi WebhookInfo) LastErrorTime() time.Time { return time.Unix(wi.LastErrorDate, 0) } func (w WebhookInfo) LastErrorTime() time.Time { return time.Unix(w.LastErrorDate, 0) }
func (wi WebhookInfo) HasURL() bool { return wi.URL != "" } func (w WebhookInfo) HasURL() bool { return w.URL != "" }
func (wi WebhookInfo) URI() *http.URI { func (w WebhookInfo) URI() *http.URI {
if !wi.HasURL() { if !w.HasURL() {
return nil return nil
} }
u := http.AcquireURI() u := http.AcquireURI()
u.Update(wi.URL) u.Update(w.URL)
return u return u
} }

View File

@ -3,24 +3,19 @@ package telegram
type ( type (
// EditMessageTextParameters represents data for EditMessageText method. // EditMessageTextParameters represents data for EditMessageText method.
EditMessageText struct { EditMessageText struct {
// Required if inline_message_id is not specified. Unique identifier for the // Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// target chat or username of the target channel (in the format
// @channelusername)
ChatID int64 `json:"chat_id,omitempty"` ChatID int64 `json:"chat_id,omitempty"`
// Required if inline_message_id is not specified. Identifier of the sent // Required if inline_message_id is not specified. Identifier of the sent message
// message
MessageID int `json:"message_id,omitempty"` MessageID int `json:"message_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the // Required if chat_id and message_id are not specified. Identifier of the inline message
// inline message
InlineMessageID string `json:"inline_message_id,omitempty"` InlineMessageID string `json:"inline_message_id,omitempty"`
// New text of the message // New text of the message
Text string `json:"text"` Text string `json:"text"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
// fixed-width text or inline URLs in your bot's message.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// Disables link previews for links in this message // Disables link previews for links in this message
@ -32,24 +27,19 @@ type (
// EditMessageCaptionParameters represents data for EditMessageCaption method. // EditMessageCaptionParameters represents data for EditMessageCaption method.
EditMessageCaption struct { EditMessageCaption struct {
// Required if inline_message_id is not specified. Unique identifier for the // Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// target chat or username of the target channel (in the format
// @channelusername)
ChatID int64 `json:"chat_id,omitempty"` ChatID int64 `json:"chat_id,omitempty"`
// Required if inline_message_id is not specified. Identifier of // Required if inline_message_id is not specified. Identifier of the sent message
// the sent message
MessageID int `json:"message_id,omitempty"` MessageID int `json:"message_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the // Required if chat_id and message_id are not specified. Identifier of the inline message
// inline message
InlineMessageID string `json:"inline_message_id,omitempty"` InlineMessageID string `json:"inline_message_id,omitempty"`
// New caption of the message // New caption of the message
Caption string `json:"caption,omitempty"` Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, // Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
// fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"` ParseMode string `json:"parse_mode,omitempty"`
// A JSON-serialized object for an inline keyboard. // A JSON-serialized object for an inline keyboard.
@ -76,17 +66,13 @@ type (
// EditMessageReplyMarkupParameters represents data for EditMessageReplyMarkup method. // EditMessageReplyMarkupParameters represents data for EditMessageReplyMarkup method.
EditMessageReplyMarkup struct { EditMessageReplyMarkup struct {
// Required if inline_message_id is not specified. Unique identifier for the // Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
// target chat or username of the target channel (in the format
// @channelusername)
ChatID int64 `json:"chat_id,omitempty"` ChatID int64 `json:"chat_id,omitempty"`
// Required if inline_message_id is not specified. Identifier of the sent // Required if inline_message_id is not specified. Identifier of the sent message
// message
MessageID int `json:"message_id,omitempty"` MessageID int `json:"message_id,omitempty"`
// Required if chat_id and message_id are not specified. Identifier of the // Required if chat_id and message_id are not specified. Identifier of the inline message
// inline message
InlineMessageID string `json:"inline_message_id,omitempty"` InlineMessageID string `json:"inline_message_id,omitempty"`
// A JSON-serialized object for an inline keyboard. // A JSON-serialized object for an inline keyboard.
@ -114,10 +100,8 @@ type (
} }
) )
// EditMessageText edit text and game messages sent by the bot or via the bot // EditMessageText edit text and game messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
// (for inline bots). On success, if edited message is sent by the bot, the func (b Bot) EditMessageText(p *EditMessageText) (*Message, error) {
// edited Message is returned, otherwise True is returned.
func (b *Bot) EditMessageText(p *EditMessageText) (*Message, error) {
src, err := b.Do(MethodEditMessageText, p) src, err := b.Do(MethodEditMessageText, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -136,10 +120,8 @@ func (b *Bot) EditMessageText(p *EditMessageText) (*Message, error) {
return result, nil return result, nil
} }
// EditMessageCaption edit captions of messages sent by the bot or via the bot // EditMessageCaption edit captions of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
// (for inline bots). On success, if edited message is sent by the bot, the func (b Bot) EditMessageCaption(p *EditMessageCaption) (*Message, error) {
// edited Message is returned, otherwise True is returned.
func (b *Bot) EditMessageCaption(p *EditMessageCaption) (*Message, error) {
src, err := b.Do(MethodEditMessageCaption, p) src, err := b.Do(MethodEditMessageCaption, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -158,13 +140,8 @@ func (b *Bot) EditMessageCaption(p *EditMessageCaption) (*Message, error) {
return result, nil return result, nil
} }
// EditMessageMedia edit audio, document, photo, or video messages. If a message // EditMessageMedia edit audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. Use previously uploaded file via its file_id or specify a URL. On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned.
// is a part of a message album, then it can be edited only to a photo or a video. func (b Bot) EditMessageMedia(p EditMessageMedia) (*Message, error) {
// Otherwise, message type can be changed arbitrarily. When inline message is
// edited, new file can't be uploaded. Use previously uploaded file via its
// file_id or specify a URL. On success, if the edited message was sent by the
// bot, the edited Message is returned, otherwise True is returned.
func (b *Bot) EditMessageMedia(p EditMessageMedia) (*Message, error) {
src, err := b.Do(MethodEditMessageMedia, p) src, err := b.Do(MethodEditMessageMedia, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -183,10 +160,8 @@ func (b *Bot) EditMessageMedia(p EditMessageMedia) (*Message, error) {
return result, nil return result, nil
} }
// EditMessageReplyMarkup edit only the reply markup of messages sent by the bot // EditMessageReplyMarkup edit only the reply markup of messages sent by the bot or via the bot (for inline bots). On success, if edited message is sent by the bot, the edited Message is returned, otherwise True is returned.
// or via the bot (for inline bots). On success, if edited message is sent by the func (b Bot) EditMessageReplyMarkup(p EditMessageReplyMarkup) (*Message, error) {
// bot, the edited Message is returned, otherwise True is returned.
func (b *Bot) EditMessageReplyMarkup(p EditMessageReplyMarkup) (*Message, error) {
src, err := b.Do(MethodEditMessageReplyMarkup, p) src, err := b.Do(MethodEditMessageReplyMarkup, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -205,7 +180,8 @@ func (b *Bot) EditMessageReplyMarkup(p EditMessageReplyMarkup) (*Message, error)
return result, nil return result, nil
} }
func (b *Bot) StopPoll(p StopPoll) (*Poll, error) { // StopPoll stop a poll which was sent by the bot. On success, the stopped Poll with the final results is returned.
func (b Bot) StopPoll(p StopPoll) (*Poll, error) {
src, err := b.Do(MethodStopPoll, p) src, err := b.Do(MethodStopPoll, p)
if err != nil { if err != nil {
return nil, err return nil, err
@ -234,11 +210,8 @@ func (b *Bot) StopPoll(p StopPoll) (*Poll, error) {
// - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there. // - If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.
// //
// Returns True on success. // Returns True on success.
func (b *Bot) DeleteMessage(chatID int64, messageID int) (bool, error) { func (b Bot) DeleteMessage(cid int64, mid int) (bool, error) {
src, err := b.Do(MethodDeleteMessage, DeleteMessage{ src, err := b.Do(MethodDeleteMessage, DeleteMessage{ChatID: cid, MessageID: mid})
ChatID: chatID,
MessageID: messageID,
})
if err != nil { if err != nil {
return false, err return false, err
} }