all repos — telegram-bot-api @ 483f21c48bebae648c4464138be96b1344151035

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	}
236
237	return m.Text[entity.Length+1:]
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	SetName   string     `json:"set_name"`  // optional
294}
295
296// Video contains information about a video.
297type Video struct {
298	FileID    string     `json:"file_id"`
299	Width     int        `json:"width"`
300	Height    int        `json:"height"`
301	Duration  int        `json:"duration"`
302	Thumbnail *PhotoSize `json:"thumb"`     // optional
303	MimeType  string     `json:"mime_type"` // optional
304	FileSize  int        `json:"file_size"` // optional
305}
306
307// VideoNote contains information about a video.
308type VideoNote struct {
309	FileID    string     `json:"file_id"`
310	Length    int        `json:"length"`
311	Duration  int        `json:"duration"`
312	Thumbnail *PhotoSize `json:"thumb"`     // optional
313	FileSize  int        `json:"file_size"` // optional
314}
315
316// Voice contains information about a voice.
317type Voice struct {
318	FileID   string `json:"file_id"`
319	Duration int    `json:"duration"`
320	MimeType string `json:"mime_type"` // optional
321	FileSize int    `json:"file_size"` // optional
322}
323
324// Contact contains information about a contact.
325//
326// Note that LastName and UserID may be empty.
327type Contact struct {
328	PhoneNumber string `json:"phone_number"`
329	FirstName   string `json:"first_name"`
330	LastName    string `json:"last_name"` // optional
331	UserID      int    `json:"user_id"`   // optional
332}
333
334// Location contains information about a place.
335type Location struct {
336	Longitude float64 `json:"longitude"`
337	Latitude  float64 `json:"latitude"`
338}
339
340// Venue contains information about a venue, including its Location.
341type Venue struct {
342	Location     Location `json:"location"`
343	Title        string   `json:"title"`
344	Address      string   `json:"address"`
345	FoursquareID string   `json:"foursquare_id"` // optional
346}
347
348// UserProfilePhotos contains a set of user profile photos.
349type UserProfilePhotos struct {
350	TotalCount int           `json:"total_count"`
351	Photos     [][]PhotoSize `json:"photos"`
352}
353
354// File contains information about a file to download from Telegram.
355type File struct {
356	FileID   string `json:"file_id"`
357	FileSize int    `json:"file_size"` // optional
358	FilePath string `json:"file_path"` // optional
359}
360
361// Link returns a full path to the download URL for a File.
362//
363// It requires the Bot Token to create the link.
364func (f *File) Link(token string) string {
365	return fmt.Sprintf(FileEndpoint, token, f.FilePath)
366}
367
368// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
369type ReplyKeyboardMarkup struct {
370	Keyboard        [][]KeyboardButton `json:"keyboard"`
371	ResizeKeyboard  bool               `json:"resize_keyboard"`   // optional
372	OneTimeKeyboard bool               `json:"one_time_keyboard"` // optional
373	Selective       bool               `json:"selective"`         // optional
374}
375
376// KeyboardButton is a button within a custom keyboard.
377type KeyboardButton struct {
378	Text            string `json:"text"`
379	RequestContact  bool   `json:"request_contact"`
380	RequestLocation bool   `json:"request_location"`
381}
382
383// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
384type ReplyKeyboardHide struct {
385	HideKeyboard bool `json:"hide_keyboard"`
386	Selective    bool `json:"selective"` // optional
387}
388
389// ReplyKeyboardRemove allows the Bot to hide a custom keyboard.
390type ReplyKeyboardRemove struct {
391	RemoveKeyboard bool `json:"remove_keyboard"`
392	Selective      bool `json:"selective"`
393}
394
395// InlineKeyboardMarkup is a custom keyboard presented for an inline bot.
396type InlineKeyboardMarkup struct {
397	InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
398}
399
400// InlineKeyboardButton is a button within a custom keyboard for
401// inline query responses.
402//
403// Note that some values are references as even an empty string
404// will change behavior.
405//
406// CallbackGame, if set, MUST be first button in first row.
407type InlineKeyboardButton struct {
408	Text                         string        `json:"text"`
409	URL                          *string       `json:"url,omitempty"`                              // optional
410	CallbackData                 *string       `json:"callback_data,omitempty"`                    // optional
411	SwitchInlineQuery            *string       `json:"switch_inline_query,omitempty"`              // optional
412	SwitchInlineQueryCurrentChat *string       `json:"switch_inline_query_current_chat,omitempty"` // optional
413	CallbackGame                 *CallbackGame `json:"callback_game,omitempty"`                    // optional
414	Pay                          bool          `json:"pay,omitempty"`                              // optional
415}
416
417// CallbackQuery is data sent when a keyboard button with callback data
418// is clicked.
419type CallbackQuery struct {
420	ID              string   `json:"id"`
421	From            *User    `json:"from"`
422	Message         *Message `json:"message"`           // optional
423	InlineMessageID string   `json:"inline_message_id"` // optional
424	ChatInstance    string   `json:"chat_instance"`
425	Data            string   `json:"data"`            // optional
426	GameShortName   string   `json:"game_short_name"` // optional
427}
428
429// ForceReply allows the Bot to have users directly reply to it without
430// additional interaction.
431type ForceReply struct {
432	ForceReply bool `json:"force_reply"`
433	Selective  bool `json:"selective"` // optional
434}
435
436// ChatMember is information about a member in a chat.
437type ChatMember struct {
438	User                  *User  `json:"user"`
439	Status                string `json:"status"`
440	UntilDate             int64  `json:"until_date,omitempty"`                // optional
441	CanBeEdited           bool   `json:"can_be_edited,omitempty"`             // optional
442	CanChangeInfo         bool   `json:"can_change_info,omitempty"`           // optional
443	CanPostMessages       bool   `json:"can_post_messages,omitempty"`         // optional
444	CanEditMessages       bool   `json:"can_edit_messages,omitempty"`         // optional
445	CanDeleteMessages     bool   `json:"can_delete_messages,omitempty"`       // optional
446	CanInviteUsers        bool   `json:"can_invite_users,omitempty"`          // optional
447	CanRestrictMembers    bool   `json:"can_restrict_members,omitempty"`      // optional
448	CanPinMessages        bool   `json:"can_pin_messages,omitempty"`          // optional
449	CanPromoteMembers     bool   `json:"can_promote_members,omitempty"`       // optional
450	CanSendMessages       bool   `json:"can_send_messages,omitempty"`         // optional
451	CanSendMediaMessages  bool   `json:"can_send_media_messages,omitempty"`   // optional
452	CanSendOtherMessages  bool   `json:"can_send_other_messages,omitempty"`   // optional
453	CanAddWebPagePreviews bool   `json:"can_add_web_page_previews,omitempty"` // optional
454}
455
456// IsCreator returns if the ChatMember was the creator of the chat.
457func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" }
458
459// IsAdministrator returns if the ChatMember is a chat administrator.
460func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" }
461
462// IsMember returns if the ChatMember is a current member of the chat.
463func (chat ChatMember) IsMember() bool { return chat.Status == "member" }
464
465// HasLeft returns if the ChatMember left the chat.
466func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
467
468// WasKicked returns if the ChatMember was kicked from the chat.
469func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
470
471// Game is a game within Telegram.
472type Game struct {
473	Title        string          `json:"title"`
474	Description  string          `json:"description"`
475	Photo        []PhotoSize     `json:"photo"`
476	Text         string          `json:"text"`
477	TextEntities []MessageEntity `json:"text_entities"`
478	Animation    Animation       `json:"animation"`
479}
480
481// Animation is a GIF animation demonstrating the game.
482type Animation struct {
483	FileID   string    `json:"file_id"`
484	Thumb    PhotoSize `json:"thumb"`
485	FileName string    `json:"file_name"`
486	MimeType string    `json:"mime_type"`
487	FileSize int       `json:"file_size"`
488}
489
490// GameHighScore is a user's score and position on the leaderboard.
491type GameHighScore struct {
492	Position int  `json:"position"`
493	User     User `json:"user"`
494	Score    int  `json:"score"`
495}
496
497// CallbackGame is for starting a game in an inline keyboard button.
498type CallbackGame struct{}
499
500// WebhookInfo is information about a currently set webhook.
501type WebhookInfo struct {
502	URL                  string `json:"url"`
503	HasCustomCertificate bool   `json:"has_custom_certificate"`
504	PendingUpdateCount   int    `json:"pending_update_count"`
505	LastErrorDate        int    `json:"last_error_date"`    // optional
506	LastErrorMessage     string `json:"last_error_message"` // optional
507}
508
509// IsSet returns true if a webhook is currently set.
510func (info WebhookInfo) IsSet() bool {
511	return info.URL != ""
512}
513
514// InlineQuery is a Query from Telegram for an inline request.
515type InlineQuery struct {
516	ID       string    `json:"id"`
517	From     *User     `json:"from"`
518	Location *Location `json:"location"` // optional
519	Query    string    `json:"query"`
520	Offset   string    `json:"offset"`
521}
522
523// InlineQueryResultArticle is an inline query response article.
524type InlineQueryResultArticle struct {
525	Type                string                `json:"type"`                            // required
526	ID                  string                `json:"id"`                              // required
527	Title               string                `json:"title"`                           // required
528	InputMessageContent interface{}           `json:"input_message_content,omitempty"` // required
529	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
530	URL                 string                `json:"url"`
531	HideURL             bool                  `json:"hide_url"`
532	Description         string                `json:"description"`
533	ThumbURL            string                `json:"thumb_url"`
534	ThumbWidth          int                   `json:"thumb_width"`
535	ThumbHeight         int                   `json:"thumb_height"`
536}
537
538// InlineQueryResultPhoto is an inline query response photo.
539type InlineQueryResultPhoto struct {
540	Type                string                `json:"type"`      // required
541	ID                  string                `json:"id"`        // required
542	URL                 string                `json:"photo_url"` // required
543	MimeType            string                `json:"mime_type"`
544	Width               int                   `json:"photo_width"`
545	Height              int                   `json:"photo_height"`
546	ThumbURL            string                `json:"thumb_url"`
547	Title               string                `json:"title"`
548	Description         string                `json:"description"`
549	Caption             string                `json:"caption"`
550	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
551	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
552}
553
554// InlineQueryResultGIF is an inline query response GIF.
555type InlineQueryResultGIF struct {
556	Type                string                `json:"type"`    // required
557	ID                  string                `json:"id"`      // required
558	URL                 string                `json:"gif_url"` // required
559	Width               int                   `json:"gif_width"`
560	Height              int                   `json:"gif_height"`
561	Duration            int                   `json:"gif_duration"`
562	ThumbURL            string                `json:"thumb_url"`
563	Title               string                `json:"title"`
564	Caption             string                `json:"caption"`
565	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
566	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
567}
568
569// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
570type InlineQueryResultMPEG4GIF struct {
571	Type                string                `json:"type"`      // required
572	ID                  string                `json:"id"`        // required
573	URL                 string                `json:"mpeg4_url"` // required
574	Width               int                   `json:"mpeg4_width"`
575	Height              int                   `json:"mpeg4_height"`
576	Duration            int                   `json:"mpeg4_duration"`
577	ThumbURL            string                `json:"thumb_url"`
578	Title               string                `json:"title"`
579	Caption             string                `json:"caption"`
580	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
581	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
582}
583
584// InlineQueryResultVideo is an inline query response video.
585type InlineQueryResultVideo struct {
586	Type                string                `json:"type"`      // required
587	ID                  string                `json:"id"`        // required
588	URL                 string                `json:"video_url"` // required
589	MimeType            string                `json:"mime_type"` // required
590	ThumbURL            string                `json:"thumb_url"`
591	Title               string                `json:"title"`
592	Caption             string                `json:"caption"`
593	Width               int                   `json:"video_width"`
594	Height              int                   `json:"video_height"`
595	Duration            int                   `json:"video_duration"`
596	Description         string                `json:"description"`
597	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
598	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
599}
600
601// InlineQueryResultAudio is an inline query response audio.
602type InlineQueryResultAudio struct {
603	Type                string                `json:"type"`      // required
604	ID                  string                `json:"id"`        // required
605	URL                 string                `json:"audio_url"` // required
606	Title               string                `json:"title"`     // required
607	Caption             string                `json:"caption"`
608	Performer           string                `json:"performer"`
609	Duration            int                   `json:"audio_duration"`
610	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
611	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
612}
613
614// InlineQueryResultVoice is an inline query response voice.
615type InlineQueryResultVoice struct {
616	Type                string                `json:"type"`      // required
617	ID                  string                `json:"id"`        // required
618	URL                 string                `json:"voice_url"` // required
619	Title               string                `json:"title"`     // required
620	Caption             string                `json:"caption"`
621	Duration            int                   `json:"voice_duration"`
622	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
623	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
624}
625
626// InlineQueryResultDocument is an inline query response document.
627type InlineQueryResultDocument struct {
628	Type                string                `json:"type"`  // required
629	ID                  string                `json:"id"`    // required
630	Title               string                `json:"title"` // required
631	Caption             string                `json:"caption"`
632	URL                 string                `json:"document_url"` // required
633	MimeType            string                `json:"mime_type"`    // required
634	Description         string                `json:"description"`
635	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
636	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
637	ThumbURL            string                `json:"thumb_url"`
638	ThumbWidth          int                   `json:"thumb_width"`
639	ThumbHeight         int                   `json:"thumb_height"`
640}
641
642// InlineQueryResultLocation is an inline query response location.
643type InlineQueryResultLocation struct {
644	Type                string                `json:"type"`      // required
645	ID                  string                `json:"id"`        // required
646	Latitude            float64               `json:"latitude"`  // required
647	Longitude           float64               `json:"longitude"` // required
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,omitempty"`
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}
687
688// InputVenueMessageContent contains a venue for displaying
689// as an inline query result.
690type InputVenueMessageContent struct {
691	Latitude     float64 `json:"latitude"`
692	Longitude    float64 `json:"longitude"`
693	Title        string  `json:"title"`
694	Address      string  `json:"address"`
695	FoursquareID string  `json:"foursquare_id"`
696}
697
698// InputContactMessageContent contains a contact for displaying
699// as an inline query result.
700type InputContactMessageContent struct {
701	PhoneNumber string `json:"phone_number"`
702	FirstName   string `json:"first_name"`
703	LastName    string `json:"last_name"`
704}
705
706// Invoice contains basic information about an invoice.
707type Invoice struct {
708	Title          string `json:"title"`
709	Description    string `json:"description"`
710	StartParameter string `json:"start_parameter"`
711	Currency       string `json:"currency"`
712	TotalAmount    int    `json:"total_amount"`
713}
714
715// LabeledPrice represents a portion of the price for goods or services.
716type LabeledPrice struct {
717	Label  string `json:"label"`
718	Amount int    `json:"amount"`
719}
720
721// ShippingAddress represents a shipping address.
722type ShippingAddress struct {
723	CountryCode string `json:"country_code"`
724	State       string `json:"state"`
725	City        string `json:"city"`
726	StreetLine1 string `json:"street_line1"`
727	StreetLine2 string `json:"street_line2"`
728	PostCode    string `json:"post_code"`
729}
730
731// OrderInfo represents information about an order.
732type OrderInfo struct {
733	Name            string           `json:"name,omitempty"`
734	PhoneNumber     string           `json:"phone_number,omitempty"`
735	Email           string           `json:"email,omitempty"`
736	ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
737}
738
739// ShippingOption represents one shipping option.
740type ShippingOption struct {
741	ID     string          `json:"id"`
742	Title  string          `json:"title"`
743	Prices *[]LabeledPrice `json:"prices"`
744}
745
746// SuccessfulPayment contains basic information about a successful payment.
747type SuccessfulPayment struct {
748	Currency                string     `json:"currency"`
749	TotalAmount             int        `json:"total_amount"`
750	InvoicePayload          string     `json:"invoice_payload"`
751	ShippingOptionID        string     `json:"shipping_option_id,omitempty"`
752	OrderInfo               *OrderInfo `json:"order_info,omitempty"`
753	TelegramPaymentChargeID string     `json:"telegram_payment_charge_id"`
754	ProviderPaymentChargeID string     `json:"provider_payment_charge_id"`
755}
756
757// ShippingQuery contains information about an incoming shipping query.
758type ShippingQuery struct {
759	ID              string           `json:"id"`
760	From            *User            `json:"from"`
761	InvoicePayload  string           `json:"invoice_payload"`
762	ShippingAddress *ShippingAddress `json:"shipping_address"`
763}
764
765// PreCheckoutQuery contains information about an incoming pre-checkout query.
766type PreCheckoutQuery struct {
767	ID               string     `json:"id"`
768	From             *User      `json:"from"`
769	Currency         string     `json:"currency"`
770	TotalAmount      int        `json:"total_amount"`
771	InvoicePayload   string     `json:"invoice_payload"`
772	ShippingOptionID string     `json:"shipping_option_id,omitempty"`
773	OrderInfo        *OrderInfo `json:"order_info,omitempty"`
774}
775
776// Error is an error containing extra information returned by the Telegram API.
777type Error struct {
778	Message string
779	ResponseParameters
780}
781
782func (e Error) Error() string {
783	return e.Message
784}