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