all repos — telegram-bot-api @ 7031d820be302f01d2e6380912101e3be6736878

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}
 60
 61// String displays a simple text version of a user.
 62//
 63// It is normally a user's username, but falls back to a first/last
 64// name as available.
 65func (u *User) String() string {
 66	if u.UserName != "" {
 67		return u.UserName
 68	}
 69
 70	name := u.FirstName
 71	if u.LastName != "" {
 72		name += " " + u.LastName
 73	}
 74
 75	return name
 76}
 77
 78// GroupChat is a group chat.
 79type GroupChat struct {
 80	ID    int    `json:"id"`
 81	Title string `json:"title"`
 82}
 83
 84// ChatPhoto represents a chat photo.
 85type ChatPhoto struct {
 86	SmallFileID string `json:"small_file_id"`
 87	BigFileID   string `json:"big_file_id"`
 88}
 89
 90// Chat contains information about the place a message was sent.
 91type Chat struct {
 92	ID                  int64      `json:"id"`
 93	Type                string     `json:"type"`
 94	Title               string     `json:"title"`                          // optional
 95	UserName            string     `json:"username"`                       // optional
 96	FirstName           string     `json:"first_name"`                     // optional
 97	LastName            string     `json:"last_name"`                      // optional
 98	AllMembersAreAdmins bool       `json:"all_members_are_administrators"` // optional
 99	Photo               *ChatPhoto `json:"photo"`
100	Description         string     `json:"description,omitempty"` // optional
101	InviteLink          string     `json:"invite_link,omitempty"` // optional
102}
103
104// IsPrivate returns if the Chat is a private conversation.
105func (c Chat) IsPrivate() bool {
106	return c.Type == "private"
107}
108
109// IsGroup returns if the Chat is a group.
110func (c Chat) IsGroup() bool {
111	return c.Type == "group"
112}
113
114// IsSuperGroup returns if the Chat is a supergroup.
115func (c Chat) IsSuperGroup() bool {
116	return c.Type == "supergroup"
117}
118
119// IsChannel returns if the Chat is a channel.
120func (c Chat) IsChannel() bool {
121	return c.Type == "channel"
122}
123
124// ChatConfig returns a ChatConfig struct for chat related methods.
125func (c Chat) ChatConfig() ChatConfig {
126	return ChatConfig{ChatID: c.ID}
127}
128
129// Message is returned by almost every request, and contains data about
130// almost anything.
131type Message struct {
132	MessageID             int                `json:"message_id"`
133	From                  *User              `json:"from"` // optional
134	Date                  int                `json:"date"`
135	Chat                  *Chat              `json:"chat"`
136	ForwardFrom           *User              `json:"forward_from"`            // optional
137	ForwardFromChat       *Chat              `json:"forward_from_chat"`       // optional
138	ForwardFromMessageID  int                `json:"forward_from_message_id"` // optional
139	ForwardDate           int                `json:"forward_date"`            // optional
140	ReplyToMessage        *Message           `json:"reply_to_message"`        // optional
141	EditDate              int                `json:"edit_date"`               // optional
142	Text                  string             `json:"text"`                    // optional
143	Entities              *[]MessageEntity   `json:"entities"`                // optional
144	Audio                 *Audio             `json:"audio"`                   // optional
145	Document              *Document          `json:"document"`                // optional
146	Game                  *Game              `json:"game"`                    // optional
147	Photo                 *[]PhotoSize       `json:"photo"`                   // optional
148	Sticker               *Sticker           `json:"sticker"`                 // optional
149	Video                 *Video             `json:"video"`                   // optional
150	VideoNote             *VideoNote         `json:"video_note"`              // optional
151	Voice                 *Voice             `json:"voice"`                   // optional
152	Caption               string             `json:"caption"`                 // optional
153	Contact               *Contact           `json:"contact"`                 // optional
154	Location              *Location          `json:"location"`                // optional
155	Venue                 *Venue             `json:"venue"`                   // optional
156	NewChatMembers        *[]User            `json:"new_chat_members"`        // optional
157	LeftChatMember        *User              `json:"left_chat_member"`        // optional
158	NewChatTitle          string             `json:"new_chat_title"`          // optional
159	NewChatPhoto          *[]PhotoSize       `json:"new_chat_photo"`          // optional
160	DeleteChatPhoto       bool               `json:"delete_chat_photo"`       // optional
161	GroupChatCreated      bool               `json:"group_chat_created"`      // optional
162	SuperGroupChatCreated bool               `json:"supergroup_chat_created"` // optional
163	ChannelChatCreated    bool               `json:"channel_chat_created"`    // optional
164	MigrateToChatID       int64              `json:"migrate_to_chat_id"`      // optional
165	MigrateFromChatID     int64              `json:"migrate_from_chat_id"`    // optional
166	PinnedMessage         *Message           `json:"pinned_message"`          // optional
167	Invoice               *Invoice           `json:"invoice"`                 // optional
168	SuccessfulPayment     *SuccessfulPayment `json:"successful_payment"`      // optional
169}
170
171// Time converts the message timestamp into a Time.
172func (m *Message) Time() time.Time {
173	return time.Unix(int64(m.Date), 0)
174}
175
176// IsCommand returns true if message starts with a "bot_command" entity.
177func (m *Message) IsCommand() bool {
178	if m.Entities == nil || len(*m.Entities) == 0 {
179		return false
180	}
181
182	entity := (*m.Entities)[0]
183	return entity.Offset == 0 && entity.Type == "bot_command"
184}
185
186// Command checks if the message was a command and if it was, returns the
187// command. If the Message was not a command, it returns an empty string.
188//
189// If the command contains the at name syntax, it is removed. Use
190// CommandWithAt() if you do not want that.
191func (m *Message) Command() string {
192	command := m.CommandWithAt()
193
194	if i := strings.Index(command, "@"); i != -1 {
195		command = command[:i]
196	}
197
198	return command
199}
200
201// CommandWithAt checks if the message was a command and if it was, returns the
202// command. If the Message was not a command, it returns an empty string.
203//
204// If the command contains the at name syntax, it is not removed. Use Command()
205// if you want that.
206func (m *Message) CommandWithAt() string {
207	if !m.IsCommand() {
208		return ""
209	}
210
211	// IsCommand() checks that the message begins with a bot_command entity
212	entity := (*m.Entities)[0]
213	return m.Text[1:entity.Length]
214}
215
216// CommandArguments checks if the message was a command and if it was,
217// returns all text after the command name. If the Message was not a
218// command, it returns an empty string.
219//
220// Note: The first character after the command name is omitted:
221// - "/foo bar baz" yields "bar baz", not " bar baz"
222// - "/foo-bar baz" yields "bar baz", too
223// Even though the latter is not a command conforming to the spec, the API
224// marks "/foo" as command entity.
225func (m *Message) CommandArguments() string {
226	if !m.IsCommand() {
227		return ""
228	}
229
230	// IsCommand() checks that the message begins with a bot_command entity
231	entity := (*m.Entities)[0]
232	if len(m.Text) == entity.Length {
233		return "" // The command makes up the whole message
234	} else {
235		return m.Text[entity.Length+1:]
236	}
237}
238
239// MessageEntity contains information about data in a Message.
240type MessageEntity struct {
241	Type   string `json:"type"`
242	Offset int    `json:"offset"`
243	Length int    `json:"length"`
244	URL    string `json:"url"`  // optional
245	User   *User  `json:"user"` // optional
246}
247
248// ParseURL attempts to parse a URL contained within a MessageEntity.
249func (entity MessageEntity) ParseURL() (*url.URL, error) {
250	if entity.URL == "" {
251		return nil, errors.New(ErrBadURL)
252	}
253
254	return url.Parse(entity.URL)
255}
256
257// PhotoSize contains information about photos.
258type PhotoSize struct {
259	FileID   string `json:"file_id"`
260	Width    int    `json:"width"`
261	Height   int    `json:"height"`
262	FileSize int    `json:"file_size"` // optional
263}
264
265// Audio contains information about audio.
266type Audio struct {
267	FileID    string `json:"file_id"`
268	Duration  int    `json:"duration"`
269	Performer string `json:"performer"` // optional
270	Title     string `json:"title"`     // optional
271	MimeType  string `json:"mime_type"` // optional
272	FileSize  int    `json:"file_size"` // optional
273}
274
275// Document contains information about a document.
276type Document struct {
277	FileID    string     `json:"file_id"`
278	Thumbnail *PhotoSize `json:"thumb"`     // optional
279	FileName  string     `json:"file_name"` // optional
280	MimeType  string     `json:"mime_type"` // optional
281	FileSize  int        `json:"file_size"` // optional
282}
283
284// Sticker contains information about a sticker.
285type Sticker struct {
286	FileID    string     `json:"file_id"`
287	Width     int        `json:"width"`
288	Height    int        `json:"height"`
289	Thumbnail *PhotoSize `json:"thumb"`     // optional
290	Emoji     string     `json:"emoji"`     // optional
291	FileSize  int        `json:"file_size"` // optional
292}
293
294// Video contains information about a video.
295type Video struct {
296	FileID    string     `json:"file_id"`
297	Width     int        `json:"width"`
298	Height    int        `json:"height"`
299	Duration  int        `json:"duration"`
300	Thumbnail *PhotoSize `json:"thumb"`     // optional
301	MimeType  string     `json:"mime_type"` // optional
302	FileSize  int        `json:"file_size"` // optional
303}
304
305// VideoNote contains information about a video.
306type VideoNote struct {
307	FileID    string     `json:"file_id"`
308	Length    int        `json:"length"`
309	Duration  int        `json:"duration"`
310	Thumbnail *PhotoSize `json:"thumb"`     // optional
311	FileSize  int        `json:"file_size"` // optional
312}
313
314// Voice contains information about a voice.
315type Voice struct {
316	FileID   string `json:"file_id"`
317	Duration int    `json:"duration"`
318	MimeType string `json:"mime_type"` // optional
319	FileSize int    `json:"file_size"` // optional
320}
321
322// Contact contains information about a contact.
323//
324// Note that LastName and UserID may be empty.
325type Contact struct {
326	PhoneNumber string `json:"phone_number"`
327	FirstName   string `json:"first_name"`
328	LastName    string `json:"last_name"` // optional
329	UserID      int    `json:"user_id"`   // optional
330}
331
332// Location contains information about a place.
333type Location struct {
334	Longitude  float64 `json:"longitude"`
335	Latitude   float64 `json:"latitude"`
336	LivePeriod int     `json:"live_period"`
337}
338
339// Venue contains information about a venue, including its Location.
340type Venue struct {
341	Location     Location `json:"location"`
342	Title        string   `json:"title"`
343	Address      string   `json:"address"`
344	FoursquareID string   `json:"foursquare_id"` // optional
345}
346
347// UserProfilePhotos contains a set of user profile photos.
348type UserProfilePhotos struct {
349	TotalCount int           `json:"total_count"`
350	Photos     [][]PhotoSize `json:"photos"`
351}
352
353// File contains information about a file to download from Telegram.
354type File struct {
355	FileID   string `json:"file_id"`
356	FileSize int    `json:"file_size"` // optional
357	FilePath string `json:"file_path"` // optional
358}
359
360// Link returns a full path to the download URL for a File.
361//
362// It requires the Bot Token to create the link.
363func (f *File) Link(token string) string {
364	return fmt.Sprintf(FileEndpoint, token, f.FilePath)
365}
366
367// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
368type ReplyKeyboardMarkup struct {
369	Keyboard        [][]KeyboardButton `json:"keyboard"`
370	ResizeKeyboard  bool               `json:"resize_keyboard"`   // optional
371	OneTimeKeyboard bool               `json:"one_time_keyboard"` // optional
372	Selective       bool               `json:"selective"`         // optional
373}
374
375// KeyboardButton is a button within a custom keyboard.
376type KeyboardButton struct {
377	Text            string `json:"text"`
378	RequestContact  bool   `json:"request_contact"`
379	RequestLocation bool   `json:"request_location"`
380}
381
382// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
383type ReplyKeyboardHide struct {
384	HideKeyboard bool `json:"hide_keyboard"`
385	Selective    bool `json:"selective"` // optional
386}
387
388// ReplyKeyboardRemove allows the Bot to hide a custom keyboard.
389type ReplyKeyboardRemove struct {
390	RemoveKeyboard bool `json:"remove_keyboard"`
391	Selective      bool `json:"selective"`
392}
393
394// InlineKeyboardMarkup is a custom keyboard presented for an inline bot.
395type InlineKeyboardMarkup struct {
396	InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
397}
398
399// InlineKeyboardButton is a button within a custom keyboard for
400// inline query responses.
401//
402// Note that some values are references as even an empty string
403// will change behavior.
404//
405// CallbackGame, if set, MUST be first button in first row.
406type InlineKeyboardButton struct {
407	Text                         string        `json:"text"`
408	URL                          *string       `json:"url,omitempty"`                              // optional
409	CallbackData                 *string       `json:"callback_data,omitempty"`                    // optional
410	SwitchInlineQuery            *string       `json:"switch_inline_query,omitempty"`              // optional
411	SwitchInlineQueryCurrentChat *string       `json:"switch_inline_query_current_chat,omitempty"` // optional
412	CallbackGame                 *CallbackGame `json:"callback_game,omitempty"`                    // optional
413	Pay                          bool          `json:"pay,omitempty"`			       // optional
414}
415
416// CallbackQuery is data sent when a keyboard button with callback data
417// is clicked.
418type CallbackQuery struct {
419	ID              string   `json:"id"`
420	From            *User    `json:"from"`
421	Message         *Message `json:"message"`           // optional
422	InlineMessageID string   `json:"inline_message_id"` // optional
423	ChatInstance    string   `json:"chat_instance"`
424	Data            string   `json:"data"`            // optional
425	GameShortName   string   `json:"game_short_name"` // optional
426}
427
428// ForceReply allows the Bot to have users directly reply to it without
429// additional interaction.
430type ForceReply struct {
431	ForceReply bool `json:"force_reply"`
432	Selective  bool `json:"selective"` // optional
433}
434
435// ChatMember is information about a member in a chat.
436type ChatMember struct {
437	User                  *User  `json:"user"`
438	Status                string `json:"status"`
439	UntilDate             int64  `json:"until_date,omitempty"`                // optional
440	CanBeEdited           bool   `json:"can_be_edited,omitempty"`             // optional
441	CanChangeInfo         bool   `json:"can_change_info,omitempty"`           // optional
442	CanPostMessages       bool   `json:"can_post_messages,omitempty"`         // optional
443	CanEditMessages       bool   `json:"can_edit_messages,omitempty"`         // optional
444	CanDeleteMessages     bool   `json:"can_delete_messages,omitempty"`       // optional
445	CanInviteUsers        bool   `json:"can_invite_users,omitempty"`          // optional
446	CanRestrictMembers    bool   `json:"can_restrict_members,omitempty"`      // optional
447	CanPinMessages        bool   `json:"can_pin_messages,omitempty"`          // optional
448	CanPromoteMembers     bool   `json:"can_promote_members,omitempty"`       // optional
449	CanSendMessages       bool   `json:"can_send_messages,omitempty"`         // optional
450	CanSendMediaMessages  bool   `json:"can_send_media_messages,omitempty"`   // optional
451	CanSendOtherMessages  bool   `json:"can_send_other_messages,omitempty"`   // optional
452	CanAddWebPagePreviews bool   `json:"can_add_web_page_previews,omitempty"` // optional
453}
454
455// IsCreator returns if the ChatMember was the creator of the chat.
456func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" }
457
458// IsAdministrator returns if the ChatMember is a chat administrator.
459func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" }
460
461// IsMember returns if the ChatMember is a current member of the chat.
462func (chat ChatMember) IsMember() bool { return chat.Status == "member" }
463
464// HasLeft returns if the ChatMember left the chat.
465func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
466
467// WasKicked returns if the ChatMember was kicked from the chat.
468func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
469
470// Game is a game within Telegram.
471type Game struct {
472	Title        string          `json:"title"`
473	Description  string          `json:"description"`
474	Photo        []PhotoSize     `json:"photo"`
475	Text         string          `json:"text"`
476	TextEntities []MessageEntity `json:"text_entities"`
477	Animation    Animation       `json:"animation"`
478}
479
480// Animation is a GIF animation demonstrating the game.
481type Animation struct {
482	FileID   string    `json:"file_id"`
483	Thumb    PhotoSize `json:"thumb"`
484	FileName string    `json:"file_name"`
485	MimeType string    `json:"mime_type"`
486	FileSize int       `json:"file_size"`
487}
488
489// GameHighScore is a user's score and position on the leaderboard.
490type GameHighScore struct {
491	Position int  `json:"position"`
492	User     User `json:"user"`
493	Score    int  `json:"score"`
494}
495
496// CallbackGame is for starting a game in an inline keyboard button.
497type CallbackGame struct{}
498
499// WebhookInfo is information about a currently set webhook.
500type WebhookInfo struct {
501	URL                  string `json:"url"`
502	HasCustomCertificate bool   `json:"has_custom_certificate"`
503	PendingUpdateCount   int    `json:"pending_update_count"`
504	LastErrorDate        int    `json:"last_error_date"`    // optional
505	LastErrorMessage     string `json:"last_error_message"` // optional
506}
507
508// IsSet returns true if a webhook is currently set.
509func (info WebhookInfo) IsSet() bool {
510	return info.URL != ""
511}
512
513// InlineQuery is a Query from Telegram for an inline request.
514type InlineQuery struct {
515	ID       string    `json:"id"`
516	From     *User     `json:"from"`
517	Location *Location `json:"location"` // optional
518	Query    string    `json:"query"`
519	Offset   string    `json:"offset"`
520}
521
522// InlineQueryResultArticle is an inline query response article.
523type InlineQueryResultArticle struct {
524	Type                string                `json:"type"`                            // required
525	ID                  string                `json:"id"`                              // required
526	Title               string                `json:"title"`                           // required
527	InputMessageContent interface{}           `json:"input_message_content,omitempty"` // required
528	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
529	URL                 string                `json:"url"`
530	HideURL             bool                  `json:"hide_url"`
531	Description         string                `json:"description"`
532	ThumbURL            string                `json:"thumb_url"`
533	ThumbWidth          int                   `json:"thumb_width"`
534	ThumbHeight         int                   `json:"thumb_height"`
535}
536
537// InlineQueryResultPhoto is an inline query response photo.
538type InlineQueryResultPhoto struct {
539	Type                string                `json:"type"`      // required
540	ID                  string                `json:"id"`        // required
541	URL                 string                `json:"photo_url"` // required
542	MimeType            string                `json:"mime_type"`
543	Width               int                   `json:"photo_width"`
544	Height              int                   `json:"photo_height"`
545	ThumbURL            string                `json:"thumb_url"`
546	Title               string                `json:"title"`
547	Description         string                `json:"description"`
548	Caption             string                `json:"caption"`
549	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
550	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
551}
552
553// InlineQueryResultGIF is an inline query response GIF.
554type InlineQueryResultGIF struct {
555	Type                string                `json:"type"`    // required
556	ID                  string                `json:"id"`      // required
557	URL                 string                `json:"gif_url"` // required
558	Width               int                   `json:"gif_width"`
559	Height              int                   `json:"gif_height"`
560	Duration            int                   `json:"gif_duration"`
561	ThumbURL            string                `json:"thumb_url"`
562	Title               string                `json:"title"`
563	Caption             string                `json:"caption"`
564	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
565	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
566}
567
568// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
569type InlineQueryResultMPEG4GIF struct {
570	Type                string                `json:"type"`      // required
571	ID                  string                `json:"id"`        // required
572	URL                 string                `json:"mpeg4_url"` // required
573	Width               int                   `json:"mpeg4_width"`
574	Height              int                   `json:"mpeg4_height"`
575	Duration            int                   `json:"mpeg4_duration"`
576	ThumbURL            string                `json:"thumb_url"`
577	Title               string                `json:"title"`
578	Caption             string                `json:"caption"`
579	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
580	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
581}
582
583// InlineQueryResultVideo is an inline query response video.
584type InlineQueryResultVideo struct {
585	Type                string                `json:"type"`      // required
586	ID                  string                `json:"id"`        // required
587	URL                 string                `json:"video_url"` // required
588	MimeType            string                `json:"mime_type"` // required
589	ThumbURL            string                `json:"thumb_url"`
590	Title               string                `json:"title"`
591	Caption             string                `json:"caption"`
592	Width               int                   `json:"video_width"`
593	Height              int                   `json:"video_height"`
594	Duration            int                   `json:"video_duration"`
595	Description         string                `json:"description"`
596	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
597	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
598}
599
600// InlineQueryResultAudio is an inline query response audio.
601type InlineQueryResultAudio struct {
602	Type                string                `json:"type"`      // required
603	ID                  string                `json:"id"`        // required
604	URL                 string                `json:"audio_url"` // required
605	Title               string                `json:"title"`     // required
606	Caption             string                `json:"caption"`
607	Performer           string                `json:"performer"`
608	Duration            int                   `json:"audio_duration"`
609	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
610	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
611}
612
613// InlineQueryResultVoice is an inline query response voice.
614type InlineQueryResultVoice struct {
615	Type                string                `json:"type"`      // required
616	ID                  string                `json:"id"`        // required
617	URL                 string                `json:"voice_url"` // required
618	Title               string                `json:"title"`     // required
619	Caption             string                `json:"caption"`
620	Duration            int                   `json:"voice_duration"`
621	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
622	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
623}
624
625// InlineQueryResultDocument is an inline query response document.
626type InlineQueryResultDocument struct {
627	Type                string                `json:"type"`  // required
628	ID                  string                `json:"id"`    // required
629	Title               string                `json:"title"` // required
630	Caption             string                `json:"caption"`
631	URL                 string                `json:"document_url"` // required
632	MimeType            string                `json:"mime_type"`    // required
633	Description         string                `json:"description"`
634	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
635	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
636	ThumbURL            string                `json:"thumb_url"`
637	ThumbWidth          int                   `json:"thumb_width"`
638	ThumbHeight         int                   `json:"thumb_height"`
639}
640
641// InlineQueryResultLocation is an inline query response location.
642type InlineQueryResultLocation struct {
643	Type                string                `json:"type"`        // required
644	ID                  string                `json:"id"`          // required
645	Latitude            float64               `json:"latitude"`    // required
646	Longitude           float64               `json:"longitude"`   // required
647	LivePeriod          int                   `json:"live_period"` // optional
648	Title               string                `json:"title"`       // required
649	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
650	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
651	ThumbURL            string                `json:"thumb_url"`
652	ThumbWidth          int                   `json:"thumb_width"`
653	ThumbHeight         int                   `json:"thumb_height"`
654}
655
656// InlineQueryResultGame is an inline query response game.
657type InlineQueryResultGame struct {
658	Type          string                `json:"type"`
659	ID            string                `json:"id"`
660	GameShortName string                `json:"game_short_name"`
661	ReplyMarkup   *InlineKeyboardMarkup `json:"reply_markup"`
662}
663
664// ChosenInlineResult is an inline query result chosen by a User
665type ChosenInlineResult struct {
666	ResultID        string    `json:"result_id"`
667	From            *User     `json:"from"`
668	Location        *Location `json:"location"`
669	InlineMessageID string    `json:"inline_message_id"`
670	Query           string    `json:"query"`
671}
672
673// InputTextMessageContent contains text for displaying
674// as an inline query result.
675type InputTextMessageContent struct {
676	Text                  string `json:"message_text"`
677	ParseMode             string `json:"parse_mode"`
678	DisableWebPagePreview bool   `json:"disable_web_page_preview"`
679}
680
681// InputLocationMessageContent contains a location for displaying
682// as an inline query result.
683type InputLocationMessageContent struct {
684	Latitude   float64 `json:"latitude"`
685	Longitude  float64 `json:"longitude"`
686	LivePeriod int     `json:"live_period"`
687}
688
689// InputVenueMessageContent contains a venue for displaying
690// as an inline query result.
691type InputVenueMessageContent struct {
692	Latitude     float64 `json:"latitude"`
693	Longitude    float64 `json:"longitude"`
694	Title        string  `json:"title"`
695	Address      string  `json:"address"`
696	FoursquareID string  `json:"foursquare_id"`
697}
698
699// InputContactMessageContent contains a contact for displaying
700// as an inline query result.
701type InputContactMessageContent struct {
702	PhoneNumber string `json:"phone_number"`
703	FirstName   string `json:"first_name"`
704	LastName    string `json:"last_name"`
705}
706
707// Invoice contains basic information about an invoice.
708type Invoice struct {
709	Title          string `json:"title"`
710	Description    string `json:"description"`
711	StartParameter string `json:"start_parameter"`
712	Currency       string `json:"currency"`
713	TotalAmount    int    `json:"total_amount"`
714}
715
716// LabeledPrice represents a portion of the price for goods or services.
717type LabeledPrice struct {
718	Label  string `json:"label"`
719	Amount int    `json:"amount"`
720}
721
722// ShippingAddress represents a shipping address.
723type ShippingAddress struct {
724	CountryCode string `json:"country_code"`
725	State       string `json:"state"`
726	City        string `json:"city"`
727	StreetLine1 string `json:"street_line1"`
728	StreetLine2 string `json:"street_line2"`
729	PostCode    string `json:"post_code"`
730}
731
732// OrderInfo represents information about an order.
733type OrderInfo struct {
734	Name            string           `json:"name,omitempty"`
735	PhoneNumber     string           `json:"phone_number,omitempty"`
736	Email           string           `json:"email,omitempty"`
737	ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
738}
739
740// ShippingOption represents one shipping option.
741type ShippingOption struct {
742	ID     string          `json:"id"`
743	Title  string          `json:"title"`
744	Prices *[]LabeledPrice `json:"prices"`
745}
746
747// SuccessfulPayment contains basic information about a successful payment.
748type SuccessfulPayment struct {
749	Currency                string     `json:"currency"`
750	TotalAmount             int        `json:"total_amount"`
751	InvoicePayload          string     `json:"invoice_payload"`
752	ShippingOptionID        string     `json:"shipping_option_id,omitempty"`
753	OrderInfo               *OrderInfo `json:"order_info,omitempty"`
754	TelegramPaymentChargeID string     `json:"telegram_payment_charge_id"`
755	ProviderPaymentChargeID string     `json:"provider_payment_charge_id"`
756}
757
758// ShippingQuery contains information about an incoming shipping query.
759type ShippingQuery struct {
760	ID              string           `json:"id"`
761	From            *User            `json:"from"`
762	InvoicePayload  string           `json:"invoice_payload"`
763	ShippingAddress *ShippingAddress `json:"shipping_address"`
764}
765
766// PreCheckoutQuery contains information about an incoming pre-checkout query.
767type PreCheckoutQuery struct {
768	ID               string     `json:"id"`
769	From             *User      `json:"from"`
770	Currency         string     `json:"currency"`
771	TotalAmount      int        `json:"total_amount"`
772	InvoicePayload   string     `json:"invoice_payload"`
773	ShippingOptionID string     `json:"shipping_option_id,omitempty"`
774	OrderInfo        *OrderInfo `json:"order_info,omitempty"`
775}