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}
349
350// ChatAnimation contains information about an animation.
351type ChatAnimation struct {
352 FileID string `json:"file_id"`
353 Width int `json:"width"`
354 Height int `json:"height"`
355 Duration int `json:"duration"`
356 Thumbnail *PhotoSize `json:"thumb"` // optional
357 FileName string `json:"file_name"` // optional
358 MimeType string `json:"mime_type"` // optional
359 FileSize int `json:"file_size"` // optional
360}
361
362// Video contains information about a video.
363type Video struct {
364 FileID string `json:"file_id"`
365 Width int `json:"width"`
366 Height int `json:"height"`
367 Duration int `json:"duration"`
368 Thumbnail *PhotoSize `json:"thumb"` // optional
369 MimeType string `json:"mime_type"` // optional
370 FileSize int `json:"file_size"` // optional
371}
372
373// VideoNote contains information about a video.
374type VideoNote struct {
375 FileID string `json:"file_id"`
376 Length int `json:"length"`
377 Duration int `json:"duration"`
378 Thumbnail *PhotoSize `json:"thumb"` // optional
379 FileSize int `json:"file_size"` // optional
380}
381
382// Voice contains information about a voice.
383type Voice struct {
384 FileID string `json:"file_id"`
385 Duration int `json:"duration"`
386 MimeType string `json:"mime_type"` // optional
387 FileSize int `json:"file_size"` // optional
388}
389
390// Contact contains information about a contact.
391//
392// Note that LastName and UserID may be empty.
393type Contact struct {
394 PhoneNumber string `json:"phone_number"`
395 FirstName string `json:"first_name"`
396 LastName string `json:"last_name"` // optional
397 UserID int `json:"user_id"` // optional
398}
399
400// Location contains information about a place.
401type Location struct {
402 Longitude float64 `json:"longitude"`
403 Latitude float64 `json:"latitude"`
404}
405
406// Venue contains information about a venue, including its Location.
407type Venue struct {
408 Location Location `json:"location"`
409 Title string `json:"title"`
410 Address string `json:"address"`
411 FoursquareID string `json:"foursquare_id"` // optional
412}
413
414// UserProfilePhotos contains a set of user profile photos.
415type UserProfilePhotos struct {
416 TotalCount int `json:"total_count"`
417 Photos [][]PhotoSize `json:"photos"`
418}
419
420// File contains information about a file to download from Telegram.
421type File struct {
422 FileID string `json:"file_id"`
423 FileSize int `json:"file_size"` // optional
424 FilePath string `json:"file_path"` // optional
425}
426
427// Link returns a full path to the download URL for a File.
428//
429// It requires the Bot Token to create the link.
430func (f *File) Link(token string) string {
431 return fmt.Sprintf(FileEndpoint, token, f.FilePath)
432}
433
434// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
435type ReplyKeyboardMarkup struct {
436 Keyboard [][]KeyboardButton `json:"keyboard"`
437 ResizeKeyboard bool `json:"resize_keyboard"` // optional
438 OneTimeKeyboard bool `json:"one_time_keyboard"` // optional
439 Selective bool `json:"selective"` // optional
440}
441
442// KeyboardButton is a button within a custom keyboard.
443type KeyboardButton struct {
444 Text string `json:"text"`
445 RequestContact bool `json:"request_contact"`
446 RequestLocation bool `json:"request_location"`
447}
448
449// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
450type ReplyKeyboardHide struct {
451 HideKeyboard bool `json:"hide_keyboard"`
452 Selective bool `json:"selective"` // optional
453}
454
455// ReplyKeyboardRemove allows the Bot to hide a custom keyboard.
456type ReplyKeyboardRemove struct {
457 RemoveKeyboard bool `json:"remove_keyboard"`
458 Selective bool `json:"selective"`
459}
460
461// InlineKeyboardMarkup is a custom keyboard presented for an inline bot.
462type InlineKeyboardMarkup struct {
463 InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
464}
465
466// InlineKeyboardButton is a button within a custom keyboard for
467// inline query responses.
468//
469// Note that some values are references as even an empty string
470// will change behavior.
471//
472// CallbackGame, if set, MUST be first button in first row.
473type InlineKeyboardButton struct {
474 Text string `json:"text"`
475 URL *string `json:"url,omitempty"` // optional
476 CallbackData *string `json:"callback_data,omitempty"` // optional
477 SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional
478 SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional
479 CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional
480 Pay bool `json:"pay,omitempty"` // optional
481}
482
483// CallbackQuery is data sent when a keyboard button with callback data
484// is clicked.
485type CallbackQuery struct {
486 ID string `json:"id"`
487 From *User `json:"from"`
488 Message *Message `json:"message"` // optional
489 InlineMessageID string `json:"inline_message_id"` // optional
490 ChatInstance string `json:"chat_instance"`
491 Data string `json:"data"` // optional
492 GameShortName string `json:"game_short_name"` // optional
493}
494
495// ForceReply allows the Bot to have users directly reply to it without
496// additional interaction.
497type ForceReply struct {
498 ForceReply bool `json:"force_reply"`
499 Selective bool `json:"selective"` // optional
500}
501
502// ChatMember is information about a member in a chat.
503type ChatMember struct {
504 User *User `json:"user"`
505 Status string `json:"status"`
506 UntilDate int64 `json:"until_date,omitempty"` // optional
507 CanBeEdited bool `json:"can_be_edited,omitempty"` // optional
508 CanChangeInfo bool `json:"can_change_info,omitempty"` // optional
509 CanPostMessages bool `json:"can_post_messages,omitempty"` // optional
510 CanEditMessages bool `json:"can_edit_messages,omitempty"` // optional
511 CanDeleteMessages bool `json:"can_delete_messages,omitempty"` // optional
512 CanInviteUsers bool `json:"can_invite_users,omitempty"` // optional
513 CanRestrictMembers bool `json:"can_restrict_members,omitempty"` // optional
514 CanPinMessages bool `json:"can_pin_messages,omitempty"` // optional
515 CanPromoteMembers bool `json:"can_promote_members,omitempty"` // optional
516 CanSendMessages bool `json:"can_send_messages,omitempty"` // optional
517 CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"` // optional
518 CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` // optional
519 CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` // optional
520}
521
522// IsCreator returns if the ChatMember was the creator of the chat.
523func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" }
524
525// IsAdministrator returns if the ChatMember is a chat administrator.
526func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" }
527
528// IsMember returns if the ChatMember is a current member of the chat.
529func (chat ChatMember) IsMember() bool { return chat.Status == "member" }
530
531// HasLeft returns if the ChatMember left the chat.
532func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
533
534// WasKicked returns if the ChatMember was kicked from the chat.
535func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
536
537// Game is a game within Telegram.
538type Game struct {
539 Title string `json:"title"`
540 Description string `json:"description"`
541 Photo []PhotoSize `json:"photo"`
542 Text string `json:"text"`
543 TextEntities []MessageEntity `json:"text_entities"`
544 Animation Animation `json:"animation"`
545}
546
547// Animation is a GIF animation demonstrating the game.
548type Animation struct {
549 FileID string `json:"file_id"`
550 Thumb PhotoSize `json:"thumb"`
551 FileName string `json:"file_name"`
552 MimeType string `json:"mime_type"`
553 FileSize int `json:"file_size"`
554}
555
556// GameHighScore is a user's score and position on the leaderboard.
557type GameHighScore struct {
558 Position int `json:"position"`
559 User User `json:"user"`
560 Score int `json:"score"`
561}
562
563// CallbackGame is for starting a game in an inline keyboard button.
564type CallbackGame struct{}
565
566// WebhookInfo is information about a currently set webhook.
567type WebhookInfo struct {
568 URL string `json:"url"`
569 HasCustomCertificate bool `json:"has_custom_certificate"`
570 PendingUpdateCount int `json:"pending_update_count"`
571 LastErrorDate int `json:"last_error_date"` // optional
572 LastErrorMessage string `json:"last_error_message"` // optional
573}
574
575// IsSet returns true if a webhook is currently set.
576func (info WebhookInfo) IsSet() bool {
577 return info.URL != ""
578}
579
580// InputMediaPhoto contains a photo for displaying as part of a media group.
581type InputMediaPhoto struct {
582 Type string `json:"type"`
583 Media string `json:"media"`
584 Caption string `json:"caption"`
585 ParseMode string `json:"parse_mode"`
586}
587
588// InputMediaVideo contains a video for displaying as part of a media group.
589type InputMediaVideo struct {
590 Type string `json:"type"`
591 Media string `json:"media"`
592 // thumb intentionally missing as it is not currently compatible
593 Caption string `json:"caption"`
594 ParseMode string `json:"parse_mode"`
595 Width int `json:"width"`
596 Height int `json:"height"`
597 Duration int `json:"duration"`
598 SupportsStreaming bool `json:"supports_streaming"`
599}
600
601// InlineQuery is a Query from Telegram for an inline request.
602type InlineQuery struct {
603 ID string `json:"id"`
604 From *User `json:"from"`
605 Location *Location `json:"location"` // optional
606 Query string `json:"query"`
607 Offset string `json:"offset"`
608}
609
610// InlineQueryResultArticle is an inline query response article.
611type InlineQueryResultArticle struct {
612 Type string `json:"type"` // required
613 ID string `json:"id"` // required
614 Title string `json:"title"` // required
615 InputMessageContent interface{} `json:"input_message_content,omitempty"` // required
616 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
617 URL string `json:"url"`
618 HideURL bool `json:"hide_url"`
619 Description string `json:"description"`
620 ThumbURL string `json:"thumb_url"`
621 ThumbWidth int `json:"thumb_width"`
622 ThumbHeight int `json:"thumb_height"`
623}
624
625// InlineQueryResultPhoto is an inline query response photo.
626type InlineQueryResultPhoto struct {
627 Type string `json:"type"` // required
628 ID string `json:"id"` // required
629 URL string `json:"photo_url"` // required
630 MimeType string `json:"mime_type"`
631 Width int `json:"photo_width"`
632 Height int `json:"photo_height"`
633 ThumbURL string `json:"thumb_url"`
634 Title string `json:"title"`
635 Description string `json:"description"`
636 Caption string `json:"caption"`
637 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
638 InputMessageContent interface{} `json:"input_message_content,omitempty"`
639}
640
641// InlineQueryResultCachedPhoto is an inline query response with cached photo.
642type InlineQueryResultCachedPhoto struct {
643 Type string `json:"type"` // required
644 ID string `json:"id"` // required
645 PhotoID string `json:"photo_file_id"` // required
646 Title string `json:"title"`
647 Description string `json:"description"`
648 Caption string `json:"caption"`
649 ParseMode string `json:"parse_mode"`
650 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
651 InputMessageContent interface{} `json:"input_message_content,omitempty"`
652}
653
654// InlineQueryResultGIF is an inline query response GIF.
655type InlineQueryResultGIF struct {
656 Type string `json:"type"` // required
657 ID string `json:"id"` // required
658 URL string `json:"gif_url"` // required
659 ThumbURL string `json:"thumb_url"` // required
660 Width int `json:"gif_width,omitempty"`
661 Height int `json:"gif_height,omitempty"`
662 Duration int `json:"gif_duration,omitempty"`
663 Title string `json:"title,omitempty"`
664 Caption string `json:"caption,omitempty"`
665 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
666 InputMessageContent interface{} `json:"input_message_content,omitempty"`
667}
668
669// InlineQueryResultCachedGIF is an inline query response with cached gif.
670type InlineQueryResultCachedGIF struct {
671 Type string `json:"type"` // required
672 ID string `json:"id"` // required
673 GifID string `json:"gif_file_id"` // required
674 Title string `json:"title"`
675 Caption string `json:"caption"`
676 ParseMode string `json:"parse_mode"`
677 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
678 InputMessageContent interface{} `json:"input_message_content,omitempty"`
679}
680
681// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
682type InlineQueryResultMPEG4GIF struct {
683 Type string `json:"type"` // required
684 ID string `json:"id"` // required
685 URL string `json:"mpeg4_url"` // required
686 Width int `json:"mpeg4_width"`
687 Height int `json:"mpeg4_height"`
688 Duration int `json:"mpeg4_duration"`
689 ThumbURL string `json:"thumb_url"`
690 Title string `json:"title"`
691 Caption string `json:"caption"`
692 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
693 InputMessageContent interface{} `json:"input_message_content,omitempty"`
694}
695
696// InlineQueryResultCachedMpeg4Gif is an inline query response with cached
697// H.264/MPEG-4 AVC video without sound gif.
698type InlineQueryResultCachedMpeg4Gif struct {
699 Type string `json:"type"` // required
700 ID string `json:"id"` // required
701 MGifID string `json:"mpeg4_file_id"` // required
702 Title string `json:"title"`
703 Caption string `json:"caption"`
704 ParseMode string `json:"parse_mode"`
705 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
706 InputMessageContent interface{} `json:"input_message_content,omitempty"`
707}
708
709// InlineQueryResultVideo is an inline query response video.
710type InlineQueryResultVideo struct {
711 Type string `json:"type"` // required
712 ID string `json:"id"` // required
713 URL string `json:"video_url"` // required
714 MimeType string `json:"mime_type"` // required
715 ThumbURL string `json:"thumb_url"`
716 Title string `json:"title"`
717 Caption string `json:"caption"`
718 Width int `json:"video_width"`
719 Height int `json:"video_height"`
720 Duration int `json:"video_duration"`
721 Description string `json:"description"`
722 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
723 InputMessageContent interface{} `json:"input_message_content,omitempty"`
724}
725
726// InlineQueryResultCachedVideo is an inline query response with cached video.
727type InlineQueryResultCachedVideo struct {
728 Type string `json:"type"` // required
729 ID string `json:"id"` // required
730 VideoID string `json:"video_file_id"` // required
731 Title string `json:"title"` // required
732 Description string `json:"description"`
733 Caption string `json:"caption"`
734 ParseMode string `json:"parse_mode"`
735 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
736 InputMessageContent interface{} `json:"input_message_content,omitempty"`
737}
738
739// InlineQueryResultAudio is an inline query response audio.
740type InlineQueryResultAudio struct {
741 Type string `json:"type"` // required
742 ID string `json:"id"` // required
743 URL string `json:"audio_url"` // required
744 Title string `json:"title"` // required
745 Caption string `json:"caption"`
746 Performer string `json:"performer"`
747 Duration int `json:"audio_duration"`
748 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
749 InputMessageContent interface{} `json:"input_message_content,omitempty"`
750}
751
752// InlineQueryResultCachedAudio is an inline query response with cached audio.
753type InlineQueryResultCachedAudio struct {
754 Type string `json:"type"` // required
755 ID string `json:"id"` // required
756 AudioID string `json:"audio_file_id"` // required
757 Caption string `json:"caption"`
758 ParseMode string `json:"parse_mode"`
759 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
760 InputMessageContent interface{} `json:"input_message_content,omitempty"`
761}
762
763// InlineQueryResultVoice is an inline query response voice.
764type InlineQueryResultVoice struct {
765 Type string `json:"type"` // required
766 ID string `json:"id"` // required
767 URL string `json:"voice_url"` // required
768 Title string `json:"title"` // required
769 Caption string `json:"caption"`
770 Duration int `json:"voice_duration"`
771 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
772 InputMessageContent interface{} `json:"input_message_content,omitempty"`
773}
774
775// InlineQueryResultCachedVoice is an inline query response with cached voice.
776type InlineQueryResultCachedVoice struct {
777 Type string `json:"type"` // required
778 ID string `json:"id"` // required
779 VoiceID string `json:"voice_file_id"` // required
780 Title string `json:"title"` // required
781 Caption string `json:"caption"`
782 ParseMode string `json:"parse_mode"`
783 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
784 InputMessageContent interface{} `json:"input_message_content,omitempty"`
785}
786
787// InlineQueryResultDocument is an inline query response document.
788type InlineQueryResultDocument struct {
789 Type string `json:"type"` // required
790 ID string `json:"id"` // required
791 Title string `json:"title"` // required
792 Caption string `json:"caption"`
793 URL string `json:"document_url"` // required
794 MimeType string `json:"mime_type"` // required
795 Description string `json:"description"`
796 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
797 InputMessageContent interface{} `json:"input_message_content,omitempty"`
798 ThumbURL string `json:"thumb_url"`
799 ThumbWidth int `json:"thumb_width"`
800 ThumbHeight int `json:"thumb_height"`
801}
802
803// InlineQueryResultCachedDocument is an inline query response with cached document.
804type InlineQueryResultCachedDocument struct {
805 Type string `json:"type"` // required
806 ID string `json:"id"` // required
807 DocumentID string `json:"document_file_id"` // required
808 Title string `json:"title"` // required
809 Caption string `json:"caption"`
810 Description string `json:"description"`
811 ParseMode string `json:"parse_mode"`
812 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
813 InputMessageContent interface{} `json:"input_message_content,omitempty"`
814}
815
816// InlineQueryResultLocation is an inline query response location.
817type InlineQueryResultLocation struct {
818 Type string `json:"type"` // required
819 ID string `json:"id"` // required
820 Latitude float64 `json:"latitude"` // required
821 Longitude float64 `json:"longitude"` // required
822 Title string `json:"title"` // required
823 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
824 InputMessageContent interface{} `json:"input_message_content,omitempty"`
825 ThumbURL string `json:"thumb_url"`
826 ThumbWidth int `json:"thumb_width"`
827 ThumbHeight int `json:"thumb_height"`
828}
829
830// InlineQueryResultVenue is an inline query response venue.
831type InlineQueryResultVenue struct {
832 Type string `json:"type"` // required
833 ID string `json:"id"` // required
834 Latitude float64 `json:"latitude"` // required
835 Longitude float64 `json:"longitude"` // required
836 Title string `json:"title"` // required
837 Address string `json:"address"` // required
838 FoursquareID string `json:"foursquare_id"`
839 FoursquareType string `json:"foursquare_type"`
840 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
841 InputMessageContent interface{} `json:"input_message_content,omitempty"`
842 ThumbURL string `json:"thumb_url"`
843 ThumbWidth int `json:"thumb_width"`
844 ThumbHeight int `json:"thumb_height"`
845}
846
847// InlineQueryResultGame is an inline query response game.
848type InlineQueryResultGame struct {
849 Type string `json:"type"`
850 ID string `json:"id"`
851 GameShortName string `json:"game_short_name"`
852 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
853}
854
855// ChosenInlineResult is an inline query result chosen by a User
856type ChosenInlineResult struct {
857 ResultID string `json:"result_id"`
858 From *User `json:"from"`
859 Location *Location `json:"location"`
860 InlineMessageID string `json:"inline_message_id"`
861 Query string `json:"query"`
862}
863
864// InputTextMessageContent contains text for displaying
865// as an inline query result.
866type InputTextMessageContent struct {
867 Text string `json:"message_text"`
868 ParseMode string `json:"parse_mode"`
869 DisableWebPagePreview bool `json:"disable_web_page_preview"`
870}
871
872// InputLocationMessageContent contains a location for displaying
873// as an inline query result.
874type InputLocationMessageContent struct {
875 Latitude float64 `json:"latitude"`
876 Longitude float64 `json:"longitude"`
877}
878
879// InputVenueMessageContent contains a venue for displaying
880// as an inline query result.
881type InputVenueMessageContent struct {
882 Latitude float64 `json:"latitude"`
883 Longitude float64 `json:"longitude"`
884 Title string `json:"title"`
885 Address string `json:"address"`
886 FoursquareID string `json:"foursquare_id"`
887}
888
889// InputContactMessageContent contains a contact for displaying
890// as an inline query result.
891type InputContactMessageContent struct {
892 PhoneNumber string `json:"phone_number"`
893 FirstName string `json:"first_name"`
894 LastName string `json:"last_name"`
895}
896
897// Invoice contains basic information about an invoice.
898type Invoice struct {
899 Title string `json:"title"`
900 Description string `json:"description"`
901 StartParameter string `json:"start_parameter"`
902 Currency string `json:"currency"`
903 TotalAmount int `json:"total_amount"`
904}
905
906// LabeledPrice represents a portion of the price for goods or services.
907type LabeledPrice struct {
908 Label string `json:"label"`
909 Amount int `json:"amount"`
910}
911
912// ShippingAddress represents a shipping address.
913type ShippingAddress struct {
914 CountryCode string `json:"country_code"`
915 State string `json:"state"`
916 City string `json:"city"`
917 StreetLine1 string `json:"street_line1"`
918 StreetLine2 string `json:"street_line2"`
919 PostCode string `json:"post_code"`
920}
921
922// OrderInfo represents information about an order.
923type OrderInfo struct {
924 Name string `json:"name,omitempty"`
925 PhoneNumber string `json:"phone_number,omitempty"`
926 Email string `json:"email,omitempty"`
927 ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
928}
929
930// ShippingOption represents one shipping option.
931type ShippingOption struct {
932 ID string `json:"id"`
933 Title string `json:"title"`
934 Prices *[]LabeledPrice `json:"prices"`
935}
936
937// SuccessfulPayment contains basic information about a successful payment.
938type SuccessfulPayment struct {
939 Currency string `json:"currency"`
940 TotalAmount int `json:"total_amount"`
941 InvoicePayload string `json:"invoice_payload"`
942 ShippingOptionID string `json:"shipping_option_id,omitempty"`
943 OrderInfo *OrderInfo `json:"order_info,omitempty"`
944 TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
945 ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
946}
947
948// ShippingQuery contains information about an incoming shipping query.
949type ShippingQuery struct {
950 ID string `json:"id"`
951 From *User `json:"from"`
952 InvoicePayload string `json:"invoice_payload"`
953 ShippingAddress *ShippingAddress `json:"shipping_address"`
954}
955
956// PreCheckoutQuery contains information about an incoming pre-checkout query.
957type PreCheckoutQuery struct {
958 ID string `json:"id"`
959 From *User `json:"from"`
960 Currency string `json:"currency"`
961 TotalAmount int `json:"total_amount"`
962 InvoicePayload string `json:"invoice_payload"`
963 ShippingOptionID string `json:"shipping_option_id,omitempty"`
964 OrderInfo *OrderInfo `json:"order_info,omitempty"`
965}
966
967// Error is an error containing extra information returned by the Telegram API.
968type Error struct {
969 Code int
970 Message string
971 ResponseParameters
972}
973
974func (e Error) Error() string {
975 return e.Message
976}