all repos — telegram-bot-api @ 5aaa0b2d03cc570c5c04e52021b509822c980c3f

Golang bindings for the Telegram Bot API

types.go (view raw)

  1package tgbotapi
  2
  3import (
  4	"encoding/json"
  5	"errors"
  6	"fmt"
  7	"net/url"
  8	"strings"
  9	"time"
 10)
 11
 12// APIResponse is a response from the Telegram API with the result
 13// stored raw.
 14type APIResponse struct {
 15	Ok          bool                `json:"ok"`
 16	Result      json.RawMessage     `json:"result"`
 17	ErrorCode   int                 `json:"error_code"`
 18	Description string              `json:"description"`
 19	Parameters  *ResponseParameters `json:"parameters"`
 20}
 21
 22// ResponseParameters are various errors that can be returned in APIResponse.
 23type ResponseParameters struct {
 24	MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
 25	RetryAfter      int   `json:"retry_after"`        // optional
 26}
 27
 28// Update is an update response, from GetUpdates.
 29type Update struct {
 30	UpdateID           int                 `json:"update_id"`
 31	Message            *Message            `json:"message"`
 32	EditedMessage      *Message            `json:"edited_message"`
 33	ChannelPost        *Message            `json:"channel_post"`
 34	EditedChannelPost  *Message            `json:"edited_channel_post"`
 35	InlineQuery        *InlineQuery        `json:"inline_query"`
 36	ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
 37	CallbackQuery      *CallbackQuery      `json:"callback_query"`
 38	ShippingQuery      *ShippingQuery      `json:"shipping_query"`
 39	PreCheckoutQuery   *PreCheckoutQuery   `json:"pre_checkout_query"`
 40	Poll               *Poll               `json:"poll"`
 41	PollAnswer         *PollAnswer         `json:"poll_answer"`
 42}
 43
 44// UpdatesChannel is the channel for getting updates.
 45type UpdatesChannel <-chan Update
 46
 47// Clear discards all unprocessed incoming updates.
 48func (ch UpdatesChannel) Clear() {
 49	for len(ch) != 0 {
 50		<-ch
 51	}
 52}
 53
 54// User is a user on Telegram.
 55type User struct {
 56	ID                      int    `json:"id"`
 57	FirstName               string `json:"first_name"`
 58	LastName                string `json:"last_name"`                   // optional
 59	UserName                string `json:"username"`                    // optional
 60	LanguageCode            string `json:"language_code"`               // optional
 61	IsBot                   bool   `json:"is_bot"`                      // optional
 62	CanJoinGroups           bool   `json:"can_join_groups"`             // optional
 63	CanReadAllGroupMessages bool   `json:"can_read_all_group_messages"` // optional
 64	SupportsInlineQueries   bool   `json:"supports_inline_queries"`     // optional
 65}
 66
 67// String displays a simple text version of a user.
 68//
 69// It is normally a user's username, but falls back to a first/last
 70// name as available.
 71func (u *User) String() string {
 72	if u.UserName != "" {
 73		return u.UserName
 74	}
 75
 76	name := u.FirstName
 77	if u.LastName != "" {
 78		name += " " + u.LastName
 79	}
 80
 81	return name
 82}
 83
 84// GroupChat is a group chat.
 85type GroupChat struct {
 86	ID    int    `json:"id"`
 87	Title string `json:"title"`
 88}
 89
 90// ChatPhoto represents a chat photo.
 91type ChatPhoto struct {
 92	SmallFileID       string `json:"small_file_id"`
 93	SmallFileUniqueID string `json:"small_file_unique_id"`
 94	BigFileID         string `json:"big_file_id"`
 95	BigFileUniqueID   string `json:"big_file_unique_id"`
 96}
 97
 98// ChatPermissions describes actions that a non-administrator user is
 99// allowed to take in a chat. All fields are optional.
