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