all repos — telegram-bot-api @ db88019230b2befb84cb3cbd97fe8802049df821

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