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