all repos — telegram-bot-api @ 7ff5871e2875951ebf0fbdea7c174337c9600136

Golang bindings for the Telegram Bot API

types.go (view raw)

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