all repos — telegram-bot-api @ fd860fdd66745e140316aa97698ba458c330c58e

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