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