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

View File

@ -1,8 +1,7 @@
package telegram
type (
// Game represents a game. Use BotFather to create and edit games, their short names will act as unique
// identifiers.
// Game represents a game. Use BotFather to create and edit games, their short names will act as unique identifiers.
Game struct {
// Title of the game
Title string `json:"title"`
@ -10,9 +9,7 @@ type (
// Description of the game
Description string `json:"description"`
// 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.
// 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.
Text string `json:"text,omitempty"`
// Photo that will be displayed in the game message in chats.
@ -45,8 +42,7 @@ type (
// Unique identifier for the target chat
ChatID int64 `json:"chat_id"`
// Short name of the game, serves as the unique identifier for the game. Set up your games via
// Botfather.
// Short name of the game, serves as the unique identifier for the game. Set up your games via Botfather.
GameShortName string `json:"game_short_name"`
// 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.
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
// shown. If not empty, the first button must launch the game.
// 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.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
@ -71,8 +66,7 @@ type (
// Required if inline_message_id is not specified. Identifier of the sent message
MessageID int `json:"message_id,omitempty"`
// Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or
// banning cheaters
// Pass True, if the high score is allowed to decrease. This can be useful when fixing mistakes or banning cheaters
Force bool `json:"force,omitempty"`
// 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.
func (b *Bot) SendGame(p SendGame) (*Message, error) {
func (b Bot) SendGame(p SendGame) (*Message, error) {
src, err := b.Do(MethodSendGame, p)
if err != nil {
return nil, err
@ -121,10 +115,8 @@ func (b *Bot) SendGame(p SendGame) (*Message, error) {
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
// 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.
func (b *Bot) SetGameScore(p SetGameScore) (*Message, error) {
// 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.
func (b Bot) SetGameScore(p SetGameScore) (*Message, error) {
src, err := b.Do(MethodSetGameScore, p)
if err != nil {
return nil, err
@ -143,9 +135,8 @@ func (b *Bot) SetGameScore(p SetGameScore) (*Message, error) {
return result, nil
}
// 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.
func (b *Bot) GetGameHighScores(p GetGameHighScores) ([]*GameHighScore, error) {
// 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.
func (b Bot) GetGameHighScores(p GetGameHighScores) ([]*GameHighScore, error) {
src, err := b.Do(MethodGetGameHighScores, p)
if err != nil {
return nil, err

199
inline.go
View File

@ -60,10 +60,7 @@ type (
ThumbHeight int `json:"thumb_height,omitempty"`
}
// 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.
// 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.
InlineQueryResultPhoto struct {
// Type of the result, must be photo
Type string `json:"type"`
@ -71,8 +68,7 @@ type (
// Unique identifier for this result, 1-64 bytes
ID string `json:"id"`
// A valid URL of the photo. Photo must be in jpeg format. Photo size
// must not exceed 5MB
// A valid URL of the photo. Photo must be in jpeg format. Photo size must not exceed 5MB
PhotoURL string `json:"photo_url"`
// URL of the thumbnail for the photo
@ -87,8 +83,7 @@ type (
// Caption of the photo to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Width of the photo
@ -104,10 +99,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultGif struct {
// Type of the result, must be gif
Type string `json:"type"`
@ -127,8 +119,7 @@ type (
// Caption of the GIF file to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Width of the GIF
@ -147,11 +138,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultMpeg4Gif struct {
// Type of the result, must be mpeg4_gif
Type string `json:"type"`
@ -187,14 +174,9 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
//
// If an InlineQueryResultVideo message contains an embedded video (e.g.,
// YouTube), you must replace its content using input_message_content.
// If an InlineQueryResultVideo message contains an embedded video (e.g., YouTube), you must replace its content using input_message_content.
InlineQueryResultVideo struct {
// Type of the result, must be video
Type string `json:"type"`
@ -217,8 +199,7 @@ type (
// Caption of the video to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Short description of the result
@ -236,16 +217,11 @@ type (
// Inline keyboard attached to the message
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
// 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).
// 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).
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultAudio struct {
// Type of the result, must be audio
Type string `json:"type"`
@ -262,8 +238,7 @@ type (
// Caption, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Performer
@ -279,10 +254,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultVoice struct {
// Type of the result, must be voice
Type string `json:"type"`
@ -299,8 +271,7 @@ type (
// Caption, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Recording duration in seconds
@ -313,11 +284,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultDocument struct {
// Type of the result, must be document
Type string `json:"type"`
@ -331,15 +298,13 @@ type (
// Caption of the document to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// A valid URL for the file
DocumentURL string `json:"document_url"`
// Mime type of the content of the file, either "application/pdf" or
// "application/zip"
// Mime type of the content of the file, either "application/pdf" or "application/zip"
MimeType string `json:"mime_type"`
// Short description of the result
@ -361,10 +326,7 @@ type (
ThumbHeight int `json:"thumb_height,omitempty"`
}
// 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.
// 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.
InlineQueryResultLocation struct {
// Type of the result, must be location
Type string `json:"type"`
@ -397,9 +359,7 @@ type (
ThumbHeight int `json:"thumb_height,omitempty"`
}
// 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.
// 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.
InlineQueryResultVenue struct {
// Type of the result, must be venue
Type string `json:"type"`
@ -416,9 +376,7 @@ type (
// Foursquare identifier of the venue if known
FoursquareID string `json:"foursquare_id,omitempty"`
// Foursquare type of the venue, if known. (For example,
// "arts_entertainment/default", "arts_entertainment/aquarium" or
// "food/icecream".)
// Foursquare type of the venue, if known. (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".)
FoursquareType string `json:"foursquare_type,omitempty"`
// Url of the thumbnail for the result
@ -443,10 +401,7 @@ type (
ThumbHeight int `json:"thumb_height,omitempty"`
}
// 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.
// 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.
InlineQueryResultContact struct {
// Type of the result, must be contact
Type string `json:"type"`
@ -497,10 +452,7 @@ type (
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// 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.
// 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.
InlineQueryResultCachedPhoto struct {
// Type of the result, must be photo
Type string `json:"type"`
@ -520,8 +472,7 @@ type (
// Caption of the photo to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message
@ -531,11 +482,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultCachedGif struct {
// Type of the result, must be gif
Type string `json:"type"`
@ -552,8 +499,7 @@ type (
// Caption of the GIF file to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message
@ -563,11 +509,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultCachedMpeg4Gif struct {
// Type of the result, must be mpeg4_gif
Type string `json:"type"`
@ -584,8 +526,7 @@ type (
// Caption of the MPEG-4 file to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message
@ -595,10 +536,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultCachedSticker struct {
// Type of the result, must be sticker
Type string `json:"type"`
@ -616,10 +554,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultCachedDocument struct {
// Type of the result, must be document
Type string `json:"type"`
@ -639,8 +574,7 @@ type (
// Caption of the document to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message
@ -650,11 +584,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultCachedVideo struct {
// Type of the result, must be video
Type string `json:"type"`
@ -674,8 +604,7 @@ type (
// Caption of the video to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message
@ -685,10 +614,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultCachedVoice struct {
// Type of the result, must be voice
Type string `json:"type"`
@ -705,8 +631,7 @@ type (
// Caption, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message
@ -716,10 +641,7 @@ type (
InputMessageContent InputMessageContent `json:"input_message_content,omitempty"`
}
// 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.
// 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.
InlineQueryResultCachedAudio struct {
// Type of the result, must be audio
Type string `json:"type"`
@ -733,8 +655,7 @@ type (
// Caption, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Inline keyboard attached to the message
@ -749,22 +670,19 @@ type (
isInputMessageContent()
}
// InputTextMessageContent represents the content of a text message to be
// sent as the result of an inline query.
// InputTextMessageContent represents the content of a text message to be sent as the result of an inline query.
InputTextMessageContent struct {
// Text of the message to be sent, 1-4096 characters
MessageText string `json:"message_text"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in your bot's message.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
ParseMode string `json:"parse_mode,omitempty"`
// Disables link previews for links in the sent message
DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
}
// InputLocationMessageContent represents the content of a location message
// to be sent as the result of an inline query.
// InputLocationMessageContent represents the content of a location message to be sent as the result of an inline query.
InputLocationMessageContent struct {
// Latitude of the location in degrees
Latitude float32 `json:"latitude"`
@ -776,8 +694,7 @@ type (
LivePeriod int `json:"live_period,omitempty"`
}
// InputVenueMessageContent represents the content of a venue message to be
// sent as the result of an inline query.
// InputVenueMessageContent represents the content of a venue message to be sent as the result of an inline query.
InputVenueMessageContent struct {
// Latitude of the location in degrees
Latitude float32 `json:"latitude"`
@ -794,14 +711,11 @@ type (
// Foursquare identifier of the venue, if known
FoursquareID string `json:"foursquare_id,omitempty"`
// Foursquare type of the venue, if known. (For example,
// "arts_entertainment/default", "arts_entertainment/aquarium" or
// "food/icecream".)
// Foursquare type of the venue, if known. (For example, "arts_entertainment/default", "arts_entertainment/aquarium" or "food/icecream".)
FoursquareType string `json:"foursquare_type,omitempty"`
}
// InputContactMessageContent represents the content of a contact message to
// be sent as the result of an inline query.
// InputContactMessageContent represents the content of a contact message to be sent as the result of an inline query.
InputContactMessageContent struct {
// Contact's phone number
PhoneNumber string `json:"phone_number"`
@ -816,15 +730,12 @@ type (
VCard string `json:"vcard,omitempty"`
}
// ChosenInlineResult represents a result of an inline query that was chosen
// by the user and sent to their chat partner.
// ChosenInlineResult represents a result of an inline query that was chosen by the user and sent to their chat partner.
ChosenInlineResult struct {
// The unique identifier for the result that was chosen
ResultID string `json:"result_id"`
// 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.
// 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.
InlineMessageID string `json:"inline_message_id,omitempty"`
// The query that was used to obtain the result
@ -842,32 +753,22 @@ type (
// Unique identifier for the answered query
InlineQueryID string `json:"inline_query_id"`
// 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.
// 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.
NextOffset string `json:"next_offset,omitempty"`
// 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
// 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
SwitchPrivateMessageText string `json:"switch_pm_text,omitempty"`
// 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.
// 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.
SwitchPrivateMessageParameter string `json:"switch_pm_parameter,omitempty"`
// A JSON-serialized array of results for the inline query
Results []InlineQueryResult `json:"results"`
// The maximum amount of time in seconds that the result of the inline query
// may be cached on the server. Defaults to 300.
// The maximum amount of time in seconds that the result of the inline query may be cached on the server. Defaults to 300.
CacheTime int `json:"cache_time,omitempty"`
// 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
// 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
IsPersonal bool `json:"is_personal,omitempty"`
}
@ -879,7 +780,7 @@ type (
// AnswerInlineQuery send answers to an inline query. On success, True is returned.
//
// 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)
if err != nil {
return false, err

View File

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

View File

@ -44,12 +44,12 @@ func NewWidget(accessToken string) *Widget {
// received by comparing the received hash parameter with the hexadecimal
// 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.
func (w *Widget) CheckAuthorization(u User) (bool, error) {
func (w Widget) CheckAuthorization(u User) (bool, error) {
hash, err := w.GenerateHash(u)
return hash == u.Hash, err
}
func (w *Widget) GenerateHash(u User) (string, error) {
func (w Widget) GenerateHash(u User) (string, error) {
a := http.AcquireArgs()
defer http.ReleaseArgs(a)

View File

@ -1,12 +1,10 @@
package login
import (
"time"
)
import "time"
// FullName return user first name only or full name if last name is present.
func (u *User) FullName() string {
if u == nil || u.FirstName == "" {
func (u User) FullName() string {
if u.FirstName == "" {
return ""
}
@ -19,8 +17,8 @@ func (u *User) FullName() string {
}
// AuthTime convert AuthDate field into time.Time.
func (u *User) AuthTime() time.Time {
if u == nil || u.AuthDate == 0 {
func (u User) AuthTime() time.Time {
if u.AuthDate == 0 {
return time.Time{}
}
@ -28,16 +26,10 @@ func (u *User) AuthTime() time.Time {
}
// HasLastName checks what the current user has a LastName.
func (u *User) HasLastName() bool {
return u != nil && u.LastName != ""
}
func (u User) HasLastName() bool { return u.LastName != "" }
// HasUsername checks what the current user has a username.
func (u *User) HasUsername() bool {
return u != nil && u.Username != ""
}
func (u User) HasUsername() bool { return u.Username != "" }
// HasPhoto checks what the current user has a photo.
func (u *User) HasPhoto() bool {
return u != nil && u.PhotoURL != ""
}
func (u User) HasPhoto() bool { return 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.
func (b *Bot) GetMe() (*User, error) {
func (b Bot) GetMe() (*User, error) {
src, err := b.Do(MethodGetMe, nil)
if err != nil {
return nil, err
@ -680,7 +680,7 @@ func (b *Bot) GetMe() (*User, error) {
}
// 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)
if err != nil {
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.
func (b *Bot) ForwardMessage(p ForwardMessage) (*Message, error) {
func (b Bot) ForwardMessage(p ForwardMessage) (*Message, error) {
src, err := b.Do(MethodForwardMessage, p)
if err != nil {
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.
func (b *Bot) SendPhoto(p SendPhoto) (*Message, error) {
func (b Bot) SendPhoto(p SendPhoto) (*Message, error) {
params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
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.
//
// 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["chat_id"] = strconv.FormatInt(p.ChatID, 10)
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.
func (b *Bot) SendDocument(p SendDocument) (*Message, error) {
func (b Bot) SendDocument(p SendDocument) (*Message, error) {
params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
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.
func (b *Bot) SendVideo(p SendVideo) (*Message, error) {
func (b Bot) SendVideo(p SendVideo) (*Message, error) {
params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
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.
func (b *Bot) SendAnimation(p SendAnimation) (*Message, error) {
func (b Bot) SendAnimation(p SendAnimation) (*Message, error) {
params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
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.
func (b *Bot) SendVoice(p SendVoice) (*Message, error) {
func (b Bot) SendVoice(p SendVoice) (*Message, error) {
params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
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.
func (b *Bot) SendVideoNote(p SendVideoNote) (*Message, error) {
func (b Bot) SendVideoNote(p SendVideoNote) (*Message, error) {
params := make(map[string]string)
params["chat_id"] = strconv.FormatInt(p.ChatID, 10)
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.
func (b *Bot) SendMediaGroup(p SendMediaGroup) ([]*Message, error) {
func (b Bot) SendMediaGroup(p SendMediaGroup) ([]*Message, error) {
media := make([]string, len(p.Media), 10)
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.
func (b *Bot) SendLocation(p SendLocation) (*Message, error) {
func (b Bot) SendLocation(p SendLocation) (*Message, error) {
src, err := b.Do(MethodSendLocation, p)
if err != nil {
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.
func (b *Bot) EditMessageLiveLocation(p *EditMessageLiveLocation) (*Message, bool, error) {
func (b Bot) EditMessageLiveLocation(p EditMessageLiveLocation) (*Message, bool, error) {
src, err := b.Do(MethodEditMessageLiveLocation, p)
if err != nil {
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.
func (b *Bot) StopMessageLiveLocation(p StopMessageLiveLocation) (*Message, bool, error) {
func (b Bot) StopMessageLiveLocation(p StopMessageLiveLocation) (*Message, bool, error) {
src, err := b.Do(MethodStopMessageLiveLocation, p)
if err != nil {
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.
func (b *Bot) SendVenue(p SendVenue) (*Message, error) {
func (b Bot) SendVenue(p SendVenue) (*Message, error) {
src, err := b.Do(MethodSendVenue, p)
if err != nil {
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.
func (b *Bot) SendContact(p SendContact) (*Message, error) {
func (b Bot) SendContact(p SendContact) (*Message, error) {
src, err := b.Do(MethodSendContact, p)
if err != nil {
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.
func (b *Bot) SendPoll(p SendPoll) (*Message, error) {
func (b Bot) SendPoll(p SendPoll) (*Message, error) {
src, err := b.Do(MethodSendPoll, p)
if err != nil {
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.
//
// 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) {
src, err := b.Do(MethodSendChatAction, SendChatAction{
ChatID: chatID, Action: action,
})
func (b Bot) SendChatAction(cid int64, action string) (bool, error) {
src, err := b.Do(MethodSendChatAction, SendChatAction{ChatID: cid, Action: action})
if err != nil {
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.
func (b *Bot) GetUserProfilePhotos(p GetUserProfilePhotos) (*UserProfilePhotos, error) {
func (b Bot) GetUserProfilePhotos(p GetUserProfilePhotos) (*UserProfilePhotos, error) {
src, err := b.Do(MethodGetUserProfilePhotos, p)
if err != nil {
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.
//
// 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) {
src, err := b.Do(MethodGetFile, GetFile{FileID: fileID})
func (b Bot) GetFile(fid string) (*File, error) {
src, err := b.Do(MethodGetFile, GetFile{FileID: fid})
if err != nil {
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.
//
// 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)
if err != nil {
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.
func (b *Bot) UnbanChatMember(chatID int64, userID int) (bool, error) {
src, err := b.Do(MethodUnbanChatMember, UnbanChatMember{
ChatID: chatID, UserID: userID,
})
func (b Bot) UnbanChatMember(cid int64, uid int) (bool, error) {
src, err := b.Do(MethodUnbanChatMember, UnbanChatMember{ChatID: cid, UserID: uid})
if err != nil {
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.
func (b *Bot) RestrictChatMember(p RestrictChatMember) (bool, error) {
func (b Bot) RestrictChatMember(p RestrictChatMember) (bool, error) {
src, err := b.Do(MethodRestrictChatMember, p)
if err != nil {
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.
func (b *Bot) PromoteChatMember(p PromoteChatMember) (bool, error) {
func (b Bot) PromoteChatMember(p PromoteChatMember) (bool, error) {
src, err := b.Do(MethodPromoteChatMember, p)
if err != nil {
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.
func (b *Bot) SetChatAdministratorCustomTitle(p SetChatAdministratorCustomTitle) (bool, error) {
func (b Bot) SetChatAdministratorCustomTitle(p SetChatAdministratorCustomTitle) (bool, error) {
src, err := b.Do(MethodSetChatAdministratorCustomTitle, p)
if err != nil {
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.
func (b *Bot) SetChatPermissions(p SetChatPermissions) (bool, error) {
func (b Bot) SetChatPermissions(p SetChatPermissions) (bool, error) {
src, err := b.Do(MethodSetChatPermissions, p)
if err != nil {
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.
func (b *Bot) ExportChatInviteLink(chatID int64) (string, error) {
src, err := b.Do(MethodExportChatInviteLink, ExportChatInviteLink{ChatID: chatID})
func (b Bot) ExportChatInviteLink(cid int64) (string, error) {
src, err := b.Do(MethodExportChatInviteLink, ExportChatInviteLink{ChatID: cid})
if err != nil {
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.
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["chat_id"] = strconv.FormatInt(chatID, 10)
params["chat_id"] = strconv.FormatInt(cid, 10)
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
}
files := make([]*InputFile, 0)
if chatPhoto.IsAttachment() {
files = append(files, chatPhoto)
if photo.IsAttachment() {
files = append(files, photo)
}
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.
func (b *Bot) DeleteChatPhoto(chatID int64) (bool, error) {
src, err := b.Do(MethodDeleteChatPhoto, DeleteChatPhoto{ChatID: chatID})
func (b Bot) DeleteChatPhoto(cid int64) (bool, error) {
src, err := b.Do(MethodDeleteChatPhoto, DeleteChatPhoto{ChatID: cid})
if err != nil {
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.
func (b *Bot) SetChatTitle(chatID int64, title string) (bool, error) {
src, err := b.Do(MethodSetChatTitle, SetChatTitle{
ChatID: chatID, Title: title,
})
func (b Bot) SetChatTitle(cid int64, title string) (bool, error) {
src, err := b.Do(MethodSetChatTitle, SetChatTitle{ChatID: cid, Title: title})
if err != nil {
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.
func (b *Bot) SetChatDescription(chatID int64, description string) (bool, error) {
src, err := b.Do(MethodSetChatDescription, SetChatDescription{
ChatID: chatID, Description: description,
})
func (b Bot) SetChatDescription(cid int64, txt string) (bool, error) {
src, err := b.Do(MethodSetChatDescription, SetChatDescription{ChatID: cid, Description: txt})
if err != nil {
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.
func (b *Bot) PinChatMessage(p *PinChatMessage) (bool, error) {
func (b Bot) PinChatMessage(p PinChatMessage) (bool, error) {
src, err := b.Do(MethodPinChatMessage, p)
if err != nil {
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.
func (b *Bot) UnpinChatMessage(chatID int64) (bool, error) {
src, err := b.Do(MethodUnpinChatMessage, UnpinChatMessage{ChatID: chatID})
func (b Bot) UnpinChatMessage(cid int64) (bool, error) {
src, err := b.Do(MethodUnpinChatMessage, UnpinChatMessage{ChatID: cid})
if err != nil {
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.
func (b *Bot) LeaveChat(chatID int64) (bool, error) {
src, err := b.Do(MethodLeaveChat, LeaveChat{ChatID: chatID})
func (b Bot) LeaveChat(cid int64) (bool, error) {
src, err := b.Do(MethodLeaveChat, LeaveChat{ChatID: cid})
if err != nil {
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.
func (b *Bot) GetChat(chatID int64) (*Chat, error) {
src, err := b.Do(MethodGetChat, GetChat{ChatID: chatID})
func (b Bot) GetChat(cid int64) (*Chat, error) {
src, err := b.Do(MethodGetChat, GetChat{ChatID: cid})
if err != nil {
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.
func (b *Bot) GetChatAdministrators(chatID int64) ([]*ChatMember, error) {
src, err := b.Do(MethodGetChatAdministrators, GetChatAdministrators{ChatID: chatID})
func (b Bot) GetChatAdministrators(cid int64) ([]*ChatMember, error) {
src, err := b.Do(MethodGetChatAdministrators, GetChatAdministrators{ChatID: cid})
if err != nil {
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.
func (b *Bot) GetChatMembersCount(chatID int64) (int, error) {
src, err := b.Do(MethodGetChatMembersCount, GetChatMembersCount{ChatID: chatID})
func (b Bot) GetChatMembersCount(cid int64) (int, error) {
src, err := b.Do(MethodGetChatMembersCount, GetChatMembersCount{ChatID: cid})
if err != nil {
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.
func (b *Bot) GetChatMember(chatID int64, userID int) (*ChatMember, error) {
src, err := b.Do(MethodGetChatMember, GetChatMember{
ChatID: chatID, UserID: userID,
})
func (b Bot) GetChatMember(cid int64, uid int) (*ChatMember, error) {
src, err := b.Do(MethodGetChatMember, GetChatMember{ChatID: cid, UserID: uid})
if err != nil {
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.
func (b *Bot) SetChatStickerSet(chatID int64, stickerSetName string) (bool, error) {
src, err := b.Do(MethodSetChatStickerSet, SetChatStickerSet{
ChatID: chatID, StickerSetName: stickerSetName,
})
func (b Bot) SetChatStickerSet(cid int64, name string) (bool, error) {
src, err := b.Do(MethodSetChatStickerSet, SetChatStickerSet{ChatID: cid, StickerSetName: name})
if err != nil {
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.
func (b *Bot) DeleteChatStickerSet(chatID int64) (bool, error) {
src, err := b.Do(MethodDeleteChatStickerSet, DeleteChatStickerSet{ChatID: chatID})
func (b Bot) DeleteChatStickerSet(cid int64) (bool, error) {
src, err := b.Do(MethodDeleteChatStickerSet, DeleteChatStickerSet{ChatID: cid})
if err != nil {
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.
func (b *Bot) AnswerCallbackQuery(p AnswerCallbackQuery) (bool, error) {
func (b Bot) AnswerCallbackQuery(p AnswerCallbackQuery) (bool, error) {
src, err := b.Do(MethodAnswerCallbackQuery, p)
if err != nil {
return false, err

View File

@ -14,20 +14,16 @@ import "errors"
*/
type (
// PassportData contains information about Telegram Passport data shared with
// the bot by the user.
// PassportData contains information about Telegram Passport data shared with the bot by the user.
PassportData struct {
// Array with information about documents and other Telegram Passport
// elements that was shared with the bot
// Array with information about documents and other Telegram Passport elements that was shared with the bot
Data []*EncryptedPassportElement `json:"data"`
// Encrypted credentials required to decrypt the data
Credentials *EncryptedCredentials `json:"credentials"`
}
// PassportFile represents a file uploaded to Telegram Passport. Currently all
// Telegram Passport files are in JPEG format when decrypted and don't exceed
// 10MB.
// PassportFile represents a file uploaded to Telegram Passport. Currently all Telegram Passport files are in JPEG format when decrypted and don't exceed 10MB.
PassportFile struct {
// Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"`
@ -42,17 +38,12 @@ type (
FileDate int `json:"file_date"`
}
// EncryptedPassportElement contains information about documents or other
// Telegram Passport elements shared with the bot by the user.
// EncryptedPassportElement contains information about documents or other Telegram Passport elements shared with the bot by the user.
EncryptedPassportElement struct {
// Element type.
Type string `json:"type"`
// 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.
// 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.
Data string `json:"data,omitempty"`
// 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
Email string `json:"email,omitempty"`
// 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.
// 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.
Files []*PassportFile `json:"files,omitempty"`
// 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.
// 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.
FrontSide *PassportFile `json:"front_side,omitempty"`
// 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.
// 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.
ReverseSide *PassportFile `json:"reverse_side,omitempty"`
// 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.
// 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.
Selfie *PassportFile `json:"selfie,omitempty"`
// 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.
// 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.
Translation []*PassportFile `json:"translation,omitempty"`
// Base64-encoded element hash for using in PassportElementErrorUnspecified
Hash string `json:"hash"`
}
// 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.
// 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.
EncryptedCredentials struct {
// Base64-encoded encrypted JSON-serialized data with unique user's
// payload, data hashes and secrets required for EncryptedPassportElement
// decryption and authentication
// Base64-encoded encrypted JSON-serialized data with unique user's payload, data hashes and secrets required for EncryptedPassportElement decryption and authentication
Data string `json:"data"`
// Base64-encoded data hash for data authentication
Hash string `json:"hash"`
// Base64-encoded secret, encrypted with the bot's public RSA key,
// required for data decryption
// Base64-encoded secret, encrypted with the bot's public RSA key, required for data decryption
Secret string `json:"secret"`
}
// PassportElementError represents an error in the Telegram Passport element
// which was submitted that should be resolved by the user.
// PassportElementError represents an error in the Telegram Passport element which was submitted that should be resolved by the user.
PassportElementError interface {
PassportElementErrorMessage() string
PassportElementErrorSource() string
PassportElementErrorType() string
}
// 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.
// 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.
PassportElementErrorDataField struct {
// Error source, must be data
Source string `json:"source"`
// The section of the user's Telegram Passport which has the error, one
// of "personal_details", "passport", "driver_license", "identity_card",
// "internal_passport", "address"
// The section of the user's Telegram Passport which has the error, one of "personal_details", "passport", "driver_license", "identity_card", "internal_passport", "address"
Type string `json:"type"`
// Name of the data field which has the error
@ -145,15 +108,12 @@ type (
Message string `json:"message"`
}
// 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.
// 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.
PassportElementErrorFrontSide struct {
// Error source, must be front_side
Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one
// of "passport", "driver_license", "identity_card", "internal_passport"
// The section of the user's Telegram Passport which has the issue, one of "passport", "driver_license", "identity_card", "internal_passport"
Type string `json:"type"`
// Base64-encoded hash of the file with the front side of the document
@ -163,15 +123,12 @@ type (
Message string `json:"message"`
}
// 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.
// 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.
PassportElementErrorReverseSide struct {
// Error source, must be reverse_side
Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one
// of "driver_license", "identity_card"
// The section of the user's Telegram Passport which has the issue, one of "driver_license", "identity_card"
Type string `json:"type"`
// Base64-encoded hash of the file with the reverse side of the document
@ -181,15 +138,12 @@ type (
Message string `json:"message"`
}
// PassportElementErrorSelfie represents an issue with the selfie with a
// document. The error is considered resolved when the file with the selfie
// changes.
// PassportElementErrorSelfie represents an issue with the selfie with a document. The error is considered resolved when the file with the selfie changes.
PassportElementErrorSelfie struct {
// Error source, must be selfie
Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one
// of "passport", "driver_license", "identity_card", "internal_passport"
// The section of the user's Telegram Passport which has the issue, one of "passport", "driver_license", "identity_card", "internal_passport"
Type string `json:"type"`
// Base64-encoded hash of the file with the selfie
@ -199,15 +153,12 @@ type (
Message string `json:"message"`
}
// PassportElementErrorFile represents an issue with a document scan. The
// error is considered resolved when the file with the document scan changes.
// PassportElementErrorFile represents an issue with a document scan. The error is considered resolved when the file with the document scan changes.
PassportElementErrorFile struct {
// Error source, must be file
Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one
// of "utility_bill", "bank_statement", "rental_agreement",
// "passport_registration", "temporary_registration"
// The section of the user's Telegram Passport which has the issue, one of "utility_bill", "bank_statement", "rental_agreement", "passport_registration", "temporary_registration"
Type string `json:"type"`
// Base64-encoded file hash
@ -217,16 +168,12 @@ type (
Message string `json:"message"`
}
// PassportElementErrorFiles represents an issue with a list of scans. The
// error is considered resolved when the list of files containing the scans
// changes.
// PassportElementErrorFiles represents an issue with a list of scans. The error is considered resolved when the list of files containing the scans changes.
PassportElementErrorFiles struct {
// Error source, must be files
Source string `json:"source"`
// The section of the user's Telegram Passport which has the issue, one
// of "utility_bill", "bank_statement", "rental_agreement",
// "passport_registration", "temporary_registration"
// The section of the user's Telegram Passport which has the issue, one of "utility_bill", "bank_statement", "rental_agreement", "passport_registration", "temporary_registration"
Type string `json:"type"`
// List of base64-encoded file hashes
@ -236,17 +183,12 @@ type (
Message string `json:"message"`
}
// 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.
// 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.
PassportElementErrorTranslationFile struct {
// Error source, must be translation_file
Source string `json:"source"`
// 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”
// 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”
Type string `json:"type"`
// Base64-encoded file hash
@ -256,17 +198,12 @@ type (
Message string `json:"message"`
}
// PassportElementErrorTranslationFiles represents an issue with the translated
// version of a document. The error is considered resolved when a file with the
// document translation change.
// PassportElementErrorTranslationFiles represents an issue with the translated version of a document. The error is considered resolved when a file with the document translation change.
PassportElementErrorTranslationFiles struct {
// Error source, must be translation_files
Source string `json:"source"`
// 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”
// 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”
Type string `json:"type"`
// List of base64-encoded file hashes
@ -276,8 +213,7 @@ type (
Message string `json:"message"`
}
// PassportElementErrorUnspecified represents an issue in an unspecified place.
// The error is considered resolved when new data is added.
// PassportElementErrorUnspecified represents an issue in an unspecified place. The error is considered resolved when new data is added.
PassportElementErrorUnspecified struct {
// Error source, must be unspecified
Source string `json:"source"`
@ -302,14 +238,10 @@ type (
// AuthParameters represent a Telegram Passport auth parameters for SDK.
Auth struct {
// 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.
// 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.
BotID int `json:"bot_id"`
// A JSON-serialized object describing the data you want to
// request
// A JSON-serialized object describing the data you want to request
Scope *PassportScope `json:"scope"`
// Public key of the bot
@ -317,19 +249,13 @@ type (
// Bot-specified nonce.
//
// 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.
// 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.
Nonce string `json:"nonce"`
}
// PassportScope represents the data to be requested.
PassportScope struct {
// List of requested elements, each type may be used only once
// in the entire array of PassportScopeElement objects
// List of requested elements, each type may be used only once in the entire array of PassportScopeElement objects
Data []*PassportScopeElement `json:"data"`
// Scope version, must be 1
@ -347,34 +273,25 @@ type (
// List of elements one of which must be provided;
OneOf []*PassportScopeElementOne `json:"one_of"`
// Use this parameter if you want to request a selfie with the
// document from this list that the user chooses to upload.
// Use this parameter if you want to request a selfie with the document from this list that the user chooses to upload.
Selfie bool `json:"selfie,omitempty"`
// 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.
// 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.
Translation bool `json:"translation,omitempty"`
}
// 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.
// 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.
PassportScopeElementOne struct {
// Element type.
Type string `json:"type"`
// Use this parameter if you want to request a selfie with the
// document as well.
// Use this parameter if you want to request a selfie with the document as well.
Selfie bool `json:"selfie,omitempty"`
// Use this parameter if you want to request a translation of
// the document as well.
// Use this parameter if you want to request a translation of the document as well.
Translation bool `json:"translation,omitempty"`
// Use this parameter to request the first, last and middle name
// of the user in the language of the user's country of residence.
// Use this parameter to request the first, last and middle name of the user in the language of the user's country of residence.
NativeNames bool `json:"native_names,omitempty"`
}
@ -532,8 +449,7 @@ type (
Nonce string `json:"nonce"`
}
// SecureData represents the credentials required to decrypt encrypted
// data. All fields are optional and depend on fields that were requested.
// SecureData represents the credentials required to decrypt encrypted data. All fields are optional and depend on fields that were requested.
SecureData struct {
// Credentials for encrypted personal details
PersonalDetails *SecureValue `json:"personal_details,omitempty"`
@ -569,9 +485,7 @@ type (
TemporaryRegistration *SecureValue `json:"temporary_registration,omitempty"`
}
// SecureValue represents the credentials required to decrypt encrypted
// values. All fields are optional and depend on the type of fields that
// were requested.
// SecureValue represents the credentials required to decrypt encrypted values. All fields are optional and depend on the type of fields that were requested.
SecureValue struct {
// Credentials for encrypted Telegram Passport data.
Data *DataCredentials `json:"data,omitempty"`
@ -592,8 +506,7 @@ type (
Files []*FileCredentials `json:"files,omitempty"`
}
// DataCredentials can be used to decrypt encrypted data from the data
// field in EncryptedPassportElement.
// DataCredentials can be used to decrypt encrypted data from the data field in EncryptedPassportElement.
DataCredentials struct {
// Checksum of encrypted data
DataHash string `json:"data_hash"`
@ -602,9 +515,7 @@ type (
Secret string `json:"secret"`
}
// FileCredentials can be used to decrypt encrypted files from the
// front_side, reverse_side, selfie, files and translation fields in
// EncryptedPassportElement.
// FileCredentials can be used to decrypt encrypted files from the front_side, reverse_side, selfie, files and translation fields in EncryptedPassportElement.
FileCredentials struct {
// Checksum of encrypted file
FileHash string `json:"file_hash"`
@ -616,17 +527,10 @@ type (
var ErrNotEqual = errors.New("credentials hash and credentials data hash is not equal")
// 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.
// 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.
//
// 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.
func (b *Bot) SetPassportDataErrors(uid int, errors ...PassportElementError) (bool, error) {
// 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.
func (b Bot) SetPassportDataErrors(uid int, errors ...PassportElementError) (bool, error) {
src, err := b.Do(MethodSetPassportDataErrors, SetPassportDataErrors{
UserID: uid, Errors: errors,
})

View File

@ -6,11 +6,7 @@ type (
// Portion label
Label string `json:"label"`
// 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).
// 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).
Amount int `json:"amount"`
}
@ -29,11 +25,7 @@ type (
// Three-letter ISO 4217 currency code
Currency string `json:"currency"`
// 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).
// 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).
TotalAmount int `json:"total_amount"`
}
@ -102,11 +94,7 @@ type (
// Provider payment identifier
ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
// 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).
// 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).
TotalAmount int `json:"total_amount"`
// Order info provided by the user
@ -145,11 +133,7 @@ type (
// User who sent the query
From *User `json:"from"`
// 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).
// 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).
TotalAmount int `json:"total_amount"`
// Order info provided by the user
@ -167,32 +151,25 @@ type (
// Product description, 1-255 characters
Description string `json:"description"`
// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
// the user, use for your internal processes.
// Bot-defined invoice payload, 1-128 bytes. This will not be displayed to the user, use for your internal processes.
Payload string `json:"payload"`
// Payments provider token, obtained via Botfather
ProviderToken string `json:"provider_token"`
// Unique deep-linking parameter that can be used to generate this invoice
// when used as a start parameter
// Unique deep-linking parameter that can be used to generate this invoice when used as a start parameter
StartParameter string `json:"start_parameter"`
// Three-letter ISO 4217 currency code, see more on currencies
Currency string `json:"currency"`
// 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.
// 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.
ProviderData string `json:"provider_data,omitempty"`
// 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.
// 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.
PhotoURL string `json:"photo_url,omitempty"`
// Price breakdown, a list of components (e.g. product price, tax, discount,
// delivery cost, delivery tax, bonus, etc.)
// Price breakdown, a list of components (e.g. product price, tax, discount, delivery cost, delivery tax, bonus, etc.)
Prices []*LabeledPrice `json:"prices"`
// Photo size
@ -216,20 +193,16 @@ type (
// Pass True, if you require the user's email to complete the order
NeedEmail bool `json:"need_email,omitempty"`
// Pass True, if you require the user's shipping address to complete the
// order
// Pass True, if you require the user's shipping address to complete the order
NeedShippingAddress bool `json:"need_shipping_address,omitempty"`
// Pass True, if the final price depends on the shipping method
IsFlexible bool `json:"is_flexible,omitempty"`
// Sends the message silently. Users will receive a notification with no
// sound.
// Sends the message silently. Users will receive a notification with no sound.
DisableNotification bool `json:"disable_notification,omitempty"`
// 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.
// 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.
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
@ -238,44 +211,31 @@ type (
// Unique identifier for the query to be answered
ShippingQueryID string `json:"shipping_query_id"`
// 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.
// 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.
ErrorMessage string `json:"error_message,omitempty"`
// 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)
// 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)
Ok bool `json:"ok"`
// Required if ok is True. A JSON-serialized array of available shipping
// options.
// Required if ok is True. A JSON-serialized array of available shipping options.
ShippingOptions []*ShippingOption `json:"shipping_options,omitempty"`
}
// AnswerPreCheckoutQueryParameters represents data for AnswerPreCheckoutQuery
// method.
// AnswerPreCheckoutQueryParameters represents data for AnswerPreCheckoutQuery method.
AnswerPreCheckoutQuery struct {
// Unique identifier for the query to be answered
PreCheckoutQueryID string `json:"pre_checkout_query_id"`
// 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.
// 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.
ErrorMessage string `json:"error_message,omitempty"`
// 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.
// 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.
Ok bool `json:"ok"`
}
)
// 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)
if err != nil {
return nil, err
@ -296,10 +256,8 @@ func (b *Bot) SendInvoice(p SendInvoice) (*Message, error) {
// AnswerShippingQuery reply to shipping queries.
//
// 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.
func (b *Bot) AnswerShippingQuery(p AnswerShippingQuery) (bool, error) {
// 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.
func (b Bot) AnswerShippingQuery(p AnswerShippingQuery) (bool, error) {
src, err := b.Do(MethodAnswerShippingQuery, p)
if err != nil {
return false, err
@ -320,14 +278,10 @@ func (b *Bot) AnswerShippingQuery(p AnswerShippingQuery) (bool, error) {
// AnswerPreCheckoutQuery respond to such pre-checkout queries.
//
// 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.
// 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.
//
// Note: The Bot API must receive an answer within 10 seconds after the
// pre-checkout query was sent.
func (b *Bot) AnswerPreCheckoutQuery(p AnswerShippingQuery) (bool, error) {
// Note: The Bot API must receive an answer within 10 seconds after the pre-checkout query was sent.
func (b Bot) AnswerPreCheckoutQuery(p AnswerShippingQuery) (bool, error) {
src, err := b.Do(MethodAnswerPreCheckoutQuery, p)
if err != nil {
return false, err

View File

@ -97,9 +97,7 @@ type (
// User identifier of sticker file owner
UserID int `json:"user_id"`
// 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.
// 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.
PNGSticker *InputFile `json:"png_sticker"`
}
@ -107,22 +105,13 @@ type (
// User identifier of created sticker set owner
UserID int `json:"user_id"`
// 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.
// 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.
Name string `json:"name"`
// Sticker set title, 1-64 characters
Title string `json:"title"`
// Png image with the sticker, must be up to 512 kilobytes in size,
// dimensions must not exceed 512px, and either width or height must
// be exactly 512px. Pass a file_id as a String to send a file that
// already exists on the Telegram servers, pass an HTTP URL as a
// String for Telegram to get a file from the Internet, or upload
// a new one using multipart/form-data.
// Png image with the sticker, must be up to 512 kilobytes in size, dimensions must not exceed 512px, and either width or height must be exactly 512px. Pass a file_id as a String to send a file that already exists on the Telegram servers, pass an HTTP URL as a String for Telegram to get a file from the Internet, or upload a new one using multipart/form-data.
PNGSticker *InputFile `json:"png_sticker"`
// One or more emoji corresponding to the sticker
@ -131,8 +120,7 @@ type (
// Pass True, if a set of mask stickers should be created
ContainsMasks bool `json:"contains_masks,omitempty"`
// A JSON-serialized object for position where the mask should be
// placed on faces
// A JSON-serialized object for position where the mask should be placed on faces
MaskPosition *MaskPosition `json:"mask_position,omitempty"`
}
@ -170,7 +158,7 @@ type (
)
// 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)
if err != nil {
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.
func (b *Bot) GetStickerSet(name string) (*StickerSet, error) {
func (b Bot) GetStickerSet(name string) (*StickerSet, error) {
src, err := b.Do(MethodGetStickerSet, GetStickerSet{Name: name})
if err != nil {
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.
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["user_id"] = strconv.Itoa(userID)
params["user_id"] = strconv.Itoa(uid)
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
}
src, err := b.Upload(MethodUploadStickerFile, params, pngSticker)
src, err := b.Upload(MethodUploadStickerFile, params, sticker)
if err != nil {
return nil, err
}

328
types.go
View File

@ -47,8 +47,7 @@ type (
// Unique identifier for this chat.
ID int64 `json:"id"`
// Type of chat, can be either "private", "group", "supergroup" or
// "channel"
// Type of chat, can be either "private", "group", "supergroup" or "channel"
Type string `json:"type"`
// Title, for supergroups, channels and group chats
@ -69,8 +68,7 @@ type (
// Description, for groups, supergroups and channel chats. Returned only in getChat.
Description string `json:"description,omitempty"`
// Chat invite link, for supergroups and channel chats. Returned only in
// getChat.
// Chat invite link, for supergroups and channel chats. Returned only in getChat.
InviteLink string `json:"invite_link,omitempty"`
// 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.
StickerSetName string `json:"sticker_set_name,omitempty"`
// True, if the bot can change group the sticker set. Returned only in
// getChat.
// True, if the bot can change group the sticker set. Returned only in getChat.
CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"`
}
@ -107,29 +104,22 @@ type (
// For forwarded messages, sender of the original message
ForwardFrom *User `json:"forward_from,omitempty"`
// For messages forwarded from channels, information about the original
// channel
// For messages forwarded from channels, information about the original channel
ForwardFromChat *Chat `json:"forward_from_chat,omitempty"`
// For messages forwarded from channels, identifier of the original
// message in the channel
// For messages forwarded from channels, identifier of the original message in the channel
ForwardFromMessageID int `json:"forward_from_message_id,omitempty"`
// For messages forwarded from channels, signature of the post author if
// present
// For messages forwarded from channels, signature of the post author if present
ForwardSignature string `json:"forward_signature,omitempty"`
// Sender's name for messages forwarded from users who disallow adding a
// link to their account in forwarded messages
// Sender's name for messages forwarded from users who disallow adding a link to their account in forwarded messages
ForwardSenderName string `json:"forward_sender_name,omitempty"`
// For forwarded messages, date the original message was sent in Unix
// time
// For forwarded messages, date the original message was sent in Unix time
ForwardDate int64 `json:"forward_date,omitempty"`
// 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.
// 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.
ReplyToMessage *Message `json:"reply_to_message,omitempty"`
// Date the message was last edited in Unix time
@ -141,16 +131,13 @@ type (
// Signature of the post author for messages in channels
AuthorSignature string `json:"author_signature,omitempty"`
// For text messages, the actual UTF-8 text of the message, 0-4096
// characters.
// For text messages, the actual UTF-8 text of the message, 0-4096 characters.
Text string `json:"text,omitempty"`
// For text messages, special entities like usernames, URLs, bot
// commands, etc. that appear in the text
// For text messages, special entities like usernames, URLs, bot commands, etc. that appear in the text
Entities []*MessageEntity `json:"entities,omitempty"`
// For messages with a caption, special entities like usernames, URLs,
// bot commands, etc. that appear in the caption
// For messages with a caption, special entities like usernames, URLs, bot commands, etc. that appear in the caption
CaptionEntities []*MessageEntity `json:"caption_entities,omitempty"`
// Message is an audio file, information about the file
@ -159,9 +146,7 @@ type (
// Message is a general file, information about the file
Document *Document `json:"document,omitempty"`
// Message is an animation, information about the animation. For backward
// compatibility, when this field is set, the document field will also be
// set
// Message is an animation, information about the animation. For backward compatibility, when this field is set, the document field will also be set
Animation *Animation `json:"animation,omitempty"`
// Message is a game, information about the game.
@ -197,12 +182,10 @@ type (
// Message is a native poll, information about the poll
Poll *Poll `json:"poll,omitempty"`
// New members that were added to the group or supergroup and information
// about them (the bot itself may be one of these members)
// New members that were added to the group or supergroup and information about them (the bot itself may be one of these members)
NewChatMembers []*User `json:"new_chat_members,omitempty"`
// A member was removed from the group, information about them (this
// member may be the bot itself)
// A member was removed from the group, information about them (this member may be the bot itself)
LeftChatMember *User `json:"left_chat_member,omitempty"`
// A chat title was changed to this value
@ -217,38 +200,25 @@ type (
// Service message: the group has been created
GroupChatCreated bool `json:"group_chat_created,omitempty"`
// 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.
// 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.
SupergroupChatCreated bool `json:"supergroup_chat_created,omitempty"`
// 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.
// 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.
ChannelChatCreated bool `json:"channel_chat_created,omitempty"`
// The group has been migrated to a supergroup with the specified
// identifier.
// The group has been migrated to a supergroup with the specified identifier.
MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"`
// The supergroup has been migrated from a group with the specified
// identifier.
// The supergroup has been migrated from a group with the specified identifier.
MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"`
// 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.
// 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.
PinnedMessage *Message `json:"pinned_message,omitempty"`
// Message is an invoice for a payment, information about the invoice.
Invoice *Invoice `json:"invoice,omitempty"`
// Message is a service message about a successful payment, information
// about the payment.
// Message is a service message about a successful payment, information about the payment.
SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"`
// The domain name of the website on which the user has logged in.
@ -261,17 +231,12 @@ type (
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// MessageEntity represents one special entity in a text message. For
// example, hashtags, usernames, URLs, etc.
// MessageEntity represents one special entity in a text message. For example, hashtags, usernames, URLs, etc.
MessageEntity struct {
// 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)
// 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)
Type string `json:"type"`
// For "text_link" only, url that will be opened after user taps on the
// text
// For "text_link" only, url that will be opened after user taps on the text
URL string `json:"url,omitempty"`
// 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
FileID string `json:"file_id"`
// 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.
// 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.
FileUniqueID string `json:"file_unique_id"`
// Photo width
@ -303,8 +267,7 @@ type (
FileSize int `json:"file_size,omitempty"`
}
// Audio represents an audio file to be treated as music by the Telegram
// clients.
// Audio represents an audio file to be treated as music by the Telegram clients.
Audio struct {
// Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"`
@ -331,8 +294,7 @@ type (
Thumb *PhotoSize `json:"thumb,omitempty"`
}
// Document represents a general file (as opposed to photos, voice messages
// and audio files).
// Document represents a general file (as opposed to photos, voice messages and audio files).
Document struct {
// Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"`
@ -380,9 +342,7 @@ type (
FileSize int `json:"file_size,omitempty"`
}
// 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.
// 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.
Animation struct {
// Unique file identifier
FileID string `json:"file_id"`
@ -430,8 +390,7 @@ type (
FileSize int `json:"file_size,omitempty"`
}
// VideoNote represents a video message (available in Telegram apps as of
// v.4.0).
// VideoNote represents a video message (available in Telegram apps as of v.4.0).
VideoNote struct {
// Identifier for this file, which can be used to download or reuse the file
FileID string `json:"file_id"`
@ -530,10 +489,7 @@ type (
Photos [][]*PhotoSize `json:"photos"`
}
// 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.
// 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.
//
// Maximum file size to download is 20 MB
File struct {
@ -546,91 +502,57 @@ type (
// File size, if known
FileSize int `json:"file_size,omitempty"`
// File path. Use https://api.telegram.org/file/bot<token>/<file_path> to
// get the file.
// File path. Use https://api.telegram.org/file/bot<token>/<file_path> to get the file.
FilePath string `json:"file_path,omitempty"`
}
// ReplyKeyboardMarkup represents a custom keyboard with reply options (see
// Introduction to bots for details and examples).
// ReplyKeyboardMarkup represents a custom keyboard with reply options (see Introduction to bots for details and examples).
ReplyKeyboardMarkup struct {
// Array of button rows, each represented by an Array of KeyboardButton
// objects
// Array of button rows, each represented by an Array of KeyboardButton objects
Keyboard [][]*KeyboardButton `json:"keyboard"`
// 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.
// 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.
ResizeKeyboard bool `json:"resize_keyboard,omitempty"`
// 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.
// 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.
OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"`
// 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.
// 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.
//
// 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.
// 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.
Selective bool `json:"selective,omitempty"`
}
// 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.
// 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.
KeyboardButton struct {
// 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
// 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
Text string `json:"text"`
// If True, the user's phone number will be sent as a contact when the
// button is pressed. Available in private chats only
// If True, the user's phone number will be sent as a contact when the button is pressed. Available in private chats only
RequestContact bool `json:"request_contact,omitempty"`
// If True, the user's current location will be sent when the button is
// pressed. Available in private chats only
// If True, the user's current location will be sent when the button is pressed. Available in private chats only
RequestLocation bool `json:"request_location,omitempty"`
}
// 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).
// 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).
ReplyKeyboardRemove struct {
// 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)
// 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)
RemoveKeyboard bool `json:"remove_keyboard"`
// 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.
// 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.
//
// 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.
// 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.
Selective bool `json:"selective,omitempty"`
}
// InlineKeyboardMarkup represents an inline keyboard that appears right next
// to the message it belongs to.
// InlineKeyboardMarkup represents an inline keyboard that appears right next to the message it belongs to.
InlineKeyboardMarkup struct {
// Array of button rows, each represented by an Array of
// InlineKeyboardButton objects
// Array of button rows, each represented by an Array of InlineKeyboardButton objects
InlineKeyboard [][]*InlineKeyboardButton `json:"inline_keyboard"`
}
// InlineKeyboardButton represents one button of an inline keyboard. You
// must use exactly one of the optional fields.
// InlineKeyboardButton represents one button of an inline keyboard. You must use exactly one of the optional fields.
InlineKeyboardButton struct {
// Label text on the button
Text string `json:"text"`
@ -638,126 +560,82 @@ type (
// HTTP url to be opened when button is pressed
URL string `json:"url,omitempty"`
// An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram
// Login Widget.
// An HTTP URL used to automatically authorize the user. Can be used as a replacement for the Telegram Login Widget.
LoginURL *LoginURL `json:"login_url,omitempty"`
// Data to be sent in a callback query to the bot when button is pressed,
// 1-64 bytes
// Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes
CallbackData string `json:"callback_data,omitempty"`
// 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.
// 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.
//
// 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.
// 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.
SwitchInlineQuery string `json:"switch_inline_query,omitempty"`
// 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.
// 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.
//
// 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.
// 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.
SwitchInlineQueryCurrentChat string `json:"switch_inline_query_current_chat,omitempty"`
// Description of the game that will be launched when the user presses
// the button.
// Description of the game that will be launched when the user presses the button.
//
// NOTE: This type of button must always be the first button in the
// first row.
// NOTE: This type of button must always be the first button in the first row.
CallbackGame *CallbackGame `json:"callback_game,omitempty"`
// Specify True, to send a Pay button.
//
// NOTE: This type of button must always be the first button in the
// first row.
// NOTE: This type of button must always be the first button in the first row.
Pay bool `json:"pay,omitempty"`
}
// LoginURL represents a parameter of the inline keyboard button used to automatically authorize a user.
LoginURL struct {
// 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.
// 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.
//
// 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.
// 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.
URL string `json:"url"`
// New text of the button in forwarded messages.
ForwardText string `json:"forward_text,omitempty"`
// 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.
// 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.
BotUsername string `json:"bot_username,omitempty"`
// Pass true to request the permission for your bot to send messages to the user.
RequestWriteAccess bool `json:"request_write_access,omitempty"`
}
// 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.
// 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.
//
// 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 ).
// 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 ).
CallbackQuery struct {
// Unique identifier for this query
ID string `json:"id"`
// Identifier of the message sent via the bot in inline mode, that
// originated the query.
// Identifier of the message sent via the bot in inline mode, that originated the query.
InlineMessageID string `json:"inline_message_id,omitempty"`
// Global identifier, uniquely corresponding to the chat to which the
// message with the callback button was sent. Useful for high scores in
// games.
// Global identifier, uniquely corresponding to the chat to which the message with the callback button was sent. Useful for high scores in games.
ChatInstance string `json:"chat_instance"`
// Data associated with the callback button. Be aware that a bad client
// can send arbitrary data in this field.
// Data associated with the callback button. Be aware that a bad client can send arbitrary data in this field.
Data string `json:"data,omitempty"`
// Short name of a Game to be returned, serves as the unique identifier
// for the game
// Short name of a Game to be returned, serves as the unique identifier for the game
GameShortName string `json:"game_short_name,omitempty"`
// Sender
From *User `json:"from"`
// 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 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 *Message `json:"message,omitempty"`
}
// 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.
// 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.
ForceReply struct {
// Shows reply interface to the user, as if they manually selected the
// bots message and tapped Reply'
// Shows reply interface to the user, as if they manually selected the bots message and tapped Reply'
ForceReply bool `json:"force_reply"`
// 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.
// 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.
Selective bool `json:"selective,omitempty"`
}
@ -781,8 +659,7 @@ type (
// Information about the user
User *User `json:"user"`
// The member's status in the chat. Can be "creator", "administrator", "member", "restricted", "left"
// or "kicked"
// The member's status in the chat. Can be "creator", "administrator", "member", "restricted", "left" or "kicked"
Status string `json:"status"`
// Owner and administrators only. Custom title for this user
@ -807,10 +684,7 @@ type (
// unban chat members
CanRestrictMembers bool `json:"can_restrict_members,omitempty"`
// 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 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)
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
@ -824,22 +698,19 @@ type (
// True, if the user is allowed to send text messages, contacts, locations and venues
CanSendMessages bool `json:"can_send_messages,omitempty"`
// True, if the user is allowed to send audios, documents, photos, videos, video notes and voice
// notes, implies can_send_messages
// True, if the user is allowed to send audios, documents, photos, videos, video notes and voice notes, implies can_send_messages
CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"`
// True, if the user is allowed to send polls, implies can_send_messages
CanSendPolls bool `json:"can_send_polls,omitempty"`
// True, if the user is allowed to send animations, games, stickers and use inline bots, implies
// can_send_media_messages
// True, if the user is allowed to send animations, games, stickers and use inline bots, implies can_send_media_messages
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
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
// supergroups
// True, if the user is allowed to change the chat title, photo and other settings. Ignored in public supergroups
CanChangeInfo bool `json:"can_change_info,omitempty"`
// 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"`
}
// ResponseParameters contains information about why a request was
// unsuccessful.
// ResponseParameters contains information about why a request was unsuccessful.
ResponseParameters struct {
// The group has been migrated to a supergroup with the specified
// identifier.
// The group has been migrated to a supergroup with the specified identifier.
MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"`
// In case of exceeding flood control, the number of seconds left to wait
// before the request can be repeated
// In case of exceeding flood control, the number of seconds left to wait before the request can be repeated
RetryAfter int `json:"retry_after,omitempty"`
}
@ -876,18 +744,13 @@ type (
// Type of the result, must be photo
Type string `json:"type"`
// 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.
// 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.
Media *InputFile `json:"media"`
// Caption of the photo to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
}
@ -896,18 +759,13 @@ type (
// Type of the result, must be video
Type string `json:"type"`
// 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.
// 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.
Media *InputFile `json:"media"`
// Caption of the video to be sent, 0-200 characters
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// Video width
@ -929,20 +787,10 @@ type (
// Type of the result, must be animation
Type string `json:"type"`
// 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.
// 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.
Media *InputFile `json:"media"`
// 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>.
// 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>.
Thumb *InputFile `json:"thumb,omitempty"`
// 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 (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 {
case f.IsFileID():
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.
Update struct {
// 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.
// 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.
UpdateID int `json:"update_id"`
// New incoming message of any kind — text, photo, sticker, etc.
@ -33,8 +29,7 @@ type (
// New incoming inline query
InlineQuery *InlineQuery `json:"inline_query,omitempty"`
// The result of an inline query that was chosen by a user and sent to
// their chat partner.
// The result of an inline query that was chosen by a user and sent to their chat partner.
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
// New incoming callback query
@ -43,8 +38,7 @@ type (
// New incoming shipping query. Only for invoices with flexible price
ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"`
// New incoming pre-checkout query. Contains full information about
// checkout
// New incoming pre-checkout query. Contains full information about checkout
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"`
// 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
URL string `json:"url"`
// Error message in human-readable format for the most recent error that
// happened when trying to deliver an update via webhook
// Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook
LastErrorMessage string `json:"last_error_message,omitempty"`
// True, if a custom certificate was provided for webhook certificate
// checks
// True, if a custom certificate was provided for webhook certificate checks
HasCustomCertificate bool `json:"has_custom_certificate"`
// Number of updates awaiting delivery
PendingUpdateCount int `json:"pending_update_count"`
// Maximum allowed number of simultaneous HTTPS connections to the
// webhook for update delivery
// Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery
MaxConnections int `json:"max_connections,omitempty"`
// Unix time for the most recent error that happened when trying to
// deliver an update via webhook
// Unix time for the most recent error that happened when trying to deliver an update via webhook
LastErrorDate int64 `json:"last_error_date,omitempty"`
// A list of update types the bot is subscribed to. Defaults to all
// update types
// A list of update types the bot is subscribed to. Defaults to all update types
AllowedUpdates []string `json:"allowed_updates,omitempty"`
}
// GetUpdatesParameters represents data for GetUpdates method.
GetUpdates struct {
// 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.
// 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.
Offset int `json:"offset,omitempty"`
// Limits the number of updates to be retrieved. Values between 1—100 are accepted. Defaults to 100.
Limit int `json:"limit,omitempty"`
// 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.
// 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.
Timeout int `json:"timeout,omitempty"`
// 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.
// 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.
//
// 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.
// 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.
AllowedUpdates []string `json:"allowed_updates,omitempty"`
}
// SetWebhookParameters represents data for SetWebhook method.
SetWebhook struct {
// HTTPS url to send updates to. Use an empty string to remove webhook
// integration
// HTTPS url to send updates to. Use an empty string to remove webhook integration
URL string `json:"url"`
// Upload your public key certificate so that the root certificate in use can
// be checked. See our self-signed guide for details.
// Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details.
Certificate InputFile `json:"certificate,omitempty"`
// 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.
// 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.
MaxConnections int `json:"max_connections,omitempty"`
// 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.
// 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.
//
// 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.
// 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.
AllowedUpdates []string `json:"allowed_updates,omitempty"`
}
)
// 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)
if err != nil {
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.
//
// 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)
// if p.Certificate != nil {
// 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.
func (b *Bot) DeleteWebhook() (bool, error) {
func (b Bot) DeleteWebhook() (bool, error) {
src, err := b.Do(MethodDeleteWebhook, nil)
if err != nil {
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.
func (b *Bot) GetWebhookInfo() (*WebhookInfo, error) {
func (b Bot) GetWebhookInfo() (*WebhookInfo, error) {
src, err := b.Do(MethodGetWebhookInfo, nil)
if err != nil {
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 {
if !wi.HasURL() {
func (w WebhookInfo) URI() *http.URI {
if !w.HasURL() {
return nil
}
u := http.AcquireURI()
u.Update(wi.URL)
u.Update(w.URL)
return u
}

View File

@ -3,24 +3,19 @@ package telegram
type (
// EditMessageTextParameters represents data for EditMessageText method.
EditMessageText struct {
// Required if inline_message_id is not specified. Unique identifier for the
// target chat or username of the target channel (in the format
// @channelusername)
// Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
ChatID int64 `json:"chat_id,omitempty"`
// 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"`
// Required if chat_id and message_id are not specified. Identifier of the
// inline message
// Required if chat_id and message_id are not specified. Identifier of the inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
// New text of the message
Text string `json:"text"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in your bot's message.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message.
ParseMode string `json:"parse_mode,omitempty"`
// Disables link previews for links in this message
@ -32,24 +27,19 @@ type (
// EditMessageCaptionParameters represents data for EditMessageCaption method.
EditMessageCaption struct {
// Required if inline_message_id is not specified. Unique identifier for the
// target chat or username of the target channel (in the format
// @channelusername)
// Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
ChatID int64 `json:"chat_id,omitempty"`
// 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"`
// Required if chat_id and message_id are not specified. Identifier of the
// inline message
// Required if chat_id and message_id are not specified. Identifier of the inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
// New caption of the message
Caption string `json:"caption,omitempty"`
// Send Markdown or HTML, if you want Telegram apps to show bold, italic,
// fixed-width text or inline URLs in the media caption.
// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.
ParseMode string `json:"parse_mode,omitempty"`
// A JSON-serialized object for an inline keyboard.
@ -76,17 +66,13 @@ type (
// EditMessageReplyMarkupParameters represents data for EditMessageReplyMarkup method.
EditMessageReplyMarkup struct {
// Required if inline_message_id is not specified. Unique identifier for the
// target chat or username of the target channel (in the format
// @channelusername)
// Required if inline_message_id is not specified. Unique identifier for the target chat or username of the target channel (in the format @channelusername)
ChatID int64 `json:"chat_id,omitempty"`
// 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"`
// Required if chat_id and message_id are not specified. Identifier of the
// inline message
// Required if chat_id and message_id are not specified. Identifier of the inline message
InlineMessageID string `json:"inline_message_id,omitempty"`
// 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
// (for inline bots). On success, if edited message is sent by the bot, the
// edited Message is returned, otherwise True is returned.
func (b *Bot) EditMessageText(p *EditMessageText) (*Message, error) {
// 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.
func (b Bot) EditMessageText(p *EditMessageText) (*Message, error) {
src, err := b.Do(MethodEditMessageText, p)
if err != nil {
return nil, err
@ -136,10 +120,8 @@ func (b *Bot) EditMessageText(p *EditMessageText) (*Message, error) {
return result, nil
}
// 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.
func (b *Bot) EditMessageCaption(p *EditMessageCaption) (*Message, error) {
// 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.
func (b Bot) EditMessageCaption(p *EditMessageCaption) (*Message, error) {
src, err := b.Do(MethodEditMessageCaption, p)
if err != nil {
return nil, err
@ -158,13 +140,8 @@ func (b *Bot) EditMessageCaption(p *EditMessageCaption) (*Message, error) {
return result, nil
}
// 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.
func (b *Bot) EditMessageMedia(p EditMessageMedia) (*Message, error) {
// 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.
func (b Bot) EditMessageMedia(p EditMessageMedia) (*Message, error) {
src, err := b.Do(MethodEditMessageMedia, p)
if err != nil {
return nil, err
@ -183,10 +160,8 @@ func (b *Bot) EditMessageMedia(p EditMessageMedia) (*Message, error) {
return result, nil
}
// 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.
func (b *Bot) EditMessageReplyMarkup(p EditMessageReplyMarkup) (*Message, error) {
// 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.
func (b Bot) EditMessageReplyMarkup(p EditMessageReplyMarkup) (*Message, error) {
src, err := b.Do(MethodEditMessageReplyMarkup, p)
if err != nil {
return nil, err
@ -205,7 +180,8 @@ func (b *Bot) EditMessageReplyMarkup(p EditMessageReplyMarkup) (*Message, error)
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)
if err != nil {
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.
//
// Returns True on success.
func (b *Bot) DeleteMessage(chatID int64, messageID int) (bool, error) {
src, err := b.Do(MethodDeleteMessage, DeleteMessage{
ChatID: chatID,
MessageID: messageID,
})
func (b Bot) DeleteMessage(cid int64, mid int) (bool, error) {
src, err := b.Do(MethodDeleteMessage, DeleteMessage{ChatID: cid, MessageID: mid})
if err != nil {
return false, err
}