all repos — telegram-bot-api @ 898e79fe47dafa598b3f61dd570aa2921628e530

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