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