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