all repos — telegram-bot-api @ 75e27e1380817b6d09f88cb9780eaa2804927840

Golang bindings for the Telegram Bot API

types.go (view raw)

   1package tgbotapi
   2
   3import (
   4	"encoding/json"
   5	"errors"
   6	"fmt"
   7	"net/url"
   8	"strings"
   9	"time"
  10)
  11
  12// APIResponse is a response from the Telegram API with the result
  13// stored raw.
  14type APIResponse struct {
  15	Ok          bool                `json:"ok"`
  16	Result      json.RawMessage     `json:"result"`
  17	ErrorCode   int                 `json:"error_code"`
  18	Description string              `json:"description"`
  19	Parameters  *ResponseParameters `json:"parameters"`
  20}
  21
  22// ResponseParameters are various errors that can be returned in APIResponse.
  23type ResponseParameters struct {
  24	MigrateToChatID int64 `json:"migrate_to_chat_id"` // optional
  25	RetryAfter      int   `json:"retry_after"`        // optional
  26}
  27
  28// Update is an update response, from GetUpdates.
  29type Update struct {
  30	UpdateID           int                 `json:"update_id"`
  31	Message            *Message            `json:"message"`
  32	EditedMessage      *Message            `json:"edited_message"`
  33	ChannelPost        *Message            `json:"channel_post"`
  34	EditedChannelPost  *Message            `json:"edited_channel_post"`
  35	InlineQuery        *InlineQuery        `json:"inline_query"`
  36	ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result"`
  37	CallbackQuery      *CallbackQuery      `json:"callback_query"`
  38	ShippingQuery      *ShippingQuery      `json:"shipping_query"`
  39	PreCheckoutQuery   *PreCheckoutQuery   `json:"pre_checkout_query"`
  40	Poll               *Poll               `json:"poll"`
  41	PollAnswer         *PollAnswer         `json:"poll_answer"`
  42}
  43
  44// UpdatesChannel is the channel for getting updates.
  45type UpdatesChannel <-chan Update
  46
  47// Clear discards all unprocessed incoming updates.
  48func (ch UpdatesChannel) Clear() {
  49	for len(ch) != 0 {
  50		<-ch
  51	}
  52}
  53
  54// User is a user on Telegram.
  55type User struct {
  56	ID                      int    `json:"id"`
  57	FirstName               string `json:"first_name"`
  58	LastName                string `json:"last_name"`                   // optional
  59	UserName                string `json:"username"`                    // optional
  60	LanguageCode            string `json:"language_code"`               // optional
  61	IsBot                   bool   `json:"is_bot"`                      // optional
  62	CanJoinGroups           bool   `json:"can_join_groups"`             // optional
  63	CanReadAllGroupMessages bool   `json:"can_read_all_group_messages"` // optional
  64	SupportsInlineQueries   bool   `json:"supports_inline_queries"`     // optional
  65}
  66
  67// String displays a simple text version of a user.
  68//
  69// It is normally a user's username, but falls back to a first/last
  70// name as available.
  71func (u *User) String() string {
  72	if u.UserName != "" {
  73		return u.UserName
  74	}
  75
  76	name := u.FirstName
  77	if u.LastName != "" {
  78		name += " " + u.LastName
  79	}
  80
  81	return name
  82}
  83
  84// GroupChat is a group chat.
  85type GroupChat struct {
  86	ID    int    `json:"id"`
  87	Title string `json:"title"`
  88}
  89
  90// ChatPhoto represents a chat photo.
  91type ChatPhoto struct {
  92	SmallFileID       string `json:"small_file_id"`
  93	SmallFileUniqueID string `json:"small_file_unique_id"`
  94	BigFileID         string `json:"big_file_id"`
  95	BigFileUniqueID   string `json:"big_file_unique_id"`
  96}
  97
  98// ChatPermissions describes actions that a non-administrator user is
  99// allowed to take in a chat. All fields are optional.
 100type ChatPermissions struct {
 101	CanSendMessages       bool `json:"can_send_messages"`
 102	CanSendMediaMessages  bool `json:"can_send_media_messages"`
 103	CanSendPolls          bool `json:"can_send_polls"`
 104	CanSendOtherMessages  bool `json:"can_send_other_messages"`
 105	CanAddWebPagePreviews bool `json:"can_add_web_page_previews"`
 106	CanChangeInfo         bool `json:"can_change_info"`
 107	CanInviteUsers        bool `json:"can_invite_users"`
 108	CanPinMessages        bool `json:"can_pin_messages"`
 109}
 110
 111// Chat contains information about the place a message was sent.
 112type Chat struct {
 113	ID                  int64            `json:"id"`
 114	Type                string           `json:"type"`
 115	Title               string           `json:"title"`                          // optional
 116	UserName            string           `json:"username"`                       // optional
 117	FirstName           string           `json:"first_name"`                     // optional
 118	LastName            string           `json:"last_name"`                      // optional
 119	AllMembersAreAdmins bool             `json:"all_members_are_administrators"` // deprecated, optional
 120	Photo               *ChatPhoto       `json:"photo"`                          // optional
 121	Description         string           `json:"description,omitempty"`          // optional
 122	InviteLink          string           `json:"invite_link,omitempty"`          // optional
 123	PinnedMessage       *Message         `json:"pinned_message"`                 // optional
 124	Permissions         *ChatPermissions `json:"permissions"`                    // optional
 125	SlowModeDelay       int              `json:"slow_mode_delay"`                // optional
 126	StickerSetName      string           `json:"sticker_set_name"`               // optional
 127	CanSetStickerSet    bool             `json:"can_set_sticker_set"`            // optional
 128}
 129
 130// IsPrivate returns if the Chat is a private conversation.
 131func (c Chat) IsPrivate() bool {
 132	return c.Type == "private"
 133}
 134
 135// IsGroup returns if the Chat is a group.
 136func (c Chat) IsGroup() bool {
 137	return c.Type == "group"
 138}
 139
 140// IsSuperGroup returns if the Chat is a supergroup.
 141func (c Chat) IsSuperGroup() bool {
 142	return c.Type == "supergroup"
 143}
 144
 145// IsChannel returns if the Chat is a channel.
 146func (c Chat) IsChannel() bool {
 147	return c.Type == "channel"
 148}
 149
 150// ChatConfig returns a ChatConfig struct for chat related methods.
 151func (c Chat) ChatConfig() ChatConfig {
 152	return ChatConfig{ChatID: c.ID}
 153}
 154
 155// Message is returned by almost every request, and contains data about
 156// almost anything.
 157type Message struct {
 158	MessageID             int                   `json:"message_id"`
 159	From                  *User                 `json:"from"` // optional
 160	Date                  int                   `json:"date"`
 161	Chat                  *Chat                 `json:"chat"`
 162	ForwardFrom           *User                 `json:"forward_from"`            // optional
 163	ForwardFromChat       *Chat                 `json:"forward_from_chat"`       // optional
 164	ForwardFromMessageID  int                   `json:"forward_from_message_id"` // optional
 165	ForwardSignature      string                `json:"forward_signature"`       // optional
 166	ForwardSenderName     string                `json:"forward_sender_name"`     // optional
 167	ForwardDate           int                   `json:"forward_date"`            // optional
 168	ReplyToMessage        *Message              `json:"reply_to_message"`        // optional
 169	EditDate              int                   `json:"edit_date"`               // optional
 170	MediaGroupID          string                `json:"media_group_id"`          // optional
 171	AuthorSignature       string                `json:"author_signature"`        // optional
 172	Text                  string                `json:"text"`                    // optional
 173	Entities              []MessageEntity       `json:"entities"`                // optional
 174	CaptionEntities       []MessageEntity       `json:"caption_entities"`        // optional
 175	Audio                 *Audio                `json:"audio"`                   // optional
 176	Document              *Document             `json:"document"`                // optional
 177	Animation             *ChatAnimation        `json:"animation"`               // optional
 178	Game                  *Game                 `json:"game"`                    // optional
 179	Photo                 []PhotoSize           `json:"photo"`                   // optional
 180	Sticker               *Sticker              `json:"sticker"`                 // optional
 181	Video                 *Video                `json:"video"`                   // optional
 182	VideoNote             *VideoNote            `json:"video_note"`              // optional
 183	Voice                 *Voice                `json:"voice"`                   // optional
 184	Caption               string                `json:"caption"`                 // optional
 185	Contact               *Contact              `json:"contact"`                 // optional
 186	Location              *Location             `json:"location"`                // optional
 187	Venue                 *Venue                `json:"venue"`                   // optional
 188	Poll                  *Poll                 `json:"poll"`                    // optional
 189	Dice                  *Dice                 `json:"dice"`                    // optional
 190	NewChatMembers        []User                `json:"new_chat_members"`        // optional
 191	LeftChatMember        *User                 `json:"left_chat_member"`        // optional
 192	NewChatTitle          string                `json:"new_chat_title"`          // optional
 193	NewChatPhoto          []PhotoSize           `json:"new_chat_photo"`          // optional
 194	DeleteChatPhoto       bool                  `json:"delete_chat_photo"`       // optional
 195	GroupChatCreated      bool                  `json:"group_chat_created"`      // optional
 196	SuperGroupChatCreated bool                  `json:"supergroup_chat_created"` // optional
 197	ChannelChatCreated    bool                  `json:"channel_chat_created"`    // optional
 198	MigrateToChatID       int64                 `json:"migrate_to_chat_id"`      // optional
 199	MigrateFromChatID     int64                 `json:"migrate_from_chat_id"`    // optional
 200	PinnedMessage         *Message              `json:"pinned_message"`          // optional
 201	Invoice               *Invoice              `json:"invoice"`                 // optional
 202	SuccessfulPayment     *SuccessfulPayment    `json:"successful_payment"`      // optional
 203	ConnectedWebsite      string                `json:"connected_website"`       // optional
 204	PassportData          *PassportData         `json:"passport_data,omitempty"` // optional
 205	ReplyMarkup           *InlineKeyboardMarkup `json:"reply_markup"`            // optional
 206}
 207
 208// Time converts the message timestamp into a Time.
 209func (m *Message) Time() time.Time {
 210	return time.Unix(int64(m.Date), 0)
 211}
 212
 213// IsCommand returns true if message starts with a "bot_command" entity.
 214func (m *Message) IsCommand() bool {
 215	if m.Entities == nil || len(m.Entities) == 0 {
 216		return false
 217	}
 218
 219	entity := m.Entities[0]
 220	return entity.Offset == 0 && entity.IsCommand()
 221}
 222
 223// Command checks if the message was a command and if it was, returns the
 224// command. If the Message was not a command, it returns an empty string.
 225//
 226// If the command contains the at name syntax, it is removed. Use
 227// CommandWithAt() if you do not want that.
 228func (m *Message) Command() string {
 229	command := m.CommandWithAt()
 230
 231	if i := strings.Index(command, "@"); i != -1 {
 232		command = command[:i]
 233	}
 234
 235	return command
 236}
 237
 238// CommandWithAt checks if the message was a command and if it was, returns the
 239// command. If the Message was not a command, it returns an empty string.
 240//
 241// If the command contains the at name syntax, it is not removed. Use Command()
 242// if you want that.
 243func (m *Message) CommandWithAt() string {
 244	if !m.IsCommand() {
 245		return ""
 246	}
 247
 248	// IsCommand() checks that the message begins with a bot_command entity
 249	entity := m.Entities[0]
 250	return m.Text[1:entity.Length]
 251}
 252
 253// CommandArguments checks if the message was a command and if it was,
 254// returns all text after the command name. If the Message was not a
 255// command, it returns an empty string.
 256//
 257// Note: The first character after the command name is omitted:
 258// - "/foo bar baz" yields "bar baz", not " bar baz"
 259// - "/foo-bar baz" yields "bar baz", too
 260// Even though the latter is not a command conforming to the spec, the API
 261// marks "/foo" as command entity.
 262func (m *Message) CommandArguments() string {
 263	if !m.IsCommand() {
 264		return ""
 265	}
 266
 267	// IsCommand() checks that the message begins with a bot_command entity
 268	entity := m.Entities[0]
 269
 270	if len(m.Text) == entity.Length {
 271		return "" // The command makes up the whole message
 272	}
 273
 274	return m.Text[entity.Length+1:]
 275}
 276
 277// MessageEntity contains information about data in a Message.
 278type MessageEntity struct {
 279	Type     string `json:"type"`
 280	Offset   int    `json:"offset"`
 281	Length   int    `json:"length"`
 282	URL      string `json:"url"`      // optional
 283	User     *User  `json:"user"`     // optional
 284	Language string `json:"language"` // optional
 285}
 286
 287// ParseURL attempts to parse a URL contained within a MessageEntity.
 288func (e MessageEntity) ParseURL() (*url.URL, error) {
 289	if e.URL == "" {
 290		return nil, errors.New(ErrBadURL)
 291	}
 292
 293	return url.Parse(e.URL)
 294}
 295
 296// IsMention returns true if the type of the message entity is "mention" (@username).
 297func (e MessageEntity) IsMention() bool {
 298	return e.Type == "mention"
 299}
 300
 301// IsHashtag returns true if the type of the message entity is "hashtag".
 302func (e MessageEntity) IsHashtag() bool {
 303	return e.Type == "hashtag"
 304}
 305
 306// IsCommand returns true if the type of the message entity is "bot_command".
 307func (e MessageEntity) IsCommand() bool {
 308	return e.Type == "bot_command"
 309}
 310
 311// IsUrl returns true if the type of the message entity is "url".
 312func (e MessageEntity) IsUrl() bool {
 313	return e.Type == "url"
 314}
 315
 316// IsEmail returns true if the type of the message entity is "email".
 317func (e MessageEntity) IsEmail() bool {
 318	return e.Type == "email"
 319}
 320
 321// IsBold returns true if the type of the message entity is "bold" (bold text).
 322func (e MessageEntity) IsBold() bool {
 323	return e.Type == "bold"
 324}
 325
 326// IsItalic returns true if the type of the message entity is "italic" (italic text).
 327func (e MessageEntity) IsItalic() bool {
 328	return e.Type == "italic"
 329}
 330
 331// IsCode returns true if the type of the message entity is "code" (monowidth string).
 332func (e MessageEntity) IsCode() bool {
 333	return e.Type == "code"
 334}
 335
 336// IsPre returns true if the type of the message entity is "pre" (monowidth block).
 337func (e MessageEntity) IsPre() bool {
 338	return e.Type == "pre"
 339}
 340
 341// IsTextLink returns true if the type of the message entity is "text_link" (clickable text URL).
 342func (e MessageEntity) IsTextLink() bool {
 343	return e.Type == "text_link"
 344}
 345
 346// PhotoSize contains information about photos.
 347type PhotoSize struct {
 348	FileID       string `json:"file_id"`
 349	FileUniqueID string `json:"file_unique_id"`
 350	Width        int    `json:"width"`
 351	Height       int    `json:"height"`
 352	FileSize     int    `json:"file_size"` // optional
 353}
 354
 355// Audio contains information about audio.
 356type Audio struct {
 357	FileID       string `json:"file_id"`
 358	FileUniqueID string `json:"file_unique_id"`
 359	Duration     int    `json:"duration"`
 360	Performer    string `json:"performer"` // optional
 361	Title        string `json:"title"`     // optional
 362	MimeType     string `json:"mime_type"` // optional
 363	FileSize     int    `json:"file_size"` // optional
 364}
 365
 366// Document contains information about a document.
 367type Document struct {
 368	FileID       string     `json:"file_id"`
 369	FileUniqueID string     `json:"file_unique_id"`
 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// Sticker contains information about a sticker.
 377type Sticker struct {
 378	FileID       string       `json:"file_id"`
 379	FileUniqueID string       `json:"file_unique_id"`
 380	Width        int          `json:"width"`
 381	Height       int          `json:"height"`
 382	IsAnimated   bool         `json:"is_animated"`
 383	Thumbnail    *PhotoSize   `json:"thumb"`         // optional
 384	Emoji        string       `json:"emoji"`         // optional
 385	SetName      string       `json:"set_name"`      // optional
 386	MaskPosition MaskPosition `json:"mask_position"` //optional
 387	FileSize     int          `json:"file_size"`     // optional
 388}
 389
 390// MaskPosition is the position of a mask.
 391type MaskPosition struct {
 392	Point     string     `json:"point"`
 393	XShift    float32    `json:"x_shift"`
 394	YShift    float32    `json:"y_shift"`
 395	Scale     float32    `json:"scale"`
 396	FileID    string     `json:"file_id"`
 397	Width     int        `json:"width"`
 398	Height    int        `json:"height"`
 399	Thumbnail *PhotoSize `json:"thumb"`     // optional
 400	Emoji     string     `json:"emoji"`     // optional
 401	FileSize  int        `json:"file_size"` // optional
 402	SetName   string     `json:"set_name"`  // optional
 403}
 404
 405// ChatAnimation contains information about an animation.
 406type ChatAnimation struct {
 407	FileID       string     `json:"file_id"`
 408	FileUniqueID string     `json:"file_unique_id"`
 409	Width        int        `json:"width"`
 410	Height       int        `json:"height"`
 411	Duration     int        `json:"duration"`
 412	Thumbnail    *PhotoSize `json:"thumb"`     // optional
 413	FileName     string     `json:"file_name"` // optional
 414	MimeType     string     `json:"mime_type"` // optional
 415	FileSize     int        `json:"file_size"` // optional
 416}
 417
 418// Video contains information about a video.
 419type Video struct {
 420	FileID       string     `json:"file_id"`
 421	FileUniqueID string     `json:"file_unique_id"`
 422	Width        int        `json:"width"`
 423	Height       int        `json:"height"`
 424	Duration     int        `json:"duration"`
 425	Thumbnail    *PhotoSize `json:"thumb"`     // optional
 426	MimeType     string     `json:"mime_type"` // optional
 427	FileSize     int        `json:"file_size"` // optional
 428}
 429
 430// VideoNote contains information about a video.
 431type VideoNote struct {
 432	FileID       string     `json:"file_id"`
 433	FileUniqueID string     `json:"file_unique_id"`
 434	Length       int        `json:"length"`
 435	Duration     int        `json:"duration"`
 436	Thumbnail    *PhotoSize `json:"thumb"`     // optional
 437	FileSize     int        `json:"file_size"` // optional
 438}
 439
 440// Voice contains information about a voice.
 441type Voice struct {
 442	FileID       string `json:"file_id"`
 443	FileUniqueID string `json:"file_unique_id"`
 444	Duration     int    `json:"duration"`
 445	MimeType     string `json:"mime_type"` // optional
 446	FileSize     int    `json:"file_size"` // optional
 447}
 448
 449// Contact contains information about a contact.
 450//
 451// Note that LastName and UserID may be empty.
 452type Contact struct {
 453	PhoneNumber string `json:"phone_number"`
 454	FirstName   string `json:"first_name"`
 455	LastName    string `json:"last_name"` // optional
 456	UserID      int    `json:"user_id"`   // optional
 457	VCard       string `json:"vcard"`     // optional
 458}
 459
 460// Location contains information about a place.
 461type Location struct {
 462	Longitude float64 `json:"longitude"`
 463	Latitude  float64 `json:"latitude"`
 464}
 465
 466// Venue contains information about a venue, including its Location.
 467type Venue struct {
 468	Location     Location `json:"location"`
 469	Title        string   `json:"title"`
 470	Address      string   `json:"address"`
 471	FoursquareID string   `json:"foursquare_id"` // optional
 472}
 473
 474// PollOption contains information about one answer option in a poll.
 475type PollOption struct {
 476	Text       string `json:"text"`
 477	VoterCount int    `json:"voter_count"`
 478}
 479
 480// PollAnswer represents an answer of a user in a non-anonymous poll.
 481type PollAnswer struct {
 482	PollID    string `json:"poll_id"`
 483	User      User   `json:"user"`
 484	OptionIDs []int  `json:"option_ids"`
 485}
 486
 487// Poll contains information about a poll.
 488type Poll struct {
 489	ID                    string       `json:"id"`
 490	Question              string       `json:"question"`
 491	Options               []PollOption `json:"options"`
 492	IsClosed              bool         `json:"is_closed"`
 493	IsAnonymous           bool         `json:"is_anonymous"`
 494	Type                  string       `json:"type"`
 495	AllowsMultipleAnswers bool         `json:"allows_multiple_answers"`
 496	CorrectOptionID       int          `json:"correct_option_id"` // optional
 497}
 498
 499// Dice represents a single dice value.
 500type Dice struct {
 501	Value int `json:"value"`
 502}
 503
 504// UserProfilePhotos contains a set of user profile photos.
 505type UserProfilePhotos struct {
 506	TotalCount int           `json:"total_count"`
 507	Photos     [][]PhotoSize `json:"photos"`
 508}
 509
 510// File contains information about a file to download from Telegram.
 511type File struct {
 512	FileID       string `json:"file_id"`
 513	FileUniqueID string `json:"file_unique_id"`
 514	FileSize     int    `json:"file_size"` // optional
 515	FilePath     string `json:"file_path"` // optional
 516}
 517
 518// Link returns a full path to the download URL for a File.
 519//
 520// It requires the Bot Token to create the link.
 521func (f *File) Link(token string) string {
 522	return fmt.Sprintf(FileEndpoint, token, f.FilePath)
 523}
 524
 525// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
 526type ReplyKeyboardMarkup struct {
 527	Keyboard        [][]KeyboardButton `json:"keyboard"`
 528	ResizeKeyboard  bool               `json:"resize_keyboard"`   // optional
 529	OneTimeKeyboard bool               `json:"one_time_keyboard"` // optional
 530	Selective       bool               `json:"selective"`         // optional
 531}
 532
 533// KeyboardButton is a button within a custom keyboard.
 534type KeyboardButton struct {
 535	Text            string                 `json:"text"`
 536	RequestContact  bool                   `json:"request_contact"`
 537	RequestLocation bool                   `json:"request_location"`
 538	RequestPoll     KeyboardButtonPollType `json:"request_poll"`
 539}
 540
 541// KeyboardButtonPollType represents type of a poll, which is allowed to
 542// be created and sent when the corresponding button is pressed.
 543type KeyboardButtonPollType struct {
 544	Type string `json:"type"`
 545}
 546
 547// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
 548type ReplyKeyboardHide struct {
 549	HideKeyboard bool `json:"hide_keyboard"`
 550	Selective    bool `json:"selective"` // optional
 551}
 552
 553// ReplyKeyboardRemove allows the Bot to hide a custom keyboard.
 554type ReplyKeyboardRemove struct {
 555	RemoveKeyboard bool `json:"remove_keyboard"`
 556	Selective      bool `json:"selective"`
 557}
 558
 559// InlineKeyboardMarkup is a custom keyboard presented for an inline bot.
 560type InlineKeyboardMarkup struct {
 561	InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
 562}
 563
 564// InlineKeyboardButton is a button within a custom keyboard for
 565// inline query responses.
 566//
 567// Note that some values are references as even an empty string
 568// will change behavior.
 569//
 570// CallbackGame, if set, MUST be first button in first row.
 571type InlineKeyboardButton struct {
 572	Text                         string        `json:"text"`
 573	URL                          *string       `json:"url,omitempty"`                              // optional
 574	LoginURL                     *LoginURL     `json:"login_url,omitempty"`                        // optional
 575	CallbackData                 *string       `json:"callback_data,omitempty"`                    // optional
 576	SwitchInlineQuery            *string       `json:"switch_inline_query,omitempty"`              // optional
 577	SwitchInlineQueryCurrentChat *string       `json:"switch_inline_query_current_chat,omitempty"` // optional
 578	CallbackGame                 *CallbackGame `json:"callback_game,omitempty"`                    // optional
 579	Pay                          bool          `json:"pay,omitempty"`                              // optional
 580}
 581
 582// LoginURL is the parameters for the login inline keyboard button type.
 583type LoginURL struct {
 584	URL                string `json:"url"`
 585	ForwardText        string `json:"forward_text"`
 586	BotUsername        string `json:"bot_username"`
 587	RequestWriteAccess bool   `json:"request_write_access"`
 588}
 589
 590// CallbackQuery is data sent when a keyboard button with callback data
 591// is clicked.
 592type CallbackQuery struct {
 593	ID              string   `json:"id"`
 594	From            *User    `json:"from"`
 595	Message         *Message `json:"message"`           // optional
 596	InlineMessageID string   `json:"inline_message_id"` // optional
 597	ChatInstance    string   `json:"chat_instance"`
 598	Data            string   `json:"data"`            // optional
 599	GameShortName   string   `json:"game_short_name"` // optional
 600}
 601
 602// ForceReply allows the Bot to have users directly reply to it without
 603// additional interaction.
 604type ForceReply struct {
 605	ForceReply bool `json:"force_reply"`
 606	Selective  bool `json:"selective"` // optional
 607}
 608
 609// ChatMember is information about a member in a chat.
 610type ChatMember struct {
 611	User                  *User  `json:"user"`
 612	Status                string `json:"status"`
 613	CustomTitle           string `json:"custom_title"`                        // optional
 614	UntilDate             int64  `json:"until_date,omitempty"`                // optional
 615	CanBeEdited           bool   `json:"can_be_edited,omitempty"`             // optional
 616	CanPostMessages       bool   `json:"can_post_messages,omitempty"`         // optional
 617	CanEditMessages       bool   `json:"can_edit_messages,omitempty"`         // optional
 618	CanDeleteMessages     bool   `json:"can_delete_messages,omitempty"`       // optional
 619	CanRestrictMembers    bool   `json:"can_restrict_members,omitempty"`      // optional
 620	CanPromoteMembers     bool   `json:"can_promote_members,omitempty"`       // optional
 621	CanChangeInfo         bool   `json:"can_change_info,omitempty"`           // optional
 622	CanInviteUsers        bool   `json:"can_invite_users,omitempty"`          // optional
 623	CanPinMessages        bool   `json:"can_pin_messages,omitempty"`          // optional
 624	IsChatMember          bool   `json:"is_member"`                           // optional
 625	CanSendMessages       bool   `json:"can_send_messages,omitempty"`         // optional
 626	CanSendMediaMessages  bool   `json:"can_send_media_messages,omitempty"`   // optional
 627	CanSendPolls          bool   `json:"can_send_polls,omitempty"`            // optional
 628	CanSendOtherMessages  bool   `json:"can_send_other_messages,omitempty"`   // optional
 629	CanAddWebPagePreviews bool   `json:"can_add_web_page_previews,omitempty"` // optional
 630}
 631
 632// IsCreator returns if the ChatMember was the creator of the chat.
 633func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" }
 634
 635// IsAdministrator returns if the ChatMember is a chat administrator.
 636func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" }
 637
 638// IsMember returns if the ChatMember is a current member of the chat.
 639func (chat ChatMember) IsMember() bool { return chat.Status == "member" }
 640
 641// HasLeft returns if the ChatMember left the chat.
 642func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
 643
 644// WasKicked returns if the ChatMember was kicked from the chat.
 645func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
 646
 647// Game is a game within Telegram.
 648type Game struct {
 649	Title        string          `json:"title"`
 650	Description  string          `json:"description"`
 651	Photo        []PhotoSize     `json:"photo"`
 652	Text         string          `json:"text"`
 653	TextEntities []MessageEntity `json:"text_entities"`
 654	Animation    Animation       `json:"animation"`
 655}
 656
 657// Animation is a GIF animation demonstrating the game.
 658type Animation struct {
 659	FileID       string    `json:"file_id"`
 660	FileUniqueID string    `json:"file_unique_id"`
 661	Thumb        PhotoSize `json:"thumb"`
 662	FileName     string    `json:"file_name"`
 663	MimeType     string    `json:"mime_type"`
 664	FileSize     int       `json:"file_size"`
 665}
 666
 667// GameHighScore is a user's score and position on the leaderboard.
 668type GameHighScore struct {
 669	Position int  `json:"position"`
 670	User     User `json:"user"`
 671	Score    int  `json:"score"`
 672}
 673
 674// CallbackGame is for starting a game in an inline keyboard button.
 675type CallbackGame struct{}
 676
 677// WebhookInfo is information about a currently set webhook.
 678type WebhookInfo struct {
 679	URL                  string `json:"url"`
 680	HasCustomCertificate bool   `json:"has_custom_certificate"`
 681	PendingUpdateCount   int    `json:"pending_update_count"`
 682	LastErrorDate        int    `json:"last_error_date"`    // optional
 683	LastErrorMessage     string `json:"last_error_message"` // optional
 684}
 685
 686// IsSet returns true if a webhook is currently set.
 687func (info WebhookInfo) IsSet() bool {
 688	return info.URL != ""
 689}
 690
 691// InlineQuery is a Query from Telegram for an inline request.
 692type InlineQuery struct {
 693	ID       string    `json:"id"`
 694	From     *User     `json:"from"`
 695	Location *Location `json:"location"` // optional
 696	Query    string    `json:"query"`
 697	Offset   string    `json:"offset"`
 698}
 699
 700// InlineQueryResultArticle is an inline query response article.
 701type InlineQueryResultArticle struct {
 702	Type                string                `json:"type"`                            // required
 703	ID                  string                `json:"id"`                              // required
 704	Title               string                `json:"title"`                           // required
 705	InputMessageContent interface{}           `json:"input_message_content,omitempty"` // required
 706	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 707	URL                 string                `json:"url"`
 708	HideURL             bool                  `json:"hide_url"`
 709	Description         string                `json:"description"`
 710	ThumbURL            string                `json:"thumb_url"`
 711	ThumbWidth          int                   `json:"thumb_width"`
 712	ThumbHeight         int                   `json:"thumb_height"`
 713}
 714
 715// InlineQueryResultPhoto is an inline query response photo.
 716type InlineQueryResultPhoto struct {
 717	Type                string                `json:"type"`      // required
 718	ID                  string                `json:"id"`        // required
 719	URL                 string                `json:"photo_url"` // required
 720	MimeType            string                `json:"mime_type"`
 721	Width               int                   `json:"photo_width"`
 722	Height              int                   `json:"photo_height"`
 723	ThumbURL            string                `json:"thumb_url"`
 724	Title               string                `json:"title"`
 725	Description         string                `json:"description"`
 726	Caption             string                `json:"caption"`
 727	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 728	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 729}
 730
 731// InlineQueryResultCachedPhoto is an inline query response with cached photo.
 732type InlineQueryResultCachedPhoto struct {
 733	Type                string                `json:"type"`          // required
 734	ID                  string                `json:"id"`            // required
 735	PhotoID             string                `json:"photo_file_id"` // required
 736	Title               string                `json:"title"`
 737	Description         string                `json:"description"`
 738	Caption             string                `json:"caption"`
 739	ParseMode           string                `json:"parse_mode"`
 740	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 741	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 742}
 743
 744// InlineQueryResultGIF is an inline query response GIF.
 745type InlineQueryResultGIF struct {
 746	Type                string                `json:"type"`      // required
 747	ID                  string                `json:"id"`        // required
 748	URL                 string                `json:"gif_url"`   // required
 749	ThumbURL            string                `json:"thumb_url"` // required
 750	Width               int                   `json:"gif_width,omitempty"`
 751	Height              int                   `json:"gif_height,omitempty"`
 752	Duration            int                   `json:"gif_duration,omitempty"`
 753	Title               string                `json:"title,omitempty"`
 754	Caption             string                `json:"caption,omitempty"`
 755	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 756	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 757}
 758
 759// InlineQueryResultCachedGIF is an inline query response with cached gif.
 760type InlineQueryResultCachedGIF struct {
 761	Type                string                `json:"type"`        // required
 762	ID                  string                `json:"id"`          // required
 763	GifID               string                `json:"gif_file_id"` // required
 764	Title               string                `json:"title"`
 765	Caption             string                `json:"caption"`
 766	ParseMode           string                `json:"parse_mode"`
 767	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 768	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 769}
 770
 771// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
 772type InlineQueryResultMPEG4GIF struct {
 773	Type                string                `json:"type"`      // required
 774	ID                  string                `json:"id"`        // required
 775	URL                 string                `json:"mpeg4_url"` // required
 776	Width               int                   `json:"mpeg4_width"`
 777	Height              int                   `json:"mpeg4_height"`
 778	Duration            int                   `json:"mpeg4_duration"`
 779	ThumbURL            string                `json:"thumb_url"`
 780	Title               string                `json:"title"`
 781	Caption             string                `json:"caption"`
 782	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 783	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 784}
 785
 786// InlineQueryResultCachedMpeg4Gif is an inline query response with cached
 787// H.264/MPEG-4 AVC video without sound gif.
 788type InlineQueryResultCachedMpeg4Gif struct {
 789	Type                string                `json:"type"`          // required
 790	ID                  string                `json:"id"`            // required
 791	MGifID              string                `json:"mpeg4_file_id"` // required
 792	Title               string                `json:"title"`
 793	Caption             string                `json:"caption"`
 794	ParseMode           string                `json:"parse_mode"`
 795	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 796	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 797}
 798
 799// InlineQueryResultVideo is an inline query response video.
 800type InlineQueryResultVideo struct {
 801	Type                string                `json:"type"`      // required
 802	ID                  string                `json:"id"`        // required
 803	URL                 string                `json:"video_url"` // required
 804	MimeType            string                `json:"mime_type"` // required
 805	ThumbURL            string                `json:"thumb_url"`
 806	Title               string                `json:"title"`
 807	Caption             string                `json:"caption"`
 808	Width               int                   `json:"video_width"`
 809	Height              int                   `json:"video_height"`
 810	Duration            int                   `json:"video_duration"`
 811	Description         string                `json:"description"`
 812	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 813	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 814}
 815
 816// InlineQueryResultCachedVideo is an inline query response with cached video.
 817type InlineQueryResultCachedVideo struct {
 818	Type                string                `json:"type"`          // required
 819	ID                  string                `json:"id"`            // required
 820	VideoID             string                `json:"video_file_id"` // required
 821	Title               string                `json:"title"`         // required
 822	Description         string                `json:"description"`
 823	Caption             string                `json:"caption"`
 824	ParseMode           string                `json:"parse_mode"`
 825	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 826	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 827}
 828
 829// InlineQueryResultAudio is an inline query response audio.
 830type InlineQueryResultAudio struct {
 831	Type                string                `json:"type"`      // required
 832	ID                  string                `json:"id"`        // required
 833	URL                 string                `json:"audio_url"` // required
 834	Title               string                `json:"title"`     // required
 835	Caption             string                `json:"caption"`
 836	Performer           string                `json:"performer"`
 837	Duration            int                   `json:"audio_duration"`
 838	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 839	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 840}
 841
 842// InlineQueryResultCachedAudio is an inline query response with cached audio.
 843type InlineQueryResultCachedAudio struct {
 844	Type                string                `json:"type"`          // required
 845	ID                  string                `json:"id"`            // required
 846	AudioID             string                `json:"audio_file_id"` // required
 847	Caption             string                `json:"caption"`
 848	ParseMode           string                `json:"parse_mode"`
 849	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 850	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 851}
 852
 853// InlineQueryResultVoice is an inline query response voice.
 854type InlineQueryResultVoice struct {
 855	Type                string                `json:"type"`      // required
 856	ID                  string                `json:"id"`        // required
 857	URL                 string                `json:"voice_url"` // required
 858	Title               string                `json:"title"`     // required
 859	Caption             string                `json:"caption"`
 860	Duration            int                   `json:"voice_duration"`
 861	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 862	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 863}
 864
 865// InlineQueryResultCachedVoice is an inline query response with cached voice.
 866type InlineQueryResultCachedVoice struct {
 867	Type                string                `json:"type"`          // required
 868	ID                  string                `json:"id"`            // required
 869	VoiceID             string                `json:"voice_file_id"` // required
 870	Title               string                `json:"title"`         // required
 871	Caption             string                `json:"caption"`
 872	ParseMode           string                `json:"parse_mode"`
 873	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 874	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 875}
 876
 877// InlineQueryResultDocument is an inline query response document.
 878type InlineQueryResultDocument struct {
 879	Type                string                `json:"type"`  // required
 880	ID                  string                `json:"id"`    // required
 881	Title               string                `json:"title"` // required
 882	Caption             string                `json:"caption"`
 883	URL                 string                `json:"document_url"` // required
 884	MimeType            string                `json:"mime_type"`    // required
 885	Description         string                `json:"description"`
 886	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 887	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 888	ThumbURL            string                `json:"thumb_url"`
 889	ThumbWidth          int                   `json:"thumb_width"`
 890	ThumbHeight         int                   `json:"thumb_height"`
 891}
 892
 893// InlineQueryResultCachedDocument is an inline query response with cached document.
 894type InlineQueryResultCachedDocument struct {
 895	Type                string                `json:"type"`             // required
 896	ID                  string                `json:"id"`               // required
 897	DocumentID          string                `json:"document_file_id"` // required
 898	Title               string                `json:"title"`            // required
 899	Caption             string                `json:"caption"`
 900	Description         string                `json:"description"`
 901	ParseMode           string                `json:"parse_mode"`
 902	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 903	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 904}
 905
 906// InlineQueryResultLocation is an inline query response location.
 907type InlineQueryResultLocation struct {
 908	Type                string                `json:"type"`        // required
 909	ID                  string                `json:"id"`          // required
 910	Latitude            float64               `json:"latitude"`    // required
 911	Longitude           float64               `json:"longitude"`   // required
 912	LivePeriod          int                   `json:"live_period"` // optional
 913	Title               string                `json:"title"`       // required
 914	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 915	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 916	ThumbURL            string                `json:"thumb_url"`
 917	ThumbWidth          int                   `json:"thumb_width"`
 918	ThumbHeight         int                   `json:"thumb_height"`
 919}
 920
 921// InlineQueryResultContact is an inline query response contact.
 922type InlineQueryResultContact struct {
 923	Type                string                `json:"type"`         // required
 924	ID                  string                `json:"id"`           // required
 925	PhoneNumber         string                `json:"phone_number"` // required
 926	FirstName           string                `json:"first_name"`   // required
 927	LastName            string                `json:"last_name"`
 928	VCard               string                `json:"vcard"`
 929	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 930	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 931	ThumbURL            string                `json:"thumb_url"`
 932	ThumbWidth          int                   `json:"thumb_width"`
 933	ThumbHeight         int                   `json:"thumb_height"`
 934}
 935
 936// InlineQueryResultVenue is an inline query response venue.
 937type InlineQueryResultVenue struct {
 938	Type                string                `json:"type"`      // required
 939	ID                  string                `json:"id"`        // required
 940	Latitude            float64               `json:"latitude"`  // required
 941	Longitude           float64               `json:"longitude"` // required
 942	Title               string                `json:"title"`     // required
 943	Address             string                `json:"address"`   // required
 944	FoursquareID        string                `json:"foursquare_id"`
 945	FoursquareType      string                `json:"foursquare_type"`
 946	ReplyMarkup         *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 947	InputMessageContent interface{}           `json:"input_message_content,omitempty"`
 948	ThumbURL            string                `json:"thumb_url"`
 949	ThumbWidth          int                   `json:"thumb_width"`
 950	ThumbHeight         int                   `json:"thumb_height"`
 951}
 952
 953// InlineQueryResultGame is an inline query response game.
 954type InlineQueryResultGame struct {
 955	Type          string                `json:"type"`
 956	ID            string                `json:"id"`
 957	GameShortName string                `json:"game_short_name"`
 958	ReplyMarkup   *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
 959}
 960
 961// ChosenInlineResult is an inline query result chosen by a User
 962type ChosenInlineResult struct {
 963	ResultID        string    `json:"result_id"`
 964	From            *User     `json:"from"`
 965	Location        *Location `json:"location"`
 966	InlineMessageID string    `json:"inline_message_id"`
 967	Query           string    `json:"query"`
 968}
 969
 970// InputTextMessageContent contains text for displaying
 971// as an inline query result.
 972type InputTextMessageContent struct {
 973	Text                  string `json:"message_text"`
 974	ParseMode             string `json:"parse_mode"`
 975	DisableWebPagePreview bool   `json:"disable_web_page_preview"`
 976}
 977
 978// InputLocationMessageContent contains a location for displaying
 979// as an inline query result.
 980type InputLocationMessageContent struct {
 981	Latitude  float64 `json:"latitude"`
 982	Longitude float64 `json:"longitude"`
 983}
 984
 985// InputVenueMessageContent contains a venue for displaying
 986// as an inline query result.
 987type InputVenueMessageContent struct {
 988	Latitude     float64 `json:"latitude"`
 989	Longitude    float64 `json:"longitude"`
 990	Title        string  `json:"title"`
 991	Address      string  `json:"address"`
 992	FoursquareID string  `json:"foursquare_id"`
 993}
 994
 995// InputContactMessageContent contains a contact for displaying
 996// as an inline query result.
 997type InputContactMessageContent struct {
 998	PhoneNumber string `json:"phone_number"`
 999	FirstName   string `json:"first_name"`
1000	LastName    string `json:"last_name"`
1001	VCard       string `json:"vcard"`
1002}
1003
1004// Invoice contains basic information about an invoice.
1005type Invoice struct {
1006	Title          string `json:"title"`
1007	Description    string `json:"description"`
1008	StartParameter string `json:"start_parameter"`
1009	Currency       string `json:"currency"`
1010	TotalAmount    int    `json:"total_amount"`
1011}
1012
1013// LabeledPrice represents a portion of the price for goods or services.
1014type LabeledPrice struct {
1015	Label  string `json:"label"`
1016	Amount int    `json:"amount"`
1017}
1018
1019// ShippingAddress represents a shipping address.
1020type ShippingAddress struct {
1021	CountryCode string `json:"country_code"`
1022	State       string `json:"state"`
1023	City        string `json:"city"`
1024	StreetLine1 string `json:"street_line1"`
1025	StreetLine2 string `json:"street_line2"`
1026	PostCode    string `json:"post_code"`
1027}
1028
1029// OrderInfo represents information about an order.
1030type OrderInfo struct {
1031	Name            string           `json:"name,omitempty"`
1032	PhoneNumber     string           `json:"phone_number,omitempty"`
1033	Email           string           `json:"email,omitempty"`
1034	ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
1035}
1036
1037// ShippingOption represents one shipping option.
1038type ShippingOption struct {
1039	ID     string         `json:"id"`
1040	Title  string         `json:"title"`
1041	Prices []LabeledPrice `json:"prices"`
1042}
1043
1044// SuccessfulPayment contains basic information about a successful payment.
1045type SuccessfulPayment struct {
1046	Currency                string     `json:"currency"`
1047	TotalAmount             int        `json:"total_amount"`
1048	InvoicePayload          string     `json:"invoice_payload"`
1049	ShippingOptionID        string     `json:"shipping_option_id,omitempty"`
1050	OrderInfo               *OrderInfo `json:"order_info,omitempty"`
1051	TelegramPaymentChargeID string     `json:"telegram_payment_charge_id"`
1052	ProviderPaymentChargeID string     `json:"provider_payment_charge_id"`
1053}
1054
1055// ShippingQuery contains information about an incoming shipping query.
1056type ShippingQuery struct {
1057	ID              string           `json:"id"`
1058	From            *User            `json:"from"`
1059	InvoicePayload  string           `json:"invoice_payload"`
1060	ShippingAddress *ShippingAddress `json:"shipping_address"`
1061}
1062
1063// PreCheckoutQuery contains information about an incoming pre-checkout query.
1064type PreCheckoutQuery struct {
1065	ID               string     `json:"id"`
1066	From             *User      `json:"from"`
1067	Currency         string     `json:"currency"`
1068	TotalAmount      int        `json:"total_amount"`
1069	InvoicePayload   string     `json:"invoice_payload"`
1070	ShippingOptionID string     `json:"shipping_option_id,omitempty"`
1071	OrderInfo        *OrderInfo `json:"order_info,omitempty"`
1072}
1073
1074// StickerSet is a collection of stickers.
1075type StickerSet struct {
1076	Name          string     `json:"name"`
1077	Title         string     `json:"title"`
1078	IsAnimated    bool       `json:"is_animated"`
1079	ContainsMasks bool       `json:"contains_masks"`
1080	Stickers      []Sticker  `json:"stickers"`
1081	Thumb         *PhotoSize `json:"thumb"`
1082}
1083
1084// BotCommand represents Telegram's understanding of a command.
1085type BotCommand struct {
1086	Command     string `json:"command"`
1087	Description string `json:"description"`
1088}
1089
1090// BaseInputMedia is a base type for the InputMedia types.
1091type BaseInputMedia struct {
1092	Type      string `json:"type"`
1093	Media     string `json:"media"`
1094	Caption   string `json:"caption"`
1095	ParseMode string `json:"parse_mode"`
1096}
1097
1098// InputMediaPhoto is a photo to send as part of a media group.
1099type InputMediaPhoto struct {
1100	BaseInputMedia
1101}
1102
1103// InputMediaVideo is a video to send as part of a media group.
1104type InputMediaVideo struct {
1105	BaseInputMedia
1106	Width             int  `json:"width"`
1107	Height            int  `json:"height"`
1108	Duration          int  `json:"duration"`
1109	SupportsStreaming bool `json:"supports_streaming"`
1110}
1111
1112// InputMediaAnimation is an animation to send as part of a media group.
1113type InputMediaAnimation struct {
1114	BaseInputMedia
1115	Width    int `json:"width"`
1116	Height   int `json:"height"`
1117	Duration int `json:"duration"`
1118}
1119
1120// InputMediaAudio is a audio to send as part of a media group.
1121type InputMediaAudio struct {
1122	BaseInputMedia
1123	Duration  int    `json:"duration"`
1124	Performer string `json:"performer"`
1125	Title     string `json:"title"`
1126}
1127
1128// InputMediaDocument is a audio to send as part of a media group.
1129type InputMediaDocument struct {
1130	BaseInputMedia
1131}
1132
1133// Error is an error containing extra information returned by the Telegram API.
1134type Error struct {
1135	Code    int
1136	Message string
1137	ResponseParameters
1138}
1139
1140// Error message string.
1141func (e Error) Error() string {
1142	return e.Message
1143}