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// Error is an error containing extra information returned by the Telegram API.
23type Error struct {
24 Code int
25 Message string
26 ResponseParameters
27}
28
29// Error message string.
30func (e Error) Error() string {
31 return e.Message
32}
33
34// Update is an update response, from GetUpdates.
35type Update struct {
36 // UpdateID is the update's unique identifier.
37 // Update identifiers start from a certain positive number and increase
38 // sequentially.
39 // This ID becomes especially handy if you're using Webhooks,
40 // since it allows you to ignore repeated updates or to restore
41 // the correct update sequence, should they get out of order.
42 // If there are no new updates for at least a week, then identifier
43 // of the next update will be chosen randomly instead of sequentially.
44 UpdateID int `json:"update_id"`
45 // Message new incoming message of any kind — text, photo, sticker, etc.
46 //
47 // optional
48 Message *Message `json:"message,omitempty"`
49 // EditedMessage new version of a message that is known to the bot and was
50 // edited
51 //
52 // optional
53 EditedMessage *Message `json:"edited_message,omitempty"`
54 // ChannelPost new version of a message that is known to the bot and was
55 // edited
56 //
57 // optional
58 ChannelPost *Message `json:"channel_post,omitempty"`
59 // EditedChannelPost new incoming channel post of any kind — text, photo,
60 // sticker, etc.
61 //
62 // optional
63 EditedChannelPost *Message `json:"edited_channel_post,omitempty"`
64 // InlineQuery new incoming inline query
65 //
66 // optional
67 InlineQuery *InlineQuery `json:"inline_query,omitempty"`
68 // ChosenInlineResult is the result of an inline query
69 // that was chosen by a user and sent to their chat partner.
70 // Please see our documentation on the feedback collecting
71 // for details on how to enable these updates for your bot.
72 //
73 // optional
74 ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
75 // CallbackQuery new incoming callback query
76 //
77 // optional
78 CallbackQuery *CallbackQuery `json:"callback_query,omitempty"`
79 // ShippingQuery new incoming shipping query. Only for invoices with
80 // flexible price
81 //
82 // optional
83 ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"`
84 // PreCheckoutQuery new incoming pre-checkout query. Contains full
85 // information about checkout
86 //
87 // optional
88 PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"`
89 // Pool new poll state. Bots receive only updates about stopped polls and
90 // polls, which are sent by the bot
91 //
92 // optional
93 Poll *Poll `json:"poll,omitempty"`
94 // PollAnswer user changed their answer in a non-anonymous poll. Bots
95 // receive new votes only in polls that were sent by the bot itself.
96 //
97 // optional
98 PollAnswer *PollAnswer `json:"poll_answer,omitempty"`
99 // MyChatMember is the bot's chat member status was updated in a chat. For
100 // private chats, this update is received only when the bot is blocked or
101 // unblocked by the user.
102 //
103 // optional
104 MyChatMember *ChatMemberUpdated `json:"my_chat_member"`
105 // ChatMember is a chat member's status was updated in a chat. The bot must
106 // be an administrator in the chat and must explicitly specify "chat_member"
107 // in the list of allowed_updates to receive these updates.
108 //
109 // optional
110 ChatMember *ChatMemberUpdated `json:"chat_member"`
111 // ChatJoinRequest is a request to join the chat has been sent. The bot must
112 // have the can_invite_users administrator right in the chat to receive
113 // these updates.
114 //
115 // optional
116 ChatJoinRequest *ChatJoinRequest `json:"chat_join_request"`
117}
118
119// SentFrom returns the user who sent an update. Can be nil, if Telegram did not provide information
120// about the user in the update object.
121func (u *Update) SentFrom() *User {
122 switch {
123 case u.Message != nil:
124 return u.Message.From
125 case u.EditedMessage != nil:
126 return u.EditedMessage.From
127 case u.InlineQuery != nil:
128 return u.InlineQuery.From
129 case u.ChosenInlineResult != nil:
130 return u.ChosenInlineResult.From
131 case u.CallbackQuery != nil:
132 return u.CallbackQuery.From
133 case u.ShippingQuery != nil:
134 return u.ShippingQuery.From
135 case u.PreCheckoutQuery != nil:
136 return u.PreCheckoutQuery.From
137 default:
138 return nil
139 }
140}
141
142// CallbackData returns the callback query data, if it exists.
143func (u *Update) CallbackData() string {
144 if u.CallbackQuery != nil {
145 return u.CallbackQuery.Data
146 }
147 return ""
148}
149
150// FromChat returns the chat where an update occurred.
151func (u *Update) FromChat() *Chat {
152 switch {
153 case u.Message != nil:
154 return u.Message.Chat
155 case u.EditedMessage != nil:
156 return u.EditedMessage.Chat
157 case u.ChannelPost != nil:
158 return u.ChannelPost.Chat
159 case u.EditedChannelPost != nil:
160 return u.EditedChannelPost.Chat
161 case u.CallbackQuery != nil:
162 return u.CallbackQuery.Message.Chat
163 default:
164 return nil
165 }
166}
167
168// UpdatesChannel is the channel for getting updates.
169type UpdatesChannel <-chan Update
170
171// Clear discards all unprocessed incoming updates.
172func (ch UpdatesChannel) Clear() {
173 for len(ch) != 0 {
174 <-ch
175 }
176}
177
178// User represents a Telegram user or bot.
179type User struct {
180 // ID is a unique identifier for this user or bot
181 ID int64 `json:"id"`
182 // IsBot true, if this user is a bot
183 //
184 // optional
185 IsBot bool `json:"is_bot,omitempty"`
186 // IsPremium true, if user has Telegram Premium
187 //
188 // optional
189 IsPremium bool `json:"is_premium,omitempty"`
190 // FirstName user's or bot's first name
191 FirstName string `json:"first_name"`
192 // LastName user's or bot's last name
193 //
194 // optional
195 LastName string `json:"last_name,omitempty"`
196 // UserName user's or bot's username
197 //
198 // optional
199 UserName string `json:"username,omitempty"`
200 // LanguageCode IETF language tag of the user's language
201 // more info: https://en.wikipedia.org/wiki/IETF_language_tag
202 //
203 // optional
204 LanguageCode string `json:"language_code,omitempty"`
205 // CanJoinGroups is true, if the bot can be invited to groups.
206 // Returned only in getMe.
207 //
208 // optional
209 CanJoinGroups bool `json:"can_join_groups,omitempty"`
210 // CanReadAllGroupMessages is true, if privacy mode is disabled for the bot.
211 // Returned only in getMe.
212 //
213 // optional
214 CanReadAllGroupMessages bool `json:"can_read_all_group_messages,omitempty"`
215 // SupportsInlineQueries is true, if the bot supports inline queries.
216 // Returned only in getMe.
217 //
218 // optional
219 SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"`
220}
221
222// String displays a simple text version of a user.
223//
224// It is normally a user's username, but falls back to a first/last
225// name as available.
226func (u *User) String() string {
227 if u == nil {
228 return ""
229 }
230 if u.UserName != "" {
231 return u.UserName
232 }
233
234 name := u.FirstName
235 if u.LastName != "" {
236 name += " " + u.LastName
237 }
238
239 return name
240}
241
242// Chat represents a chat.
243type Chat struct {
244 // ID is a unique identifier for this chat
245 ID int64 `json:"id"`
246 // Type of chat, can be either “private”, “group”, “supergroup” or “channel”
247 Type string `json:"type"`
248 // Title for supergroups, channels and group chats
249 //
250 // optional
251 Title string `json:"title,omitempty"`
252 // UserName for private chats, supergroups and channels if available
253 //
254 // optional
255 UserName string `json:"username,omitempty"`
256 // FirstName of the other party in a private chat
257 //
258 // optional
259 FirstName string `json:"first_name,omitempty"`
260 // LastName of the other party in a private chat
261 //
262 // optional
263 LastName string `json:"last_name,omitempty"`
264 // Photo is a chat photo
265 Photo *ChatPhoto `json:"photo"`
266 // Bio is the bio of the other party in a private chat. Returned only in
267 // getChat
268 //
269 // optional
270 Bio string `json:"bio,omitempty"`
271 // HasPrivateForwards is true if privacy settings of the other party in the
272 // private chat allows to use tg://user?id=<user_id> links only in chats
273 // with the user. Returned only in getChat.
274 //
275 // optional
276 HasPrivateForwards bool `json:"has_private_forwards,omitempty"`
277 // Description for groups, supergroups and channel chats
278 //
279 // optional
280 Description string `json:"description,omitempty"`
281 // InviteLink is a chat invite link, for groups, supergroups and channel chats.
282 // Each administrator in a chat generates their own invite links,
283 // so the bot must first generate the link using exportChatInviteLink
284 //
285 // optional
286 InviteLink string `json:"invite_link,omitempty"`
287 // PinnedMessage is the pinned message, for groups, supergroups and channels
288 //
289 // optional
290 PinnedMessage *Message `json:"pinned_message,omitempty"`
291 // Permissions are default chat member permissions, for groups and
292 // supergroups. Returned only in getChat.
293 //
294 // optional
295 Permissions *ChatPermissions `json:"permissions,omitempty"`
296 // SlowModeDelay is for supergroups, the minimum allowed delay between
297 // consecutive messages sent by each unpriviledged user. Returned only in
298 // getChat.
299 //
300 // optional
301 SlowModeDelay int `json:"slow_mode_delay,omitempty"`
302 // MessageAutoDeleteTime is the time after which all messages sent to the
303 // chat will be automatically deleted; in seconds. Returned only in getChat.
304 //
305 // optional
306 MessageAutoDeleteTime int `json:"message_auto_delete_time,omitempty"`
307 // HasProtectedContent is true if messages from the chat can't be forwarded
308 // to other chats. Returned only in getChat.
309 //
310 // optional
311 HasProtectedContent bool `json:"has_protected_content,omitempty"`
312 // StickerSetName is for supergroups, name of group sticker set.Returned
313 // only in getChat.
314 //
315 // optional
316 StickerSetName string `json:"sticker_set_name,omitempty"`
317 // CanSetStickerSet is true, if the bot can change the group sticker set.
318 // Returned only in getChat.
319 //
320 // optional
321 CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"`
322 // LinkedChatID is a unique identifier for the linked chat, i.e. the
323 // discussion group identifier for a channel and vice versa; for supergroups
324 // and channel chats.
325 //
326 // optional
327 LinkedChatID int64 `json:"linked_chat_id,omitempty"`
328 // Location is for supergroups, the location to which the supergroup is
329 // connected. Returned only in getChat.
330 //
331 // optional
332 Location *ChatLocation `json:"location"`
333}
334
335// IsPrivate returns if the Chat is a private conversation.
336func (c Chat) IsPrivate() bool {
337 return c.Type == "private"
338}
339
340// IsGroup returns if the Chat is a group.
341func (c Chat) IsGroup() bool {
342 return c.Type == "group"
343}
344
345// IsSuperGroup returns if the Chat is a supergroup.
346func (c Chat) IsSuperGroup() bool {
347 return c.Type == "supergroup"
348}
349
350// IsChannel returns if the Chat is a channel.
351func (c Chat) IsChannel() bool {
352 return c.Type == "channel"
353}
354
355// ChatConfig returns a ChatConfig struct for chat related methods.
356func (c Chat) ChatConfig() ChatConfig {
357 return ChatConfig{ChatID: c.ID}
358}
359
360// Message represents a message.
361type Message struct {
362 // MessageID is a unique message identifier inside this chat
363 MessageID int `json:"message_id"`
364 // From is a sender, empty for messages sent to channels;
365 //
366 // optional
367 From *User `json:"from,omitempty"`
368 // SenderChat is the sender of the message, sent on behalf of a chat. The
369 // channel itself for channel messages. The supergroup itself for messages
370 // from anonymous group administrators. The linked channel for messages
371 // automatically forwarded to the discussion group
372 //
373 // optional
374 SenderChat *Chat `json:"sender_chat,omitempty"`
375 // Date of the message was sent in Unix time
376 Date int `json:"date"`
377 // Chat is the conversation the message belongs to
378 Chat *Chat `json:"chat"`
379 // ForwardFrom for forwarded messages, sender of the original message;
380 //
381 // optional
382 ForwardFrom *User `json:"forward_from,omitempty"`
383 // ForwardFromChat for messages forwarded from channels,
384 // information about the original channel;
385 //
386 // optional
387 ForwardFromChat *Chat `json:"forward_from_chat,omitempty"`
388 // ForwardFromMessageID for messages forwarded from channels,
389 // identifier of the original message in the channel;
390 //
391 // optional
392 ForwardFromMessageID int `json:"forward_from_message_id,omitempty"`
393 // ForwardSignature for messages forwarded from channels, signature of the
394 // post author if present
395 //
396 // optional
397 ForwardSignature string `json:"forward_signature,omitempty"`
398 // ForwardSenderName is the sender's name for messages forwarded from users
399 // who disallow adding a link to their account in forwarded messages
400 //
401 // optional
402 ForwardSenderName string `json:"forward_sender_name,omitempty"`
403 // ForwardDate for forwarded messages, date the original message was sent in Unix time;
404 //
405 // optional
406 ForwardDate int `json:"forward_date,omitempty"`
407 // IsAutomaticForward is true if the message is a channel post that was
408 // automatically forwarded to the connected discussion group.
409 //
410 // optional
411 IsAutomaticForward bool `json:"is_automatic_forward,omitempty"`
412 // ReplyToMessage for replies, the original message.
413 // Note that the Message object in this field will not contain further ReplyToMessage fields
414 // even if it itself is a reply;
415 //
416 // optional
417 ReplyToMessage *Message `json:"reply_to_message,omitempty"`
418 // ViaBot through which the message was sent;
419 //
420 // optional
421 ViaBot *User `json:"via_bot,omitempty"`
422 // EditDate of the message was last edited in Unix time;
423 //
424 // optional
425 EditDate int `json:"edit_date,omitempty"`
426 // HasProtectedContent is true if the message can't be forwarded.
427 //
428 // optional
429 HasProtectedContent bool `json:"has_protected_content,omitempty"`
430 // MediaGroupID is the unique identifier of a media message group this message belongs to;
431 //
432 // optional
433 MediaGroupID string `json:"media_group_id,omitempty"`
434 // AuthorSignature is the signature of the post author for messages in channels;
435 //
436 // optional
437 AuthorSignature string `json:"author_signature,omitempty"`
438 // Text is for text messages, the actual UTF-8 text of the message, 0-4096 characters;
439 //
440 // optional
441 Text string `json:"text,omitempty"`
442 // Entities are for text messages, special entities like usernames,
443 // URLs, bot commands, etc. that appear in the text;
444 //
445 // optional
446 Entities []MessageEntity `json:"entities,omitempty"`
447 // Animation message is an animation, information about the animation.
448 // For backward compatibility, when this field is set, the document field will also be set;
449 //
450 // optional
451 Animation *Animation `json:"animation,omitempty"`
452 // PremiumAnimation message is an animation, information about the animation.
453 // For backward compatibility, when this field is set, the document field will also be set;
454 //
455 // optional
456 PremiumAnimation *Animation `json:"premium_animation,omitempty"`
457 // Audio message is an audio file, information about the file;
458 //
459 // optional
460 Audio *Audio `json:"audio,omitempty"`
461 // Document message is a general file, information about the file;
462 //
463 // optional
464 Document *Document `json:"document,omitempty"`
465 // Photo message is a photo, available sizes of the photo;
466 //
467 // optional
468 Photo []PhotoSize `json:"photo,omitempty"`
469 // Sticker message is a sticker, information about the sticker;
470 //
471 // optional
472 Sticker *Sticker `json:"sticker,omitempty"`
473 // Video message is a video, information about the video;
474 //
475 // optional
476 Video *Video `json:"video,omitempty"`
477 // VideoNote message is a video note, information about the video message;
478 //
479 // optional
480 VideoNote *VideoNote `json:"video_note,omitempty"`
481 // Voice message is a voice message, information about the file;
482 //
483 // optional
484 Voice *Voice `json:"voice,omitempty"`
485 // Caption for the animation, audio, document, photo, video or voice, 0-1024 characters;
486 //
487 // optional
488 Caption string `json:"caption,omitempty"`
489 // CaptionEntities;
490 //
491 // optional
492 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
493 // Contact message is a shared contact, information about the contact;
494 //
495 // optional
496 Contact *Contact `json:"contact,omitempty"`
497 // Dice is a dice with random value;
498 //
499 // optional
500 Dice *Dice `json:"dice,omitempty"`
501 // Game message is a game, information about the game;
502 //
503 // optional
504 Game *Game `json:"game,omitempty"`
505 // Poll is a native poll, information about the poll;
506 //
507 // optional
508 Poll *Poll `json:"poll,omitempty"`
509 // Venue message is a venue, information about the venue.
510 // For backward compatibility, when this field is set, the location field
511 // will also be set;
512 //
513 // optional
514 Venue *Venue `json:"venue,omitempty"`
515 // Location message is a shared location, information about the location;
516 //
517 // optional
518 Location *Location `json:"location,omitempty"`
519 // NewChatMembers that were added to the group or supergroup
520 // and information about them (the bot itself may be one of these members);
521 //
522 // optional
523 NewChatMembers []User `json:"new_chat_members,omitempty"`
524 // LeftChatMember is a member was removed from the group,
525 // information about them (this member may be the bot itself);
526 //
527 // optional
528 LeftChatMember *User `json:"left_chat_member,omitempty"`
529 // NewChatTitle is a chat title was changed to this value;
530 //
531 // optional
532 NewChatTitle string `json:"new_chat_title,omitempty"`
533 // NewChatPhoto is a chat photo was change to this value;
534 //
535 // optional
536 NewChatPhoto []PhotoSize `json:"new_chat_photo,omitempty"`
537 // DeleteChatPhoto is a service message: the chat photo was deleted;
538 //
539 // optional
540 DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"`
541 // GroupChatCreated is a service message: the group has been created;
542 //
543 // optional
544 GroupChatCreated bool `json:"group_chat_created,omitempty"`
545 // SuperGroupChatCreated is a service message: the supergroup has been created.
546 // This field can't be received in a message coming through updates,
547 // because bot can't be a member of a supergroup when it is created.
548 // It can only be found in ReplyToMessage if someone replies to a very first message
549 // in a directly created supergroup;
550 //
551 // optional
552 SuperGroupChatCreated bool `json:"supergroup_chat_created,omitempty"`
553 // ChannelChatCreated is a service message: the channel has been created.
554 // This field can't be received in a message coming through updates,
555 // because bot can't be a member of a channel when it is created.
556 // It can only be found in ReplyToMessage
557 // if someone replies to a very first message in a channel;
558 //
559 // optional
560 ChannelChatCreated bool `json:"channel_chat_created,omitempty"`
561 // MessageAutoDeleteTimerChanged is a service message: auto-delete timer
562 // settings changed in the chat.
563 //
564 // optional
565 MessageAutoDeleteTimerChanged *MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed"`
566 // MigrateToChatID is the group has been migrated to a supergroup with the specified identifier.
567 // This number may be greater than 32 bits and some programming languages
568 // may have difficulty/silent defects in interpreting it.
569 // But it is smaller than 52 bits, so a signed 64-bit integer
570 // or double-precision float type are safe for storing this identifier;
571 //
572 // optional
573 MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"`
574 // MigrateFromChatID is the supergroup has been migrated from a group with the specified identifier.
575 // This number may be greater than 32 bits and some programming languages
576 // may have difficulty/silent defects in interpreting it.
577 // But it is smaller than 52 bits, so a signed 64-bit integer
578 // or double-precision float type are safe for storing this identifier;
579 //
580 // optional
581 MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"`
582 // PinnedMessage is a specified message was pinned.
583 // Note that the Message object in this field will not contain further ReplyToMessage
584 // fields even if it is itself a reply;
585 //
586 // optional
587 PinnedMessage *Message `json:"pinned_message,omitempty"`
588 // Invoice message is an invoice for a payment;
589 //
590 // optional
591 Invoice *Invoice `json:"invoice,omitempty"`
592 // SuccessfulPayment message is a service message about a successful payment,
593 // information about the payment;
594 //
595 // optional
596 SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"`
597 // ConnectedWebsite is the domain name of the website on which the user has
598 // logged in;
599 //
600 // optional
601 ConnectedWebsite string `json:"connected_website,omitempty"`
602 // PassportData is a Telegram Passport data;
603 //
604 // optional
605 PassportData *PassportData `json:"passport_data,omitempty"`
606 // ProximityAlertTriggered is a service message. A user in the chat
607 // triggered another user's proximity alert while sharing Live Location
608 //
609 // optional
610 ProximityAlertTriggered *ProximityAlertTriggered `json:"proximity_alert_triggered"`
611 // VoiceChatScheduled is a service message: voice chat scheduled.
612 //
613 // optional
614 VoiceChatScheduled *VoiceChatScheduled `json:"voice_chat_scheduled"`
615 // VoiceChatStarted is a service message: voice chat started.
616 //
617 // optional
618 VoiceChatStarted *VoiceChatStarted `json:"voice_chat_started"`
619 // VoiceChatEnded is a service message: voice chat ended.
620 //
621 // optional
622 VoiceChatEnded *VoiceChatEnded `json:"voice_chat_ended"`
623 // VoiceChatParticipantsInvited is a service message: new participants
624 // invited to a voice chat.
625 //
626 // optional
627 VoiceChatParticipantsInvited *VoiceChatParticipantsInvited `json:"voice_chat_participants_invited"`
628 // ReplyMarkup is the Inline keyboard attached to the message.
629 // login_url buttons are represented as ordinary url buttons.
630 //
631 // optional
632 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
633}
634
635// Time converts the message timestamp into a Time.
636func (m *Message) Time() time.Time {
637 return time.Unix(int64(m.Date), 0)
638}
639
640// IsCommand returns true if message starts with a "bot_command" entity.
641func (m *Message) IsCommand() bool {
642 if m.Entities == nil || len(m.Entities) == 0 {
643 return false
644 }
645
646 entity := m.Entities[0]
647 return entity.Offset == 0 && entity.IsCommand()
648}
649
650// Command checks if the message was a command and if it was, returns the
651// command. If the Message was not a command, it returns an empty string.
652//
653// If the command contains the at name syntax, it is removed. Use
654// CommandWithAt() if you do not want that.
655func (m *Message) Command() string {
656 command := m.CommandWithAt()
657
658 if i := strings.Index(command, "@"); i != -1 {
659 command = command[:i]
660 }
661
662 return command
663}
664
665// CommandWithAt checks if the message was a command and if it was, returns the
666// command. If the Message was not a command, it returns an empty string.
667//
668// If the command contains the at name syntax, it is not removed. Use Command()
669// if you want that.
670func (m *Message) CommandWithAt() string {
671 if !m.IsCommand() {
672 return ""
673 }
674
675 // IsCommand() checks that the message begins with a bot_command entity
676 entity := m.Entities[0]
677 return m.Text[1:entity.Length]
678}
679
680// CommandArguments checks if the message was a command and if it was,
681// returns all text after the command name. If the Message was not a
682// command, it returns an empty string.
683//
684// Note: The first character after the command name is omitted:
685// - "/foo bar baz" yields "bar baz", not " bar baz"
686// - "/foo-bar baz" yields "bar baz", too
687// Even though the latter is not a command conforming to the spec, the API
688// marks "/foo" as command entity.
689func (m *Message) CommandArguments() string {
690 if !m.IsCommand() {
691 return ""
692 }
693
694 // IsCommand() checks that the message begins with a bot_command entity
695 entity := m.Entities[0]
696
697 if len(m.Text) == entity.Length {
698 return "" // The command makes up the whole message
699 }
700
701 return m.Text[entity.Length+1:]
702}
703
704// MessageID represents a unique message identifier.
705type MessageID struct {
706 MessageID int `json:"message_id"`
707}
708
709// MessageEntity represents one special entity in a text message.
710type MessageEntity struct {
711 // Type of the entity.
712 // Can be:
713 // “mention” (@username),
714 // “hashtag” (#hashtag),
715 // “cashtag” ($USD),
716 // “bot_command” (/start@jobs_bot),
717 // “url” (https://telegram.org),
718 // “email” (do-not-reply@telegram.org),
719 // “phone_number” (+1-212-555-0123),
720 // “bold” (bold text),
721 // “italic” (italic text),
722 // “underline” (underlined text),
723 // “strikethrough” (strikethrough text),
724 // "spoiler" (spoiler message),
725 // “code” (monowidth string),
726 // “pre” (monowidth block),
727 // “text_link” (for clickable text URLs),
728 // “text_mention” (for users without usernames)
729 Type string `json:"type"`
730 // Offset in UTF-16 code units to the start of the entity
731 Offset int `json:"offset"`
732 // Length
733 Length int `json:"length"`
734 // URL for “text_link” only, url that will be opened after user taps on the text
735 //
736 // optional
737 URL string `json:"url,omitempty"`
738 // User for “text_mention” only, the mentioned user
739 //
740 // optional
741 User *User `json:"user,omitempty"`
742 // Language for “pre” only, the programming language of the entity text
743 //
744 // optional
745 Language string `json:"language,omitempty"`
746}
747
748// ParseURL attempts to parse a URL contained within a MessageEntity.
749func (e MessageEntity) ParseURL() (*url.URL, error) {
750 if e.URL == "" {
751 return nil, errors.New(ErrBadURL)
752 }
753
754 return url.Parse(e.URL)
755}
756
757// IsMention returns true if the type of the message entity is "mention" (@username).
758func (e MessageEntity) IsMention() bool {
759 return e.Type == "mention"
760}
761
762// IsHashtag returns true if the type of the message entity is "hashtag".
763func (e MessageEntity) IsHashtag() bool {
764 return e.Type == "hashtag"
765}
766
767// IsCommand returns true if the type of the message entity is "bot_command".
768func (e MessageEntity) IsCommand() bool {
769 return e.Type == "bot_command"
770}
771
772// IsURL returns true if the type of the message entity is "url".
773func (e MessageEntity) IsURL() bool {
774 return e.Type == "url"
775}
776
777// IsEmail returns true if the type of the message entity is "email".
778func (e MessageEntity) IsEmail() bool {
779 return e.Type == "email"
780}
781
782// IsBold returns true if the type of the message entity is "bold" (bold text).
783func (e MessageEntity) IsBold() bool {
784 return e.Type == "bold"
785}
786
787// IsItalic returns true if the type of the message entity is "italic" (italic text).
788func (e MessageEntity) IsItalic() bool {
789 return e.Type == "italic"
790}
791
792// IsCode returns true if the type of the message entity is "code" (monowidth string).
793func (e MessageEntity) IsCode() bool {
794 return e.Type == "code"
795}
796
797// IsPre returns true if the type of the message entity is "pre" (monowidth block).
798func (e MessageEntity) IsPre() bool {
799 return e.Type == "pre"
800}
801
802// IsTextLink returns true if the type of the message entity is "text_link" (clickable text URL).
803func (e MessageEntity) IsTextLink() bool {
804 return e.Type == "text_link"
805}
806
807// PhotoSize represents one size of a photo or a file / sticker thumbnail.
808type PhotoSize struct {
809 // FileID identifier for this file, which can be used to download or reuse
810 // the file
811 FileID string `json:"file_id"`
812 // FileUniqueID is the unique identifier for this file, which is supposed to
813 // be the same over time and for different bots. Can't be used to download
814 // or reuse the file.
815 FileUniqueID string `json:"file_unique_id"`
816 // Width photo width
817 Width int `json:"width"`
818 // Height photo height
819 Height int `json:"height"`
820 // FileSize file size
821 //
822 // optional
823 FileSize int `json:"file_size,omitempty"`
824}
825
826// Animation represents an animation file.
827type Animation struct {
828 // FileID is the identifier for this file, which can be used to download or reuse
829 // the file
830 FileID string `json:"file_id"`
831 // FileUniqueID is the unique identifier for this file, which is supposed to
832 // be the same over time and for different bots. Can't be used to download
833 // or reuse the file.
834 FileUniqueID string `json:"file_unique_id"`
835 // Width video width as defined by sender
836 Width int `json:"width"`
837 // Height video height as defined by sender
838 Height int `json:"height"`
839 // Duration of the video in seconds as defined by sender
840 Duration int `json:"duration"`
841 // Thumbnail animation thumbnail as defined by sender
842 //
843 // optional
844 Thumbnail *PhotoSize `json:"thumb,omitempty"`
845 // FileName original animation filename as defined by sender
846 //
847 // optional
848 FileName string `json:"file_name,omitempty"`
849 // MimeType of the file as defined by sender
850 //
851 // optional
852 MimeType string `json:"mime_type,omitempty"`
853 // FileSize file size
854 //
855 // optional
856 FileSize int `json:"file_size,omitempty"`
857}
858
859// Audio represents an audio file to be treated as music by the Telegram clients.
860type Audio struct {
861 // FileID is an identifier for this file, which can be used to download or
862 // reuse the file
863 FileID string `json:"file_id"`
864 // FileUniqueID is the unique identifier for this file, which is supposed to
865 // be the same over time and for different bots. Can't be used to download
866 // or reuse the file.
867 FileUniqueID string `json:"file_unique_id"`
868 // Duration of the audio in seconds as defined by sender
869 Duration int `json:"duration"`
870 // Performer of the audio as defined by sender or by audio tags
871 //
872 // optional
873 Performer string `json:"performer,omitempty"`
874 // Title of the audio as defined by sender or by audio tags
875 //
876 // optional
877 Title string `json:"title,omitempty"`
878 // FileName is the original filename as defined by sender
879 //
880 // optional
881 FileName string `json:"file_name,omitempty"`
882 // MimeType of the file as defined by sender
883 //
884 // optional
885 MimeType string `json:"mime_type,omitempty"`
886 // FileSize file size
887 //
888 // optional
889 FileSize int `json:"file_size,omitempty"`
890 // Thumbnail is the album cover to which the music file belongs
891 //
892 // optional
893 Thumbnail *PhotoSize `json:"thumb,omitempty"`
894}
895
896// Document represents a general file.
897type Document struct {
898 // FileID is an identifier for this file, which can be used to download or
899 // reuse the file
900 FileID string `json:"file_id"`
901 // FileUniqueID is the unique identifier for this file, which is supposed to
902 // be the same over time and for different bots. Can't be used to download
903 // or reuse the file.
904 FileUniqueID string `json:"file_unique_id"`
905 // Thumbnail document thumbnail as defined by sender
906 //
907 // optional
908 Thumbnail *PhotoSize `json:"thumb,omitempty"`
909 // FileName original filename as defined by sender
910 //
911 // optional
912 FileName string `json:"file_name,omitempty"`
913 // MimeType of the file as defined by sender
914 //
915 // optional
916 MimeType string `json:"mime_type,omitempty"`
917 // FileSize file size
918 //
919 // optional
920 FileSize int `json:"file_size,omitempty"`
921}
922
923// Video represents a video file.
924type Video struct {
925 // FileID identifier for this file, which can be used to download or reuse
926 // the file
927 FileID string `json:"file_id"`
928 // FileUniqueID is the unique identifier for this file, which is supposed to
929 // be the same over time and for different bots. Can't be used to download
930 // or reuse the file.
931 FileUniqueID string `json:"file_unique_id"`
932 // Width video width as defined by sender
933 Width int `json:"width"`
934 // Height video height as defined by sender
935 Height int `json:"height"`
936 // Duration of the video in seconds as defined by sender
937 Duration int `json:"duration"`
938 // Thumbnail video thumbnail
939 //
940 // optional
941 Thumbnail *PhotoSize `json:"thumb,omitempty"`
942 // FileName is the original filename as defined by sender
943 //
944 // optional
945 FileName string `json:"file_name,omitempty"`
946 // MimeType of a file as defined by sender
947 //
948 // optional
949 MimeType string `json:"mime_type,omitempty"`
950 // FileSize file size
951 //
952 // optional
953 FileSize int `json:"file_size,omitempty"`
954}
955
956// VideoNote object represents a video message.
957type VideoNote struct {
958 // FileID identifier for this file, which can be used to download or reuse the file
959 FileID string `json:"file_id"`
960 // FileUniqueID is the unique identifier for this file, which is supposed to
961 // be the same over time and for different bots. Can't be used to download
962 // or reuse the file.
963 FileUniqueID string `json:"file_unique_id"`
964 // Length video width and height (diameter of the video message) as defined by sender
965 Length int `json:"length"`
966 // Duration of the video in seconds as defined by sender
967 Duration int `json:"duration"`
968 // Thumbnail video thumbnail
969 //
970 // optional
971 Thumbnail *PhotoSize `json:"thumb,omitempty"`
972 // FileSize file size
973 //
974 // optional
975 FileSize int `json:"file_size,omitempty"`
976}
977
978// Voice represents a voice note.
979type Voice struct {
980 // FileID identifier for this file, which can be used to download or reuse the file
981 FileID string `json:"file_id"`
982 // FileUniqueID is the unique identifier for this file, which is supposed to
983 // be the same over time and for different bots. Can't be used to download
984 // or reuse the file.
985 FileUniqueID string `json:"file_unique_id"`
986 // Duration of the audio in seconds as defined by sender
987 Duration int `json:"duration"`
988 // MimeType of the file as defined by sender
989 //
990 // optional
991 MimeType string `json:"mime_type,omitempty"`
992 // FileSize file size
993 //
994 // optional
995 FileSize int `json:"file_size,omitempty"`
996}
997
998// Contact represents a phone contact.
999//
1000// Note that LastName and UserID may be empty.
1001type Contact struct {
1002 // PhoneNumber contact's phone number
1003 PhoneNumber string `json:"phone_number"`
1004 // FirstName contact's first name
1005 FirstName string `json:"first_name"`
1006 // LastName contact's last name
1007 //
1008 // optional
1009 LastName string `json:"last_name,omitempty"`
1010 // UserID contact's user identifier in Telegram
1011 //
1012 // optional
1013 UserID int64 `json:"user_id,omitempty"`
1014 // VCard is additional data about the contact in the form of a vCard.
1015 //
1016 // optional
1017 VCard string `json:"vcard,omitempty"`
1018}
1019
1020// Dice represents an animated emoji that displays a random value.
1021type Dice struct {
1022 // Emoji on which the dice throw animation is based
1023 Emoji string `json:"emoji"`
1024 // Value of the dice
1025 Value int `json:"value"`
1026}
1027
1028// PollOption contains information about one answer option in a poll.
1029type PollOption struct {
1030 // Text is the option text, 1-100 characters
1031 Text string `json:"text"`
1032 // VoterCount is the number of users that voted for this option
1033 VoterCount int `json:"voter_count"`
1034}
1035
1036// PollAnswer represents an answer of a user in a non-anonymous poll.
1037type PollAnswer struct {
1038 // PollID is the unique poll identifier
1039 PollID string `json:"poll_id"`
1040 // User who changed the answer to the poll
1041 User User `json:"user"`
1042 // OptionIDs is the 0-based identifiers of poll options chosen by the user.
1043 // May be empty if user retracted vote.
1044 OptionIDs []int `json:"option_ids"`
1045}
1046
1047// Poll contains information about a poll.
1048type Poll struct {
1049 // ID is the unique poll identifier
1050 ID string `json:"id"`
1051 // Question is the poll question, 1-255 characters
1052 Question string `json:"question"`
1053 // Options is the list of poll options
1054 Options []PollOption `json:"options"`
1055 // TotalVoterCount is the total numbers of users who voted in the poll
1056 TotalVoterCount int `json:"total_voter_count"`
1057 // IsClosed is if the poll is closed
1058 IsClosed bool `json:"is_closed"`
1059 // IsAnonymous is if the poll is anonymous
1060 IsAnonymous bool `json:"is_anonymous"`
1061 // Type is the poll type, currently can be "regular" or "quiz"
1062 Type string `json:"type"`
1063 // AllowsMultipleAnswers is true, if the poll allows multiple answers
1064 AllowsMultipleAnswers bool `json:"allows_multiple_answers"`
1065 // CorrectOptionID is the 0-based identifier of the correct answer option.
1066 // Available only for polls in quiz mode, which are closed, or was sent (not
1067 // forwarded) by the bot or to the private chat with the bot.
1068 //
1069 // optional
1070 CorrectOptionID int `json:"correct_option_id,omitempty"`
1071 // Explanation is text that is shown when a user chooses an incorrect answer
1072 // or taps on the lamp icon in a quiz-style poll, 0-200 characters
1073 //
1074 // optional
1075 Explanation string `json:"explanation,omitempty"`
1076 // ExplanationEntities are special entities like usernames, URLs, bot
1077 // commands, etc. that appear in the explanation
1078 //
1079 // optional
1080 ExplanationEntities []MessageEntity `json:"explanation_entities,omitempty"`
1081 // OpenPeriod is the amount of time in seconds the poll will be active
1082 // after creation
1083 //
1084 // optional
1085 OpenPeriod int `json:"open_period,omitempty"`
1086 // CloseDate is the point in time (unix timestamp) when the poll will be
1087 // automatically closed
1088 //
1089 // optional
1090 CloseDate int `json:"close_date,omitempty"`
1091}
1092
1093// Location represents a point on the map.
1094type Location struct {
1095 // Longitude as defined by sender
1096 Longitude float64 `json:"longitude"`
1097 // Latitude as defined by sender
1098 Latitude float64 `json:"latitude"`
1099 // HorizontalAccuracy is the radius of uncertainty for the location,
1100 // measured in meters; 0-1500
1101 //
1102 // optional
1103 HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"`
1104 // LivePeriod is time relative to the message sending date, during which the
1105 // location can be updated, in seconds. For active live locations only.
1106 //
1107 // optional
1108 LivePeriod int `json:"live_period,omitempty"`
1109 // Heading is the direction in which user is moving, in degrees; 1-360. For
1110 // active live locations only.
1111 //
1112 // optional
1113 Heading int `json:"heading,omitempty"`
1114 // ProximityAlertRadius is the maximum distance for proximity alerts about
1115 // approaching another chat member, in meters. For sent live locations only.
1116 //
1117 // optional
1118 ProximityAlertRadius int `json:"proximity_alert_radius,omitempty"`
1119}
1120
1121// Venue represents a venue.
1122type Venue struct {
1123 // Location is the venue location
1124 Location Location `json:"location"`
1125 // Title is the name of the venue
1126 Title string `json:"title"`
1127 // Address of the venue
1128 Address string `json:"address"`
1129 // FoursquareID is the foursquare identifier of the venue
1130 //
1131 // optional
1132 FoursquareID string `json:"foursquare_id,omitempty"`
1133 // FoursquareType is the foursquare type of the venue
1134 //
1135 // optional
1136 FoursquareType string `json:"foursquare_type,omitempty"`
1137 // GooglePlaceID is the Google Places identifier of the venue
1138 //
1139 // optional
1140 GooglePlaceID string `json:"google_place_id,omitempty"`
1141 // GooglePlaceType is the Google Places type of the venue
1142 //
1143 // optional
1144 GooglePlaceType string `json:"google_place_type,omitempty"`
1145}
1146
1147// ProximityAlertTriggered represents a service message sent when a user in the
1148// chat triggers a proximity alert sent by another user.
1149type ProximityAlertTriggered struct {
1150 // Traveler is the user that triggered the alert
1151 Traveler User `json:"traveler"`
1152 // Watcher is the user that set the alert
1153 Watcher User `json:"watcher"`
1154 // Distance is the distance between the users
1155 Distance int `json:"distance"`
1156}
1157
1158// MessageAutoDeleteTimerChanged represents a service message about a change in
1159// auto-delete timer settings.
1160type MessageAutoDeleteTimerChanged struct {
1161 // New auto-delete time for messages in the chat.
1162 MessageAutoDeleteTime int `json:"message_auto_delete_time"`
1163}
1164
1165// VoiceChatScheduled represents a service message about a voice chat scheduled
1166// in the chat.
1167type VoiceChatScheduled struct {
1168 // Point in time (Unix timestamp) when the voice chat is supposed to be
1169 // started by a chat administrator
1170 StartDate int `json:"start_date"`
1171}
1172
1173// Time converts the scheduled start date into a Time.
1174func (m *VoiceChatScheduled) Time() time.Time {
1175 return time.Unix(int64(m.StartDate), 0)
1176}
1177
1178// VoiceChatStarted represents a service message about a voice chat started in
1179// the chat.
1180type VoiceChatStarted struct{}
1181
1182// VoiceChatEnded represents a service message about a voice chat ended in the
1183// chat.
1184type VoiceChatEnded struct {
1185 // Voice chat duration; in seconds.
1186 Duration int `json:"duration"`
1187}
1188
1189// VoiceChatParticipantsInvited represents a service message about new members
1190// invited to a voice chat.
1191type VoiceChatParticipantsInvited struct {
1192 // New members that were invited to the voice chat.
1193 //
1194 // optional
1195 Users []User `json:"users"`
1196}
1197
1198// UserProfilePhotos contains a set of user profile photos.
1199type UserProfilePhotos struct {
1200 // TotalCount total number of profile pictures the target user has
1201 TotalCount int `json:"total_count"`
1202 // Photos requested profile pictures (in up to 4 sizes each)
1203 Photos [][]PhotoSize `json:"photos"`
1204}
1205
1206// File contains information about a file to download from Telegram.
1207type File struct {
1208 // FileID identifier for this file, which can be used to download or reuse
1209 // the file
1210 FileID string `json:"file_id"`
1211 // FileUniqueID is the unique identifier for this file, which is supposed to
1212 // be the same over time and for different bots. Can't be used to download
1213 // or reuse the file.
1214 FileUniqueID string `json:"file_unique_id"`
1215 // FileSize file size, if known
1216 //
1217 // optional
1218 FileSize int `json:"file_size,omitempty"`
1219 // FilePath file path
1220 //
1221 // optional
1222 FilePath string `json:"file_path,omitempty"`
1223}
1224
1225// Link returns a full path to the download URL for a File.
1226//
1227// It requires the Bot token to create the link.
1228func (f *File) Link(token string) string {
1229 return fmt.Sprintf(FileEndpoint, token, f.FilePath)
1230}
1231
1232// ReplyKeyboardMarkup represents a custom keyboard with reply options.
1233type ReplyKeyboardMarkup struct {
1234 // Keyboard is an array of button rows, each represented by an Array of KeyboardButton objects
1235 Keyboard [][]KeyboardButton `json:"keyboard"`
1236 // ResizeKeyboard requests clients to resize the keyboard vertically for optimal fit
1237 // (e.g., make the keyboard smaller if there are just two rows of buttons).
1238 // Defaults to false, in which case the custom keyboard
1239 // is always of the same height as the app's standard keyboard.
1240 //
1241 // optional
1242 ResizeKeyboard bool `json:"resize_keyboard,omitempty"`
1243 // OneTimeKeyboard requests clients to hide the keyboard as soon as it's been used.
1244 // The keyboard will still be available, but clients will automatically display
1245 // the usual letter-keyboard in the chat – the user can press a special button
1246 // in the input field to see the custom keyboard again.
1247 // Defaults to false.
1248 //
1249 // optional
1250 OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"`
1251 // InputFieldPlaceholder is the placeholder to be shown in the input field when
1252 // the keyboard is active; 1-64 characters.
1253 //
1254 // optional
1255 InputFieldPlaceholder string `json:"input_field_placeholder,omitempty"`
1256 // Selective use this parameter if you want to show the keyboard to specific users only.
1257 // Targets:
1258 // 1) users that are @mentioned in the text of the Message object;
1259 // 2) if the bot's message is a reply (has Message.ReplyToMessage not nil), sender of the original message.
1260 //
1261 // Example: A user requests to change the bot's language,
1262 // bot replies to the request with a keyboard to select the new language.
1263 // Other users in the group don't see the keyboard.
1264 //
1265 // optional
1266 Selective bool `json:"selective,omitempty"`
1267}
1268
1269// KeyboardButton represents one button of the reply keyboard. For simple text
1270// buttons String can be used instead of this object to specify text of the
1271// button. Optional fields request_contact, request_location, and request_poll
1272// are mutually exclusive.
1273type KeyboardButton struct {
1274 // Text of the button. If none of the optional fields are used,
1275 // it will be sent as a message when the button is pressed.
1276 Text string `json:"text"`
1277 // RequestContact if True, the user's phone number will be sent
1278 // as a contact when the button is pressed.
1279 // Available in private chats only.
1280 //
1281 // optional
1282 RequestContact bool `json:"request_contact,omitempty"`
1283 // RequestLocation if True, the user's current location will be sent when
1284 // the button is pressed.
1285 // Available in private chats only.
1286 //
1287 // optional
1288 RequestLocation bool `json:"request_location,omitempty"`
1289 // RequestPoll if True, the user will be asked to create a poll and send it
1290 // to the bot when the button is pressed. Available in private chats only
1291 //
1292 // optional
1293 RequestPoll *KeyboardButtonPollType `json:"request_poll,omitempty"`
1294}
1295
1296// KeyboardButtonPollType represents type of poll, which is allowed to
1297// be created and sent when the corresponding button is pressed.
1298type KeyboardButtonPollType struct {
1299 // Type is if quiz is passed, the user will be allowed to create only polls
1300 // in the quiz mode. If regular is passed, only regular polls will be
1301 // allowed. Otherwise, the user will be allowed to create a poll of any type.
1302 Type string `json:"type"`
1303}
1304
1305// ReplyKeyboardRemove Upon receiving a message with this object, Telegram
1306// clients will remove the current custom keyboard and display the default
1307// letter-keyboard. By default, custom keyboards are displayed until a new
1308// keyboard is sent by a bot. An exception is made for one-time keyboards
1309// that are hidden immediately after the user presses a button.
1310type ReplyKeyboardRemove struct {
1311 // RemoveKeyboard requests clients to remove the custom keyboard
1312 // (user will not be able to summon this keyboard;
1313 // if you want to hide the keyboard from sight but keep it accessible,
1314 // use one_time_keyboard in ReplyKeyboardMarkup).
1315 RemoveKeyboard bool `json:"remove_keyboard"`
1316 // Selective use this parameter if you want to remove the keyboard for specific users only.
1317 // Targets:
1318 // 1) users that are @mentioned in the text of the Message object;
1319 // 2) if the bot's message is a reply (has Message.ReplyToMessage not nil), sender of the original message.
1320 //
1321 // Example: A user votes in a poll, bot returns confirmation message
1322 // in reply to the vote and removes the keyboard for that user,
1323 // while still showing the keyboard with poll options to users who haven't voted yet.
1324 //
1325 // optional
1326 Selective bool `json:"selective,omitempty"`
1327}
1328
1329// InlineKeyboardMarkup represents an inline keyboard that appears right next to
1330// the message it belongs to.
1331type InlineKeyboardMarkup struct {
1332 // InlineKeyboard array of button rows, each represented by an Array of
1333 // InlineKeyboardButton objects
1334 InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"`
1335}
1336
1337// InlineKeyboardButton represents one button of an inline keyboard. You must
1338// use exactly one of the optional fields.
1339//
1340// Note that some values are references as even an empty string
1341// will change behavior.
1342//
1343// CallbackGame, if set, MUST be first button in first row.
1344type InlineKeyboardButton struct {
1345 // Text label text on the button
1346 Text string `json:"text"`
1347 // URL HTTP or tg:// url to be opened when button is pressed.
1348 //
1349 // optional
1350 URL *string `json:"url,omitempty"`
1351 // LoginURL is an HTTP URL used to automatically authorize the user. Can be
1352 // used as a replacement for the Telegram Login Widget
1353 //
1354 // optional
1355 LoginURL *LoginURL `json:"login_url,omitempty"`
1356 // CallbackData data to be sent in a callback query to the bot when button is pressed, 1-64 bytes.
1357 //
1358 // optional
1359 CallbackData *string `json:"callback_data,omitempty"`
1360 // SwitchInlineQuery if set, pressing the button will prompt the user to select one of their chats,
1361 // open that chat and insert the bot's username and the specified inline query in the input field.
1362 // Can be empty, in which case just the bot's username will be inserted.
1363 //
1364 // This offers an easy way for users to start using your bot
1365 // in inline mode when they are currently in a private chat with it.
1366 // Especially useful when combined with switch_pm… actions – in this case
1367 // the user will be automatically returned to the chat they switched from,
1368 // skipping the chat selection screen.
1369 //
1370 // optional
1371 SwitchInlineQuery *string `json:"switch_inline_query,omitempty"`
1372 // SwitchInlineQueryCurrentChat if set, pressing the button will insert the bot's username
1373 // and the specified inline query in the current chat's input field.
1374 // Can be empty, in which case only the bot's username will be inserted.
1375 //
1376 // This offers a quick way for the user to open your bot in inline mode
1377 // in the same chat – good for selecting something from multiple options.
1378 //
1379 // optional
1380 SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"`
1381 // CallbackGame description of the game that will be launched when the user presses the button.
1382 //
1383 // optional
1384 CallbackGame *CallbackGame `json:"callback_game,omitempty"`
1385 // Pay specify True, to send a Pay button.
1386 //
1387 // NOTE: This type of button must always be the first button in the first row.
1388 //
1389 // optional
1390 Pay bool `json:"pay,omitempty"`
1391}
1392
1393// LoginURL represents a parameter of the inline keyboard button used to
1394// automatically authorize a user. Serves as a great replacement for the
1395// Telegram Login Widget when the user is coming from Telegram. All the user
1396// needs to do is tap/click a button and confirm that they want to log in.
1397type LoginURL struct {
1398 // URL is an HTTP URL to be opened with user authorization data added to the
1399 // query string when the button is pressed. If the user refuses to provide
1400 // authorization data, the original URL without information about the user
1401 // will be opened. The data added is the same as described in Receiving
1402 // authorization data.
1403 //
1404 // NOTE: You must always check the hash of the received data to verify the
1405 // authentication and the integrity of the data as described in Checking
1406 // authorization.
1407 URL string `json:"url"`
1408 // ForwardText is the new text of the button in forwarded messages
1409 //
1410 // optional
1411 ForwardText string `json:"forward_text,omitempty"`
1412 // BotUsername is the username of a bot, which will be used for user
1413 // authorization. See Setting up a bot for more details. If not specified,
1414 // the current bot's username will be assumed. The url's domain must be the
1415 // same as the domain linked with the bot. See Linking your domain to the
1416 // bot for more details.
1417 //
1418 // optional
1419 BotUsername string `json:"bot_username,omitempty"`
1420 // RequestWriteAccess if true requests permission for your bot to send
1421 // messages to the user
1422 //
1423 // optional
1424 RequestWriteAccess bool `json:"request_write_access,omitempty"`
1425}
1426
1427// CallbackQuery represents an incoming callback query from a callback button in
1428// an inline keyboard. If the button that originated the query was attached to a
1429// message sent by the bot, the field message will be present. If the button was
1430// attached to a message sent via the bot (in inline mode), the field
1431// inline_message_id will be present. Exactly one of the fields data or
1432// game_short_name will be present.
1433type CallbackQuery struct {
1434 // ID unique identifier for this query
1435 ID string `json:"id"`
1436 // From sender
1437 From *User `json:"from"`
1438 // Message with the callback button that originated the query.
1439 // Note that message content and message date will not be available if the
1440 // message is too old.
1441 //
1442 // optional
1443 Message *Message `json:"message,omitempty"`
1444 // InlineMessageID identifier of the message sent via the bot in inline
1445 // mode, that originated the query.
1446 //
1447 // optional
1448 InlineMessageID string `json:"inline_message_id,omitempty"`
1449 // ChatInstance global identifier, uniquely corresponding to the chat to
1450 // which the message with the callback button was sent. Useful for high
1451 // scores in games.
1452 ChatInstance string `json:"chat_instance"`
1453 // Data associated with the callback button. Be aware that
1454 // a bad client can send arbitrary data in this field.
1455 //
1456 // optional
1457 Data string `json:"data,omitempty"`
1458 // GameShortName short name of a Game to be returned, serves as the unique identifier for the game.
1459 //
1460 // optional
1461 GameShortName string `json:"game_short_name,omitempty"`
1462}
1463
1464// ForceReply when receiving a message with this object, Telegram clients will
1465// display a reply interface to the user (act as if the user has selected the
1466// bot's message and tapped 'Reply'). This can be extremely useful if you want
1467// to create user-friendly step-by-step interfaces without having to sacrifice
1468// privacy mode.
1469type ForceReply struct {
1470 // ForceReply shows reply interface to the user,
1471 // as if they manually selected the bot's message and tapped 'Reply'.
1472 ForceReply bool `json:"force_reply"`
1473 // InputFieldPlaceholder is the placeholder to be shown in the input field when
1474 // the reply is active; 1-64 characters.
1475 //
1476 // optional
1477 InputFieldPlaceholder string `json:"input_field_placeholder,omitempty"`
1478 // Selective use this parameter if you want to force reply from specific users only.
1479 // Targets:
1480 // 1) users that are @mentioned in the text of the Message object;
1481 // 2) if the bot's message is a reply (has Message.ReplyToMessage not nil), sender of the original message.
1482 //
1483 // optional
1484 Selective bool `json:"selective,omitempty"`
1485}
1486
1487// ChatPhoto represents a chat photo.
1488type ChatPhoto struct {
1489 // SmallFileID is a file identifier of small (160x160) chat photo.
1490 // This file_id can be used only for photo download and
1491 // only for as long as the photo is not changed.
1492 SmallFileID string `json:"small_file_id"`
1493 // SmallFileUniqueID is a unique file identifier of small (160x160) chat
1494 // photo, which is supposed to be the same over time and for different bots.
1495 // Can't be used to download or reuse the file.
1496 SmallFileUniqueID string `json:"small_file_unique_id"`
1497 // BigFileID is a file identifier of big (640x640) chat photo.
1498 // This file_id can be used only for photo download and
1499 // only for as long as the photo is not changed.
1500 BigFileID string `json:"big_file_id"`
1501 // BigFileUniqueID is a file identifier of big (640x640) chat photo, which
1502 // is supposed to be the same over time and for different bots. Can't be
1503 // used to download or reuse the file.
1504 BigFileUniqueID string `json:"big_file_unique_id"`
1505}
1506
1507// ChatInviteLink represents an invite link for a chat.
1508type ChatInviteLink struct {
1509 // InviteLink is the invite link. If the link was created by another chat
1510 // administrator, then the second part of the link will be replaced with “…”.
1511 InviteLink string `json:"invite_link"`
1512 // Creator of the link.
1513 Creator User `json:"creator"`
1514 // CreatesJoinRequest is true if users joining the chat via the link need to
1515 // be approved by chat administrators.
1516 //
1517 // optional
1518 CreatesJoinRequest bool `json:"creates_join_request"`
1519 // IsPrimary is true, if the link is primary.
1520 IsPrimary bool `json:"is_primary"`
1521 // IsRevoked is true, if the link is revoked.
1522 IsRevoked bool `json:"is_revoked"`
1523 // Name is the name of the invite link.
1524 //
1525 // optional
1526 Name string `json:"name"`
1527 // ExpireDate is the point in time (Unix timestamp) when the link will
1528 // expire or has been expired.
1529 //
1530 // optional
1531 ExpireDate int `json:"expire_date"`
1532 // MemberLimit is the maximum number of users that can be members of the
1533 // chat simultaneously after joining the chat via this invite link; 1-99999.
1534 //
1535 // optional
1536 MemberLimit int `json:"member_limit"`
1537 // PendingJoinRequestCount is the number of pending join requests created
1538 // using this link.
1539 //
1540 // optional
1541 PendingJoinRequestCount int `json:"pending_join_request_count"`
1542}
1543
1544// ChatMember contains information about one member of a chat.
1545type ChatMember struct {
1546 // User information about the user
1547 User *User `json:"user"`
1548 // Status the member's status in the chat.
1549 // Can be
1550 // “creator”,
1551 // “administrator”,
1552 // “member”,
1553 // “restricted”,
1554 // “left” or
1555 // “kicked”
1556 Status string `json:"status"`
1557 // CustomTitle owner and administrators only. Custom title for this user
1558 //
1559 // optional
1560 CustomTitle string `json:"custom_title,omitempty"`
1561 // IsAnonymous owner and administrators only. True, if the user's presence
1562 // in the chat is hidden
1563 //
1564 // optional
1565 IsAnonymous bool `json:"is_anonymous"`
1566 // UntilDate restricted and kicked only.
1567 // Date when restrictions will be lifted for this user;
1568 // unix time.
1569 //
1570 // optional
1571 UntilDate int64 `json:"until_date,omitempty"`
1572 // CanBeEdited administrators only.
1573 // True, if the bot is allowed to edit administrator privileges of that user.
1574 //
1575 // optional
1576 CanBeEdited bool `json:"can_be_edited,omitempty"`
1577 // CanManageChat administrators only.
1578 // True, if the administrator can access the chat event log, chat
1579 // statistics, message statistics in channels, see channel members, see
1580 // anonymous administrators in supergroups and ignore slow mode. Implied by
1581 // any other administrator privilege.
1582 //
1583 // optional
1584 CanManageChat bool `json:"can_manage_chat"`
1585 // CanPostMessages administrators only.
1586 // True, if the administrator can post in the channel;
1587 // channels only.
1588 //
1589 // optional
1590 CanPostMessages bool `json:"can_post_messages,omitempty"`
1591 // CanEditMessages administrators only.
1592 // True, if the administrator can edit messages of other users and can pin messages;
1593 // channels only.
1594 //
1595 // optional
1596 CanEditMessages bool `json:"can_edit_messages,omitempty"`
1597 // CanDeleteMessages administrators only.
1598 // True, if the administrator can delete messages of other users.
1599 //
1600 // optional
1601 CanDeleteMessages bool `json:"can_delete_messages,omitempty"`
1602 // CanManageVoiceChats administrators only.
1603 // True, if the administrator can manage voice chats.
1604 //
1605 // optional
1606 CanManageVoiceChats bool `json:"can_manage_voice_chats"`
1607 // CanRestrictMembers administrators only.
1608 // True, if the administrator can restrict, ban or unban chat members.
1609 //
1610 // optional
1611 CanRestrictMembers bool `json:"can_restrict_members,omitempty"`
1612 // CanPromoteMembers administrators only.
1613 // True, if the administrator can add new administrators
1614 // with a subset of their own privileges or demote administrators that he has promoted,
1615 // directly or indirectly (promoted by administrators that were appointed by the user).
1616 //
1617 // optional
1618 CanPromoteMembers bool `json:"can_promote_members,omitempty"`
1619 // CanChangeInfo administrators and restricted only.
1620 // True, if the user is allowed to change the chat title, photo and other settings.
1621 //
1622 // optional
1623 CanChangeInfo bool `json:"can_change_info,omitempty"`
1624 // CanInviteUsers administrators and restricted only.
1625 // True, if the user is allowed to invite new users to the chat.
1626 //
1627 // optional
1628 CanInviteUsers bool `json:"can_invite_users,omitempty"`
1629 // CanPinMessages administrators and restricted only.
1630 // True, if the user is allowed to pin messages; groups and supergroups only
1631 //
1632 // optional
1633 CanPinMessages bool `json:"can_pin_messages,omitempty"`
1634 // IsMember is true, if the user is a member of the chat at the moment of
1635 // the request
1636 IsMember bool `json:"is_member"`
1637 // CanSendMessages
1638 //
1639 // optional
1640 CanSendMessages bool `json:"can_send_messages,omitempty"`
1641 // CanSendMediaMessages restricted only.
1642 // True, if the user is allowed to send text messages, contacts, locations and venues
1643 //
1644 // optional
1645 CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"`
1646 // CanSendPolls restricted only.
1647 // True, if the user is allowed to send polls
1648 //
1649 // optional
1650 CanSendPolls bool `json:"can_send_polls,omitempty"`
1651 // CanSendOtherMessages restricted only.
1652 // True, if the user is allowed to send audios, documents,
1653 // photos, videos, video notes and voice notes.
1654 //
1655 // optional
1656 CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"`
1657 // CanAddWebPagePreviews restricted only.
1658 // True, if the user is allowed to add web page previews to their messages.
1659 //
1660 // optional
1661 CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"`
1662}
1663
1664// IsCreator returns if the ChatMember was the creator of the chat.
1665func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" }
1666
1667// IsAdministrator returns if the ChatMember is a chat administrator.
1668func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" }
1669
1670// HasLeft returns if the ChatMember left the chat.
1671func (chat ChatMember) HasLeft() bool { return chat.Status == "left" }
1672
1673// WasKicked returns if the ChatMember was kicked from the chat.
1674func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" }
1675
1676// ChatMemberUpdated represents changes in the status of a chat member.
1677type ChatMemberUpdated struct {
1678 // Chat the user belongs to.
1679 Chat Chat `json:"chat"`
1680 // From is the performer of the action, which resulted in the change.
1681 From User `json:"from"`
1682 // Date the change was done in Unix time.
1683 Date int `json:"date"`
1684 // Previous information about the chat member.
1685 OldChatMember ChatMember `json:"old_chat_member"`
1686 // New information about the chat member.
1687 NewChatMember ChatMember `json:"new_chat_member"`
1688 // InviteLink is the link which was used by the user to join the chat;
1689 // for joining by invite link events only.
1690 //
1691 // optional
1692 InviteLink *ChatInviteLink `json:"invite_link"`
1693}
1694
1695// ChatJoinRequest represents a join request sent to a chat.
1696type ChatJoinRequest struct {
1697 // Chat to which the request was sent.
1698 Chat Chat `json:"chat"`
1699 // User that sent the join request.
1700 From User `json:"from"`
1701 // Date the request was sent in Unix time.
1702 Date int `json:"date"`
1703 // Bio of the user.
1704 //
1705 // optional
1706 Bio string `json:"bio"`
1707 // InviteLink is the link that was used by the user to send the join request.
1708 //
1709 // optional
1710 InviteLink *ChatInviteLink `json:"invite_link"`
1711}
1712
1713// ChatPermissions describes actions that a non-administrator user is
1714// allowed to take in a chat. All fields are optional.
1715type ChatPermissions struct {
1716 // CanSendMessages is true, if the user is allowed to send text messages,
1717 // contacts, locations and venues
1718 //
1719 // optional
1720 CanSendMessages bool `json:"can_send_messages,omitempty"`
1721 // CanSendMediaMessages is true, if the user is allowed to send audios,
1722 // documents, photos, videos, video notes and voice notes, implies
1723 // can_send_messages
1724 //
1725 // optional
1726 CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"`
1727 // CanSendPolls is true, if the user is allowed to send polls, implies
1728 // can_send_messages
1729 //
1730 // optional
1731 CanSendPolls bool `json:"can_send_polls,omitempty"`
1732 // CanSendOtherMessages is true, if the user is allowed to send animations,
1733 // games, stickers and use inline bots, implies can_send_media_messages
1734 //
1735 // optional
1736 CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"`
1737 // CanAddWebPagePreviews is true, if the user is allowed to add web page
1738 // previews to their messages, implies can_send_media_messages
1739 //
1740 // optional
1741 CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"`
1742 // CanChangeInfo is true, if the user is allowed to change the chat title,
1743 // photo and other settings. Ignored in public supergroups
1744 //
1745 // optional
1746 CanChangeInfo bool `json:"can_change_info,omitempty"`
1747 // CanInviteUsers is true, if the user is allowed to invite new users to the
1748 // chat
1749 //
1750 // optional
1751 CanInviteUsers bool `json:"can_invite_users,omitempty"`
1752 // CanPinMessages is true, if the user is allowed to pin messages. Ignored
1753 // in public supergroups
1754 //
1755 // optional
1756 CanPinMessages bool `json:"can_pin_messages,omitempty"`
1757}
1758
1759// ChatLocation represents a location to which a chat is connected.
1760type ChatLocation struct {
1761 // Location is the location to which the supergroup is connected. Can't be a
1762 // live location.
1763 Location Location `json:"location"`
1764 // Address is the location address; 1-64 characters, as defined by the chat
1765 // owner
1766 Address string `json:"address"`
1767}
1768
1769// BotCommand represents a bot command.
1770type BotCommand struct {
1771 // Command text of the command, 1-32 characters.
1772 // Can contain only lowercase English letters, digits and underscores.
1773 Command string `json:"command"`
1774 // Description of the command, 3-256 characters.
1775 Description string `json:"description"`
1776}
1777
1778// BotCommandScope represents the scope to which bot commands are applied.
1779//
1780// It contains the fields for all types of scopes, different types only support
1781// specific (or no) fields.
1782type BotCommandScope struct {
1783 Type string `json:"type"`
1784 ChatID int64 `json:"chat_id,omitempty"`
1785 UserID int64 `json:"user_id,omitempty"`
1786}
1787
1788// ResponseParameters are various errors that can be returned in APIResponse.
1789type ResponseParameters struct {
1790 // The group has been migrated to a supergroup with the specified identifier.
1791 //
1792 // optional
1793 MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"`
1794 // In case of exceeding flood control, the number of seconds left to wait
1795 // before the request can be repeated.
1796 //
1797 // optional
1798 RetryAfter int `json:"retry_after,omitempty"`
1799}
1800
1801// BaseInputMedia is a base type for the InputMedia types.
1802type BaseInputMedia struct {
1803 // Type of the result.
1804 Type string `json:"type"`
1805 // Media file to send. Pass a file_id to send a file
1806 // that exists on the Telegram servers (recommended),
1807 // pass an HTTP URL for Telegram to get a file from the Internet,
1808 // or pass “attach://<file_attach_name>” to upload a new one
1809 // using multipart/form-data under <file_attach_name> name.
1810 Media RequestFileData `json:"media"`
1811 // thumb intentionally missing as it is not currently compatible
1812
1813 // Caption of the video to be sent, 0-1024 characters after entities parsing.
1814 //
1815 // optional
1816 Caption string `json:"caption,omitempty"`
1817 // ParseMode mode for parsing entities in the video caption.
1818 // See formatting options for more details
1819 // (https://core.telegram.org/bots/api#formatting-options).
1820 //
1821 // optional
1822 ParseMode string `json:"parse_mode,omitempty"`
1823 // CaptionEntities is a list of special entities that appear in the caption,
1824 // which can be specified instead of parse_mode
1825 //
1826 // optional
1827 CaptionEntities []MessageEntity `json:"caption_entities"`
1828}
1829
1830// InputMediaPhoto is a photo to send as part of a media group.
1831type InputMediaPhoto struct {
1832 BaseInputMedia
1833}
1834
1835// InputMediaVideo is a video to send as part of a media group.
1836type InputMediaVideo struct {
1837 BaseInputMedia
1838 // Thumbnail of the file sent; can be ignored if thumbnail generation for
1839 // the file is supported server-side.
1840 //
1841 // optional
1842 Thumb RequestFileData `json:"thumb,omitempty"`
1843 // Width video width
1844 //
1845 // optional
1846 Width int `json:"width,omitempty"`
1847 // Height video height
1848 //
1849 // optional
1850 Height int `json:"height,omitempty"`
1851 // Duration video duration
1852 //
1853 // optional
1854 Duration int `json:"duration,omitempty"`
1855 // SupportsStreaming pass True, if the uploaded video is suitable for streaming.
1856 //
1857 // optional
1858 SupportsStreaming bool `json:"supports_streaming,omitempty"`
1859}
1860
1861// InputMediaAnimation is an animation to send as part of a media group.
1862type InputMediaAnimation struct {
1863 BaseInputMedia
1864 // Thumbnail of the file sent; can be ignored if thumbnail generation for
1865 // the file is supported server-side.
1866 //
1867 // optional
1868 Thumb RequestFileData `json:"thumb,omitempty"`
1869 // Width video width
1870 //
1871 // optional
1872 Width int `json:"width,omitempty"`
1873 // Height video height
1874 //
1875 // optional
1876 Height int `json:"height,omitempty"`
1877 // Duration video duration
1878 //
1879 // optional
1880 Duration int `json:"duration,omitempty"`
1881}
1882
1883// InputMediaAudio is an audio to send as part of a media group.
1884type InputMediaAudio struct {
1885 BaseInputMedia
1886 // Thumbnail of the file sent; can be ignored if thumbnail generation for
1887 // the file is supported server-side.
1888 //
1889 // optional
1890 Thumb RequestFileData `json:"thumb,omitempty"`
1891 // Duration of the audio in seconds
1892 //
1893 // optional
1894 Duration int `json:"duration,omitempty"`
1895 // Performer of the audio
1896 //
1897 // optional
1898 Performer string `json:"performer,omitempty"`
1899 // Title of the audio
1900 //
1901 // optional
1902 Title string `json:"title,omitempty"`
1903}
1904
1905// InputMediaDocument is a general file to send as part of a media group.
1906type InputMediaDocument struct {
1907 BaseInputMedia
1908 // Thumbnail of the file sent; can be ignored if thumbnail generation for
1909 // the file is supported server-side.
1910 //
1911 // optional
1912 Thumb RequestFileData `json:"thumb,omitempty"`
1913 // DisableContentTypeDetection disables automatic server-side content type
1914 // detection for files uploaded using multipart/form-data. Always true, if
1915 // the document is sent as part of an album
1916 //
1917 // optional
1918 DisableContentTypeDetection bool `json:"disable_content_type_detection,omitempty"`
1919}
1920
1921// Sticker represents a sticker.
1922type Sticker struct {
1923 // FileID is an identifier for this file, which can be used to download or
1924 // reuse the file
1925 FileID string `json:"file_id"`
1926 // FileUniqueID is a unique identifier for this file,
1927 // which is supposed to be the same over time and for different bots.
1928 // Can't be used to download or reuse the file.
1929 FileUniqueID string `json:"file_unique_id"`
1930 // Width sticker width
1931 Width int `json:"width"`
1932 // Height sticker height
1933 Height int `json:"height"`
1934 // IsAnimated true, if the sticker is animated
1935 //
1936 // optional
1937 IsAnimated bool `json:"is_animated,omitempty"`
1938 // Thumbnail sticker thumbnail in the .WEBP or .JPG format
1939 //
1940 // optional
1941 Thumbnail *PhotoSize `json:"thumb,omitempty"`
1942 // Emoji associated with the sticker
1943 //
1944 // optional
1945 Emoji string `json:"emoji,omitempty"`
1946 // SetName of the sticker set to which the sticker belongs
1947 //
1948 // optional
1949 SetName string `json:"set_name,omitempty"`
1950 // MaskPosition is for mask stickers, the position where the mask should be
1951 // placed
1952 //
1953 // optional
1954 MaskPosition *MaskPosition `json:"mask_position,omitempty"`
1955 // FileSize
1956 //
1957 // optional
1958 FileSize int `json:"file_size,omitempty"`
1959}
1960
1961// StickerSet represents a sticker set.
1962type StickerSet struct {
1963 // Name sticker set name
1964 Name string `json:"name"`
1965 // Title sticker set title
1966 Title string `json:"title"`
1967 // IsAnimated true, if the sticker set contains animated stickers
1968 IsAnimated bool `json:"is_animated"`
1969 // ContainsMasks true, if the sticker set contains masks
1970 ContainsMasks bool `json:"contains_masks"`
1971 // Stickers list of all set stickers
1972 Stickers []Sticker `json:"stickers"`
1973 // Thumb is the sticker set thumbnail in the .WEBP or .TGS format
1974 Thumbnail *PhotoSize `json:"thumb"`
1975}
1976
1977// MaskPosition describes the position on faces where a mask should be placed
1978// by default.
1979type MaskPosition struct {
1980 // The part of the face relative to which the mask should be placed.
1981 // One of “forehead”, “eyes”, “mouth”, or “chin”.
1982 Point string `json:"point"`
1983 // Shift by X-axis measured in widths of the mask scaled to the face size,
1984 // from left to right. For example, choosing -1.0 will place mask just to
1985 // the left of the default mask position.
1986 XShift float64 `json:"x_shift"`
1987 // Shift by Y-axis measured in heights of the mask scaled to the face size,
1988 // from top to bottom. For example, 1.0 will place the mask just below the
1989 // default mask position.
1990 YShift float64 `json:"y_shift"`
1991 // Mask scaling coefficient. For example, 2.0 means double size.
1992 Scale float64 `json:"scale"`
1993}
1994
1995// Game represents a game. Use BotFather to create and edit games, their short
1996// names will act as unique identifiers.
1997type Game struct {
1998 // Title of the game
1999 Title string `json:"title"`
2000 // Description of the game
2001 Description string `json:"description"`
2002 // Photo that will be displayed in the game message in chats.
2003 Photo []PhotoSize `json:"photo"`
2004 // Text a brief description of the game or high scores included in the game message.
2005 // Can be automatically edited to include current high scores for the game
2006 // when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters.
2007 //
2008 // optional
2009 Text string `json:"text,omitempty"`
2010 // TextEntities special entities that appear in text, such as usernames, URLs, bot commands, etc.
2011 //
2012 // optional
2013 TextEntities []MessageEntity `json:"text_entities,omitempty"`
2014 // Animation is an animation that will be displayed in the game message in chats.
2015 // Upload via BotFather (https://t.me/botfather).
2016 //
2017 // optional
2018 Animation Animation `json:"animation,omitempty"`
2019}
2020
2021// GameHighScore is a user's score and position on the leaderboard.
2022type GameHighScore struct {
2023 // Position in high score table for the game
2024 Position int `json:"position"`
2025 // User user
2026 User User `json:"user"`
2027 // Score score
2028 Score int `json:"score"`
2029}
2030
2031// CallbackGame is for starting a game in an inline keyboard button.
2032type CallbackGame struct{}
2033
2034// WebhookInfo is information about a currently set webhook.
2035type WebhookInfo struct {
2036 // URL webhook URL, may be empty if webhook is not set up.
2037 URL string `json:"url"`
2038 // HasCustomCertificate true, if a custom certificate was provided for webhook certificate checks.
2039 HasCustomCertificate bool `json:"has_custom_certificate"`
2040 // PendingUpdateCount number of updates awaiting delivery.
2041 PendingUpdateCount int `json:"pending_update_count"`
2042 // IPAddress is the currently used webhook IP address
2043 //
2044 // optional
2045 IPAddress string `json:"ip_address,omitempty"`
2046 // LastErrorDate unix time for the most recent error
2047 // that happened when trying to deliver an update via webhook.
2048 //
2049 // optional
2050 LastErrorDate int `json:"last_error_date,omitempty"`
2051 // LastErrorMessage error message in human-readable format for the most recent error
2052 // that happened when trying to deliver an update via webhook.
2053 //
2054 // optional
2055 LastErrorMessage string `json:"last_error_message,omitempty"`
2056 // MaxConnections maximum allowed number of simultaneous
2057 // HTTPS connections to the webhook for update delivery.
2058 //
2059 // optional
2060 MaxConnections int `json:"max_connections,omitempty"`
2061 // AllowedUpdates is a list of update types the bot is subscribed to.
2062 // Defaults to all update types
2063 //
2064 // optional
2065 AllowedUpdates []string `json:"allowed_updates,omitempty"`
2066}
2067
2068// IsSet returns true if a webhook is currently set.
2069func (info WebhookInfo) IsSet() bool {
2070 return info.URL != ""
2071}
2072
2073// InlineQuery is a Query from Telegram for an inline request.
2074type InlineQuery struct {
2075 // ID unique identifier for this query
2076 ID string `json:"id"`
2077 // From sender
2078 From *User `json:"from"`
2079 // Query text of the query (up to 256 characters).
2080 Query string `json:"query"`
2081 // Offset of the results to be returned, can be controlled by the bot.
2082 Offset string `json:"offset"`
2083 // Type of the chat, from which the inline query was sent. Can be either
2084 // “sender” for a private chat with the inline query sender, “private”,
2085 // “group”, “supergroup”, or “channel”. The chat type should be always known
2086 // for requests sent from official clients and most third-party clients,
2087 // unless the request was sent from a secret chat
2088 //
2089 // optional
2090 ChatType string `json:"chat_type"`
2091 // Location sender location, only for bots that request user location.
2092 //
2093 // optional
2094 Location *Location `json:"location,omitempty"`
2095}
2096
2097// InlineQueryResultCachedAudio is an inline query response with cached audio.
2098type InlineQueryResultCachedAudio struct {
2099 // Type of the result, must be audio
2100 Type string `json:"type"`
2101 // ID unique identifier for this result, 1-64 bytes
2102 ID string `json:"id"`
2103 // AudioID a valid file identifier for the audio file
2104 AudioID string `json:"audio_file_id"`
2105 // Caption 0-1024 characters after entities parsing
2106 //
2107 // optional
2108 Caption string `json:"caption,omitempty"`
2109 // ParseMode mode for parsing entities in the video caption.
2110 // See formatting options for more details
2111 // (https://core.telegram.org/bots/api#formatting-options).
2112 //
2113 // optional
2114 ParseMode string `json:"parse_mode,omitempty"`
2115 // CaptionEntities is a list of special entities that appear in the caption,
2116 // which can be specified instead of parse_mode
2117 //
2118 // optional
2119 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2120 // ReplyMarkup inline keyboard attached to the message
2121 //
2122 // optional
2123 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2124 // InputMessageContent content of the message to be sent instead of the audio
2125 //
2126 // optional
2127 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2128}
2129
2130// InlineQueryResultCachedDocument is an inline query response with cached document.
2131type InlineQueryResultCachedDocument struct {
2132 // Type of the result, must be a document
2133 Type string `json:"type"`
2134 // ID unique identifier for this result, 1-64 bytes
2135 ID string `json:"id"`
2136 // DocumentID a valid file identifier for the file
2137 DocumentID string `json:"document_file_id"`
2138 // Title for the result
2139 //
2140 // optional
2141 Title string `json:"title,omitempty"`
2142 // Caption of the document to be sent, 0-1024 characters after entities parsing
2143 //
2144 // optional
2145 Caption string `json:"caption,omitempty"`
2146 // Description short description of the result
2147 //
2148 // optional
2149 Description string `json:"description,omitempty"`
2150 // ParseMode mode for parsing entities in the video caption.
2151 // // See formatting options for more details
2152 // // (https://core.telegram.org/bots/api#formatting-options).
2153 //
2154 // optional
2155 ParseMode string `json:"parse_mode,omitempty"`
2156 // CaptionEntities is a list of special entities that appear in the caption,
2157 // which can be specified instead of parse_mode
2158 //
2159 // optional
2160 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2161 // ReplyMarkup inline keyboard attached to the message
2162 //
2163 // optional
2164 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2165 // InputMessageContent content of the message to be sent instead of the file
2166 //
2167 // optional
2168 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2169}
2170
2171// InlineQueryResultCachedGIF is an inline query response with cached gif.
2172type InlineQueryResultCachedGIF struct {
2173 // Type of the result, must be gif.
2174 Type string `json:"type"`
2175 // ID unique identifier for this result, 1-64 bytes.
2176 ID string `json:"id"`
2177 // GifID a valid file identifier for the GIF file.
2178 GIFID string `json:"gif_file_id"`
2179 // Title for the result
2180 //
2181 // optional
2182 Title string `json:"title,omitempty"`
2183 // Caption of the GIF file to be sent, 0-1024 characters after entities parsing.
2184 //
2185 // optional
2186 Caption string `json:"caption,omitempty"`
2187 // ParseMode mode for parsing entities in the caption.
2188 // See formatting options for more details
2189 // (https://core.telegram.org/bots/api#formatting-options).
2190 //
2191 // optional
2192 ParseMode string `json:"parse_mode,omitempty"`
2193 // CaptionEntities is a list of special entities that appear in the caption,
2194 // which can be specified instead of parse_mode
2195 //
2196 // optional
2197 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2198 // ReplyMarkup inline keyboard attached to the message.
2199 //
2200 // optional
2201 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2202 // InputMessageContent content of the message to be sent instead of the GIF animation.
2203 //
2204 // optional
2205 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2206}
2207
2208// InlineQueryResultCachedMPEG4GIF is an inline query response with cached
2209// H.264/MPEG-4 AVC video without sound gif.
2210type InlineQueryResultCachedMPEG4GIF struct {
2211 // Type of the result, must be mpeg4_gif
2212 Type string `json:"type"`
2213 // ID unique identifier for this result, 1-64 bytes
2214 ID string `json:"id"`
2215 // MPEG4FileID a valid file identifier for the MP4 file
2216 MPEG4FileID string `json:"mpeg4_file_id"`
2217 // Title for the result
2218 //
2219 // optional
2220 Title string `json:"title,omitempty"`
2221 // Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing.
2222 //
2223 // optional
2224 Caption string `json:"caption,omitempty"`
2225 // ParseMode mode for parsing entities in the caption.
2226 // See formatting options for more details
2227 // (https://core.telegram.org/bots/api#formatting-options).
2228 //
2229 // optional
2230 ParseMode string `json:"parse_mode,omitempty"`
2231 // ParseMode mode for parsing entities in the video caption.
2232 // See formatting options for more details
2233 // (https://core.telegram.org/bots/api#formatting-options).
2234 //
2235 // optional
2236 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2237 // ReplyMarkup inline keyboard attached to the message.
2238 //
2239 // optional
2240 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2241 // InputMessageContent content of the message to be sent instead of the video animation.
2242 //
2243 // optional
2244 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2245}
2246
2247// InlineQueryResultCachedPhoto is an inline query response with cached photo.
2248type InlineQueryResultCachedPhoto struct {
2249 // Type of the result, must be a photo.
2250 Type string `json:"type"`
2251 // ID unique identifier for this result, 1-64 bytes.
2252 ID string `json:"id"`
2253 // PhotoID a valid file identifier of the photo.
2254 PhotoID string `json:"photo_file_id"`
2255 // Title for the result.
2256 //
2257 // optional
2258 Title string `json:"title,omitempty"`
2259 // Description short description of the result.
2260 //
2261 // optional
2262 Description string `json:"description,omitempty"`
2263 // Caption of the photo to be sent, 0-1024 characters after entities parsing.
2264 //
2265 // optional
2266 Caption string `json:"caption,omitempty"`
2267 // ParseMode mode for parsing entities in the photo caption.
2268 // See formatting options for more details
2269 // (https://core.telegram.org/bots/api#formatting-options).
2270 //
2271 // optional
2272 ParseMode string `json:"parse_mode,omitempty"`
2273 // CaptionEntities is a list of special entities that appear in the caption,
2274 // which can be specified instead of parse_mode
2275 //
2276 // optional
2277 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2278 // ReplyMarkup inline keyboard attached to the message.
2279 //
2280 // optional
2281 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2282 // InputMessageContent content of the message to be sent instead of the photo.
2283 //
2284 // optional
2285 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2286}
2287
2288// InlineQueryResultCachedSticker is an inline query response with cached sticker.
2289type InlineQueryResultCachedSticker struct {
2290 // Type of the result, must be a sticker
2291 Type string `json:"type"`
2292 // ID unique identifier for this result, 1-64 bytes
2293 ID string `json:"id"`
2294 // StickerID a valid file identifier of the sticker
2295 StickerID string `json:"sticker_file_id"`
2296 // Title is a title
2297 Title string `json:"title"`
2298 // ReplyMarkup inline keyboard attached to the message
2299 //
2300 // optional
2301 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2302 // InputMessageContent content of the message to be sent instead of the sticker
2303 //
2304 // optional
2305 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2306}
2307
2308// InlineQueryResultCachedVideo is an inline query response with cached video.
2309type InlineQueryResultCachedVideo struct {
2310 // Type of the result, must be video
2311 Type string `json:"type"`
2312 // ID unique identifier for this result, 1-64 bytes
2313 ID string `json:"id"`
2314 // VideoID a valid file identifier for the video file
2315 VideoID string `json:"video_file_id"`
2316 // Title for the result
2317 Title string `json:"title"`
2318 // Description short description of the result
2319 //
2320 // optional
2321 Description string `json:"description,omitempty"`
2322 // Caption of the video to be sent, 0-1024 characters after entities parsing
2323 //
2324 // optional
2325 Caption string `json:"caption,omitempty"`
2326 // ParseMode mode for parsing entities in the video caption.
2327 // See formatting options for more details
2328 // (https://core.telegram.org/bots/api#formatting-options).
2329 //
2330 // optional
2331 ParseMode string `json:"parse_mode,omitempty"`
2332 // CaptionEntities is a list of special entities that appear in the caption,
2333 // which can be specified instead of parse_mode
2334 //
2335 // optional
2336 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2337 // ReplyMarkup inline keyboard attached to the message
2338 //
2339 // optional
2340 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2341 // InputMessageContent content of the message to be sent instead of the video
2342 //
2343 // optional
2344 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2345}
2346
2347// InlineQueryResultCachedVoice is an inline query response with cached voice.
2348type InlineQueryResultCachedVoice struct {
2349 // Type of the result, must be voice
2350 Type string `json:"type"`
2351 // ID unique identifier for this result, 1-64 bytes
2352 ID string `json:"id"`
2353 // VoiceID a valid file identifier for the voice message
2354 VoiceID string `json:"voice_file_id"`
2355 // Title voice message title
2356 Title string `json:"title"`
2357 // Caption 0-1024 characters after entities parsing
2358 //
2359 // optional
2360 Caption string `json:"caption,omitempty"`
2361 // ParseMode mode for parsing entities in the video caption.
2362 // See formatting options for more details
2363 // (https://core.telegram.org/bots/api#formatting-options).
2364 //
2365 // optional
2366 ParseMode string `json:"parse_mode,omitempty"`
2367 // CaptionEntities is a list of special entities that appear in the caption,
2368 // which can be specified instead of parse_mode
2369 //
2370 // optional
2371 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2372 // ReplyMarkup inline keyboard attached to the message
2373 //
2374 // optional
2375 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2376 // InputMessageContent content of the message to be sent instead of the voice message
2377 //
2378 // optional
2379 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2380}
2381
2382// InlineQueryResultArticle represents a link to an article or web page.
2383type InlineQueryResultArticle struct {
2384 // Type of the result, must be article.
2385 Type string `json:"type"`
2386 // ID unique identifier for this result, 1-64 Bytes.
2387 ID string `json:"id"`
2388 // Title of the result
2389 Title string `json:"title"`
2390 // InputMessageContent content of the message to be sent.
2391 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2392 // ReplyMarkup Inline keyboard attached to the message.
2393 //
2394 // optional
2395 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2396 // URL of the result.
2397 //
2398 // optional
2399 URL string `json:"url,omitempty"`
2400 // HideURL pass True, if you don't want the URL to be shown in the message.
2401 //
2402 // optional
2403 HideURL bool `json:"hide_url,omitempty"`
2404 // Description short description of the result.
2405 //
2406 // optional
2407 Description string `json:"description,omitempty"`
2408 // ThumbURL url of the thumbnail for the result
2409 //
2410 // optional
2411 ThumbURL string `json:"thumb_url,omitempty"`
2412 // ThumbWidth thumbnail width
2413 //
2414 // optional
2415 ThumbWidth int `json:"thumb_width,omitempty"`
2416 // ThumbHeight thumbnail height
2417 //
2418 // optional
2419 ThumbHeight int `json:"thumb_height,omitempty"`
2420}
2421
2422// InlineQueryResultAudio is an inline query response audio.
2423type InlineQueryResultAudio struct {
2424 // Type of the result, must be audio
2425 Type string `json:"type"`
2426 // ID unique identifier for this result, 1-64 bytes
2427 ID string `json:"id"`
2428 // URL a valid url for the audio file
2429 URL string `json:"audio_url"`
2430 // Title is a title
2431 Title string `json:"title"`
2432 // Caption 0-1024 characters after entities parsing
2433 //
2434 // optional
2435 Caption string `json:"caption,omitempty"`
2436 // ParseMode mode for parsing entities in the video caption.
2437 // See formatting options for more details
2438 // (https://core.telegram.org/bots/api#formatting-options).
2439 //
2440 // optional
2441 ParseMode string `json:"parse_mode,omitempty"`
2442 // CaptionEntities is a list of special entities that appear in the caption,
2443 // which can be specified instead of parse_mode
2444 //
2445 // optional
2446 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2447 // Performer is a performer
2448 //
2449 // optional
2450 Performer string `json:"performer,omitempty"`
2451 // Duration audio duration in seconds
2452 //
2453 // optional
2454 Duration int `json:"audio_duration,omitempty"`
2455 // ReplyMarkup inline keyboard attached to the message
2456 //
2457 // optional
2458 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2459 // InputMessageContent content of the message to be sent instead of the audio
2460 //
2461 // optional
2462 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2463}
2464
2465// InlineQueryResultContact is an inline query response contact.
2466type InlineQueryResultContact struct {
2467 Type string `json:"type"` // required
2468 ID string `json:"id"` // required
2469 PhoneNumber string `json:"phone_number"` // required
2470 FirstName string `json:"first_name"` // required
2471 LastName string `json:"last_name"`
2472 VCard string `json:"vcard"`
2473 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2474 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2475 ThumbURL string `json:"thumb_url"`
2476 ThumbWidth int `json:"thumb_width"`
2477 ThumbHeight int `json:"thumb_height"`
2478}
2479
2480// InlineQueryResultGame is an inline query response game.
2481type InlineQueryResultGame struct {
2482 // Type of the result, must be game
2483 Type string `json:"type"`
2484 // ID unique identifier for this result, 1-64 bytes
2485 ID string `json:"id"`
2486 // GameShortName short name of the game
2487 GameShortName string `json:"game_short_name"`
2488 // ReplyMarkup inline keyboard attached to the message
2489 //
2490 // optional
2491 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2492}
2493
2494// InlineQueryResultDocument is an inline query response document.
2495type InlineQueryResultDocument struct {
2496 // Type of the result, must be a document
2497 Type string `json:"type"`
2498 // ID unique identifier for this result, 1-64 bytes
2499 ID string `json:"id"`
2500 // Title for the result
2501 Title string `json:"title"`
2502 // Caption of the document to be sent, 0-1024 characters after entities parsing
2503 //
2504 // optional
2505 Caption string `json:"caption,omitempty"`
2506 // URL a valid url for the file
2507 URL string `json:"document_url"`
2508 // MimeType of the content of the file, either “application/pdf” or “application/zip”
2509 MimeType string `json:"mime_type"`
2510 // Description short description of the result
2511 //
2512 // optional
2513 Description string `json:"description,omitempty"`
2514 // ReplyMarkup inline keyboard attached to the message
2515 //
2516 // optional
2517 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2518 // InputMessageContent content of the message to be sent instead of the file
2519 //
2520 // optional
2521 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2522 // ThumbURL url of the thumbnail (jpeg only) for the file
2523 //
2524 // optional
2525 ThumbURL string `json:"thumb_url,omitempty"`
2526 // ThumbWidth thumbnail width
2527 //
2528 // optional
2529 ThumbWidth int `json:"thumb_width,omitempty"`
2530 // ThumbHeight thumbnail height
2531 //
2532 // optional
2533 ThumbHeight int `json:"thumb_height,omitempty"`
2534}
2535
2536// InlineQueryResultGIF is an inline query response GIF.
2537type InlineQueryResultGIF struct {
2538 // Type of the result, must be gif.
2539 Type string `json:"type"`
2540 // ID unique identifier for this result, 1-64 bytes.
2541 ID string `json:"id"`
2542 // URL a valid URL for the GIF file. File size must not exceed 1MB.
2543 URL string `json:"gif_url"`
2544 // ThumbURL url of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result.
2545 ThumbURL string `json:"thumb_url"`
2546 // Width of the GIF
2547 //
2548 // optional
2549 Width int `json:"gif_width,omitempty"`
2550 // Height of the GIF
2551 //
2552 // optional
2553 Height int `json:"gif_height,omitempty"`
2554 // Duration of the GIF
2555 //
2556 // optional
2557 Duration int `json:"gif_duration,omitempty"`
2558 // Title for the result
2559 //
2560 // optional
2561 Title string `json:"title,omitempty"`
2562 // Caption of the GIF file to be sent, 0-1024 characters after entities parsing.
2563 //
2564 // optional
2565 Caption string `json:"caption,omitempty"`
2566 // ParseMode mode for parsing entities in the video caption.
2567 // See formatting options for more details
2568 // (https://core.telegram.org/bots/api#formatting-options).
2569 //
2570 // optional
2571 ParseMode string `json:"parse_mode,omitempty"`
2572 // CaptionEntities is a list of special entities that appear in the caption,
2573 // which can be specified instead of parse_mode
2574 //
2575 // optional
2576 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2577 // ReplyMarkup inline keyboard attached to the message
2578 //
2579 // optional
2580 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2581 // InputMessageContent content of the message to be sent instead of the GIF animation.
2582 //
2583 // optional
2584 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2585}
2586
2587// InlineQueryResultLocation is an inline query response location.
2588type InlineQueryResultLocation struct {
2589 // Type of the result, must be location
2590 Type string `json:"type"`
2591 // ID unique identifier for this result, 1-64 Bytes
2592 ID string `json:"id"`
2593 // Latitude of the location in degrees
2594 Latitude float64 `json:"latitude"`
2595 // Longitude of the location in degrees
2596 Longitude float64 `json:"longitude"`
2597 // Title of the location
2598 Title string `json:"title"`
2599 // HorizontalAccuracy is the radius of uncertainty for the location,
2600 // measured in meters; 0-1500
2601 //
2602 // optional
2603 HorizontalAccuracy float64 `json:"horizontal_accuracy"`
2604 // LivePeriod is the period in seconds for which the location can be
2605 // updated, should be between 60 and 86400.
2606 //
2607 // optional
2608 LivePeriod int `json:"live_period"`
2609 // Heading is for live locations, a direction in which the user is moving,
2610 // in degrees. Must be between 1 and 360 if specified.
2611 //
2612 // optional
2613 Heading int `json:"heading"`
2614 // ProximityAlertRadius is for live locations, a maximum distance for
2615 // proximity alerts about approaching another chat member, in meters. Must
2616 // be between 1 and 100000 if specified.
2617 //
2618 // optional
2619 ProximityAlertRadius int `json:"proximity_alert_radius"`
2620 // ReplyMarkup inline keyboard attached to the message
2621 //
2622 // optional
2623 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2624 // InputMessageContent content of the message to be sent instead of the location
2625 //
2626 // optional
2627 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2628 // ThumbURL url of the thumbnail for the result
2629 //
2630 // optional
2631 ThumbURL string `json:"thumb_url,omitempty"`
2632 // ThumbWidth thumbnail width
2633 //
2634 // optional
2635 ThumbWidth int `json:"thumb_width,omitempty"`
2636 // ThumbHeight thumbnail height
2637 //
2638 // optional
2639 ThumbHeight int `json:"thumb_height,omitempty"`
2640}
2641
2642// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF.
2643type InlineQueryResultMPEG4GIF struct {
2644 // Type of the result, must be mpeg4_gif
2645 Type string `json:"type"`
2646 // ID unique identifier for this result, 1-64 bytes
2647 ID string `json:"id"`
2648 // URL a valid URL for the MP4 file. File size must not exceed 1MB
2649 URL string `json:"mpeg4_url"`
2650 // Width video width
2651 //
2652 // optional
2653 Width int `json:"mpeg4_width"`
2654 // Height vVideo height
2655 //
2656 // optional
2657 Height int `json:"mpeg4_height"`
2658 // Duration video duration
2659 //
2660 // optional
2661 Duration int `json:"mpeg4_duration"`
2662 // ThumbURL url of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result.
2663 ThumbURL string `json:"thumb_url"`
2664 // Title for the result
2665 //
2666 // optional
2667 Title string `json:"title,omitempty"`
2668 // Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing.
2669 //
2670 // optional
2671 Caption string `json:"caption,omitempty"`
2672 // ParseMode mode for parsing entities in the video caption.
2673 // See formatting options for more details
2674 // (https://core.telegram.org/bots/api#formatting-options).
2675 //
2676 // optional
2677 ParseMode string `json:"parse_mode,omitempty"`
2678 // CaptionEntities is a list of special entities that appear in the caption,
2679 // which can be specified instead of parse_mode
2680 //
2681 // optional
2682 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2683 // ReplyMarkup inline keyboard attached to the message
2684 //
2685 // optional
2686 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2687 // InputMessageContent content of the message to be sent instead of the video animation
2688 //
2689 // optional
2690 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2691}
2692
2693// InlineQueryResultPhoto is an inline query response photo.
2694type InlineQueryResultPhoto struct {
2695 // Type of the result, must be article.
2696 Type string `json:"type"`
2697 // ID unique identifier for this result, 1-64 Bytes.
2698 ID string `json:"id"`
2699 // URL a valid URL of the photo. Photo must be in jpeg format.
2700 // Photo size must not exceed 5MB.
2701 URL string `json:"photo_url"`
2702 // MimeType
2703 MimeType string `json:"mime_type"`
2704 // Width of the photo
2705 //
2706 // optional
2707 Width int `json:"photo_width,omitempty"`
2708 // Height of the photo
2709 //
2710 // optional
2711 Height int `json:"photo_height,omitempty"`
2712 // ThumbURL url of the thumbnail for the photo.
2713 //
2714 // optional
2715 ThumbURL string `json:"thumb_url,omitempty"`
2716 // Title for the result
2717 //
2718 // optional
2719 Title string `json:"title,omitempty"`
2720 // Description short description of the result
2721 //
2722 // optional
2723 Description string `json:"description,omitempty"`
2724 // Caption of the photo to be sent, 0-1024 characters after entities parsing.
2725 //
2726 // optional
2727 Caption string `json:"caption,omitempty"`
2728 // ParseMode mode for parsing entities in the photo caption.
2729 // See formatting options for more details
2730 // (https://core.telegram.org/bots/api#formatting-options).
2731 //
2732 // optional
2733 ParseMode string `json:"parse_mode,omitempty"`
2734 // ReplyMarkup inline keyboard attached to the message.
2735 //
2736 // optional
2737 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2738 // CaptionEntities is a list of special entities that appear in the caption,
2739 // which can be specified instead of parse_mode
2740 //
2741 // optional
2742 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2743 // InputMessageContent content of the message to be sent instead of the photo.
2744 //
2745 // optional
2746 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2747}
2748
2749// InlineQueryResultVenue is an inline query response venue.
2750type InlineQueryResultVenue struct {
2751 // Type of the result, must be venue
2752 Type string `json:"type"`
2753 // ID unique identifier for this result, 1-64 Bytes
2754 ID string `json:"id"`
2755 // Latitude of the venue location in degrees
2756 Latitude float64 `json:"latitude"`
2757 // Longitude of the venue location in degrees
2758 Longitude float64 `json:"longitude"`
2759 // Title of the venue
2760 Title string `json:"title"`
2761 // Address of the venue
2762 Address string `json:"address"`
2763 // FoursquareID foursquare identifier of the venue if known
2764 //
2765 // optional
2766 FoursquareID string `json:"foursquare_id,omitempty"`
2767 // FoursquareType foursquare type of the venue, if known.
2768 // (For example, “arts_entertainment/default”, “arts_entertainment/aquarium” or “food/icecream”.)
2769 //
2770 // optional
2771 FoursquareType string `json:"foursquare_type,omitempty"`
2772 // GooglePlaceID is the Google Places identifier of the venue
2773 //
2774 // optional
2775 GooglePlaceID string `json:"google_place_id,omitempty"`
2776 // GooglePlaceType is the Google Places type of the venue
2777 //
2778 // optional
2779 GooglePlaceType string `json:"google_place_type,omitempty"`
2780 // ReplyMarkup inline keyboard attached to the message
2781 //
2782 // optional
2783 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2784 // InputMessageContent content of the message to be sent instead of the venue
2785 //
2786 // optional
2787 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2788 // ThumbURL url of the thumbnail for the result
2789 //
2790 // optional
2791 ThumbURL string `json:"thumb_url,omitempty"`
2792 // ThumbWidth thumbnail width
2793 //
2794 // optional
2795 ThumbWidth int `json:"thumb_width,omitempty"`
2796 // ThumbHeight thumbnail height
2797 //
2798 // optional
2799 ThumbHeight int `json:"thumb_height,omitempty"`
2800}
2801
2802// InlineQueryResultVideo is an inline query response video.
2803type InlineQueryResultVideo struct {
2804 // Type of the result, must be video
2805 Type string `json:"type"`
2806 // ID unique identifier for this result, 1-64 bytes
2807 ID string `json:"id"`
2808 // URL a valid url for the embedded video player or video file
2809 URL string `json:"video_url"`
2810 // MimeType of the content of video url, “text/html” or “video/mp4”
2811 MimeType string `json:"mime_type"`
2812 //
2813 // ThumbURL url of the thumbnail (jpeg only) for the video
2814 // optional
2815 ThumbURL string `json:"thumb_url,omitempty"`
2816 // Title for the result
2817 Title string `json:"title"`
2818 // Caption of the video to be sent, 0-1024 characters after entities parsing
2819 //
2820 // optional
2821 Caption string `json:"caption,omitempty"`
2822 // Width video width
2823 //
2824 // optional
2825 Width int `json:"video_width,omitempty"`
2826 // Height video height
2827 //
2828 // optional
2829 Height int `json:"video_height,omitempty"`
2830 // Duration video duration in seconds
2831 //
2832 // optional
2833 Duration int `json:"video_duration,omitempty"`
2834 // Description short description of the result
2835 //
2836 // optional
2837 Description string `json:"description,omitempty"`
2838 // ReplyMarkup inline keyboard attached to the message
2839 //
2840 // optional
2841 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2842 // InputMessageContent content of the message to be sent instead of the video.
2843 // This field is required if InlineQueryResultVideo is used to send
2844 // an HTML-page as a result (e.g., a YouTube video).
2845 //
2846 // optional
2847 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2848}
2849
2850// InlineQueryResultVoice is an inline query response voice.
2851type InlineQueryResultVoice struct {
2852 // Type of the result, must be voice
2853 Type string `json:"type"`
2854 // ID unique identifier for this result, 1-64 bytes
2855 ID string `json:"id"`
2856 // URL a valid URL for the voice recording
2857 URL string `json:"voice_url"`
2858 // Title recording title
2859 Title string `json:"title"`
2860 // Caption 0-1024 characters after entities parsing
2861 //
2862 // optional
2863 Caption string `json:"caption,omitempty"`
2864 // ParseMode mode for parsing entities in the video caption.
2865 // See formatting options for more details
2866 // (https://core.telegram.org/bots/api#formatting-options).
2867 //
2868 // optional
2869 ParseMode string `json:"parse_mode,omitempty"`
2870 // CaptionEntities is a list of special entities that appear in the caption,
2871 // which can be specified instead of parse_mode
2872 //
2873 // optional
2874 CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
2875 // Duration recording duration in seconds
2876 //
2877 // optional
2878 Duration int `json:"voice_duration,omitempty"`
2879 // ReplyMarkup inline keyboard attached to the message
2880 //
2881 // optional
2882 ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
2883 // InputMessageContent content of the message to be sent instead of the voice recording
2884 //
2885 // optional
2886 InputMessageContent interface{} `json:"input_message_content,omitempty"`
2887}
2888
2889// ChosenInlineResult is an inline query result chosen by a User
2890type ChosenInlineResult struct {
2891 // ResultID the unique identifier for the result that was chosen
2892 ResultID string `json:"result_id"`
2893 // From the user that chose the result
2894 From *User `json:"from"`
2895 // Location sender location, only for bots that require user location
2896 //
2897 // optional
2898 Location *Location `json:"location,omitempty"`
2899 // InlineMessageID identifier of the sent inline message.
2900 // Available only if there is an inline keyboard attached to the message.
2901 // Will be also received in callback queries and can be used to edit the message.
2902 //
2903 // optional
2904 InlineMessageID string `json:"inline_message_id,omitempty"`
2905 // Query the query that was used to obtain the result
2906 Query string `json:"query"`
2907}
2908
2909// InputTextMessageContent contains text for displaying
2910// as an inline query result.
2911type InputTextMessageContent struct {
2912 // Text of the message to be sent, 1-4096 characters
2913 Text string `json:"message_text"`
2914 // ParseMode mode for parsing entities in the message text.
2915 // See formatting options for more details
2916 // (https://core.telegram.org/bots/api#formatting-options).
2917 //
2918 // optional
2919 ParseMode string `json:"parse_mode,omitempty"`
2920 // Entities is a list of special entities that appear in message text, which
2921 // can be specified instead of parse_mode
2922 //
2923 // optional
2924 Entities []MessageEntity `json:"entities,omitempty"`
2925 // DisableWebPagePreview disables link previews for links in the sent message
2926 //
2927 // optional
2928 DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"`
2929}
2930
2931// InputLocationMessageContent contains a location for displaying
2932// as an inline query result.
2933type InputLocationMessageContent struct {
2934 // Latitude of the location in degrees
2935 Latitude float64 `json:"latitude"`
2936 // Longitude of the location in degrees
2937 Longitude float64 `json:"longitude"`
2938 // HorizontalAccuracy is the radius of uncertainty for the location,
2939 // measured in meters; 0-1500
2940 //
2941 // optional
2942 HorizontalAccuracy float64 `json:"horizontal_accuracy"`
2943 // LivePeriod is the period in seconds for which the location can be
2944 // updated, should be between 60 and 86400
2945 //
2946 // optional
2947 LivePeriod int `json:"live_period,omitempty"`
2948 // Heading is for live locations, a direction in which the user is moving,
2949 // in degrees. Must be between 1 and 360 if specified.
2950 //
2951 // optional
2952 Heading int `json:"heading"`
2953 // ProximityAlertRadius is for live locations, a maximum distance for
2954 // proximity alerts about approaching another chat member, in meters. Must
2955 // be between 1 and 100000 if specified.
2956 //
2957 // optional
2958 ProximityAlertRadius int `json:"proximity_alert_radius"`
2959}
2960
2961// InputVenueMessageContent contains a venue for displaying
2962// as an inline query result.
2963type InputVenueMessageContent struct {
2964 // Latitude of the venue in degrees
2965 Latitude float64 `json:"latitude"`
2966 // Longitude of the venue in degrees
2967 Longitude float64 `json:"longitude"`
2968 // Title name of the venue
2969 Title string `json:"title"`
2970 // Address of the venue
2971 Address string `json:"address"`
2972 // FoursquareID foursquare identifier of the venue, if known
2973 //
2974 // optional
2975 FoursquareID string `json:"foursquare_id,omitempty"`
2976 // FoursquareType Foursquare type of the venue, if known
2977 //
2978 // optional
2979 FoursquareType string `json:"foursquare_type,omitempty"`
2980 // GooglePlaceID is the Google Places identifier of the venue
2981 //
2982 // optional
2983 GooglePlaceID string `json:"google_place_id"`
2984 // GooglePlaceType is the Google Places type of the venue
2985 //
2986 // optional
2987 GooglePlaceType string `json:"google_place_type"`
2988}
2989
2990// InputContactMessageContent contains a contact for displaying
2991// as an inline query result.
2992type InputContactMessageContent struct {
2993 // PhoneNumber contact's phone number
2994 PhoneNumber string `json:"phone_number"`
2995 // FirstName contact's first name
2996 FirstName string `json:"first_name"`
2997 // LastName contact's last name
2998 //
2999 // optional
3000 LastName string `json:"last_name,omitempty"`
3001 // Additional data about the contact in the form of a vCard
3002 //
3003 // optional
3004 VCard string `json:"vcard,omitempty"`
3005}
3006
3007// InputInvoiceMessageContent represents the content of an invoice message to be
3008// sent as the result of an inline query.
3009type InputInvoiceMessageContent struct {
3010 // Product name, 1-32 characters
3011 Title string `json:"title"`
3012 // Product description, 1-255 characters
3013 Description string `json:"description"`
3014 // Bot-defined invoice payload, 1-128 bytes. This will not be displayed to
3015 // the user, use for your internal processes.
3016 Payload string `json:"payload"`
3017 // Payment provider token, obtained via Botfather
3018 ProviderToken string `json:"provider_token"`
3019 // Three-letter ISO 4217 currency code
3020 Currency string `json:"currency"`
3021 // Price breakdown, a JSON-serialized list of components (e.g. product
3022 // price, tax, discount, delivery cost, delivery tax, bonus, etc.)
3023 Prices []LabeledPrice `json:"prices"`
3024 // The maximum accepted amount for tips in the smallest units of the
3025 // currency (integer, not float/double).
3026 //
3027 // optional
3028 MaxTipAmount int `json:"max_tip_amount,omitempty"`
3029 // An array of suggested amounts of tip in the smallest units of the
3030 // currency (integer, not float/double). At most 4 suggested tip amounts can
3031 // be specified. The suggested tip amounts must be positive, passed in a
3032 // strictly increased order and must not exceed max_tip_amount.
3033 //
3034 // optional
3035 SuggestedTipAmounts []int `json:"suggested_tip_amounts,omitempty"`
3036 // A JSON-serialized object for data about the invoice, which will be shared
3037 // with the payment provider. A detailed description of the required fields
3038 // should be provided by the payment provider.
3039 //
3040 // optional
3041 ProviderData string `json:"provider_data,omitempty"`
3042 // URL of the product photo for the invoice. Can be a photo of the goods or
3043 // a marketing image for a service. People like it better when they see what
3044 // they are paying for.
3045 //
3046 // optional
3047 PhotoURL string `json:"photo_url,omitempty"`
3048 // Photo size
3049 //
3050 // optional
3051 PhotoSize int `json:"photo_size,omitempty"`
3052 // Photo width
3053 //
3054 // optional
3055 PhotoWidth int `json:"photo_width,omitempty"`
3056 // Photo height
3057 //
3058 // optional
3059 PhotoHeight int `json:"photo_height,omitempty"`
3060 // Pass True, if you require the user's full name to complete the order
3061 //
3062 // optional
3063 NeedName bool `json:"need_name,omitempty"`
3064 // Pass True, if you require the user's phone number to complete the order
3065 //
3066 // optional
3067 NeedPhoneNumber bool `json:"need_phone_number,omitempty"`
3068 // Pass True, if you require the user's email address to complete the order
3069 //
3070 // optional
3071 NeedEmail bool `json:"need_email,omitempty"`
3072 // Pass True, if you require the user's shipping address to complete the order
3073 //
3074 // optional
3075 NeedShippingAddress bool `json:"need_shipping_address,omitempty"`
3076 // Pass True, if user's phone number should be sent to provider
3077 //
3078 // optional
3079 SendPhoneNumberToProvider bool `json:"send_phone_number_to_provider,omitempty"`
3080 // Pass True, if user's email address should be sent to provider
3081 //
3082 // optional
3083 SendEmailToProvider bool `json:"send_email_to_provider,omitempty"`
3084 // Pass True, if the final price depends on the shipping method
3085 //
3086 // optional
3087 IsFlexible bool `json:"is_flexible,omitempty"`
3088}
3089
3090// LabeledPrice represents a portion of the price for goods or services.
3091type LabeledPrice struct {
3092 // Label portion label
3093 Label string `json:"label"`
3094 // Amount price of the product in the smallest units of the currency (integer, not float/double).
3095 // For example, for a price of US$ 1.45 pass amount = 145.
3096 // See the exp parameter in currencies.json
3097 // (https://core.telegram.org/bots/payments/currencies.json),
3098 // it shows the number of digits past the decimal point
3099 // for each currency (2 for the majority of currencies).
3100 Amount int `json:"amount"`
3101}
3102
3103// Invoice contains basic information about an invoice.
3104type Invoice struct {
3105 // Title product name
3106 Title string `json:"title"`
3107 // Description product description
3108 Description string `json:"description"`
3109 // StartParameter unique bot deep-linking parameter that can be used to generate this invoice
3110 StartParameter string `json:"start_parameter"`
3111 // Currency three-letter ISO 4217 currency code
3112 // (see https://core.telegram.org/bots/payments#supported-currencies)
3113 Currency string `json:"currency"`
3114 // TotalAmount total price in the smallest units of the currency (integer, not float/double).
3115 // For example, for a price of US$ 1.45 pass amount = 145.
3116 // See the exp parameter in currencies.json
3117 // (https://core.telegram.org/bots/payments/currencies.json),
3118 // it shows the number of digits past the decimal point
3119 // for each currency (2 for the majority of currencies).
3120 TotalAmount int `json:"total_amount"`
3121}
3122
3123// ShippingAddress represents a shipping address.
3124type ShippingAddress struct {
3125 // CountryCode ISO 3166-1 alpha-2 country code
3126 CountryCode string `json:"country_code"`
3127 // State if applicable
3128 State string `json:"state"`
3129 // City city
3130 City string `json:"city"`
3131 // StreetLine1 first line for the address
3132 StreetLine1 string `json:"street_line1"`
3133 // StreetLine2 second line for the address
3134 StreetLine2 string `json:"street_line2"`
3135 // PostCode address post code
3136 PostCode string `json:"post_code"`
3137}
3138
3139// OrderInfo represents information about an order.
3140type OrderInfo struct {
3141 // Name user name
3142 //
3143 // optional
3144 Name string `json:"name,omitempty"`
3145 // PhoneNumber user's phone number
3146 //
3147 // optional
3148 PhoneNumber string `json:"phone_number,omitempty"`
3149 // Email user email
3150 //
3151 // optional
3152 Email string `json:"email,omitempty"`
3153 // ShippingAddress user shipping address
3154 //
3155 // optional
3156 ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"`
3157}
3158
3159// ShippingOption represents one shipping option.
3160type ShippingOption struct {
3161 // ID shipping option identifier
3162 ID string `json:"id"`
3163 // Title option title
3164 Title string `json:"title"`
3165 // Prices list of price portions
3166 Prices []LabeledPrice `json:"prices"`
3167}
3168
3169// SuccessfulPayment contains basic information about a successful payment.
3170type SuccessfulPayment struct {
3171 // Currency three-letter ISO 4217 currency code
3172 // (see https://core.telegram.org/bots/payments#supported-currencies)
3173 Currency string `json:"currency"`
3174 // TotalAmount total price in the smallest units of the currency (integer, not float/double).
3175 // For example, for a price of US$ 1.45 pass amount = 145.
3176 // See the exp parameter in currencies.json,
3177 // (https://core.telegram.org/bots/payments/currencies.json)
3178 // it shows the number of digits past the decimal point
3179 // for each currency (2 for the majority of currencies).
3180 TotalAmount int `json:"total_amount"`
3181 // InvoicePayload bot specified invoice payload
3182 InvoicePayload string `json:"invoice_payload"`
3183 // ShippingOptionID identifier of the shipping option chosen by the user
3184 //
3185 // optional
3186 ShippingOptionID string `json:"shipping_option_id,omitempty"`
3187 // OrderInfo order info provided by the user
3188 //
3189 // optional
3190 OrderInfo *OrderInfo `json:"order_info,omitempty"`
3191 // TelegramPaymentChargeID telegram payment identifier
3192 TelegramPaymentChargeID string `json:"telegram_payment_charge_id"`
3193 // ProviderPaymentChargeID provider payment identifier
3194 ProviderPaymentChargeID string `json:"provider_payment_charge_id"`
3195}
3196
3197// ShippingQuery contains information about an incoming shipping query.
3198type ShippingQuery struct {
3199 // ID unique query identifier
3200 ID string `json:"id"`
3201 // From user who sent the query
3202 From *User `json:"from"`
3203 // InvoicePayload bot specified invoice payload
3204 InvoicePayload string `json:"invoice_payload"`
3205 // ShippingAddress user specified shipping address
3206 ShippingAddress *ShippingAddress `json:"shipping_address"`
3207}
3208
3209// PreCheckoutQuery contains information about an incoming pre-checkout query.
3210type PreCheckoutQuery struct {
3211 // ID unique query identifier
3212 ID string `json:"id"`
3213 // From user who sent the query
3214 From *User `json:"from"`
3215 // Currency three-letter ISO 4217 currency code
3216 // // (see https://core.telegram.org/bots/payments#supported-currencies)
3217 Currency string `json:"currency"`
3218 // TotalAmount total price in the smallest units of the currency (integer, not float/double).
3219 // // For example, for a price of US$ 1.45 pass amount = 145.
3220 // // See the exp parameter in currencies.json,
3221 // // (https://core.telegram.org/bots/payments/currencies.json)
3222 // // it shows the number of digits past the decimal point
3223 // // for each currency (2 for the majority of currencies).
3224 TotalAmount int `json:"total_amount"`
3225 // InvoicePayload bot specified invoice payload
3226 InvoicePayload string `json:"invoice_payload"`
3227 // ShippingOptionID identifier of the shipping option chosen by the user
3228 //
3229 // optional
3230 ShippingOptionID string `json:"shipping_option_id,omitempty"`
3231 // OrderInfo order info provided by the user
3232 //
3233 // optional
3234 OrderInfo *OrderInfo `json:"order_info,omitempty"`
3235}