all repos — telegram-bot-api @ a005cff757a80dcb6ce777ca32b6308a02124c90

Golang bindings for the Telegram Bot API

types.go (view raw)

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