all repos — telegram-bot-api @ 57be98801107f19622d22a718cdc4a5f52cc0712

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.UserName != "" {
 68		return u.UserName
 69	}
 70
 71	name := u.FirstName
 72	if u.LastName != "" {
 73		name += " " + u.LastName
 74	}
 75
 76	return name
 77}
 78
 79// GroupChat is a group chat.
 80type GroupChat struct {
 81	ID    int    `json:"id"`
 82	Title string `json:"title"`
 83}
 84
 85// ChatPhoto represents a chat photo.
 86type ChatPhoto struct {
 87	SmallFileID string `json:"small_file_id"`
 88	BigFileID   string `json:"big_file_id"`
 89}
 90
 91// Chat contains information about the place a message was sent.
 92type Chat struct {
 93	ID                  int64      `json:"id"`
 94	Type                string     `json:"type"`
 95	Title               string     `json:"title"`                          // optional
 96	UserName            string     `json:"username"`                       // optional
 97	FirstName           string     `json:"first_name"`                     // optional
 98	LastName            string     `json:"last_name"`                      // optional
 99	AllMembersAreAdmins bool       `json:"all_members_are_administrators"` // optional
100	Photo               *ChatPhoto `json:"photo"`
101	Description         string     `json:"description,omitempty"` // optional
102	InviteLink          string     `json:"invite_link,omitempty"` // optional
103}
104
105// IsPrivate returns if the Chat is a private conversation.
106func (c Chat) IsPrivate() bool {
107	return c.Type == "private"
108}
109
110// IsGroup returns if the Chat is a group.
111func (c Chat) IsGroup() bool {
112	return c.Type == "group"
113}
114
115// IsSuperGroup returns if the Chat is a supergroup.
116func (c Chat) IsSuperGroup() bool {
117	return c.Type == "supergroup"
118}
119
120// IsChannel returns if the Chat is a channel.
121func (c Chat) IsChannel() bool {
122	return c.Type == "channel"
123}
124
125// ChatConfig returns a ChatConfig struct for chat related methods.
126func (c Chat) ChatConfig() ChatConfig {
127	return ChatConfig{ChatID: c.ID}
128}
129
130// Message is returned by almost every request, and contains data about
131// almost anything.
132type Message struct {
133	MessageID             int                `json:"message_id"`
134	From                  *User              `json:"from"` // optional
135	Date                  int                `json:"date"`
136	Chat                  *Chat              `json:"chat"`
137	ForwardFrom           *User              `json:"forward_from"`            // optional
138	ForwardFromChat       *Chat              `json:"forward_from_chat"`       // optional
139	ForwardFromMessageID  int                `json:"forward_from_message_id"` // optional
140	ForwardDate           int                `json:"forward_date"`            // optional
141	ReplyToMessage        *Message           `json:"reply_to_message"`        // optional
142	EditDate              int                `json:"edit_date"`               // optional
143	Text                  string             `json:"text"`                    // optional
144	Entities              *[]MessageEntity   `json:"entities"`                // optional
145	Audio                 *Audio             `json:"audio"`                   // optional
146	Document              *Document          `json:"document"`                // optional
147	Game                  *Game              `json:"game"`                    // optional
148	Photo                 *[]PhotoSize       `json:"photo"`                   // optional
149	Sticker               *Sticker           `json:"sticker"`                 // optional
150	Video                 *Video             `json:"video"`                   // optional
151	VideoNote             *VideoNote         `json:"video_note"`              // optional
152	Voice                 *Voice             `json:"voice"`                   // optional
153	Caption               string             `json:"caption"`                 // optional
154	Contact               *Contact           `json:"contact"`                 // optional
155	Location              *Location          `json:"location"`                // optional
156	Venue                 *Venue             `json:"venue"`                   // optional
157	NewChatMembers        *[]User            `json:"new_chat_members"`        // optional
158	LeftChatMember        *User              `json:"left_chat_member"`        // optional
159	NewChatTitle          string             `json:"new_chat_title"`          // optional
160	NewChatPhoto          *[]PhotoSize       `json:"new_chat_photo"`          // optional
161	DeleteChatPhoto       bool               `json:"delete_chat_photo"`       // optional
162	GroupChatCreated      bool               `json:"group_chat_created"`      // optional
163	SuperGroupChatCreated bool               `json:"supergroup_chat_created"` // optional
164	ChannelChatCreated    bool               `json:"channel_chat_created"`    // optional
165	MigrateToChatID       int64              `json:"migrate_to_chat_id"`      // optional
166	MigrateFromChatID     int64              `json:"migrate_from_chat_id"`    // optional
167	PinnedMessage         *Message           `json:"pinned_message"`          // optional
168	Invoice               *Invoice           `json:"invoice"`                 // optional
169	SuccessfulPayment     *SuccessfulPayment `json:"successful_payment"`      // optional
170}
171
172// Time converts the message timestamp into a Time.
173func (m *Message) Time() time.Time {
174	return time.Unix(int64(m.Date), 0)
175}
176
177// IsCommand returns true if message starts with a "bot_command" entity.
178func (m *Message) IsCommand() bool {
179	if m.Entities == nil || len(*m.Entities) == 0 {
180		return false
181	}
182
183	entity := (*m.Entities)[0]
184	return entity.Offset == 0 && entity.Type == "bot_command"
185}
186
187// Command checks if the message was a command and if it was, returns the
188// command. If the Message was not a command, it returns an empty string.
189//
190// If the command contains the at name syntax, it is removed. Use
191// CommandWithAt() if you do not want that.
192func (m *Message) Command() string {
193	command := m.CommandWithAt()
194
195	if i := strings.Index(command, "@"); i != -1 {
196		command = command[:i]
197	}
198
199	return command
200}
201
202// CommandWithAt checks if the message was a command and if it was, returns the
203// command. If the Message was not a command, it returns an empty string.
204//
205// If the command contains the at name syntax, it is not removed. Use Command()
206// if you want that.
207func (m *Message) CommandWithAt() string {
208	if !m.IsCommand() {
209		return ""
210	}
211
212	// IsCommand() checks that the message begins with a bot_command entity
213	entity := (*m.Entities)[0]
214	return m.Text[1:entity.Length]
215}
216
217// CommandArguments checks if the message was a command and if it was,
218// returns all text after the command name. If the Message was not a
219// command, it returns an empty string.
220//
221// Note: The first character after the command name is omitted:
222// - "/foo bar baz" yields "bar baz", not " bar baz"
223// - "/foo-bar baz" yields "bar baz", too
224// Even though the latter is not a command conforming to the spec, the API
225// marks "/foo" as command entity.
226func (m *Message) CommandArguments() string {
227	if !m.IsCommand() {
228		return ""
229	}
230
231	// IsCommand() checks that the message begins with a bot_command entity
232	entity := (*m.Entities)[0]
233	if len(m.Text) == entity.Length {
234		return "" // The command makes up the whole message
235	} else {
236		return m.Text[entity.Length+1:]
237	}
238}
239
240// MessageEntity contains information about data in a Message.
241type MessageEntity struct {
242	Type   string `json:"type"`
243	Offset int    `json:"offset"`
244	Length int    `json:"length"`
245	URL    string `json:"url"`  // optional
246	User   *User  `json:"user"` // optional
247}
248
249// ParseURL attempts to parse a URL contained within a MessageEntity.
250func (entity MessageEntity) ParseURL() (*url.URL, error) {
251	if entity.URL == "" {
252		return nil, errors.New(ErrBadURL)
253	}
254
255	return url.Parse(entity.URL)
256}
257
258// PhotoSize contains information about photos.
259type PhotoSize struct {
260	FileID   string `json:"file_id"`
261	Width    int    `json:"width"`
262	Height   int    `json:"height"`
263	FileSize int    `json:"file_size"` // optional
264}
265
266// Audio contains information about audio.
267type Audio struct {
268	FileID    string `json:"file_id"`
269	Duration  int    `json:"duration"`
270	Performer string `json:"performer"` // optional
271	Title     string `json:"title"`     // optional
272	MimeType  string `json:"mime_type"` // optional
273	FileSize  int    `json:"file_size"` // optional
274}
275
276// Document contains information about a document.
277type Document struct {
278	FileID    string     `json:"file_id"`
279	Thumbnail *PhotoSize `json:"thumb"`     // optional
280	FileName  string     `json:"file_name"` // optional
281	MimeType  string     `json:"mime_type"` // optional
282	FileSize  int        `json:"file_size"` // optional
283}
284
285// Sticker contains information about a sticker.
286type Sticker struct {
287	FileID    string     `json:"file_id"`
288	Width     int        `json:"width"`
289	Height    int        `json:"height"`
290	Thumbnail *PhotoSize `json:"thumb"`     // optional
291	Emoji     string     `json:"emoji"`     // optional
292	FileSize  int        `json:"file_size"` // optional
293}
294
295// Video contains information about a video.
296type Video struct {
297	FileID    string     `json:"file_id"`
298	Width     int        `json:"width"`
299	Height    int        `json:"height"`
300	Duration  int        `json:"duration"`
301	Thumbnail *PhotoSize `json:"thumb"`     // optional
302	MimeType  string     `json:"mime_type"` // optional
303	FileSize  int        `json:"file_size"` // optional
304}
305
306// VideoNote contains information about a video.
307type VideoNote struct {
308	FileID    string     `json:"file_id"`
309	Length    int        `json:"length"`
310	Duration  int        `json:"duration"`
311	Thumbnail *PhotoSize `json:"thumb"`     // optional
312	FileSize  int        `json:"file_size"` // optional
313}
314
315// Voice contains information about a voice.
316type Voice struct {
317	FileID   string `json:"file_id"`
318	Duration int    `json:"duration"`
319	MimeType string `json:"mime_type"` // optional
320	FileSize int    `json:"file_size"` // optional
321}
322
323// Contact contains information about a contact.
324//
325// Note that LastName and UserID may be empty.
326type Contact struct {
327	PhoneNumber string `json:"phone_number"`
328	FirstName   string `json:"first_name"`
329	LastName    string `json:"last_name"` // optional
330	UserID      int    `json:"user_id"`   // optional
331}
332
333// Location contains information about a place.
334type Location struct {
335	Longitude float64 `json:"longitude"`
336	Latitude  float64 `json:"latitude"`
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	Title               string                `json:"title"`     // required
648	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
649	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
650	ThumbURL            string                `json:"thumb_url"`
651	ThumbWidth          int                   `json:"thumb_width"`
652	ThumbHeight         int                   `json:"thumb_height"`
653}
654
655// InlineQueryResultGame is an inline query response game.
656type InlineQueryResultGame struct {
657	Type          string                `json:"type"`
658	ID            string                `json:"id"`
659	GameShortName string                `json:"game_short_name"`
660	ReplyMarkup   *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
661}
662
663// ChosenInlineResult is an inline query result chosen by a User
664type ChosenInlineResult struct {
665	ResultID        string    `json:"result_id"`
666	From            *User     `json:"from"`
667	Location        *Location `json:"location"`
668	InlineMessageID string    `json:"inline_message_id"`
669	Query           string    `json:"query"`
670}
671
672// InputTextMessageContent contains text for displaying
673// as an inline query result.
674type InputTextMessageContent struct {
675	Text                  string `json:"message_text"`
676	ParseMode             string `json:"parse_mode"`
677	DisableWebPagePreview bool   `json:"disable_web_page_preview"`
678}
679
680// InputLocationMessageContent contains a location for displaying
681// as an inline query result.
682type InputLocationMessageContent struct {
683	Latitude  float64 `json:"latitude"`
684	Longitude float64 `json:"longitude"`
685}
686
687// InputVenueMessageContent contains a venue for displaying
688// as an inline query result.
689type InputVenueMessageContent struct {
690	Latitude     float64 `json:"latitude"`
691	Longitude    float64 `json:"longitude"`
692	Title        string  `json:"title"`
693	Address      string  `json:"address"`
694	FoursquareID string  `json:"foursquare_id"`
695}
696
697// InputContactMessageContent contains a contact for displaying
698// as an inline query result.
699type InputContactMessageContent struct {
700	PhoneNumber string `json:"phone_number"`
701	FirstName   string `json:"first_name"`
702	LastName    string `json:"last_name"`
703}
704
705// Invoice contains basic information about an invoice.
706type Invoice struct {
707	Title          string `json:"title"`
708	Description    string `json:"description"`
709	StartParameter string `json:"start_parameter"`
710	Currency       string `json:"currency"`
711	TotalAmount    int    `json:"total_amount"`
712}
713
714// LabeledPrice represents a portion of the price for goods or services.
715type LabeledPrice struct {
716	Label  string `json:"label"`
717	Amount int    `json:"amount"`
718}
719
720// ShippingAddress represents a shipping address.
721type ShippingAddress struct {
722	CountryCode string `json:"country_code"`
723	State       string `json:"state"`
724	City        string `json:"city"`
725	StreetLine1 string `json:"street_line1"`
726	StreetLine2 string `json:"street_line2"`
727	PostCode    string `json:"post_code"`
728}
729
730// OrderInfo represents information about an order.
731type OrderInfo struct {
732	Name            string           `json:"name,omitempty"`
733	PhoneNumber     string           `json:"phone_number,omitempty"`
734	Email           string           `json:"email,omitempty"`
735	ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
736}
737
738// ShippingOption represents one shipping option.
739type ShippingOption struct {
740	ID     string          `json:"id"`
741	Title  string          `json:"title"`
742	Prices *[]LabeledPrice `json:"prices"`
743}
744
745// SuccessfulPayment contains basic information about a successful payment.
746type SuccessfulPayment struct {
747	Currency                string     `json:"currency"`
748	TotalAmount             int        `json:"total_amount"`
749	InvoicePayload          string     `json:"invoice_payload"`
750	ShippingOptionID        string     `json:"shipping_option_id,omitempty"`
751	OrderInfo               *OrderInfo `json:"order_info,omitempty"`
752	TelegramPaymentChargeID string     `json:"telegram_payment_charge_id"`
753	ProviderPaymentChargeID string     `json:"provider_payment_charge_id"`
754}
755
756// ShippingQuery contains information about an incoming shipping query.
757type ShippingQuery struct {
758	ID              string           `json:"id"`
759	From            *User            `json:"from"`
760	InvoicePayload  string           `json:"invoice_payload"`
761	ShippingAddress *ShippingAddress `json:"shipping_address"`
762}
763
764// PreCheckoutQuery contains information about an incoming pre-checkout query.
765type PreCheckoutQuery struct {
766	ID               string     `json:"id"`
767	From             *User      `json:"from"`
768	Currency         string     `json:"currency"`
769	TotalAmount      int        `json:"total_amount"`
770	InvoicePayload   string     `json:"invoice_payload"`
771	ShippingOptionID string     `json:"shipping_option_id,omitempty"`
772	OrderInfo        *OrderInfo `json:"order_info,omitempty"`
773}