all repos — telegram-bot-api @ 5ebb3edeffaa49f5bdf05e6f810d171714211628

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	CustomTitle           string `json:"custom_title,omitempty"`              // optional
 521	UntilDate             int64  `json:"until_date,omitempty"`                // optional
 522	CanBeEdited           bool   `json:"can_be_edited,omitempty"`             // optional
 523	CanChangeInfo         bool   `json:"can_change_info,omitempty"`           // optional
 524	CanPostMessages       bool   `json:"can_post_messages,omitempty"`         // optional
 525	CanEditMessages       bool   `json:"can_edit_messages,omitempty"`         // optional
 526	CanDeleteMessages     bool   `json:"can_delete_messages,omitempty"`       // optional
 527	CanInviteUsers        bool   `json:"can_invite_users,omitempty"`          // optional
 528	CanRestrictMembers    bool   `json:"can_restrict_members,omitempty"`      // optional
 529	CanPinMessages        bool   `json:"can_pin_messages,omitempty"`          // optional
 530	CanPromoteMembers     bool   `json:"can_promote_members,omitempty"`       // optional
 531	CanSendMessages       bool   `json:"can_send_messages,omitempty"`         // optional
 532	CanSendMediaMessages  bool   `json:"can_send_media_messages,omitempty"`   // optional
 533	CanSendOtherMessages  bool   `json:"can_send_other_messages,omitempty"`   // optional
 534	CanAddWebPagePreviews bool   `json:"can_add_web_page_previews,omitempty"` // optional
 535}
 536
 537// IsCreator returns if the ChatMember was the creator of the chat.
 538func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" }
 539
 540// IsAdministrator returns if the ChatMember is a chat administrator.
 541func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" }
 542
 543// IsMember returns if the ChatMember is a current member of the chat.
 544func (chat ChatMember) IsMember() bool { return chat.Status == "member" }
 545
 546// HasLeft returns if the ChatMember left the chat.
 547func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
 548
 549// WasKicked returns if the ChatMember was kicked from the chat.
 550func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
 551
 552// Game is a game within Telegram.
 553type Game struct {
 554	Title        string          `json:"title"`
 555	Description  string          `json:"description"`
 556	Photo        []PhotoSize     `json:"photo"`
 557	Text         string          `json:"text"`
 558	TextEntities []MessageEntity `json:"text_entities"`
 559	Animation    Animation       `json:"animation"`
 560}
 561
 562// Animation is a GIF animation demonstrating the game.
 563type Animation struct {
 564	FileID   string    `json:"file_id"`
 565	Thumb    PhotoSize `json:"thumb"`
 566	FileName string    `json:"file_name"`
 567	MimeType string    `json:"mime_type"`
 568	FileSize int       `json:"file_size"`
 569}
 570
 571// GameHighScore is a user's score and position on the leaderboard.
 572type GameHighScore struct {
 573	Position int  `json:"position"`
 574	User     User `json:"user"`
 575	Score    int  `json:"score"`
 576}
 577
 578// CallbackGame is for starting a game in an inline keyboard button.
 579type CallbackGame struct{}
 580
 581// WebhookInfo is information about a currently set webhook.
 582type WebhookInfo struct {
 583	URL                  string `json:"url"`
 584	HasCustomCertificate bool   `json:"has_custom_certificate"`
 585	PendingUpdateCount   int    `json:"pending_update_count"`
 586	LastErrorDate        int    `json:"last_error_date"`    // optional
 587	LastErrorMessage     string `json:"last_error_message"` // optional
 588	MaxConnections       int    `json:"max_connections"`    // optional
 589}
 590
 591// IsSet returns true if a webhook is currently set.
 592func (info WebhookInfo) IsSet() bool {
 593	return info.URL != ""
 594}
 595
 596// InputMediaPhoto contains a photo for displaying as part of a media group.
 597type InputMediaPhoto struct {
 598	Type      string `json:"type"`
 599	Media     string `json:"media"`
 600	Caption   string `json:"caption"`
 601	ParseMode string `json:"parse_mode"`
 602}
 603
 604// InputMediaVideo contains a video for displaying as part of a media group.
 605type InputMediaVideo struct {
 606	Type  string `json:"type"`
 607	Media string `json:"media"`
 608	// thumb intentionally missing as it is not currently compatible
 609	Caption           string `json:"caption"`
 610	ParseMode         string `json:"parse_mode"`
 611	Width             int    `json:"width"`
 612	Height            int    `json:"height"`
 613	Duration          int    `json:"duration"`
 614	SupportsStreaming bool   `json:"supports_streaming"`
 615}
 616
 617// InlineQuery is a Query from Telegram for an inline request.
 618type InlineQuery struct {
 619	ID       string    `json:"id"`
 620	From     *User     `json:"from"`
 621	Location *Location `json:"location"` // optional
 622	Query    string    `json:"query"`
 623	Offset   string    `json:"offset"`
 624}
 625
 626// InlineQueryResultArticle is an inline query response article.
 627type InlineQueryResultArticle struct {
 628	Type                string                `json:"type"`                            // required
 629	ID                  string                `json:"id"`                              // required
 630	Title               string                `json:"title"`                           // required
 631	InputMessageContent interface{}           `json:"input_message_content,omitempty"` // required
 632	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 633	URL                 string                `json:"url"`
 634	HideURL             bool                  `json:"hide_url"`
 635	Description         string                `json:"description"`
 636	ThumbURL            string                `json:"thumb_url"`
 637	ThumbWidth          int                   `json:"thumb_width"`
 638	ThumbHeight         int                   `json:"thumb_height"`
 639}
 640
 641// InlineQueryResultPhoto is an inline query response photo.
 642type InlineQueryResultPhoto struct {
 643	Type                string                `json:"type"`      // required
 644	ID                  string                `json:"id"`        // required
 645	URL                 string                `json:"photo_url"` // required
 646	MimeType            string                `json:"mime_type"`
 647	Width               int                   `json:"photo_width"`
 648	Height              int                   `json:"photo_height"`
 649	ThumbURL            string                `json:"thumb_url"`
 650	Title               string                `json:"title"`
 651	Description         string                `json:"description"`
 652	Caption             string                `json:"caption"`
 653	ParseMode           string                `json:"parse_mode"`
 654	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 655	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 656}
 657
 658// InlineQueryResultCachedPhoto is an inline query response with cached photo.
 659type InlineQueryResultCachedPhoto struct {
 660	Type                string                `json:"type"`          // required
 661	ID                  string                `json:"id"`            // required
 662	PhotoID             string                `json:"photo_file_id"` // required
 663	Title               string                `json:"title"`
 664	Description         string                `json:"description"`
 665	Caption             string                `json:"caption"`
 666	ParseMode           string                `json:"parse_mode"`
 667	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 668	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 669}
 670
 671// InlineQueryResultGIF is an inline query response GIF.
 672type InlineQueryResultGIF struct {
 673	Type                string                `json:"type"`      // required
 674	ID                  string                `json:"id"`        // required
 675	URL                 string                `json:"gif_url"`   // required
 676	ThumbURL            string                `json:"thumb_url"` // required
 677	Width               int                   `json:"gif_width,omitempty"`
 678	Height              int                   `json:"gif_height,omitempty"`
 679	Duration            int                   `json:"gif_duration,omitempty"`
 680	Title               string                `json:"title,omitempty"`
 681	Caption             string                `json:"caption,omitempty"`
 682	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 683	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 684}
 685
 686// InlineQueryResultCachedGIF is an inline query response with cached gif.
 687type InlineQueryResultCachedGIF struct {
 688	Type                string                `json:"type"`        // required
 689	ID                  string                `json:"id"`          // required
 690	GifID               string                `json:"gif_file_id"` // required
 691	Title               string                `json:"title"`
 692	Caption             string                `json:"caption"`
 693	ParseMode           string                `json:"parse_mode"`
 694	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 695	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 696}
 697
 698// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
 699type InlineQueryResultMPEG4GIF struct {
 700	Type                string                `json:"type"`      // required
 701	ID                  string                `json:"id"`        // required
 702	URL                 string                `json:"mpeg4_url"` // required
 703	Width               int                   `json:"mpeg4_width"`
 704	Height              int                   `json:"mpeg4_height"`
 705	Duration            int                   `json:"mpeg4_duration"`
 706	ThumbURL            string                `json:"thumb_url"`
 707	Title               string                `json:"title"`
 708	Caption             string                `json:"caption"`
 709	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 710	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 711}
 712
 713// InlineQueryResultCachedMpeg4Gif is an inline query response with cached
 714// H.264/MPEG-4 AVC video without sound gif.
 715type InlineQueryResultCachedMpeg4Gif struct {
 716	Type                string                `json:"type"`          // required
 717	ID                  string                `json:"id"`            // required
 718	MGifID              string                `json:"mpeg4_file_id"` // required
 719	Title               string                `json:"title"`
 720	Caption             string                `json:"caption"`
 721	ParseMode           string                `json:"parse_mode"`
 722	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 723	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 724}
 725
 726// InlineQueryResultVideo is an inline query response video.
 727type InlineQueryResultVideo struct {
 728	Type                string                `json:"type"`      // required
 729	ID                  string                `json:"id"`        // required
 730	URL                 string                `json:"video_url"` // required
 731	MimeType            string                `json:"mime_type"` // required
 732	ThumbURL            string                `json:"thumb_url"`
 733	Title               string                `json:"title"`
 734	Caption             string                `json:"caption"`
 735	Width               int                   `json:"video_width"`
 736	Height              int                   `json:"video_height"`
 737	Duration            int                   `json:"video_duration"`
 738	Description         string                `json:"description"`
 739	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 740	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 741}
 742
 743// InlineQueryResultCachedVideo is an inline query response with cached video.
 744type InlineQueryResultCachedVideo struct {
 745	Type                string                `json:"type"`          // required
 746	ID                  string                `json:"id"`            // required
 747	VideoID             string                `json:"video_file_id"` // required
 748	Title               string                `json:"title"`         // required
 749	Description         string                `json:"description"`
 750	Caption             string                `json:"caption"`
 751	ParseMode           string                `json:"parse_mode"`
 752	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 753	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 754}
 755
 756// InlineQueryResultCachedSticker is an inline query response with cached sticker.
 757type InlineQueryResultCachedSticker struct {
 758	Type                string                `json:"type"`            // required
 759	ID                  string                `json:"id"`              // required
 760	StickerID           string                `json:"sticker_file_id"` // required
 761	Title               string                `json:"title"`           // required
 762	ParseMode           string                `json:"parse_mode"`
 763	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 764	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 765}
 766
 767// InlineQueryResultAudio is an inline query response audio.
 768type InlineQueryResultAudio struct {
 769	Type                string                `json:"type"`      // required
 770	ID                  string                `json:"id"`        // required
 771	URL                 string                `json:"audio_url"` // required
 772	Title               string                `json:"title"`     // required
 773	Caption             string                `json:"caption"`
 774	Performer           string                `json:"performer"`
 775	Duration            int                   `json:"audio_duration"`
 776	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 777	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 778}
 779
 780// InlineQueryResultCachedAudio is an inline query response with cached audio.
 781type InlineQueryResultCachedAudio struct {
 782	Type                string                `json:"type"`          // required
 783	ID                  string                `json:"id"`            // required
 784	AudioID             string                `json:"audio_file_id"` // required
 785	Caption             string                `json:"caption"`
 786	ParseMode           string                `json:"parse_mode"`
 787	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 788	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 789}
 790
 791// InlineQueryResultVoice is an inline query response voice.
 792type InlineQueryResultVoice struct {
 793	Type                string                `json:"type"`      // required
 794	ID                  string                `json:"id"`        // required
 795	URL                 string                `json:"voice_url"` // required
 796	Title               string                `json:"title"`     // required
 797	Caption             string                `json:"caption"`
 798	Duration            int                   `json:"voice_duration"`
 799	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 800	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 801}
 802
 803// InlineQueryResultCachedVoice is an inline query response with cached voice.
 804type InlineQueryResultCachedVoice struct {
 805	Type                string                `json:"type"`          // required
 806	ID                  string                `json:"id"`            // required
 807	VoiceID             string                `json:"voice_file_id"` // required
 808	Title               string                `json:"title"`         // required
 809	Caption             string                `json:"caption"`
 810	ParseMode           string                `json:"parse_mode"`
 811	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 812	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 813}
 814
 815// InlineQueryResultDocument is an inline query response document.
 816type InlineQueryResultDocument struct {
 817	Type                string                `json:"type"`  // required
 818	ID                  string                `json:"id"`    // required
 819	Title               string                `json:"title"` // required
 820	Caption             string                `json:"caption"`
 821	URL                 string                `json:"document_url"` // required
 822	MimeType            string                `json:"mime_type"`    // required
 823	Description         string                `json:"description"`
 824	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 825	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 826	ThumbURL            string                `json:"thumb_url"`
 827	ThumbWidth          int                   `json:"thumb_width"`
 828	ThumbHeight         int                   `json:"thumb_height"`
 829}
 830
 831// InlineQueryResultCachedDocument is an inline query response with cached document.
 832type InlineQueryResultCachedDocument struct {
 833	Type                string                `json:"type"`             // required
 834	ID                  string                `json:"id"`               // required
 835	DocumentID          string                `json:"document_file_id"` // required
 836	Title               string                `json:"title"`            // required
 837	Caption             string                `json:"caption"`
 838	Description         string                `json:"description"`
 839	ParseMode           string                `json:"parse_mode"`
 840	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 841	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 842}
 843
 844// InlineQueryResultLocation is an inline query response location.
 845type InlineQueryResultLocation struct {
 846	Type                string                `json:"type"`      // required
 847	ID                  string                `json:"id"`        // required
 848	Latitude            float64               `json:"latitude"`  // required
 849	Longitude           float64               `json:"longitude"` // required
 850	Title               string                `json:"title"`     // required
 851	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 852	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 853	ThumbURL            string                `json:"thumb_url"`
 854	ThumbWidth          int                   `json:"thumb_width"`
 855	ThumbHeight         int                   `json:"thumb_height"`
 856}
 857
 858// InlineQueryResultVenue is an inline query response venue.
 859type InlineQueryResultVenue struct {
 860	Type                string                `json:"type"`      // required
 861	ID                  string                `json:"id"`        // required
 862	Latitude            float64               `json:"latitude"`  // required
 863	Longitude           float64               `json:"longitude"` // required
 864	Title               string                `json:"title"`     // required
 865	Address             string                `json:"address"`   // required
 866	FoursquareID        string                `json:"foursquare_id"`
 867	FoursquareType      string                `json:"foursquare_type"`
 868	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 869	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 870	ThumbURL            string                `json:"thumb_url"`
 871	ThumbWidth          int                   `json:"thumb_width"`
 872	ThumbHeight         int                   `json:"thumb_height"`
 873}
 874
 875// InlineQueryResultGame is an inline query response game.
 876type InlineQueryResultGame struct {
 877	Type          string                `json:"type"`
 878	ID            string                `json:"id"`
 879	GameShortName string                `json:"game_short_name"`
 880	ReplyMarkup   *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 881}
 882
 883// ChosenInlineResult is an inline query result chosen by a User
 884type ChosenInlineResult struct {
 885	ResultID        string    `json:"result_id"`
 886	From            *User     `json:"from"`
 887	Location        *Location `json:"location"`
 888	InlineMessageID string    `json:"inline_message_id"`
 889	Query           string    `json:"query"`
 890}
 891
 892// InputTextMessageContent contains text for displaying
 893// as an inline query result.
 894type InputTextMessageContent struct {
 895	Text                  string `json:"message_text"`
 896	ParseMode             string `json:"parse_mode"`
 897	DisableWebPagePreview bool   `json:"disable_web_page_preview"`
 898}
 899
 900// InputLocationMessageContent contains a location for displaying
 901// as an inline query result.
 902type InputLocationMessageContent struct {
 903	Latitude  float64 `json:"latitude"`
 904	Longitude float64 `json:"longitude"`
 905}
 906
 907// InputVenueMessageContent contains a venue for displaying
 908// as an inline query result.
 909type InputVenueMessageContent struct {
 910	Latitude     float64 `json:"latitude"`
 911	Longitude    float64 `json:"longitude"`
 912	Title        string  `json:"title"`
 913	Address      string  `json:"address"`
 914	FoursquareID string  `json:"foursquare_id"`
 915}
 916
 917// InputContactMessageContent contains a contact for displaying
 918// as an inline query result.
 919type InputContactMessageContent struct {
 920	PhoneNumber string `json:"phone_number"`
 921	FirstName   string `json:"first_name"`
 922	LastName    string `json:"last_name"`
 923}
 924
 925// Invoice contains basic information about an invoice.
 926type Invoice struct {
 927	Title          string `json:"title"`
 928	Description    string `json:"description"`
 929	StartParameter string `json:"start_parameter"`
 930	Currency       string `json:"currency"`
 931	TotalAmount    int    `json:"total_amount"`
 932}
 933
 934// LabeledPrice represents a portion of the price for goods or services.
 935type LabeledPrice struct {
 936	Label  string `json:"label"`
 937	Amount int    `json:"amount"`
 938}
 939
 940// ShippingAddress represents a shipping address.
 941type ShippingAddress struct {
 942	CountryCode string `json:"country_code"`
 943	State       string `json:"state"`
 944	City        string `json:"city"`
 945	StreetLine1 string `json:"street_line1"`
 946	StreetLine2 string `json:"street_line2"`
 947	PostCode    string `json:"post_code"`
 948}
 949
 950// OrderInfo represents information about an order.
 951type OrderInfo struct {
 952	Name            string           `json:"name,omitempty"`
 953	PhoneNumber     string           `json:"phone_number,omitempty"`
 954	Email           string           `json:"email,omitempty"`
 955	ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
 956}
 957
 958// ShippingOption represents one shipping option.
 959type ShippingOption struct {
 960	ID     string          `json:"id"`
 961	Title  string          `json:"title"`
 962	Prices *[]LabeledPrice `json:"prices"`
 963}
 964
 965// SuccessfulPayment contains basic information about a successful payment.
 966type SuccessfulPayment struct {
 967	Currency                string     `json:"currency"`
 968	TotalAmount             int        `json:"total_amount"`
 969	InvoicePayload          string     `json:"invoice_payload"`
 970	ShippingOptionID        string     `json:"shipping_option_id,omitempty"`
 971	OrderInfo               *OrderInfo `json:"order_info,omitempty"`
 972	TelegramPaymentChargeID string     `json:"telegram_payment_charge_id"`
 973	ProviderPaymentChargeID string     `json:"provider_payment_charge_id"`
 974}
 975
 976// ShippingQuery contains information about an incoming shipping query.
 977type ShippingQuery struct {
 978	ID              string           `json:"id"`
 979	From            *User            `json:"from"`
 980	InvoicePayload  string           `json:"invoice_payload"`
 981	ShippingAddress *ShippingAddress `json:"shipping_address"`
 982}
 983
 984// PreCheckoutQuery contains information about an incoming pre-checkout query.
 985type PreCheckoutQuery struct {
 986	ID               string     `json:"id"`
 987	From             *User      `json:"from"`
 988	Currency         string     `json:"currency"`
 989	TotalAmount      int        `json:"total_amount"`
 990	InvoicePayload   string     `json:"invoice_payload"`
 991	ShippingOptionID string     `json:"shipping_option_id,omitempty"`
 992	OrderInfo        *OrderInfo `json:"order_info,omitempty"`
 993}
 994
 995// Error is an error containing extra information returned by the Telegram API.
 996type Error struct {
 997	Code    int
 998	Message string
 999	ResponseParameters
1000}
1001
1002func (e Error) Error() string {
1003	return e.Message
1004}