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