all repos — telegram-bot-api @ 2339ed4639a8e0a9701f624ffd299af00476daf2

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	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
651	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
652}
653
654// InlineQueryResultCachedPhoto is an inline query response with cached photo.
655type InlineQueryResultCachedPhoto struct {
656	Type                string                `json:"type"`          // required
657	ID                  string                `json:"id"`            // required
658	PhotoID             string                `json:"photo_file_id"` // required
659	Title               string                `json:"title"`
660	Description         string                `json:"description"`
661	Caption             string                `json:"caption"`
662	ParseMode           string                `json:"parse_mode"`
663	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
664	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
665}
666
667// InlineQueryResultGIF is an inline query response GIF.
668type InlineQueryResultGIF struct {
669	Type                string                `json:"type"`      // required
670	ID                  string                `json:"id"`        // required
671	URL                 string                `json:"gif_url"`   // required
672	ThumbURL            string                `json:"thumb_url"` // required
673	Width               int                   `json:"gif_width,omitempty"`
674	Height              int                   `json:"gif_height,omitempty"`
675	Duration            int                   `json:"gif_duration,omitempty"`
676	Title               string                `json:"title,omitempty"`
677	Caption             string                `json:"caption,omitempty"`
678	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
679	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
680}
681
682// InlineQueryResultCachedGIF is an inline query response with cached gif.
683type InlineQueryResultCachedGIF struct {
684	Type                string                `json:"type"`        // required
685	ID                  string                `json:"id"`          // required
686	GifID               string                `json:"gif_file_id"` // required
687	Title               string                `json:"title"`
688	Caption             string                `json:"caption"`
689	ParseMode           string                `json:"parse_mode"`
690	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
691	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
692}
693
694// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
695type InlineQueryResultMPEG4GIF struct {
696	Type                string                `json:"type"`      // required
697	ID                  string                `json:"id"`        // required
698	URL                 string                `json:"mpeg4_url"` // required
699	Width               int                   `json:"mpeg4_width"`
700	Height              int                   `json:"mpeg4_height"`
701	Duration            int                   `json:"mpeg4_duration"`
702	ThumbURL            string                `json:"thumb_url"`
703	Title               string                `json:"title"`
704	Caption             string                `json:"caption"`
705	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
706	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
707}
708
709// InlineQueryResultCachedMpeg4Gif is an inline query response with cached
710// H.264/MPEG-4 AVC video without sound gif.
711type InlineQueryResultCachedMpeg4Gif struct {
712	Type                string                `json:"type"`          // required
713	ID                  string                `json:"id"`            // required
714	MGifID              string                `json:"mpeg4_file_id"` // required
715	Title               string                `json:"title"`
716	Caption             string                `json:"caption"`
717	ParseMode           string                `json:"parse_mode"`
718	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
719	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
720}
721
722// InlineQueryResultVideo is an inline query response video.
723type InlineQueryResultVideo struct {
724	Type                string                `json:"type"`      // required
725	ID                  string                `json:"id"`        // required
726	URL                 string                `json:"video_url"` // required
727	MimeType            string                `json:"mime_type"` // required
728	ThumbURL            string                `json:"thumb_url"`
729	Title               string                `json:"title"`
730	Caption             string                `json:"caption"`
731	Width               int                   `json:"video_width"`
732	Height              int                   `json:"video_height"`
733	Duration            int                   `json:"video_duration"`
734	Description         string                `json:"description"`
735	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
736	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
737}
738
739// InlineQueryResultCachedVideo is an inline query response with cached video.
740type InlineQueryResultCachedVideo struct {
741	Type                string                `json:"type"`          // required
742	ID                  string                `json:"id"`            // required
743	VideoID             string                `json:"video_file_id"` // required
744	Title               string                `json:"title"`         // required
745	Description         string                `json:"description"`
746	Caption             string                `json:"caption"`
747	ParseMode           string                `json:"parse_mode"`
748	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
749	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
750}
751
752// InlineQueryResultAudio is an inline query response audio.
753type InlineQueryResultAudio struct {
754	Type                string                `json:"type"`      // required
755	ID                  string                `json:"id"`        // required
756	URL                 string                `json:"audio_url"` // required
757	Title               string                `json:"title"`     // required
758	Caption             string                `json:"caption"`
759	Performer           string                `json:"performer"`
760	Duration            int                   `json:"audio_duration"`
761	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
762	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
763}
764
765// InlineQueryResultCachedAudio is an inline query response with cached audio.
766type InlineQueryResultCachedAudio struct {
767	Type                string                `json:"type"`          // required
768	ID                  string                `json:"id"`            // required
769	AudioID             string                `json:"audio_file_id"` // required
770	Caption             string                `json:"caption"`
771	ParseMode           string                `json:"parse_mode"`
772	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
773	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
774}
775
776// InlineQueryResultVoice is an inline query response voice.
777type InlineQueryResultVoice struct {
778	Type                string                `json:"type"`      // required
779	ID                  string                `json:"id"`        // required
780	URL                 string                `json:"voice_url"` // required
781	Title               string                `json:"title"`     // required
782	Caption             string                `json:"caption"`
783	Duration            int                   `json:"voice_duration"`
784	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
785	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
786}
787
788// InlineQueryResultCachedVoice is an inline query response with cached voice.
789type InlineQueryResultCachedVoice struct {
790	Type                string                `json:"type"`          // required
791	ID                  string                `json:"id"`            // required
792	VoiceID             string                `json:"voice_file_id"` // required
793	Title               string                `json:"title"`         // required
794	Caption             string                `json:"caption"`
795	ParseMode           string                `json:"parse_mode"`
796	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
797	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
798}
799
800// InlineQueryResultDocument is an inline query response document.
801type InlineQueryResultDocument struct {
802	Type                string                `json:"type"`  // required
803	ID                  string                `json:"id"`    // required
804	Title               string                `json:"title"` // required
805	Caption             string                `json:"caption"`
806	URL                 string                `json:"document_url"` // required
807	MimeType            string                `json:"mime_type"`    // required
808	Description         string                `json:"description"`
809	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
810	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
811	ThumbURL            string                `json:"thumb_url"`
812	ThumbWidth          int                   `json:"thumb_width"`
813	ThumbHeight         int                   `json:"thumb_height"`
814}
815
816// InlineQueryResultCachedDocument is an inline query response with cached document.
817type InlineQueryResultCachedDocument struct {
818	Type                string                `json:"type"`             // required
819	ID                  string                `json:"id"`               // required
820	DocumentID          string                `json:"document_file_id"` // required
821	Title               string                `json:"title"`            // required
822	Caption             string                `json:"caption"`
823	Description         string                `json:"description"`
824	ParseMode           string                `json:"parse_mode"`
825	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
826	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
827}
828
829// InlineQueryResultLocation is an inline query response location.
830type InlineQueryResultLocation struct {
831	Type                string                `json:"type"`      // required
832	ID                  string                `json:"id"`        // required
833	Latitude            float64               `json:"latitude"`  // required
834	Longitude           float64               `json:"longitude"` // required
835	Title               string                `json:"title"`     // required
836	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
837	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
838	ThumbURL            string                `json:"thumb_url"`
839	ThumbWidth          int                   `json:"thumb_width"`
840	ThumbHeight         int                   `json:"thumb_height"`
841}
842
843// InlineQueryResultVenue is an inline query response venue.
844type InlineQueryResultVenue struct {
845	Type                string                `json:"type"`      // required
846	ID                  string                `json:"id"`        // required
847	Latitude            float64               `json:"latitude"`  // required
848	Longitude           float64               `json:"longitude"` // required
849	Title               string                `json:"title"`     // required
850	Address             string                `json:"address"`   // required
851	FoursquareID        string                `json:"foursquare_id"`
852	FoursquareType      string                `json:"foursquare_type"`
853	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
854	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
855	ThumbURL            string                `json:"thumb_url"`
856	ThumbWidth          int                   `json:"thumb_width"`
857	ThumbHeight         int                   `json:"thumb_height"`
858}
859
860// InlineQueryResultGame is an inline query response game.
861type InlineQueryResultGame struct {
862	Type          string                `json:"type"`
863	ID            string                `json:"id"`
864	GameShortName string                `json:"game_short_name"`
865	ReplyMarkup   *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
866}
867
868// ChosenInlineResult is an inline query result chosen by a User
869type ChosenInlineResult struct {
870	ResultID        string    `json:"result_id"`
871	From            *User     `json:"from"`
872	Location        *Location `json:"location"`
873	InlineMessageID string    `json:"inline_message_id"`
874	Query           string    `json:"query"`
875}
876
877// InputTextMessageContent contains text for displaying
878// as an inline query result.
879type InputTextMessageContent struct {
880	Text                  string `json:"message_text"`
881	ParseMode             string `json:"parse_mode"`
882	DisableWebPagePreview bool   `json:"disable_web_page_preview"`
883}
884
885// InputLocationMessageContent contains a location for displaying
886// as an inline query result.
887type InputLocationMessageContent struct {
888	Latitude  float64 `json:"latitude"`
889	Longitude float64 `json:"longitude"`
890}
891
892// InputVenueMessageContent contains a venue for displaying
893// as an inline query result.
894type InputVenueMessageContent struct {
895	Latitude     float64 `json:"latitude"`
896	Longitude    float64 `json:"longitude"`
897	Title        string  `json:"title"`
898	Address      string  `json:"address"`
899	FoursquareID string  `json:"foursquare_id"`
900}
901
902// InputContactMessageContent contains a contact for displaying
903// as an inline query result.
904type InputContactMessageContent struct {
905	PhoneNumber string `json:"phone_number"`
906	FirstName   string `json:"first_name"`
907	LastName    string `json:"last_name"`
908}
909
910// Invoice contains basic information about an invoice.
911type Invoice struct {
912	Title          string `json:"title"`
913	Description    string `json:"description"`
914	StartParameter string `json:"start_parameter"`
915	Currency       string `json:"currency"`
916	TotalAmount    int    `json:"total_amount"`
917}
918
919// LabeledPrice represents a portion of the price for goods or services.
920type LabeledPrice struct {
921	Label  string `json:"label"`
922	Amount int    `json:"amount"`
923}
924
925// ShippingAddress represents a shipping address.
926type ShippingAddress struct {
927	CountryCode string `json:"country_code"`
928	State       string `json:"state"`
929	City        string `json:"city"`
930	StreetLine1 string `json:"street_line1"`
931	StreetLine2 string `json:"street_line2"`
932	PostCode    string `json:"post_code"`
933}
934
935// OrderInfo represents information about an order.
936type OrderInfo struct {
937	Name            string           `json:"name,omitempty"`
938	PhoneNumber     string           `json:"phone_number,omitempty"`
939	Email           string           `json:"email,omitempty"`
940	ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
941}
942
943// ShippingOption represents one shipping option.
944type ShippingOption struct {
945	ID     string          `json:"id"`
946	Title  string          `json:"title"`
947	Prices *[]LabeledPrice `json:"prices"`
948}
949
950// SuccessfulPayment contains basic information about a successful payment.
951type SuccessfulPayment struct {
952	Currency                string     `json:"currency"`
953	TotalAmount             int        `json:"total_amount"`
954	InvoicePayload          string     `json:"invoice_payload"`
955	ShippingOptionID        string     `json:"shipping_option_id,omitempty"`
956	OrderInfo               *OrderInfo `json:"order_info,omitempty"`
957	TelegramPaymentChargeID string     `json:"telegram_payment_charge_id"`
958	ProviderPaymentChargeID string     `json:"provider_payment_charge_id"`
959}
960
961// ShippingQuery contains information about an incoming shipping query.
962type ShippingQuery struct {
963	ID              string           `json:"id"`
964	From            *User            `json:"from"`
965	InvoicePayload  string           `json:"invoice_payload"`
966	ShippingAddress *ShippingAddress `json:"shipping_address"`
967}
968
969// PreCheckoutQuery contains information about an incoming pre-checkout query.
970type PreCheckoutQuery struct {
971	ID               string     `json:"id"`
972	From             *User      `json:"from"`
973	Currency         string     `json:"currency"`
974	TotalAmount      int        `json:"total_amount"`
975	InvoicePayload   string     `json:"invoice_payload"`
976	ShippingOptionID string     `json:"shipping_option_id,omitempty"`
977	OrderInfo        *OrderInfo `json:"order_info,omitempty"`
978}
979
980// Error is an error containing extra information returned by the Telegram API.
981type Error struct {
982	Code    int
983	Message string
984	ResponseParameters
985}
986
987func (e Error) Error() string {
988	return e.Message
989}