all repos — telegram-bot-api @ 4edcb0fa1ab5e691899ca33c58d79f517c6bf30f

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// InlineQueryResultCachedPhoto is an inline query response with cached photo.
555type InlineQueryResultCachedPhoto struct {
556	Type                string                `json:"type"`          // required
557	ID                  string                `json:"id"`            // required
558	PhotoID             string                `json:"photo_file_id"` // required
559	Title               string                `json:"title"`
560	Description         string                `json:"description"`
561	Caption             string                `json:"caption"`
562	ParseMode           string                `json:"parse_mode"`
563	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
564	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
565}
566
567// InlineQueryResultGIF is an inline query response GIF.
568type InlineQueryResultGIF struct {
569	Type                string                `json:"type"`    // required
570	ID                  string                `json:"id"`      // required
571	URL                 string                `json:"gif_url"` // required
572	Width               int                   `json:"gif_width"`
573	Height              int                   `json:"gif_height"`
574	Duration            int                   `json:"gif_duration"`
575	ThumbURL            string                `json:"thumb_url"`
576	Title               string                `json:"title"`
577	Caption             string                `json:"caption"`
578	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
579	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
580}
581
582// InlineQueryResultCachedGIF is an inline query response with cached gif.
583type InlineQueryResultCachedGIF struct {
584	Type                string                `json:"type"`        // required
585	ID                  string                `json:"id"`          // required
586	GifID               string                `json:"gif_file_id"` // required
587	Title               string                `json:"title"`
588	Caption             string                `json:"caption"`
589	ParseMode           string                `json:"parse_mode"`
590	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
591	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
592}
593
594// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
595type InlineQueryResultMPEG4GIF struct {
596	Type                string                `json:"type"`      // required
597	ID                  string                `json:"id"`        // required
598	URL                 string                `json:"mpeg4_url"` // required
599	Width               int                   `json:"mpeg4_width"`
600	Height              int                   `json:"mpeg4_height"`
601	Duration            int                   `json:"mpeg4_duration"`
602	ThumbURL            string                `json:"thumb_url"`
603	Title               string                `json:"title"`
604	Caption             string                `json:"caption"`
605	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
606	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
607}
608
609// InlineQueryResultCachedMpeg4Gif is an inline query response with cached
610// H.264/MPEG-4 AVC video without sound gif.
611type InlineQueryResultCachedMpeg4Gif struct {
612	Type                string                `json:"type"`          // required
613	ID                  string                `json:"id"`            // required
614	MGifID              string                `json:"mpeg4_file_id"` // required
615	Title               string                `json:"title"`
616	Caption             string                `json:"caption"`
617	ParseMode           string                `json:"parse_mode"`
618	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
619	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
620}
621
622// InlineQueryResultVideo is an inline query response video.
623type InlineQueryResultVideo struct {
624	Type                string                `json:"type"`      // required
625	ID                  string                `json:"id"`        // required
626	URL                 string                `json:"video_url"` // required
627	MimeType            string                `json:"mime_type"` // required
628	ThumbURL            string                `json:"thumb_url"`
629	Title               string                `json:"title"`
630	Caption             string                `json:"caption"`
631	Width               int                   `json:"video_width"`
632	Height              int                   `json:"video_height"`
633	Duration            int                   `json:"video_duration"`
634	Description         string                `json:"description"`
635	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
636	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
637}
638
639// InlineQueryResultCachedVideo is an inline query response with cached video.
640type InlineQueryResultCachedVideo struct {
641	Type                string                `json:"type"`          // required
642	ID                  string                `json:"id"`            // required
643	VideoID             string                `json:"video_file_id"` // required
644	Title               string                `json:"title"`         // required
645	Description         string                `json:"description"`
646	Caption             string                `json:"caption"`
647	ParseMode           string                `json:"parse_mode"`
648	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
649	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
650}
651
652// InlineQueryResultAudio is an inline query response audio.
653type InlineQueryResultAudio struct {
654	Type                string                `json:"type"`      // required
655	ID                  string                `json:"id"`        // required
656	URL                 string                `json:"audio_url"` // required
657	Title               string                `json:"title"`     // required
658	Caption             string                `json:"caption"`
659	Performer           string                `json:"performer"`
660	Duration            int                   `json:"audio_duration"`
661	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
662	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
663}
664
665// InlineQueryResultCachedAudio is an inline query response with cached audio.
666type InlineQueryResultCachedAudio struct {
667	Type                string                `json:"type"`          // required
668	ID                  string                `json:"id"`            // required
669	AudioID             string                `json:"audio_file_id"` // required
670	Caption             string                `json:"caption"`
671	ParseMode           string                `json:"parse_mode"`
672	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
673	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
674}
675
676// InlineQueryResultVoice is an inline query response voice.
677type InlineQueryResultVoice struct {
678	Type                string                `json:"type"`      // required
679	ID                  string                `json:"id"`        // required
680	URL                 string                `json:"voice_url"` // required
681	Title               string                `json:"title"`     // required
682	Caption             string                `json:"caption"`
683	Duration            int                   `json:"voice_duration"`
684	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
685	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
686}
687
688// InlineQueryResultCachedVoice is an inline query response with cached voice.
689type InlineQueryResultCachedVoice struct {
690	Type                string                `json:"type"`          // required
691	ID                  string                `json:"id"`            // required
692	VoiceID             string                `json:"voice_file_id"` // required
693	Title               string                `json:"title"`         // required
694	Caption             string                `json:"caption"`
695	ParseMode           string                `json:"parse_mode"`
696	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
697	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
698}
699
700// InlineQueryResultDocument is an inline query response document.
701type InlineQueryResultDocument struct {
702	Type                string                `json:"type"`  // required
703	ID                  string                `json:"id"`    // required
704	Title               string                `json:"title"` // required
705	Caption             string                `json:"caption"`
706	URL                 string                `json:"document_url"` // required
707	MimeType            string                `json:"mime_type"`    // required
708	Description         string                `json:"description"`
709	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
710	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
711	ThumbURL            string                `json:"thumb_url"`
712	ThumbWidth          int                   `json:"thumb_width"`
713	ThumbHeight         int                   `json:"thumb_height"`
714}
715
716// InlineQueryResultCachedDocument is an inline query response with cached document.
717type InlineQueryResultCachedDocument struct {
718	Type                string                `json:"type"`             // required
719	ID                  string                `json:"id"`               // required
720	DocumentID          string                `json:"document_file_id"` // required
721	Title               string                `json:"title"`            // required
722	Caption             string                `json:"caption"`
723	Description         string                `json:"description"`
724	ParseMode           string                `json:"parse_mode"`
725	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
726	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
727}
728
729// InlineQueryResultLocation is an inline query response location.
730type InlineQueryResultLocation struct {
731	Type                string                `json:"type"`      // required
732	ID                  string                `json:"id"`        // required
733	Latitude            float64               `json:"latitude"`  // required
734	Longitude           float64               `json:"longitude"` // required
735	Title               string                `json:"title"`     // required
736	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
737	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
738	ThumbURL            string                `json:"thumb_url"`
739	ThumbWidth          int                   `json:"thumb_width"`
740	ThumbHeight         int                   `json:"thumb_height"`
741}
742
743// InlineQueryResultGame is an inline query response game.
744type InlineQueryResultGame struct {
745	Type          string                `json:"type"`
746	ID            string                `json:"id"`
747	GameShortName string                `json:"game_short_name"`
748	ReplyMarkup   *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
749}
750
751// ChosenInlineResult is an inline query result chosen by a User
752type ChosenInlineResult struct {
753	ResultID        string    `json:"result_id"`
754	From            *User     `json:"from"`
755	Location        *Location `json:"location"`
756	InlineMessageID string    `json:"inline_message_id"`
757	Query           string    `json:"query"`
758}
759
760// InputTextMessageContent contains text for displaying
761// as an inline query result.
762type InputTextMessageContent struct {
763	Text                  string `json:"message_text"`
764	ParseMode             string `json:"parse_mode"`
765	DisableWebPagePreview bool   `json:"disable_web_page_preview"`
766}
767
768// InputLocationMessageContent contains a location for displaying
769// as an inline query result.
770type InputLocationMessageContent struct {
771	Latitude  float64 `json:"latitude"`
772	Longitude float64 `json:"longitude"`
773}
774
775// InputVenueMessageContent contains a venue for displaying
776// as an inline query result.
777type InputVenueMessageContent struct {
778	Latitude     float64 `json:"latitude"`
779	Longitude    float64 `json:"longitude"`
780	Title        string  `json:"title"`
781	Address      string  `json:"address"`
782	FoursquareID string  `json:"foursquare_id"`
783}
784
785// InputContactMessageContent contains a contact for displaying
786// as an inline query result.
787type InputContactMessageContent struct {
788	PhoneNumber string `json:"phone_number"`
789	FirstName   string `json:"first_name"`
790	LastName    string `json:"last_name"`
791}
792
793// Invoice contains basic information about an invoice.
794type Invoice struct {
795	Title          string `json:"title"`
796	Description    string `json:"description"`
797	StartParameter string `json:"start_parameter"`
798	Currency       string `json:"currency"`
799	TotalAmount    int    `json:"total_amount"`
800}
801
802// LabeledPrice represents a portion of the price for goods or services.
803type LabeledPrice struct {
804	Label  string `json:"label"`
805	Amount int    `json:"amount"`
806}
807
808// ShippingAddress represents a shipping address.
809type ShippingAddress struct {
810	CountryCode string `json:"country_code"`
811	State       string `json:"state"`
812	City        string `json:"city"`
813	StreetLine1 string `json:"street_line1"`
814	StreetLine2 string `json:"street_line2"`
815	PostCode    string `json:"post_code"`
816}
817
818// OrderInfo represents information about an order.
819type OrderInfo struct {
820	Name            string           `json:"name,omitempty"`
821	PhoneNumber     string           `json:"phone_number,omitempty"`
822	Email           string           `json:"email,omitempty"`
823	ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
824}
825
826// ShippingOption represents one shipping option.
827type ShippingOption struct {
828	ID     string          `json:"id"`
829	Title  string          `json:"title"`
830	Prices *[]LabeledPrice `json:"prices"`
831}
832
833// SuccessfulPayment contains basic information about a successful payment.
834type SuccessfulPayment struct {
835	Currency                string     `json:"currency"`
836	TotalAmount             int        `json:"total_amount"`
837	InvoicePayload          string     `json:"invoice_payload"`
838	ShippingOptionID        string     `json:"shipping_option_id,omitempty"`
839	OrderInfo               *OrderInfo `json:"order_info,omitempty"`
840	TelegramPaymentChargeID string     `json:"telegram_payment_charge_id"`
841	ProviderPaymentChargeID string     `json:"provider_payment_charge_id"`
842}
843
844// ShippingQuery contains information about an incoming shipping query.
845type ShippingQuery struct {
846	ID              string           `json:"id"`
847	From            *User            `json:"from"`
848	InvoicePayload  string           `json:"invoice_payload"`
849	ShippingAddress *ShippingAddress `json:"shipping_address"`
850}
851
852// PreCheckoutQuery contains information about an incoming pre-checkout query.
853type PreCheckoutQuery struct {
854	ID               string     `json:"id"`
855	From             *User      `json:"from"`
856	Currency         string     `json:"currency"`
857	TotalAmount      int        `json:"total_amount"`
858	InvoicePayload   string     `json:"invoice_payload"`
859	ShippingOptionID string     `json:"shipping_option_id,omitempty"`
860	OrderInfo        *OrderInfo `json:"order_info,omitempty"`
861}
862
863// Error is an error containing extra information returned by the Telegram API.
864type Error struct {
865	Message string
866	ResponseParameters
867}
868
869func (e Error) Error() string {
870	return e.Message
871}