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