100type ChatPermissions struct {
101	CanSendMessages       bool `json:"can_send_messages"`
102	CanSendMediaMessages  bool `json:"can_send_media_messages"`
103	CanSendPolls          bool `json:"can_send_polls"`
104	CanSendOtherMessages  bool `json:"can_send_other_messages"`
105	CanAddWebPagePreviews bool `json:"can_add_web_page_previews"`
106	CanChangeInfo         bool `json:"can_change_info"`
107	CanInviteUsers        bool `json:"can_invite_users"`
108	CanPinMessages        bool `json:"can_pin_messages"`
109}
110
111// Chat contains information about the place a message was sent.
112type Chat struct {
113	ID                  int64            `json:"id"`
114	Type                string           `json:"type"`
115	Title               string           `json:"title"`                          // optional
116	UserName            string           `json:"username"`                       // optional
117	FirstName           string           `json:"first_name"`                     // optional
118	LastName            string           `json:"last_name"`                      // optional
119	AllMembersAreAdmins bool             `json:"all_members_are_administrators"` // deprecated, optional
120	Photo               *ChatPhoto       `json:"photo"`                          // optional
121	Description         string           `json:"description,omitempty"`          // optional
122	InviteLink          string           `json:"invite_link,omitempty"`          // optional
123	PinnedMessage       *Message         `json:"pinned_message"`                 // optional
124	Permissions         *ChatPermissions `json:"permissions"`                    // optional
125	SlowModeDelay       int              `json:"slow_mode_delay"`                // optional
126	StickerSetName      string           `json:"sticker_set_name"`               // optional
127	CanSetStickerSet    bool             `json:"can_set_sticker_set"`            // optional
128}
129
130// IsPrivate returns if the Chat is a private conversation.
131func (c Chat) IsPrivate() bool {
132	return c.Type == "private"
133}
134
135// IsGroup returns if the Chat is a group.
136func (c Chat) IsGroup() bool {
137	return c.Type == "group"
138}
139
140// IsSuperGroup returns if the Chat is a supergroup.
141func (c Chat) IsSuperGroup() bool {
142	return c.Type == "supergroup"
143}
144
145// IsChannel returns if the Chat is a channel.
146func (c Chat) IsChannel() bool {
147	return c.Type == "channel"
148}
149
150// ChatConfig returns a ChatConfig struct for chat related methods.
151func (c Chat) ChatConfig() ChatConfig {
152	return ChatConfig{ChatID: c.ID}
153}
154
155// Message is returned by almost every request, and contains data about
156// almost anything.
157type Message struct {
158	MessageID             int                   `json:"message_id"`
159	From                  *User                 `json:"from"` // optional
160	Date                  int                   `json:"date"`
161	Chat                  *Chat                 `json:"chat"`
162	ForwardFrom           *User                 `json:"forward_from"`            // optional
163	ForwardFromChat       *Chat                 `json:"forward_from_chat"`       // optional
164	ForwardFromMessageID  int                   `json:"forward_from_message_id"` // optional
165	ForwardSignature      string                `json:"forward_signature"`       // optional
166	ForwardSenderName     string                `json:"forward_sender_name"`     // optional
167	ForwardDate           int                   `json:"forward_date"`            // optional
168	ReplyToMessage        *Message              `json:"reply_to_message"`        // optional
169	EditDate              int                   `json:"edit_date"`               // optional
170	MediaGroupID          string                `json:"media_group_id"`          // optional
171	AuthorSignature       string                `json:"author_signature"`        // optional
172	Text                  string                `json:"text"`                    // optional
173	Entities              []MessageEntity       `json:"entities"`                // optional
174	CaptionEntities       []MessageEntity       `json:"caption_entities"`        // optional
175	Audio                 *Audio                `json:"audio"`                   // optional
176	Document              *Document             `json:"document"`                // optional
177	Animation             *ChatAnimation        `json:"animation"`               // optional
178	Game                  *Game                 `json:"game"`                    // optional
179	Photo                 []PhotoSize           `json:"photo"`                   // optional
180	Sticker               *Sticker              `json:"sticker"`                 // optional
181	Video                 *Video                `json:"video"`                   // optional
182	VideoNote             *VideoNote            `json:"video_note"`              // optional
183	Voice                 *Voice                `json:"voice"`                   // optional
184	Caption               string                `json:"caption"`                 // optional
185	Contact               *Contact              `json:"contact"`                 // optional
186	Location              *Location             `json:"location"`                // optional
187	Venue                 *Venue                `json:"venue"`                   // optional
188	Poll                  *Poll                 `json:"poll"`                    // optional
189	NewChatMembers        []User                `json:"new_chat_members"`        // optional
190	LeftChatMember        *User                 `json:"left_chat_member"`        // optional
191	NewChatTitle          string                `json:"new_chat_title"`          // optional
192	NewChatPhoto          []PhotoSize           `json:"new_chat_photo"`          // optional
193	DeleteChatPhoto       bool                  `json:"delete_chat_photo"`       // optional
194	GroupChatCreated      bool                  `json:"group_chat_created"`      // optional
195	SuperGroupChatCreated bool                  `json:"supergroup_chat_created"` // optional
196	ChannelChatCreated    bool                  `json:"channel_chat_created"`    // optional
197	MigrateToChatID       int64                 `json:"migrate_to_chat_id"`      // optional
198	MigrateFromChatID     int64                 `json:"migrate_from_chat_id"`    // optional
199	PinnedMessage         *Message              `json:"pinned_message"`          // optional
200	Invoice               *Invoice              `json:"invoice"`                 // optional
201	SuccessfulPayment     *SuccessfulPayment    `json:"successful_payment"`      // optional
202	ConnectedWebsite      string                `json:"connected_website"`       // optional
203	PassportData          *PassportData         `json:"passport_data,omitempty"` // optional
204	ReplyMarkup           *InlineKeyboardMarkup `json:"reply_markup"`            // optional
205}
206
207// Time converts the message timestamp into a Time.
208func (m *Message) Time() time.Time {
209	return time.Unix(int64(m.Date), 0)
210}
211
212// IsCommand returns true if message starts with a "bot_command" entity.
213func (m *Message) IsCommand() bool {
214	if m.Entities == nil || len(m.Entities) == 0 {
215		return false
216	}
217
218	entity := m.Entities[0]
219	return entity.Offset == 0 && entity.Type == "bot_command"
220}
221
222// Command checks if the message was a command and if it was, returns the
223// command. If the Message was not a command, it returns an empty string.
224//
225// If the command contains the at name syntax, it is removed. Use
226// CommandWithAt() if you do not want that.
227func (m *Message) Command() string {
228	command := m.CommandWithAt()
229
230	if i := strings.Index(command, "@"); i != -1 {
231		command = command[:i]
232	}
233
234	return command
235}
236
237// CommandWithAt checks if the message was a command and if it was, returns the
238// command. If the Message was not a command, it returns an empty string.
239//
240// If the command contains the at name syntax, it is not removed. Use Command()
241// if you want that.
242func (m *Message) CommandWithAt() string {
243	if !m.IsCommand() {
244		return ""
245	}
246
247	// IsCommand() checks that the message begins with a bot_command entity
248	entity := m.Entities[0]
249	return m.Text[1:entity.Length]
250}
251
252// CommandArguments checks if the message was a command and if it was,
253// returns all text after the command name. If the Message was not a
254// command, it returns an empty string.
255//
256// Note: The first character after the command name is omitted:
257// - "/foo bar baz" yields "bar baz", not " bar baz"
258// - "/foo-bar baz" yields "bar baz", too
259// Even though the latter is not a command conforming to the spec, the API
260// marks "/foo" as command entity.
261func (m *Message) CommandArguments() string {
262	if !m.IsCommand() {
263		return ""
264	}
265
266	// IsCommand() checks that the message begins with a bot_command entity
267	entity := m.Entities[0]
268
269	if len(m.Text) == entity.Length {
270		return "" // The command makes up the whole message
271	}
272
273	return m.Text[entity.Length+1:]
274}
275
276// MessageEntity contains information about data in a Message.
277type MessageEntity struct {
278	Type     string `json:"type"`
279	Offset   int    `json:"offset"`
280	Length   int    `json:"length"`
281	URL      string `json:"url"`      // optional
282	User     *User  `json:"user"`     // optional
283	Language string `json:"language"` // optional
284}
285
286// ParseURL attempts to parse a URL contained within a MessageEntity.
287func (entity MessageEntity) ParseURL() (*url.URL, error) {
288	if entity.URL == "" {
289		return nil, errors.New(ErrBadURL)
290	}
291
292	return url.Parse(entity.URL)
293}
294
295// PhotoSize contains information about photos.
296type PhotoSize struct {
297	FileID       string `json:"file_id"`
298	FileUniqueID string `json:"file_unique_id"`
299	Width        int    `json:"width"`
300	Height       int    `json:"height"`
301	FileSize     int    `json:"file_size"` // optional
302}
303
304// Audio contains information about audio.
305type Audio struct {
306	FileID       string `json:"file_id"`
307	FileUniqueID string `json:"file_unique_id"`
308	Duration     int    `json:"duration"`
309	Performer    string `json:"performer"` // optional
310	Title        string `json:"title"`     // optional
311	MimeType     string `json:"mime_type"` // optional
312	FileSize     int    `json:"file_size"` // optional
313}
314
315// Document contains information about a document.
316type Document struct {
317	FileID       string     `json:"file_id"`
318	FileUniqueID string     `json:"file_unique_id"`
319	Thumbnail    *PhotoSize `json:"thumb"`     // optional
320	FileName     string     `json:"file_name"` // optional
321	MimeType     string     `json:"mime_type"` // optional
322	FileSize     int        `json:"file_size"` // optional
323}
324
325// Sticker contains information about a sticker.
326type Sticker struct {
327	FileID       string       `json:"file_id"`
328	FileUniqueID string       `json:"file_unique_id"`
329	Width        int          `json:"width"`
330	Height       int          `json:"height"`
331	IsAnimated   bool         `json:"is_animated"`
332	Thumbnail    *PhotoSize   `json:"thumb"`         // optional
333	Emoji        string       `json:"emoji"`         // optional
334	SetName      string       `json:"set_name"`      // optional
335	MaskPosition MaskPosition `json:"mask_position"` //optional
336	FileSize     int          `json:"file_size"`     // optional
337}
338
339// MaskPosition is the position of a mask.
340type MaskPosition struct {
341	Point     string     `json:"point"`
342	XShift    float32    `json:"x_shift"`
343	YShift    float32    `json:"y_shift"`
344	Scale     float32    `json:"scale"`
345	FileID    string     `json:"file_id"`
346	Width     int        `json:"width"`
347	Height    int        `json:"height"`
348	Thumbnail *PhotoSize `json:"thumb"`     // optional
349	Emoji     string     `json:"emoji"`     // optional
350	FileSize  int        `json:"file_size"` // optional
351	SetName   string     `json:"set_name"`  // optional
352}
353
354// ChatAnimation contains information about an animation.
355type ChatAnimation struct {
356	FileID    string     `json:"file_id"`
357	Width     int        `json:"width"`
358	Height    int        `json:"height"`
359	Duration  int        `json:"duration"`
360	Thumbnail *PhotoSize `json:"thumb"`     // optional
361	FileName  string     `json:"file_name"` // optional
362	MimeType  string     `json:"mime_type"` // optional
363	FileSize  int        `json:"file_size"` // optional
364}
365
366// Video contains information about a video.
367type Video struct {
368	FileID       string     `json:"file_id"`
369	FileUniqueID string     `json:"file_unique_id"`
370	Width        int        `json:"width"`
371	Height       int        `json:"height"`
372	Duration     int        `json:"duration"`
373	Thumbnail    *PhotoSize `json:"thumb"`     // optional
374	MimeType     string     `json:"mime_type"` // optional
375	FileSize     int        `json:"file_size"` // optional
376}
377
378// VideoNote contains information about a video.
379type VideoNote struct {
380	FileID       string     `json:"file_id"`
381	FileUniqueID string     `json:"file_unique_id"`
382	Length       int        `json:"length"`
383	Duration     int        `json:"duration"`
384	Thumbnail    *PhotoSize `json:"thumb"`     // optional
385	FileSize     int        `json:"file_size"` // optional
386}
387
388// Voice contains information about a voice.
389type Voice struct {
390	FileID       string `json:"file_id"`
391	FileUniqueID string `json:"file_unique_id"`
392	Duration     int    `json:"duration"`
393	MimeType     string `json:"mime_type"` // optional
394	FileSize     int    `json:"file_size"` // optional
395}
396
397// Contact contains information about a contact.
398//
399// Note that LastName and UserID may be empty.
400type Contact struct {
401	PhoneNumber string `json:"phone_number"`
402	FirstName   string `json:"first_name"`
403	LastName    string `json:"last_name"` // optional
404	UserID      int    `json:"user_id"`   // optional
405	VCard       string `json:"vcard"`     // optional
406}
407
408// Location contains information about a place.
409type Location struct {
410	Longitude float64 `json:"longitude"`
411	Latitude  float64 `json:"latitude"`
412}
413
414// Venue contains information about a venue, including its Location.
415type Venue struct {
416	Location     Location `json:"location"`
417	Title        string   `json:"title"`
418	Address      string   `json:"address"`
419	FoursquareID string   `json:"foursquare_id"` // optional
420}
421
422// PollOption contains information about one answer option in a poll.
423type PollOption struct {
424	Text       string `json:"text"`
425	VoterCount int    `json:"voter_count"`
426}
427
428// PollAnswer represents an answer of a user in a non-anonymous poll.
429type PollAnswer struct {
430	PollID    string `json:"poll_id"`
431	User      User   `json:"user"`
432	OptionIDs []int  `json:"option_ids"`
433}
434
435// Poll contains information about a poll.
436type Poll struct {
437	ID                    string       `json:"id"`
438	Question              string       `json:"question"`
439	Options               []PollOption `json:"options"`
440	IsClosed              bool         `json:"is_closed"`
441	IsAnonymous           bool         `json:"is_anonymous"`
442	Type                  string       `json:"type"`
443	AllowsMultipleAnswers bool         `json:"allows_multiple_answers"`
444	CorrectOptionID       int          `json:"correct_option_id"` // optional
445}
446
447// UserProfilePhotos contains a set of user profile photos.
448type UserProfilePhotos struct {
449	TotalCount int           `json:"total_count"`
450	Photos     [][]PhotoSize `json:"photos"`
451}
452
453// File contains information about a file to download from Telegram.
454type File struct {
455	FileID       string `json:"file_id"`
456	FileUniqueID string `json:"file_unique_id"`
457	FileSize     int    `json:"file_size"` // optional
458	FilePath     string `json:"file_path"` // optional
459}
460
461// Link returns a full path to the download URL for a File.
462//
463// It requires the Bot Token to create the link.
464func (f *File) Link(token string) string {
465	return fmt.Sprintf(FileEndpoint, token, f.FilePath)
466}
467
468// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
469type ReplyKeyboardMarkup struct {
470	Keyboard        [][]KeyboardButton `json:"keyboard"`
471	ResizeKeyboard  bool               `json:"resize_keyboard"`   // optional
472	OneTimeKeyboard bool               `json:"one_time_keyboard"` // optional
473	Selective       bool               `json:"selective"`         // optional
474}
475
476// KeyboardButton is a button within a custom keyboard.
477type KeyboardButton struct {
478	Text            string                 `json:"text"`
479	RequestContact  bool                   `json:"request_contact"`
480	RequestLocation bool                   `json:"request_location"`
481	RequestPoll     KeyboardButtonPollType `json:"request_poll"`
482}
483
484// KeyboardButtonPollType represents type of a poll, which is allowed to
485// be created and sent when the corresponding button is pressed.
486type KeyboardButtonPollType struct {
487	Type string `json:"type"`
488}
489
490// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
491type ReplyKeyboardHide struct {
492	HideKeyboard bool `json:"hide_keyboard"`
493	Selective    bool `json:"selective"` // optional
494}
495
496// ReplyKeyboardRemove allows the Bot to hide a custom keyboard.
497type ReplyKeyboardRemove struct {
498	RemoveKeyboard bool `json:"remove_keyboard"`
499	Selective      bool `json:"selective"`
500}
501
502// InlineKeyboardMarkup is a custom keyboard presented for an inline bot.
503type InlineKeyboardMarkup struct {
504	InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
505}
506
507// InlineKeyboardButton is a button within a custom keyboard for
508// inline query responses.
509//
510// Note that some values are references as even an empty string
511// will change behavior.
512//
513// CallbackGame, if set, MUST be first button in first row.
514type InlineKeyboardButton struct {
515	Text                         string        `json:"text"`
516	URL                          *string       `json:"url,omitempty"`                              // optional
517	LoginURL                     *LoginURL     `json:"login_url,omitempty"`                        // optional
518	CallbackData                 *string       `json:"callback_data,omitempty"`                    // optional
519	SwitchInlineQuery            *string       `json:"switch_inline_query,omitempty"`              // optional
520	SwitchInlineQueryCurrentChat *string       `json:"switch_inline_query_current_chat,omitempty"` // optional
521	CallbackGame                 *CallbackGame `json:"callback_game,omitempty"`                    // optional
522	Pay                          bool          `json:"pay,omitempty"`                              // optional
523}
524
525// LoginURL is the parameters for the login inline keyboard button type.
526type LoginURL struct {
527	URL                string `json:"url"`
528	ForwardText        string `json:"forward_text"`
529	BotUsername        string `json:"bot_username"`
530	RequestWriteAccess bool   `json:"request_write_access"`
531}
532
533// CallbackQuery is data sent when a keyboard button with callback data
534// is clicked.
535type CallbackQuery struct {
536	ID              string   `json:"id"`
537	From            *User    `json:"from"`
538	Message         *Message `json:"message"`           // optional
539	InlineMessageID string   `json:"inline_message_id"` // optional
540	ChatInstance    string   `json:"chat_instance"`
541	Data            string   `json:"data"`            // optional
542	GameShortName   string   `json:"game_short_name"` // optional
543}
544
545// ForceReply allows the Bot to have users directly reply to it without
546// additional interaction.
547type ForceReply struct {
548	ForceReply bool `json:"force_reply"`
549	Selective  bool `json:"selective"` // optional
550}
551
552// ChatMember is information about a member in a chat.
553type ChatMember struct {
554	User                  *User  `json:"user"`
555	Status                string `json:"status"`
556	CustomTitle           string `json:"custom_title"`                        // optional
557	UntilDate             int64  `json:"until_date,omitempty"`                // optional
558	CanBeEdited           bool   `json:"can_be_edited,omitempty"`             // optional
559	CanPostMessages       bool   `json:"can_post_messages,omitempty"`         // optional
560	CanEditMessages       bool   `json:"can_edit_messages,omitempty"`         // optional
561	CanDeleteMessages     bool   `json:"can_delete_messages,omitempty"`       // optional
562	CanRestrictMembers    bool   `json:"can_restrict_members,omitempty"`      // optional
563	CanPromoteMembers     bool   `json:"can_promote_members,omitempty"`       // optional
564	CanChangeInfo         bool   `json:"can_change_info,omitempty"`           // optional
565	CanInviteUsers        bool   `json:"can_invite_users,omitempty"`          // optional
566	CanPinMessages        bool   `json:"can_pin_messages,omitempty"`          // optional
567	IsChatMember          bool   `json:"is_member"`                           // optional
568	CanSendMessages       bool   `json:"can_send_messages,omitempty"`         // optional
569	CanSendMediaMessages  bool   `json:"can_send_media_messages,omitempty"`   // optional
570	CanSendPolls          bool   `json:"can_send_polls,omitempty"`            // optional
571	CanSendOtherMessages  bool   `json:"can_send_other_messages,omitempty"`   // optional
572	CanAddWebPagePreviews bool   `json:"can_add_web_page_previews,omitempty"` // optional
573}
574
575// IsCreator returns if the ChatMember was the creator of the chat.
576func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" }
577
578// IsAdministrator returns if the ChatMember is a chat administrator.
579func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" }
580
581// IsMember returns if the ChatMember is a current member of the chat.
582func (chat ChatMember) IsMember() bool { return chat.Status == "member" }
583
584// HasLeft returns if the ChatMember left the chat.
585func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
586
587// WasKicked returns if the ChatMember was kicked from the chat.
588func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
589
590// Game is a game within Telegram.
591type Game struct {
592	Title        string          `json:"title"`
593	Description  string          `json:"description"`
594	Photo        []PhotoSize     `json:"photo"`
595	Text         string          `json:"text"`
596	TextEntities []MessageEntity `json:"text_entities"`
597	Animation    Animation       `json:"animation"`
598}
599
600// Animation is a GIF animation demonstrating the game.
601type Animation struct {
602	FileID       string    `json:"file_id"`
603	FileUniqueID string    `json:"file_unique_id"`
604	Thumb        PhotoSize `json:"thumb"`
605	FileName     string    `json:"file_name"`
606	MimeType     string    `json:"mime_type"`
607	FileSize     int       `json:"file_size"`
608}
609
610// GameHighScore is a user's score and position on the leaderboard.
611type GameHighScore struct {
612	Position int  `json:"position"`
613	User     User `json:"user"`
614	Score    int  `json:"score"`
615}
616
617// CallbackGame is for starting a game in an inline keyboard button.
618type CallbackGame struct{}
619
620// WebhookInfo is information about a currently set webhook.
621type WebhookInfo struct {
622	URL                  string `json:"url"`
623	HasCustomCertificate bool   `json:"has_custom_certificate"`
624	PendingUpdateCount   int    `json:"pending_update_count"`
625	LastErrorDate        int    `json:"last_error_date"`    // optional
626	LastErrorMessage     string `json:"last_error_message"` // optional
627}
628
629// IsSet returns true if a webhook is currently set.
630func (info WebhookInfo) IsSet() bool {
631	return info.URL != ""
632}
633
634// InlineQuery is a Query from Telegram for an inline request.
635type InlineQuery struct {
636	ID       string    `json:"id"`
637	From     *User     `json:"from"`
638	Location *Location `json:"location"` // optional
639	Query    string    `json:"query"`
640	Offset   string    `json:"offset"`
641}
642
643// InlineQueryResultArticle is an inline query response article.
644type InlineQueryResultArticle struct {
645	Type                string                `json:"type"`                            // required
646	ID                  string                `json:"id"`                              // required
647	Title               string                `json:"title"`                           // required
648	InputMessageContent interface{}           `json:"input_message_content,omitempty"` // required
649	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
650	URL                 string                `json:"url"`
651	HideURL             bool                  `json:"hide_url"`
652	Description         string                `json:"description"`
653	ThumbURL            string                `json:"thumb_url"`
654	ThumbWidth          int                   `json:"thumb_width"`
655	ThumbHeight         int                   `json:"thumb_height"`
656}
657
658// InlineQueryResultPhoto is an inline query response photo.
659type InlineQueryResultPhoto struct {
660	Type                string                `json:"type"`      // required
661	ID                  string                `json:"id"`        // required
662	URL                 string                `json:"photo_url"` // required
663	MimeType            string                `json:"mime_type"`
664	Width               int                   `json:"photo_width"`
665	Height              int                   `json:"photo_height"`
666	ThumbURL            string                `json:"thumb_url"`
667	Title               string                `json:"title"`
668	Description         string                `json:"description"`
669	Caption             string                `json:"caption"`
670	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
671	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
672}
673
674// InlineQueryResultGIF is an inline query response GIF.
675type InlineQueryResultGIF struct {
676	Type                string                `json:"type"`    // required
677	ID                  string                `json:"id"`      // required
678	URL                 string                `json:"gif_url"` // required
679	Width               int                   `json:"gif_width"`
680	Height              int                   `json:"gif_height"`
681	Duration            int                   `json:"gif_duration"`
682	ThumbURL            string                `json:"thumb_url"`
683	Title               string                `json:"title"`
684	Caption             string                `json:"caption"`
685	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
686	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
687}
688
689// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
690type InlineQueryResultMPEG4GIF struct {
691	Type                string                `json:"type"`      // required
692	ID                  string                `json:"id"`        // required
693	URL                 string                `json:"mpeg4_url"` // required
694	Width               int                   `json:"mpeg4_width"`
695	Height              int                   `json:"mpeg4_height"`
696	Duration            int                   `json:"mpeg4_duration"`
697	ThumbURL            string                `json:"thumb_url"`
698	Title               string                `json:"title"`
699	Caption             string                `json:"caption"`
700	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
701	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
702}
703
704// InlineQueryResultVideo is an inline query response video.
705type InlineQueryResultVideo struct {
706	Type                string                `json:"type"`      // required
707	ID                  string                `json:"id"`        // required
708	URL                 string                `json:"video_url"` // required
709	MimeType            string                `json:"mime_type"` // required
710	ThumbURL            string                `json:"thumb_url"`
711	Title               string                `json:"title"`
712	Caption             string                `json:"caption"`
713	Width               int                   `json:"video_width"`
714	Height              int                   `json:"video_height"`
715	Duration            int                   `json:"video_duration"`
716	Description         string                `json:"description"`
717	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
718	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
719}
720
721// InlineQueryResultAudio is an inline query response audio.
722type InlineQueryResultAudio struct {
723	Type                string                `json:"type"`      // required
724	ID                  string                `json:"id"`        // required
725	URL                 string                `json:"audio_url"` // required
726	Title               string                `json:"title"`     // required
727	Caption             string                `json:"caption"`
728	Performer           string                `json:"performer"`
729	Duration            int                   `json:"audio_duration"`
730	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
731	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
732}
733
734// InlineQueryResultVoice is an inline query response voice.
735type InlineQueryResultVoice struct {
736	Type                string                `json:"type"`      // required
737	ID                  string                `json:"id"`        // required
738	URL                 string                `json:"voice_url"` // required
739	Title               string                `json:"title"`     // required
740	Caption             string                `json:"caption"`
741	Duration            int                   `json:"voice_duration"`
742	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
743	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
744}
745
746// InlineQueryResultDocument is an inline query response document.
747type InlineQueryResultDocument struct {
748	Type                string                `json:"type"`  // required
749	ID                  string                `json:"id"`    // required
750	Title               string                `json:"title"` // required
751	Caption             string                `json:"caption"`
752	URL                 string                `json:"document_url"` // required
753	MimeType            string                `json:"mime_type"`    // required
754	Description         string                `json:"description"`
755	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
756	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
757	ThumbURL            string                `json:"thumb_url"`
758	ThumbWidth          int                   `json:"thumb_width"`
759	ThumbHeight         int                   `json:"thumb_height"`
760}
761
762// InlineQueryResultLocation is an inline query response location.
763type InlineQueryResultLocation struct {
764	Type                string                `json:"type"`        // required
765	ID                  string                `json:"id"`          // required
766	Latitude            float64               `json:"latitude"`    // required
767	Longitude           float64               `json:"longitude"`   // required
768	LivePeriod          int                   `json:"live_period"` // optional
769	Title               string                `json:"title"`       // required
770	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
771	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
772	ThumbURL            string                `json:"thumb_url"`
773	ThumbWidth          int                   `json:"thumb_width"`
774	ThumbHeight         int                   `json:"thumb_height"`
775}
776
777// InlineQueryResultContact is an inline query response contact.
778type InlineQueryResultContact struct {
779	Type                string                `json:"type"`         // required
780	ID                  string                `json:"id"`           // required
781	PhoneNumber         string                `json:"phone_number"` // required
782	FirstName           string                `json:"first_name"`   // required
783	LastName            string                `json:"last_name"`
784	VCard               string                `json:"vcard"`
785	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
786	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
787	ThumbURL            string                `json:"thumb_url"`
788	ThumbWidth          int                   `json:"thumb_width"`
789	ThumbHeight         int                   `json:"thumb_height"`
790}
791
792// InlineQueryResultGame is an inline query response game.
793type InlineQueryResultGame struct {
794	Type          string                `json:"type"`
795	ID            string                `json:"id"`
796	GameShortName string                `json:"game_short_name"`
797	ReplyMarkup   *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
798}
799
800// ChosenInlineResult is an inline query result chosen by a User
801type ChosenInlineResult struct {
802	ResultID        string    `json:"result_id"`
803	From            *User     `json:"from"`
804	Location        *Location `json:"location"`
805	InlineMessageID string    `json:"inline_message_id"`
806	Query           string    `json:"query"`
807}
808
809// InputTextMessageContent contains text for displaying
810// as an inline query result.
811type InputTextMessageContent struct {
812	Text                  string `json:"message_text"`
813	ParseMode             string `json:"parse_mode"`
814	DisableWebPagePreview bool   `json:"disable_web_page_preview"`
815}
816
817// InputLocationMessageContent contains a location for displaying
818// as an inline query result.
819type InputLocationMessageContent struct {
820	Latitude  float64 `json:"latitude"`
821	Longitude float64 `json:"longitude"`
822}
823
824// InputVenueMessageContent contains a venue for displaying
825// as an inline query result.
826type InputVenueMessageContent struct {
827	Latitude     float64 `json:"latitude"`
828	Longitude    float64 `json:"longitude"`
829	Title        string  `json:"title"`
830	Address      string  `json:"address"`
831	FoursquareID string  `json:"foursquare_id"`
832}
833
834// InputContactMessageContent contains a contact for displaying
835// as an inline query result.
836type InputContactMessageContent struct {
837	PhoneNumber string `json:"phone_number"`
838	FirstName   string `json:"first_name"`
839	LastName    string `json:"last_name"`
840	VCard       string `json:"vcard"`
841}
842
843// Invoice contains basic information about an invoice.
844type Invoice struct {
845	Title          string `json:"title"`
846	Description    string `json:"description"`
847	StartParameter string `json:"start_parameter"`
848	Currency       string `json:"currency"`
849	TotalAmount    int    `json:"total_amount"`
850}
851
852// LabeledPrice represents a portion of the price for goods or services.
853type LabeledPrice struct {
854	Label  string `json:"label"`
855	Amount int    `json:"amount"`
856}
857
858// ShippingAddress represents a shipping address.
859type ShippingAddress struct {
860	CountryCode string `json:"country_code"`
861	State       string `json:"state"`
862	City        string `json:"city"`
863	StreetLine1 string `json:"street_line1"`
864	StreetLine2 string `json:"street_line2"`
865	PostCode    string `json:"post_code"`
866}
867
868// OrderInfo represents information about an order.
869type OrderInfo struct {
870	Name            string           `json:"name,omitempty"`
871	PhoneNumber     string           `json:"phone_number,omitempty"`
872	Email           string           `json:"email,omitempty"`
873	ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
874}
875
876// ShippingOption represents one shipping option.
877type ShippingOption struct {
878	ID     string         `json:"id"`
879	Title  string         `json:"title"`
880	Prices []LabeledPrice `json:"prices"`
881}
882
883// SuccessfulPayment contains basic information about a successful payment.
884type SuccessfulPayment struct {
885	Currency                string     `json:"currency"`
886	TotalAmount             int        `json:"total_amount"`
887	InvoicePayload          string     `json:"invoice_payload"`
888	ShippingOptionID        string     `json:"shipping_option_id,omitempty"`
889	OrderInfo               *OrderInfo `json:"order_info,omitempty"`
890	TelegramPaymentChargeID string     `json:"telegram_payment_charge_id"`
891	ProviderPaymentChargeID string     `json:"provider_payment_charge_id"`
892}
893
894// ShippingQuery contains information about an incoming shipping query.
895type ShippingQuery struct {
896	ID              string           `json:"id"`
897	From            *User            `json:"from"`
898	InvoicePayload  string           `json:"invoice_payload"`
899	ShippingAddress *ShippingAddress `json:"shipping_address"`
900}
901
902// PreCheckoutQuery contains information about an incoming pre-checkout query.
903type PreCheckoutQuery struct {
904	ID               string     `json:"id"`
905	From             *User      `json:"from"`
906	Currency         string     `json:"currency"`
907	TotalAmount      int        `json:"total_amount"`
908	InvoicePayload   string     `json:"invoice_payload"`
909	ShippingOptionID string     `json:"shipping_option_id,omitempty"`
910	OrderInfo        *OrderInfo `json:"order_info,omitempty"`
911}
912
913// StickerSet is a collection of stickers.
914type StickerSet struct {
915	Name          string    `json:"name"`
916	Title         string    `json:"title"`
917	IsAnimated    bool      `json:"is_animated"`
918	ContainsMasks bool      `json:"contains_masks"`
919	Stickers      []Sticker `json:"stickers"`
920}
921
922// BaseInputMedia is a base type for the InputMedia types.
923type BaseInputMedia struct {
924	Type      string `json:"type"`
925	Media     string `json:"media"`
926	Caption   string `json:"caption"`
927	ParseMode string `json:"parse_mode"`
928}
929
930// InputMediaPhoto is a photo to send as part of a media group.
931type InputMediaPhoto struct {
932	BaseInputMedia
933}
934
935// InputMediaVideo is a video to send as part of a media group.
936type InputMediaVideo struct {
937	BaseInputMedia
938	Width             int  `json:"width"`
939	Height            int  `json:"height"`
940	Duration          int  `json:"duration"`
941	SupportsStreaming bool `json:"supports_streaming"`
942}
943
944// InputMediaAnimation is an animation to send as part of a media group.
945type InputMediaAnimation struct {
946	BaseInputMedia
947	Width    int `json:"width"`
948	Height   int `json:"height"`
949	Duration int `json:"duration"`
950}
951
952// InputMediaAudio is a audio to send as part of a media group.
953type InputMediaAudio struct {
954	BaseInputMedia
955	Duration  int    `json:"duration"`
956	Performer string `json:"performer"`
957	Title     string `json:"title"`
958}
959
960// InputMediaDocument is a audio to send as part of a media group.
961type InputMediaDocument struct {
962	BaseInputMedia
963}
964
965// Error is an error containing extra information returned by the Telegram API.
966type Error struct {
967	Message string
968	ResponseParameters
969}
970
971// Error message string.
972func (e Error) Error() string {
973	return e.Message
974}