all repos — telegram-bot-api @ 9b191dba1eb601279c9f804c5b6f2083426bbd83

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