all repos — telegram-bot-api @ b40fac92022dc6887be0dfb7145c86a5b8a3f258

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