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