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,omitempty"`
17 ErrorCode int `json:"error_code,omitempty"`
18 Description string `json:"description,omitempty"`
19 Parameters *ResponseParameters `json:"parameters,omitempty"`
20}
21
22// ResponseParameters are various errors that can be returned in APIResponse.
23type ResponseParameters struct {
24 MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` // optional
25 RetryAfter int `json:"retry_after,omitempty"` // 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,omitempty"`
32 EditedMessage *Message `json:"edited_message,omitempty"`
33 ChannelPost *Message `json:"channel_post,omitempty"`
34 EditedChannelPost *Message `json:"edited_channel_post,omitempty"`
35 InlineQuery *InlineQuery `json:"inline_query,omitempty"`
36 ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
37 CallbackQuery *CallbackQuery `json:"callback_query,omitempty"`
38 ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"`
39 PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"`
40 Poll *Poll `json:"poll,omitempty"`
41 PollAnswer *PollAnswer `json:"poll_answer,omitempty"`
42}
43
44// UpdatesChannel is the channel for getting updates.
45type UpdatesChannel <-chan Update
46
47// Clear discards all unprocessed incoming updates.
48func (ch UpdatesChannel) Clear() {
49 for len(ch) != 0 {
50 <-ch
51 }
52}
53
54// User is a user on Telegram.
55type User struct {
56 ID int `json:"id"`
57 FirstName string `json:"first_name"`
58 LastName string `json:"last_name,omitempty"` // optional
59 UserName string `json:"username,omitempty"` // optional
60 LanguageCode string `json:"language_code,omitempty"` // optional
61 IsBot bool `json:"is_bot,omitempty"` // optional
62 CanJoinGroups bool `json:"can_join_groups,omitempty"` // optional
63 CanReadAllGroupMessages bool `json:"can_read_all_group_messages,omitempty"` // optional
64 SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"` // optional
65}
66
67// String displays a simple text version of a user.
68//
69// It is normally a user's username, but falls back to a first/last
70// name as available.
71func (u *User) String() string {
72 if u == nil {
73 return ""
74 }
75 if u.UserName != "" {
76 return u.UserName
77 }
78
79 name := u.FirstName
80 if u.LastName != "" {
81 name += " " + u.LastName
82 }
83
84 return name
85}
86
87// GroupChat is a group chat.
88type GroupChat struct {
89 ID int `json:"id"`
90 Title string `json:"title"`
91}
92
93// ChatPhoto represents a chat photo.
94type ChatPhoto struct {
95 SmallFileID string `json:"small_file_id"`
96 SmallFileUniqueID string `json:"small_file_unique_id"`
97 BigFileID string `json:"big_file_id"`
98 BigFileUniqueID string `json:"big_file_unique_id"`
99}
100
101// ChatPermissions describes actions that a non-administrator user is
102// allowed to take in a chat. All fields are optional.
103type ChatPermissions struct {
104 CanSendMessages bool `json:"can_send_messages"`
105 CanSendMediaMessages bool `json:"can_send_media_messages"`
106 CanSendPolls bool `json:"can_send_polls"`
107 CanSendOtherMessages bool `json:"can_send_other_messages"`
108 CanAddWebPagePreviews bool `json:"can_add_web_page_previews"`
109 CanChangeInfo bool `json:"can_change_info"`
110 CanInviteUsers bool `json:"can_invite_users"`
111 CanPinMessages bool `json:"can_pin_messages"`
112}
113
114// Chat contains information about the place a message was sent.
115type Chat struct {
116 ID int64 `json:"id"`
117 Type string `json:"type"`
118 Title string `json:"title,omitempty"` // optional
119 UserName string `json:"username,omitempty"` // optional
120 FirstName string `json:"first_name,omitempty"` // optional
121 LastName string `json:"last_name,omitempty"` // optional
122 AllMembersAreAdmins bool `json:"all_members_are_administrators,omitempty"` // deprecated, optional
123 Photo *ChatPhoto `json:"photo,omitempty"` // optional
124 Description string `json:"description,omitempty"` // optional
125 InviteLink string `json:"invite_link,omitempty"` // optional
126 PinnedMessage *Message `json:"pinned_message,omitempty"` // optional
127 Permissions *ChatPermissions `json:"permissions,omitempty"` // optional
128 SlowModeDelay int `json:"slow_mode_delay,omitempty"` // optional
129 StickerSetName string `json:"sticker_set_name,omitempty"` // optional
130 CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` // optional
131}
132
133// IsPrivate returns if the Chat is a private conversation.
134func (c Chat) IsPrivate() bool {
135 return c.Type == "private"
136}
137
138// IsGroup returns if the Chat is a group.
139func (c Chat) IsGroup() bool {
140 return c.Type == "group"
141}
142
143// IsSuperGroup returns if the Chat is a supergroup.
144func (c Chat) IsSuperGroup() bool {
145 return c.Type == "supergroup"
146}
147
148// IsChannel returns if the Chat is a channel.
149func (c Chat) IsChannel() bool {
150 return c.Type == "channel"
151}
152
153// ChatConfig returns a ChatConfig struct for chat related methods.
154func (c Chat) ChatConfig() ChatConfig {
155 return ChatConfig{ChatID: c.ID}
156}
157
158// Message is returned by almost every request, and contains data about
159// almost anything.
160type Message struct {
161 MessageID int `json:"message_id"`
162 From *User `json:"from,omitempty"` // optional
163 Date int `json:"date"`
164 Chat *Chat `json:"chat"`
165 ForwardFrom *User `json:"forward_from,omitempty"` // optional
166 ForwardFromChat *Chat `json:"forward_from_chat,omitempty"` // optional
167 ForwardFromMessageID int `json:"forward_from_message_id,omitempty"` // optional
168 ForwardSignature string `json:"forward_signature,omitempty"` // optional
169 ForwardSenderName string `json:"forward_sender_name,omitempty"` // optional
170 ForwardDate int `json:"forward_date,omitempty"` // optional
171 ReplyToMessage *Message `json:"reply_to_message,omitempty"` // optional
172 EditDate int `json:"edit_date,omitempty"` // optional
173 MediaGroupID string `json:"media_group_id,omitempty"` // optional
174 AuthorSignature string `json:"author_signature,omitempty"` // optional
175 Text string `json:"text,omitempty"` // optional
176 Entities []MessageEntity `json:"entities,omitempty"` // optional
177 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` // optional
178 Audio *Audio `json:"audio,omitempty"` // optional
179 Document *Document `json:"document,omitempty"` // optional
180 Animation *ChatAnimation `json:"animation,omitempty"` // optional
181 Game *Game `json:"game,omitempty"` // optional
182 Photo []PhotoSize `json:"photo,omitempty"` // optional
183 Sticker *Sticker `json:"sticker,omitempty"` // optional
184 Video *Video `json:"video,omitempty"` // optional
185 VideoNote *VideoNote `json:"video_note,omitempty"` // optional
186 Voice *Voice `json:"voice,omitempty"` // optional
187 Caption string `json:"caption,omitempty"` // optional
188 Contact *Contact `json:"contact,omitempty"` // optional
189 Location *Location `json:"location,omitempty"` // optional
190 Venue *Venue `json:"venue,omitempty"` // optional
191 Poll *Poll `json:"poll,omitempty"` // optional
192 Dice *Dice `json:"dice,omitempty"` // optional
193 NewChatMembers []User `json:"new_chat_members,omitempty"` // optional
194 LeftChatMember *User `json:"left_chat_member,omitempty"` // optional
195 NewChatTitle string `json:"new_chat_title,omitempty"` // optional
196 NewChatPhoto []PhotoSize `json:"new_chat_photo,omitempty"` // optional
197 DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"` // optional
198 GroupChatCreated bool `json:"group_chat_created,omitempty"` // optional
199 SuperGroupChatCreated bool `json:"supergroup_chat_created,omitempty"` // optional
200 ChannelChatCreated bool `json:"channel_chat_created,omitempty"` // optional
201 MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` // optional
202 MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"` // optional
203 PinnedMessage *Message `json:"pinned_message,omitempty"` // optional
204 Invoice *Invoice `json:"invoice,omitempty"` // optional
205 SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"` // optional
206 ConnectedWebsite string `json:"connected_website,omitempty"` // optional
207 PassportData *PassportData `json:"passport_data,omitempty"` // optional
208 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // optional
209}
210
211// Time converts the message timestamp into a Time.
212func (m *Message) Time() time.Time {
213 return time.Unix(int64(m.Date), 0)
214}
215
216// IsCommand returns true if message starts with a "bot_command" entity.
217func (m *Message) IsCommand() bool {
218 if m.Entities == nil || len(m.Entities) == 0 {
219 return false
220 }
221
222 entity := m.Entities[0]
223 return entity.Offset == 0 && entity.IsCommand()
224}
225
226// Command checks if the message was a command and if it was, returns the
227// command. If the Message was not a command, it returns an empty string.
228//
229// If the command contains the at name syntax, it is removed. Use
230// CommandWithAt() if you do not want that.
231func (m *Message) Command() string {
232 command := m.CommandWithAt()
233
234 if i := strings.Index(command, "@"); i != -1 {
235 command = command[:i]
236 }
237
238 return command
239}
240
241// CommandWithAt checks if the message was a command and if it was, returns the
242// command. If the Message was not a command, it returns an empty string.
243//
244// If the command contains the at name syntax, it is not removed. Use Command()
245// if you want that.
246func (m *Message) CommandWithAt() string {
247 if !m.IsCommand() {
248 return ""
249 }
250
251 // IsCommand() checks that the message begins with a bot_command entity
252 entity := m.Entities[0]
253 return m.Text[1:entity.Length]
254}
255
256// CommandArguments checks if the message was a command and if it was,
257// returns all text after the command name. If the Message was not a
258// command, it returns an empty string.
259//
260// Note: The first character after the command name is omitted:
261// - "/foo bar baz" yields "bar baz", not " bar baz"
262// - "/foo-bar baz" yields "bar baz", too
263// Even though the latter is not a command conforming to the spec, the API
264// marks "/foo" as command entity.
265func (m *Message) CommandArguments() string {
266 if !m.IsCommand() {
267 return ""
268 }
269
270 // IsCommand() checks that the message begins with a bot_command entity
271 entity := m.Entities[0]
272
273 if len(m.Text) == entity.Length {
274 return "" // The command makes up the whole message
275 }
276
277 return m.Text[entity.Length+1:]
278}
279
280// MessageEntity contains information about data in a Message.
281type MessageEntity struct {
282 Type string `json:"type"`
283 Offset int `json:"offset"`
284 Length int `json:"length"`
285 URL string `json:"url,omitempty"` // optional
286 User *User `json:"user,omitempty"` // optional
287 Language string `json:"language,omitempty"` // optional
288}
289
290// ParseURL attempts to parse a URL contained within a MessageEntity.
291func (e MessageEntity) ParseURL() (*url.URL, error) {
292 if e.URL == "" {
293 return nil, errors.New(ErrBadURL)
294 }
295
296 return url.Parse(e.URL)
297}
298
299// IsMention returns true if the type of the message entity is "mention" (@username).
300func (e MessageEntity) IsMention() bool {
301 return e.Type == "mention"
302}
303
304// IsHashtag returns true if the type of the message entity is "hashtag".
305func (e MessageEntity) IsHashtag() bool {
306 return e.Type == "hashtag"
307}
308
309// IsCommand returns true if the type of the message entity is "bot_command".
310func (e MessageEntity) IsCommand() bool {
311 return e.Type == "bot_command"
312}
313
314// IsUrl returns true if the type of the message entity is "url".
315func (e MessageEntity) IsUrl() bool {
316 return e.Type == "url"
317}
318
319// IsEmail returns true if the type of the message entity is "email".
320func (e MessageEntity) IsEmail() bool {
321 return e.Type == "email"
322}
323
324// IsBold returns true if the type of the message entity is "bold" (bold text).
325func (e MessageEntity) IsBold() bool {
326 return e.Type == "bold"
327}
328
329// IsItalic returns true if the type of the message entity is "italic" (italic text).
330func (e MessageEntity) IsItalic() bool {
331 return e.Type == "italic"
332}
333
334// IsCode returns true if the type of the message entity is "code" (monowidth string).
335func (e MessageEntity) IsCode() bool {
336 return e.Type == "code"
337}
338
339// IsPre returns true if the type of the message entity is "pre" (monowidth block).
340func (e MessageEntity) IsPre() bool {
341 return e.Type == "pre"
342}
343
344// IsTextLink returns true if the type of the message entity is "text_link" (clickable text URL).
345func (e MessageEntity) IsTextLink() bool {
346 return e.Type == "text_link"
347}
348
349// PhotoSize contains information about photos.
350type PhotoSize struct {
351 FileID string `json:"file_id"`
352 FileUniqueID string `json:"file_unique_id"`
353 Width int `json:"width"`
354 Height int `json:"height"`
355 FileSize int `json:"file_size,omitempty"` // optional
356}
357
358// Audio contains information about audio.
359type Audio struct {
360 FileID string `json:"file_id"`
361 FileUniqueID string `json:"file_unique_id"`
362 Duration int `json:"duration"`
363 Performer string `json:"performer,omitempty"` // optional
364 Title string `json:"title,omitempty"` // optional
365 MimeType string `json:"mime_type,omitempty"` // optional
366 FileSize int `json:"file_size,omitempty"` // optional
367}
368
369// Document contains information about a document.
370type Document struct {
371 FileID string `json:"file_id"`
372 FileUniqueID string `json:"file_unique_id"`
373 Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional
374 FileName string `json:"file_name,omitempty"` // optional
375 MimeType string `json:"mime_type,omitempty"` // optional
376 FileSize int `json:"file_size,omitempty"` // optional
377}
378
379// Sticker contains information about a sticker.
380type Sticker struct {
381 FileID string `json:"file_id"`
382 FileUniqueID string `json:"file_unique_id"`
383 Width int `json:"width"`
384 Height int `json:"height"`
385 IsAnimated bool `json:"is_animated"`
386 Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional
387 Emoji string `json:"emoji,omitempty"` // optional
388 SetName string `json:"set_name,omitempty"` // optional
389 MaskPosition MaskPosition `json:"mask_position,omitempty"` //optional
390 FileSize int `json:"file_size,omitempty"` // optional
391}
392
393// MaskPosition is the position of a mask.
394type MaskPosition struct {
395 Point string `json:"point"`
396 XShift float32 `json:"x_shift"`
397 YShift float32 `json:"y_shift"`
398 Scale float32 `json:"scale"`
399 FileID string `json:"file_id"`
400 Width int `json:"width"`
401 Height int `json:"height"`
402 Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional
403 Emoji string `json:"emoji,omitempty"` // optional
404 FileSize int `json:"file_size,omitempty"` // optional
405 SetName string `json:"set_name,omitempty"` // optional
406}
407
408// ChatAnimation contains information about an animation.
409type ChatAnimation struct {
410 FileID string `json:"file_id"`
411 FileUniqueID string `json:"file_unique_id"`
412 Width int `json:"width"`
413 Height int `json:"height"`
414 Duration int `json:"duration"`
415 Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional
416 FileName string `json:"file_name,omitempty"` // optional
417 MimeType string `json:"mime_type,omitempty"` // optional
418 FileSize int `json:"file_size,omitempty"` // optional
419}
420
421// Video contains information about a video.
422type Video struct {
423 FileID string `json:"file_id"`
424 FileUniqueID string `json:"file_unique_id"`
425 Width int `json:"width"`
426 Height int `json:"height"`
427 Duration int `json:"duration"`
428 Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional
429 MimeType string `json:"mime_type,omitempty"` // optional
430 FileSize int `json:"file_size,omitempty"` // optional
431}
432
433// VideoNote contains information about a video.
434type VideoNote struct {
435 FileID string `json:"file_id"`
436 FileUniqueID string `json:"file_unique_id"`
437 Length int `json:"length"`
438 Duration int `json:"duration"`
439 Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional
440 FileSize int `json:"file_size,omitempty"` // optional
441}
442
443// Voice contains information about a voice.
444type Voice struct {
445 FileID string `json:"file_id"`
446 FileUniqueID string `json:"file_unique_id"`
447 Duration int `json:"duration"`
448 MimeType string `json:"mime_type,omitempty"` // optional
449 FileSize int `json:"file_size,omitempty"` // optional
450}
451
452// Contact contains information about a contact.
453//
454// Note that LastName and UserID may be empty.
455type Contact struct {
456 PhoneNumber string `json:"phone_number"`
457 FirstName string `json:"first_name"`
458 LastName string `json:"last_name,omitempty"` // optional
459 UserID int `json:"user_id,omitempty"` // optional
460 VCard string `json:"vcard,omitempty"` // optional
461}
462
463// Location contains information about a place.
464type Location struct {
465 Longitude float64 `json:"longitude"`
466 Latitude float64 `json:"latitude"`
467}
468
469// Venue contains information about a venue, including its Location.
470type Venue struct {
471 Location Location `json:"location"`
472 Title string `json:"title"`
473 Address string `json:"address"`
474 FoursquareID string `json:"foursquare_id,omitempty"` // optional
475}
476
477// PollOption contains information about one answer option in a poll.
478type PollOption struct {
479 Text string `json:"text"`
480 VoterCount int `json:"voter_count"`
481}
482
483// PollAnswer represents an answer of a user in a non-anonymous poll.
484type PollAnswer struct {
485 PollID string `json:"poll_id"`
486 User User `json:"user"`
487 OptionIDs []int `json:"option_ids"`
488}
489
490// Poll contains information about a poll.
491type Poll struct {
492 ID string `json:"id"`
493 Question string `json:"question"`
494 Options []PollOption `json:"options"`
495 IsClosed bool `json:"is_closed"`
496 IsAnonymous bool `json:"is_anonymous"`
497 Type string `json:"type"`
498 AllowsMultipleAnswers bool `json:"allows_multiple_answers"`
499 CorrectOptionID int `json:"correct_option_id,omitempty"` // optional
500 Explanation string `json:"explanation,omitempty"` // optional
501 ExplanationEntities []MessageEntity `json:"explanation_entities,omitempty"` // optional
502 OpenPeriod int `json:"open_period,omitempty"` // optional
503 CloseDate int `json:"close_date,omitempty"` // optional
504}
505
506// Dice represents a single dice value.
507type Dice struct {
508 Emoji string `json:"emoji"`
509 Value int `json:"value"`
510}
511
512// UserProfilePhotos contains a set of user profile photos.
513type UserProfilePhotos struct {
514 TotalCount int `json:"total_count"`
515 Photos [][]PhotoSize `json:"photos"`
516}
517
518// File contains information about a file to download from Telegram.
519type File struct {
520 FileID string `json:"file_id"`
521 FileUniqueID string `json:"file_unique_id"`
522 FileSize int `json:"file_size,omitempty"` // optional
523 FilePath string `json:"file_path,omitempty"` // optional
524}
525
526// Link returns a full path to the download URL for a File.
527//
528// It requires the Bot Token to create the link.
529func (f *File) Link(token string) string {
530 return fmt.Sprintf(FileEndpoint, token, f.FilePath)
531}
532
533// ReplyKeyboardMarkup allows the Bot to set a custom keyboard.
534type ReplyKeyboardMarkup struct {
535 Keyboard [][]KeyboardButton `json:"keyboard"`
536 ResizeKeyboard bool `json:"resize_keyboard,omitempty"` // optional
537 OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"` // optional
538 Selective bool `json:"selective,omitempty"` // optional
539}
540
541// KeyboardButton is a button within a custom keyboard.
542type KeyboardButton struct {
543 Text string `json:"text"`
544 RequestContact bool `json:"request_contact"`
545 RequestLocation bool `json:"request_location"`
546 RequestPoll *KeyboardButtonPollType `json:"request_poll,omitempty"`
547}
548
549// KeyboardButtonPollType represents type of a poll, which is allowed to
550// be created and sent when the corresponding button is pressed.
551type KeyboardButtonPollType struct {
552 Type string `json:"type"`
553}
554
555// ReplyKeyboardHide allows the Bot to hide a custom keyboard.
556type ReplyKeyboardHide struct {
557 HideKeyboard bool `json:"hide_keyboard"`
558 Selective bool `json:"selective,omitempty"` // optional
559}
560
561// ReplyKeyboardRemove allows the Bot to hide a custom keyboard.
562type ReplyKeyboardRemove struct {
563 RemoveKeyboard bool `json:"remove_keyboard"`
564 Selective bool `json:"selective"`
565}
566
567// InlineKeyboardMarkup is a custom keyboard presented for an inline bot.
568type InlineKeyboardMarkup struct {
569 InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
570}
571
572// InlineKeyboardButton is a button within a custom keyboard for
573// inline query responses.
574//
575// Note that some values are references as even an empty string
576// will change behavior.
577//
578// CallbackGame, if set, MUST be first button in first row.
579type InlineKeyboardButton struct {
580 Text string `json:"text"`
581 URL *string `json:"url,omitempty"` // optional
582 LoginURL *LoginURL `json:"login_url,omitempty"` // optional
583 CallbackData *string `json:"callback_data,omitempty"` // optional
584 SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional
585 SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional
586 CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional
587 Pay bool `json:"pay,omitempty"` // optional
588}
589
590// LoginURL is the parameters for the login inline keyboard button type.
591type LoginURL struct {
592 URL string `json:"url"`
593 ForwardText string `json:"forward_text"`
594 BotUsername string `json:"bot_username"`
595 RequestWriteAccess bool `json:"request_write_access"`
596}
597
598// CallbackQuery is data sent when a keyboard button with callback data
599// is clicked.
600type CallbackQuery struct {
601 ID string `json:"id"`
602 From *User `json:"from"`
603 Message *Message `json:"message,omitempty"` // optional
604 InlineMessageID string `json:"inline_message_id,omitempty"` // optional
605 ChatInstance string `json:"chat_instance"`
606 Data string `json:"data,omitempty"` // optional
607 GameShortName string `json:"game_short_name,omitempty"` // optional
608}
609
610// ForceReply allows the Bot to have users directly reply to it without
611// additional interaction.
612type ForceReply struct {
613 ForceReply bool `json:"force_reply"`
614 Selective bool `json:"selective"` // optional
615}
616
617// ChatMember is information about a member in a chat.
618type ChatMember struct {
619 User *User `json:"user"`
620 Status string `json:"status"`
621 CustomTitle string `json:"custom_title,omitempty"` // optional
622 UntilDate int64 `json:"until_date,omitempty"` // optional
623 CanBeEdited bool `json:"can_be_edited,omitempty"` // optional
624 CanPostMessages bool `json:"can_post_messages,omitempty"` // optional
625 CanEditMessages bool `json:"can_edit_messages,omitempty"` // optional
626 CanDeleteMessages bool `json:"can_delete_messages,omitempty"` // optional
627 CanRestrictMembers bool `json:"can_restrict_members,omitempty"` // optional
628 CanPromoteMembers bool `json:"can_promote_members,omitempty"` // optional
629 CanChangeInfo bool `json:"can_change_info,omitempty"` // optional
630 CanInviteUsers bool `json:"can_invite_users,omitempty"` // optional
631 CanPinMessages bool `json:"can_pin_messages,omitempty"` // optional
632 IsChatMember bool `json:"is_member,omitempty"` // optional
633 CanSendMessages bool `json:"can_send_messages,omitempty"` // optional
634 CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"` // optional
635 CanSendPolls bool `json:"can_send_polls,omitempty"` // optional
636 CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` // optional
637 CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` // optional
638}
639
640// IsCreator returns if the ChatMember was the creator of the chat.
641func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" }
642
643// IsAdministrator returns if the ChatMember is a chat administrator.
644func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" }
645
646// IsMember returns if the ChatMember is a current member of the chat.
647func (chat ChatMember) IsMember() bool { return chat.Status == "member" }
648
649// HasLeft returns if the ChatMember left the chat.
650func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
651
652// WasKicked returns if the ChatMember was kicked from the chat.
653func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
654
655// Game is a game within Telegram.
656type Game struct {
657 Title string `json:"title"`
658 Description string `json:"description"`
659 Photo []PhotoSize `json:"photo"`
660 Text string `json:"text"`
661 TextEntities []MessageEntity `json:"text_entities"`
662 Animation Animation `json:"animation"`
663}
664
665// Animation is a GIF animation demonstrating the game.
666type Animation struct {
667 FileID string `json:"file_id"`
668 FileUniqueID string `json:"file_unique_id"`
669 Thumb PhotoSize `json:"thumb"`
670 FileName string `json:"file_name"`
671 MimeType string `json:"mime_type"`
672 FileSize int `json:"file_size"`
673}
674
675// GameHighScore is a user's score and position on the leaderboard.
676type GameHighScore struct {
677 Position int `json:"position"`
678 User User `json:"user"`
679 Score int `json:"score"`
680}
681
682// CallbackGame is for starting a game in an inline keyboard button.
683type CallbackGame struct{}
684
685// WebhookInfo is information about a currently set webhook.
686type WebhookInfo struct {
687 URL string `json:"url"`
688 HasCustomCertificate bool `json:"has_custom_certificate"`
689 PendingUpdateCount int `json:"pending_update_count"`
690 LastErrorDate int `json:"last_error_date,omitempty"` // optional
691 LastErrorMessage string `json:"last_error_message,omitempty"` // optional
692}
693
694// IsSet returns true if a webhook is currently set.
695func (info WebhookInfo) IsSet() bool {
696 return info.URL != ""
697}
698
699// InlineQuery is a Query from Telegram for an inline request.
700type InlineQuery struct {
701 ID string `json:"id"`
702 From *User `json:"from"`
703 Location *Location `json:"location,omitempty"` // optional
704 Query string `json:"query"`
705 Offset string `json:"offset"`
706}
707
708// InlineQueryResultArticle is an inline query response article.
709type InlineQueryResultArticle struct {
710 Type string `json:"type"` // required
711 ID string `json:"id"` // required
712 Title string `json:"title"` // required
713 InputMessageContent interface{} `json:"input_message_content,omitempty"` // required
714 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
715 URL string `json:"url"`
716 HideURL bool `json:"hide_url"`
717 Description string `json:"description"`
718 ThumbURL string `json:"thumb_url"`
719 ThumbWidth int `json:"thumb_width"`
720 ThumbHeight int `json:"thumb_height"`
721}
722
723// InlineQueryResultPhoto is an inline query response photo.
724type InlineQueryResultPhoto struct {
725 Type string `json:"type"` // required
726 ID string `json:"id"` // required
727 URL string `json:"photo_url"` // required
728 MimeType string `json:"mime_type"`
729 Width int `json:"photo_width"`
730 Height int `json:"photo_height"`
731 ThumbURL string `json:"thumb_url"`
732 Title string `json:"title"`
733 Description string `json:"description"`
734 Caption string `json:"caption"`
735 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
736 InputMessageContent interface{} `json:"input_message_content,omitempty"`
737}
738
739// InlineQueryResultCachedPhoto is an inline query response with cached photo.
740type InlineQueryResultCachedPhoto struct {
741 Type string `json:"type"` // required
742 ID string `json:"id"` // required
743 PhotoID string `json:"photo_file_id"` // required
744 Title string `json:"title"`
745 Description string `json:"description"`
746 Caption string `json:"caption"`
747 ParseMode string `json:"parse_mode"`
748 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
749 InputMessageContent interface{} `json:"input_message_content,omitempty"`
750}
751
752// InlineQueryResultGIF is an inline query response GIF.
753type InlineQueryResultGIF struct {
754 Type string `json:"type"` // required
755 ID string `json:"id"` // required
756 URL string `json:"gif_url"` // required
757 ThumbURL string `json:"thumb_url"` // required
758 Width int `json:"gif_width,omitempty"`
759 Height int `json:"gif_height,omitempty"`
760 Duration int `json:"gif_duration,omitempty"`
761 Title string `json:"title,omitempty"`
762 Caption string `json:"caption,omitempty"`
763 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
764 InputMessageContent interface{} `json:"input_message_content,omitempty"`
765}
766
767// InlineQueryResultCachedGIF is an inline query response with cached gif.
768type InlineQueryResultCachedGIF struct {
769 Type string `json:"type"` // required
770 ID string `json:"id"` // required
771 GifID string `json:"gif_file_id"` // required
772 Title string `json:"title"`
773 Caption string `json:"caption"`
774 ParseMode string `json:"parse_mode"`
775 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
776 InputMessageContent interface{} `json:"input_message_content,omitempty"`
777}
778
779// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
780type InlineQueryResultMPEG4GIF struct {
781 Type string `json:"type"` // required
782 ID string `json:"id"` // required
783 URL string `json:"mpeg4_url"` // required
784 Width int `json:"mpeg4_width"`
785 Height int `json:"mpeg4_height"`
786 Duration int `json:"mpeg4_duration"`
787 ThumbURL string `json:"thumb_url"`
788 Title string `json:"title"`
789 Caption string `json:"caption"`
790 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
791 InputMessageContent interface{} `json:"input_message_content,omitempty"`
792}
793
794// InlineQueryResultCachedMpeg4Gif is an inline query response with cached
795// H.264/MPEG-4 AVC video without sound gif.
796type InlineQueryResultCachedMpeg4Gif struct {
797 Type string `json:"type"` // required
798 ID string `json:"id"` // required
799 MGifID string `json:"mpeg4_file_id"` // required
800 Title string `json:"title"`
801 Caption string `json:"caption"`
802 ParseMode string `json:"parse_mode"`
803 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
804 InputMessageContent interface{} `json:"input_message_content,omitempty"`
805}
806
807// InlineQueryResultVideo is an inline query response video.
808type InlineQueryResultVideo struct {
809 Type string `json:"type"` // required
810 ID string `json:"id"` // required
811 URL string `json:"video_url"` // required
812 MimeType string `json:"mime_type"` // required
813 ThumbURL string `json:"thumb_url"`
814 Title string `json:"title"`
815 Caption string `json:"caption"`
816 Width int `json:"video_width"`
817 Height int `json:"video_height"`
818 Duration int `json:"video_duration"`
819 Description string `json:"description"`
820 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
821 InputMessageContent interface{} `json:"input_message_content,omitempty"`
822}
823
824// InlineQueryResultCachedVideo is an inline query response with cached video.
825type InlineQueryResultCachedVideo struct {
826 Type string `json:"type"` // required
827 ID string `json:"id"` // required
828 VideoID string `json:"video_file_id"` // required
829 Title string `json:"title"` // required
830 Description string `json:"description"`
831 Caption string `json:"caption"`
832 ParseMode string `json:"parse_mode"`
833 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
834 InputMessageContent interface{} `json:"input_message_content,omitempty"`
835}
836
837// InlineQueryResultCachedSticker is an inline query response with cached sticker.
838type InlineQueryResultCachedSticker struct {
839 Type string `json:"type"` // required
840 ID string `json:"id"` // required
841 StickerID string `json:"sticker_file_id"` // required
842 Title string `json:"title"` // required
843 ParseMode string `json:"parse_mode"`
844 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
845 InputMessageContent interface{} `json:"input_message_content,omitempty"`
846}
847
848// InlineQueryResultAudio is an inline query response audio.
849type InlineQueryResultAudio struct {
850 Type string `json:"type"` // required
851 ID string `json:"id"` // required
852 URL string `json:"audio_url"` // required
853 Title string `json:"title"` // required
854 Caption string `json:"caption"`
855 Performer string `json:"performer"`
856 Duration int `json:"audio_duration"`
857 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
858 InputMessageContent interface{} `json:"input_message_content,omitempty"`
859}
860
861// InlineQueryResultCachedAudio is an inline query response with cached audio.
862type InlineQueryResultCachedAudio struct {
863 Type string `json:"type"` // required
864 ID string `json:"id"` // required
865 AudioID string `json:"audio_file_id"` // required
866 Caption string `json:"caption"`
867 ParseMode string `json:"parse_mode"`
868 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
869 InputMessageContent interface{} `json:"input_message_content,omitempty"`
870}
871
872// InlineQueryResultVoice is an inline query response voice.
873type InlineQueryResultVoice struct {
874 Type string `json:"type"` // required
875 ID string `json:"id"` // required
876 URL string `json:"voice_url"` // required
877 Title string `json:"title"` // required
878 Caption string `json:"caption"`
879 Duration int `json:"voice_duration"`
880 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
881 InputMessageContent interface{} `json:"input_message_content,omitempty"`
882}
883
884// InlineQueryResultCachedVoice is an inline query response with cached voice.
885type InlineQueryResultCachedVoice struct {
886 Type string `json:"type"` // required
887 ID string `json:"id"` // required
888 VoiceID string `json:"voice_file_id"` // required
889 Title string `json:"title"` // required
890 Caption string `json:"caption"`
891 ParseMode string `json:"parse_mode"`
892 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
893 InputMessageContent interface{} `json:"input_message_content,omitempty"`
894}
895
896// InlineQueryResultDocument is an inline query response document.
897type InlineQueryResultDocument struct {
898 Type string `json:"type"` // required
899 ID string `json:"id"` // required
900 Title string `json:"title"` // required
901 Caption string `json:"caption"`
902 URL string `json:"document_url"` // required
903 MimeType string `json:"mime_type"` // required
904 Description string `json:"description"`
905 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
906 InputMessageContent interface{} `json:"input_message_content,omitempty"`
907 ThumbURL string `json:"thumb_url"`
908 ThumbWidth int `json:"thumb_width"`
909 ThumbHeight int `json:"thumb_height"`
910}
911
912// InlineQueryResultCachedDocument is an inline query response with cached document.
913type InlineQueryResultCachedDocument struct {
914 Type string `json:"type"` // required
915 ID string `json:"id"` // required
916 DocumentID string `json:"document_file_id"` // required
917 Title string `json:"title"` // required
918 Caption string `json:"caption"`
919 Description string `json:"description"`
920 ParseMode string `json:"parse_mode"`
921 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
922 InputMessageContent interface{} `json:"input_message_content,omitempty"`
923}
924
925// InlineQueryResultLocation is an inline query response location.
926type InlineQueryResultLocation struct {
927 Type string `json:"type"` // required
928 ID string `json:"id"` // required
929 Latitude float64 `json:"latitude"` // required
930 Longitude float64 `json:"longitude"` // required
931 LivePeriod int `json:"live_period"` // optional
932 Title string `json:"title"` // required
933 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
934 InputMessageContent interface{} `json:"input_message_content,omitempty"`
935 ThumbURL string `json:"thumb_url"`
936 ThumbWidth int `json:"thumb_width"`
937 ThumbHeight int `json:"thumb_height"`
938}
939
940// InlineQueryResultContact is an inline query response contact.
941type InlineQueryResultContact struct {
942 Type string `json:"type"` // required
943 ID string `json:"id"` // required
944 PhoneNumber string `json:"phone_number"` // required
945 FirstName string `json:"first_name"` // required
946 LastName string `json:"last_name"`
947 VCard string `json:"vcard"`
948 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
949 InputMessageContent interface{} `json:"input_message_content,omitempty"`
950 ThumbURL string `json:"thumb_url"`
951 ThumbWidth int `json:"thumb_width"`
952 ThumbHeight int `json:"thumb_height"`
953}
954
955// InlineQueryResultVenue is an inline query response venue.
956type InlineQueryResultVenue struct {
957 Type string `json:"type"` // required
958 ID string `json:"id"` // required
959 Latitude float64 `json:"latitude"` // required
960 Longitude float64 `json:"longitude"` // required
961 Title string `json:"title"` // required
962 Address string `json:"address"` // required
963 FoursquareID string `json:"foursquare_id"`
964 FoursquareType string `json:"foursquare_type"`
965 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
966 InputMessageContent interface{} `json:"input_message_content,omitempty"`
967 ThumbURL string `json:"thumb_url"`
968 ThumbWidth int `json:"thumb_width"`
969 ThumbHeight int `json:"thumb_height"`
970}
971
972// InlineQueryResultGame is an inline query response game.
973type InlineQueryResultGame struct {
974 Type string `json:"type"`
975 ID string `json:"id"`
976 GameShortName string `json:"game_short_name"`
977 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
978}
979
980// ChosenInlineResult is an inline query result chosen by a User
981type ChosenInlineResult struct {
982 ResultID string `json:"result_id"`
983 From *User `json:"from"`
984 Location *Location `json:"location"`
985 InlineMessageID string `json:"inline_message_id"`
986 Query string `json:"query"`
987}
988
989// InputTextMessageContent contains text for displaying
990// as an inline query result.
991type InputTextMessageContent struct {
992 Text string `json:"message_text"`
993 ParseMode string `json:"parse_mode"`
994 DisableWebPagePreview bool `json:"disable_web_page_preview"`
995}
996
997// InputLocationMessageContent contains a location for displaying
998// as an inline query result.
999type InputLocationMessageContent struct {
1000 Latitude float64 `json:"latitude"`
1001 Longitude float64 `json:"longitude"`
1002}
1003
1004// InputVenueMessageContent contains a venue for displaying
1005// as an inline query result.
1006type InputVenueMessageContent struct {
1007 Latitude float64 `json:"latitude"`
1008 Longitude float64 `json:"longitude"`
1009 Title string `json:"title"`
1010 Address string `json:"address"`
1011 FoursquareID string `json:"foursquare_id"`
1012}
1013
1014// InputContactMessageContent contains a contact for displaying
1015// as an inline query result.
1016type InputContactMessageContent struct {
1017 PhoneNumber string `json:"phone_number"`
1018 FirstName string `json:"first_name"`
1019 LastName string `json:"last_name"`
1020 VCard string `json:"vcard"`
1021}
1022
1023// Invoice contains basic information about an invoice.
1024type Invoice struct {
1025 Title string `json:"title"`
1026 Description string `json:"description"`
1027 StartParameter string `json:"start_parameter"`
1028 Currency string `json:"currency"`
1029 TotalAmount int `json:"total_amount"`
1030}
1031
1032// LabeledPrice represents a portion of the price for goods or services.
1033type LabeledPrice struct {
1034 Label string `json:"label"`
1035 Amount int `json:"amount"`
1036}
1037
1038// ShippingAddress represents a shipping address.
1039type ShippingAddress struct {
1040 CountryCode string `json:"country_code"`
1041 State string `json:"state"`
1042 City string `json:"city"`
1043 StreetLine1 string `json:"street_line1"`
1044 StreetLine2 string `json:"street_line2"`
1045 PostCode string `json:"post_code"`
1046}
1047
1048// OrderInfo represents information about an order.
1049type OrderInfo struct {
1050 Name string `json:"name,omitempty"`
1051 PhoneNumber string `json:"phone_number,omitempty"`
1052 Email string `json:"email,omitempty"`
1053 ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
1054}
1055
1056// ShippingOption represents one shipping option.
1057type ShippingOption struct {
1058 ID string `json:"id"`
1059 Title string `json:"title"`
1060 Prices []LabeledPrice `json:"prices"`
1061}
1062
1063// SuccessfulPayment contains basic information about a successful payment.
1064type SuccessfulPayment struct {
1065 Currency string `json:"currency"`
1066 TotalAmount int `json:"total_amount"`
1067 InvoicePayload string `json:"invoice_payload"`
1068 ShippingOptionID string `json:"shipping_option_id,omitempty"`
1069 OrderInfo *OrderInfo `json:"order_info,omitempty"`
1070 TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
1071 ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
1072}
1073
1074// ShippingQuery contains information about an incoming shipping query.
1075type ShippingQuery struct {
1076 ID string `json:"id"`
1077 From *User `json:"from"`
1078 InvoicePayload string `json:"invoice_payload"`
1079 ShippingAddress *ShippingAddress `json:"shipping_address"`
1080}
1081
1082// PreCheckoutQuery contains information about an incoming pre-checkout query.
1083type PreCheckoutQuery struct {
1084 ID string `json:"id"`
1085 From *User `json:"from"`
1086 Currency string `json:"currency"`
1087 TotalAmount int `json:"total_amount"`
1088 InvoicePayload string `json:"invoice_payload"`
1089 ShippingOptionID string `json:"shipping_option_id,omitempty"`
1090 OrderInfo *OrderInfo `json:"order_info,omitempty"`
1091}
1092
1093// StickerSet is a collection of stickers.
1094type StickerSet struct {
1095 Name string `json:"name"`
1096 Title string `json:"title"`
1097 IsAnimated bool `json:"is_animated"`
1098 ContainsMasks bool `json:"contains_masks"`
1099 Stickers []Sticker `json:"stickers"`
1100 Thumb *PhotoSize `json:"thumb"`
1101}
1102
1103// BotCommand represents Telegram's understanding of a command.
1104type BotCommand struct {
1105 Command string `json:"command"`
1106 Description string `json:"description"`
1107}
1108
1109// BaseInputMedia is a base type for the InputMedia types.
1110type BaseInputMedia struct {
1111 Type string `json:"type"`
1112 Media string `json:"media"`
1113 Caption string `json:"caption"`
1114 ParseMode string `json:"parse_mode"`
1115}
1116
1117// InputMediaPhoto is a photo to send as part of a media group.
1118type InputMediaPhoto struct {
1119 BaseInputMedia
1120}
1121
1122// InputMediaVideo is a video to send as part of a media group.
1123type InputMediaVideo struct {
1124 BaseInputMedia
1125 Width int `json:"width"`
1126 Height int `json:"height"`
1127 Duration int `json:"duration"`
1128 SupportsStreaming bool `json:"supports_streaming"`
1129}
1130
1131// InputMediaAnimation is an animation to send as part of a media group.
1132type InputMediaAnimation struct {
1133 BaseInputMedia
1134 Width int `json:"width"`
1135 Height int `json:"height"`
1136 Duration int `json:"duration"`
1137}
1138
1139// InputMediaAudio is a audio to send as part of a media group.
1140type InputMediaAudio struct {
1141 BaseInputMedia
1142 Duration int `json:"duration"`
1143 Performer string `json:"performer"`
1144 Title string `json:"title"`
1145}
1146
1147// InputMediaDocument is a audio to send as part of a media group.
1148type InputMediaDocument struct {
1149 BaseInputMedia
1150}
1151
1152// Error is an error containing extra information returned by the Telegram API.
1153type Error struct {
1154 Code int
1155 Message string
1156 ResponseParameters
1157}
1158
1159// Error message string.
1160func (e Error) Error() string {
1161 return e.Message
1162}