all repos — telegram-bot-api @ 20b57111fc7b1d362967c786b2052b4481e6cccb

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