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