all repos — telegram-bot-api @ fe3a0a8654d017254d5a973cf69badc1c4da4aa8

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