all repos — telegram-bot-api @ e55e8bc55aa771d1a0bcc4d05a5f135020ceba10

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