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