all repos — telegram-bot-api @ 5ce2767dadc468aaf629a3119d806f33d68e10ef

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