forked from go-telegram-bot-api/telegram-bot-api
-
Notifications
You must be signed in to change notification settings - Fork 48
/
types.go
5169 lines (4933 loc) · 185 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package tgbotapi
import (
"encoding/json"
"errors"
"fmt"
"net/url"
"strings"
"time"
)
// APIResponse is a response from the Telegram API with the result
// stored raw.
type APIResponse struct {
Ok bool `json:"ok"`
Result json.RawMessage `json:"result,omitempty"`
ErrorCode int `json:"error_code,omitempty"`
Description string `json:"description,omitempty"`
Parameters *ResponseParameters `json:"parameters,omitempty"`
}
// Error is an error containing extra information returned by the Telegram API.
type Error struct {
Code int
Message string
ResponseParameters
}
// Error message string.
func (e Error) Error() string {
return e.Message
}
// Update is an update response, from GetUpdates.
type Update struct {
// UpdateID is the update's unique identifier.
// Update identifiers start from a certain positive number and increase
// sequentially.
// This ID becomes especially handy if you're using Webhooks,
// since it allows you to ignore repeated updates or to restore
// the correct update sequence, should they get out of order.
// If there are no new updates for at least a week, then identifier
// of the next update will be chosen randomly instead of sequentially.
UpdateID int `json:"update_id"`
// Message new incoming message of any kind — text, photo, sticker, etc.
//
// optional
Message *Message `json:"message,omitempty"`
// EditedMessage new version of a message that is known to the bot and was
// edited
//
// optional
EditedMessage *Message `json:"edited_message,omitempty"`
// ChannelPost new version of a message that is known to the bot and was
// edited
//
// optional
ChannelPost *Message `json:"channel_post,omitempty"`
// EditedChannelPost new incoming channel post of any kind — text, photo,
// sticker, etc.
//
// optional
EditedChannelPost *Message `json:"edited_channel_post,omitempty"`
// BusinessConnection the bot was connected to or disconnected from a
// business account, or a user edited an existing connection with the bot
//
// optional
BusinessConnection *BusinessConnection `json:"business_connection,omitempty"`
// BusinessMessage is a new non-service message from a
// connected business account
//
// optional
BusinessMessage *Message `json:"business_message,omitempty"`
// EditedBusinessMessage is a new version of a message from a
// connected business account
//
// optional
EditedBusinessMessage *Message `json:"edited_business_message,omitempty"`
// DeletedBusinessMessages are the messages were deleted from a
// connected business account
//
// optional
DeletedBusinessMessages *BusinessMessagesDeleted `json:"deleted_business_messages,omitempty"`
// MessageReaction is a reaction to a message was changed by a user.
//
// optional
MessageReaction *MessageReactionUpdated `json:"message_reaction,omitempty"`
// MessageReactionCount reactions to a message with anonymous reactions were changed.
//
// optional
MessageReactionCount *MessageReactionCountUpdated `json:"message_reaction_count,omitempty"`
// InlineQuery new incoming inline query
//
// optional
InlineQuery *InlineQuery `json:"inline_query,omitempty"`
// ChosenInlineResult is the result of an inline query
// that was chosen by a user and sent to their chat partner.
// Please see our documentation on the feedback collecting
// for details on how to enable these updates for your bot.
//
// optional
ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"`
// CallbackQuery new incoming callback query
//
// optional
CallbackQuery *CallbackQuery `json:"callback_query,omitempty"`
// ShippingQuery new incoming shipping query. Only for invoices with
// flexible price
//
// optional
ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"`
// PreCheckoutQuery new incoming pre-checkout query. Contains full
// information about checkout
//
// optional
PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"`
// PurchasedPaidMedia is user purchased paid media with a non-empty
// payload sent by the bot in a non-channel chat
//
// optional
PurchasedPaidMedia *PaidMediaPurchased `json:"purchased_paid_media,omitempty"`
// Pool new poll state. Bots receive only updates about stopped polls and
// polls, which are sent by the bot
//
// optional
Poll *Poll `json:"poll,omitempty"`
// PollAnswer user changed their answer in a non-anonymous poll. Bots
// receive new votes only in polls that were sent by the bot itself.
//
// optional
PollAnswer *PollAnswer `json:"poll_answer,omitempty"`
// MyChatMember is the bot's chat member status was updated in a chat. For
// private chats, this update is received only when the bot is blocked or
// unblocked by the user.
//
// optional
MyChatMember *ChatMemberUpdated `json:"my_chat_member,omitempty"`
// ChatMember is a chat member's status was updated in a chat. The bot must
// be an administrator in the chat and must explicitly specify "chat_member"
// in the list of allowed_updates to receive these updates.
//
// optional
ChatMember *ChatMemberUpdated `json:"chat_member,omitempty"`
// ChatJoinRequest is a request to join the chat has been sent. The bot must
// have the can_invite_users administrator right in the chat to receive
// these updates.
//
// optional
ChatJoinRequest *ChatJoinRequest `json:"chat_join_request,omitempty"`
// ChatBoostUpdated represents a boost added to a chat or changed.
//
// optional
ChatBoost *ChatBoostUpdated `json:"chat_boost,omitempty"`
// ChatBoostRemoved represents a boost removed from a chat.
//
// optional
ChatBoostRemoved *ChatBoostRemoved `json:"removed_chat_boost,omitempty"`
}
// SentFrom returns the user who sent an update. Can be nil, if Telegram did not provide information
// about the user in the update object.
func (u *Update) SentFrom() *User {
switch {
case u.Message != nil:
return u.Message.From
case u.EditedMessage != nil:
return u.EditedMessage.From
case u.InlineQuery != nil:
return u.InlineQuery.From
case u.ChosenInlineResult != nil:
return u.ChosenInlineResult.From
case u.CallbackQuery != nil:
return u.CallbackQuery.From
case u.ShippingQuery != nil:
return u.ShippingQuery.From
case u.PreCheckoutQuery != nil:
return u.PreCheckoutQuery.From
default:
return nil
}
}
// CallbackData returns the callback query data, if it exists.
func (u *Update) CallbackData() string {
if u.CallbackQuery != nil {
return u.CallbackQuery.Data
}
return ""
}
// FromChat returns the chat where an update occurred.
func (u *Update) FromChat() *Chat {
switch {
case u.Message != nil:
return &u.Message.Chat
case u.EditedMessage != nil:
return &u.EditedMessage.Chat
case u.ChannelPost != nil:
return &u.ChannelPost.Chat
case u.EditedChannelPost != nil:
return &u.EditedChannelPost.Chat
case u.CallbackQuery != nil && u.CallbackQuery.Message != nil:
return &u.CallbackQuery.Message.Chat
default:
return nil
}
}
// UpdatesChannel is the channel for getting updates.
type UpdatesChannel <-chan Update
// Clear discards all unprocessed incoming updates.
func (ch UpdatesChannel) Clear() {
for len(ch) != 0 {
<-ch
}
}
// User represents a Telegram user or bot.
type User struct {
// ID is a unique identifier for this user or bot
ID int64 `json:"id"`
// IsBot true, if this user is a bot
//
// optional
IsBot bool `json:"is_bot,omitempty"`
// IsPremium true, if user has Telegram Premium
//
// optional
IsPremium bool `json:"is_premium,omitempty"`
// AddedToAttachmentMenu true, if this user added the bot to the attachment menu
//
// optional
AddedToAttachmentMenu bool `json:"added_to_attachment_menu,omitempty"`
// FirstName user's or bot's first name
FirstName string `json:"first_name"`
// LastName user's or bot's last name
//
// optional
LastName string `json:"last_name,omitempty"`
// UserName user's or bot's username
//
// optional
UserName string `json:"username,omitempty"`
// LanguageCode IETF language tag of the user's language
// more info: https://en.wikipedia.org/wiki/IETF_language_tag
//
// optional
LanguageCode string `json:"language_code,omitempty"`
// CanJoinGroups is true, if the bot can be invited to groups.
// Returned only in getMe.
//
// optional
CanJoinGroups bool `json:"can_join_groups,omitempty"`
// CanReadAllGroupMessages is true, if privacy mode is disabled for the bot.
// Returned only in getMe.
//
// optional
CanReadAllGroupMessages bool `json:"can_read_all_group_messages,omitempty"`
// SupportsInlineQueries is true, if the bot supports inline queries.
// Returned only in getMe.
//
// optional
SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"`
// CanConnectToBusiness is true, if the bot can be connected to a
// Telegram Business account to receive its messages.
// Returned only in getMe.
//
// optional
CanConnectToBusiness bool `json:"can_connect_to_business,omitempty"`
// True, if the bot has a main Web App. Returned only in getMe.
//
// optional
HasMainWebApp bool `json:"has_main_web_app,omitempty"`
}
// String displays a simple text version of a user.
//
// It is normally a user's username, but falls back to a first/last
// name as available.
func (u *User) String() string {
if u == nil {
return ""
}
if u.UserName != "" {
return u.UserName
}
name := u.FirstName
if u.LastName != "" {
name += " " + u.LastName
}
return name
}
// Chat represents a chat.
type Chat struct {
// ID is a unique identifier for this chat
ID int64 `json:"id"`
// Type of chat, can be either “private”, “group”, “supergroup” or “channel”
Type string `json:"type"`
// Title for supergroups, channels and group chats
//
// optional
Title string `json:"title,omitempty"`
// UserName for private chats, supergroups and channels if available
//
// optional
UserName string `json:"username,omitempty"`
// FirstName of the other party in a private chat
//
// optional
FirstName string `json:"first_name,omitempty"`
// LastName of the other party in a private chat
//
// optional
LastName string `json:"last_name,omitempty"`
// IsForum is true if the supergroup chat is a forum (has topics enabled)
//
// optional
IsForum bool `json:"is_forum,omitempty"`
}
// ChatFullInfo contains full information about a chat.
type ChatFullInfo struct {
Chat
// Photo is a chat photo
Photo *ChatPhoto `json:"photo"`
// If non-empty, the list of all active chat usernames;
// for private chats, supergroups and channels. Returned only in getChat.
//
// optional
ActiveUsernames []string `json:"active_usernames,omitempty"`
// Birthdate for private chats, the date of birth of the user.
// Returned only in getChat.
//
// optional
Birthdate *Birthdate `json:"birthdate,omitempty"`
// BusinessIntro is for private chats with business accounts, the intro of the business.
// Returned only in getChat.
//
// optional
BusinessIntro *BusinessIntro `json:"business_intro,omitempty"`
// BusinessLocation is for private chats with business accounts, the location
// of the business. Returned only in getChat.
//
// optional
BusinessLocation *BusinessLocation `json:"business_location,omitempty"`
// BusinessOpeningHours is for private chats with business accounts,
// the opening hours of the business. Returned only in getChat.
//
// optional
BusinessOpeningHours *BusinessOpeningHours `json:"business_opening_hours,omitempty"`
// PersonalChat is for private chats, the personal channel of the user.
// Returned only in getChat.
//
// optional
PersonalChat *Chat `json:"personal_chat,omitempty"`
// AvailableReactions is a list of available reactions allowed in the chat.
// If omitted, then all emoji reactions are allowed. Returned only in getChat.
//
// optional
AvailableReactions []ReactionType `json:"available_reactions,omitempty"`
// AccentColorID is an identifier of the accent color for the chat name and backgrounds of
// the chat photo, reply header, and link preview.
// See accent colors for more details. Returned only in getChat.
// Always returned in getChat.
//
// optional
AccentColorID int `json:"accent_color_id,omitempty"`
// The maximum number of reactions that can be set on a message in the chat
MaxReactionCount int `json:"max_reaction_count"`
// BackgroundCustomEmojiID is a custom emoji identifier of emoji chosen by
// the chat for the reply header and link preview background.
// Returned only in getChat.
//
// optional
BackgroundCustomEmojiID string `json:"background_custom_emoji_id,omitempty"`
// ProfileAccentColorID is ani dentifier of the accent color for the chat's profile background.
// See profile accent colors for more details. Returned only in getChat.
//
// optional
ProfileAccentColorID int `json:"profile_accent_color_id,omitempty"`
// ProfileBackgroundCustomEmojiID is a custom emoji identifier of the emoji chosen by
// the chat for its profile background. Returned only in getChat.
//
// optional
ProfileBackgroundCustomEmojiID string `json:"profile_background_custom_emoji_id,omitempty"`
// EmojiStatusCustomEmojiID is a custom emoji identifier of emoji status of the other party
// in a private chat. Returned only in getChat.
//
// optional
EmojiStatusCustomEmojiID string `json:"emoji_status_custom_emoji_id,omitempty"`
// EmojiStatusExpirationDate is a date of the emoji status of the chat or the other party
// in a private chat, in Unix time, if any. Returned only in getChat.
//
// optional
EmojiStatusExpirationDate int64 `json:"emoji_status_expiration_date,omitempty"`
// Bio is the bio of the other party in a private chat. Returned only in
// getChat
//
// optional
Bio string `json:"bio,omitempty"`
// HasPrivateForwards is true if privacy settings of the other party in the
// private chat allows to use tg://user?id=<user_id> links only in chats
// with the user. Returned only in getChat.
//
// optional
HasPrivateForwards bool `json:"has_private_forwards,omitempty"`
// HasRestrictedVoiceAndVideoMessages if the privacy settings of the other party
// restrict sending voice and video note messages
// in the private chat. Returned only in getChat.
//
// optional
HasRestrictedVoiceAndVideoMessages bool `json:"has_restricted_voice_and_video_messages,omitempty"`
// JoinToSendMessages is true, if users need to join the supergroup
// before they can send messages.
// Returned only in getChat
//
// optional
JoinToSendMessages bool `json:"join_to_send_messages,omitempty"`
// JoinByRequest is true, if all users directly joining the supergroup
// need to be approved by supergroup administrators.
// Returned only in getChat.
//
// optional
JoinByRequest bool `json:"join_by_request,omitempty"`
// Description for groups, supergroups and channel chats
//
// optional
Description string `json:"description,omitempty"`
// InviteLink is a chat invite link, for groups, supergroups and channel chats.
// Each administrator in a chat generates their own invite links,
// so the bot must first generate the link using exportChatInviteLink
//
// optional
InviteLink string `json:"invite_link,omitempty"`
// PinnedMessage is the pinned message, for groups, supergroups and channels
//
// optional
PinnedMessage *Message `json:"pinned_message,omitempty"`
// Permissions are default chat member permissions, for groups and
// supergroups. Returned only in getChat.
//
// optional
Permissions *ChatPermissions `json:"permissions,omitempty"`
// True, if paid media messages can be sent or forwarded to the channel chat.
// The field is available only for channel chats.
//
// optional
CanSendPaidMedia bool `json:"can_send_paid_media,omitempty"`
// SlowModeDelay is for supergroups, the minimum allowed delay between
// consecutive messages sent by each unprivileged user. Returned only in
// getChat.
//
// optional
SlowModeDelay int `json:"slow_mode_delay,omitempty"`
// UnrestrictBoostCount is for supergroups, the minimum number of boosts that
// a non-administrator user needs to add in order to
// ignore slow mode and chat permissions. Returned only in getChat.
//
// optional
UnrestrictBoostCount int `json:"unrestrict_boost_count,omitempty"`
// MessageAutoDeleteTime is the time after which all messages sent to the
// chat will be automatically deleted; in seconds. Returned only in getChat.
//
// optional
MessageAutoDeleteTime int `json:"message_auto_delete_time,omitempty"`
// HasAggressiveAntiSpamEnabled is true if aggressive anti-spam checks are enabled
// in the supergroup. The field is only available to chat administrators.
// Returned only in getChat.
//
// optional
HasAggressiveAntiSpamEnabled bool `json:"has_aggressive_anti_spam_enabled,omitempty"`
// HasHiddenMembers is true if non-administrators can only get
// the list of bots and administrators in the chat.
//
// optional
HasHiddenMembers bool `json:"has_hidden_members,omitempty"`
// HasProtectedContent is true if messages from the chat can't be forwarded
// to other chats. Returned only in getChat.
//
// optional
HasProtectedContent bool `json:"has_protected_content,omitempty"`
// HasVisibleHistory is True, if new chat members will have access to old messages;
// available only to chat administrators. Returned only in getChat.
//
// optional
HasVisibleHistory bool `json:"has_visible_history,omitempty"`
// StickerSetName is for supergroups, name of group sticker set.Returned
// only in getChat.
//
// optional
StickerSetName string `json:"sticker_set_name,omitempty"`
// CanSetStickerSet is true, if the bot can change the group sticker set.
// Returned only in getChat.
//
// optional
CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"`
// CustomEmojiStickerSetName is for supergroups, the name of the group's
// custom emoji sticker set. Custom emoji from this set can be used by all
// users and bots in the group. Returned only in getChat.
//
// optional
CustomEmojiStickerSetName string `json:"custom_emoji_sticker_set_name,omitempty"`
// LinkedChatID is a unique identifier for the linked chat, i.e. the
// discussion group identifier for a channel and vice versa; for supergroups
// and channel chats.
//
// optional
LinkedChatID int64 `json:"linked_chat_id,omitempty"`
// Location is for supergroups, the location to which the supergroup is
// connected. Returned only in getChat.
//
// optional
Location *ChatLocation `json:"location,omitempty"`
}
// IsPrivate returns if the Chat is a private conversation.
func (c Chat) IsPrivate() bool {
return c.Type == "private"
}
// IsGroup returns if the Chat is a group.
func (c Chat) IsGroup() bool {
return c.Type == "group"
}
// IsSuperGroup returns if the Chat is a supergroup.
func (c Chat) IsSuperGroup() bool {
return c.Type == "supergroup"
}
// IsChannel returns if the Chat is a channel.
func (c Chat) IsChannel() bool {
return c.Type == "channel"
}
// ChatConfig returns a ChatConfig struct for chat related methods.
func (c Chat) ChatConfig() ChatConfig {
return ChatConfig{ChatID: c.ID}
}
// InaccessibleMessage describes a message that was deleted or is otherwise inaccessible to the bot.
type InaccessibleMessage struct {
// Chat the message belonged to
Chat Chat `json:"chat"`
// MessageID is unique message identifier inside the chat
MessageID int `json:"message_id"`
// Date is always 0. The field can be used to differentiate regular and inaccessible messages.
Date int `json:"date"`
}
// Message represents a message.
type Message struct {
// MessageID is a unique message identifier inside this chat
MessageID int `json:"message_id"`
// Unique identifier of a message thread to which the message belongs;
// for supergroups only
//
// optional
MessageThreadID int `json:"message_thread_id,omitempty"`
// From is a sender, empty for messages sent to channels;
//
// optional
From *User `json:"from,omitempty"`
// SenderChat is the sender of the message, sent on behalf of a chat. The
// channel itself for channel messages. The supergroup itself for messages
// from anonymous group administrators. The linked channel for messages
// automatically forwarded to the discussion group
//
// optional
SenderChat *Chat `json:"sender_chat,omitempty"`
// SenderBoostCount is the number of boosts added by the user,
// if the sender of the message boosted the chat
//
// optional
SenderBoostCount int `json:"sender_boost_count,omitempty"`
// SenderBusinessBot is the bot that actually sent the message on behalf of
// the business account. Available only for outgoing messages sent on
// behalf of the connected business account.
//
// optional
SenderBusinessBot *User `json:"sender_business_bot,omitempty"`
// Date of the message was sent in Unix time
Date int `json:"date"`
// BusinessConnectionID is an unique identifier of the business connection
// from which the message was received. If non-empty, the message belongs to
// a chat of the corresponding business account that is independent from
// any potential bot chat which might share the same identifier.
//
// optional
BusinessConnectionID string `json:"business_connection_id,omitempty"`
// Chat is the conversation the message belongs to
Chat Chat `json:"chat"`
// ForwardOrigin is information about the original message for forwarded messages
//
// optional
ForwardOrigin *MessageOrigin `json:"forward_origin,omitempty"`
// IsTopicMessage true if the message is sent to a forum topic
//
// optional
IsTopicMessage bool `json:"is_topic_message,omitempty"`
// IsAutomaticForward is true if the message is a channel post that was
// automatically forwarded to the connected discussion group.
//
// optional
IsAutomaticForward bool `json:"is_automatic_forward,omitempty"`
// ReplyToMessage for replies, the original message.
// Note that the Message object in this field will not contain further ReplyToMessage fields
// even if it itself is a reply;
//
// optional
ReplyToMessage *Message `json:"reply_to_message,omitempty"`
// ExternalReply is an information about the message that is being replied to,
// which may come from another chat or forum topic.
//
// optional
ExternalReply *ExternalReplyInfo `json:"external_reply,omitempty"`
// Quote for replies that quote part of the original message, the quoted part of the message
//
// optional
Quote *TextQuote `json:"text_quote,omitempty"`
// ReplyToStory for replies to a story, the original story
//
// ReplyToStory
ReplyToStory *Story `json:"reply_to_story"`
// ViaBot through which the message was sent;
//
// optional
ViaBot *User `json:"via_bot,omitempty"`
// EditDate of the message was last edited in Unix time;
//
// optional
EditDate int `json:"edit_date,omitempty"`
// HasProtectedContent is true if the message can't be forwarded.
//
// optional
HasProtectedContent bool `json:"has_protected_content,omitempty"`
// IsFromOffline is True, if the message was sent by an implicit action,
// for example, as an away or a greeting business message, or as a scheduled message
//
// optional
IsFromOffline bool `json:"is_from_offline,omitempty"`
// MediaGroupID is the unique identifier of a media message group this message belongs to;
//
// optional
MediaGroupID string `json:"media_group_id,omitempty"`
// AuthorSignature is the signature of the post author for messages in channels;
//
// optional
AuthorSignature string `json:"author_signature,omitempty"`
// Text is for text messages, the actual UTF-8 text of the message, 0-4096 characters;
//
// optional
Text string `json:"text,omitempty"`
// Entities are for text messages, special entities like usernames,
// URLs, bot commands, etc. that appear in the text;
//
// optional
Entities []MessageEntity `json:"entities,omitempty"`
// LinkPreviewOptions are options used for link preview generation for the message,
// if it is a text message and link preview options were changed
//
// Optional
LinkPreviewOptions *LinkPreviewOptions `json:"link_preview_options,omitempty"`
// EffectID is the unique identifier of the message effect added to the message
//
// optional
EffectID string `json:"effect_id,omitempty"`
// Animation message is an animation, information about the animation.
// For backward compatibility, when this field is set, the document field will also be set;
//
// optional
Animation *Animation `json:"animation,omitempty"`
// PremiumAnimation message is an animation, information about the animation.
// For backward compatibility, when this field is set, the document field will also be set;
//
// optional
PremiumAnimation *Animation `json:"premium_animation,omitempty"`
// Audio message is an audio file, information about the file;
//
// optional
Audio *Audio `json:"audio,omitempty"`
// Document message is a general file, information about the file;
//
// optional
Document *Document `json:"document,omitempty"`
// Message contains paid media; information about the paid media
//
// optional
PaidMedia *PaidMediaInfo `json:"paid_media,omitempty"`
// Photo message is a photo, available sizes of the photo;
//
// optional
Photo []PhotoSize `json:"photo,omitempty"`
// Sticker message is a sticker, information about the sticker;
//
// optional
Sticker *Sticker `json:"sticker,omitempty"`
// Story message is a forwarded story;
//
// optional
Story *Story `json:"story,omitempty"`
// Video message is a video, information about the video;
//
// optional
Video *Video `json:"video,omitempty"`
// VideoNote message is a video note, information about the video message;
//
// optional
VideoNote *VideoNote `json:"video_note,omitempty"`
// Voice message is a voice message, information about the file;
//
// optional
Voice *Voice `json:"voice,omitempty"`
// Caption for the animation, audio, document, photo, video or voice, 0-1024 characters;
//
// optional
Caption string `json:"caption,omitempty"`
// CaptionEntities;
//
// optional
CaptionEntities []MessageEntity `json:"caption_entities,omitempty"`
// ShowCaptionAboveMedia is True, if the caption must be shown above the message media
//
// optional
ShowCaptionAboveMedia bool `json:"show_caption_above_media,omitempty"`
// HasSpoiler True, if the message media is covered by a spoiler animation
//
// optional
HasMediaSpoiler bool `json:"has_media_spoiler,omitempty"`
// Contact message is a shared contact, information about the contact;
//
// optional
Contact *Contact `json:"contact,omitempty"`
// Dice is a dice with random value;
//
// optional
Dice *Dice `json:"dice,omitempty"`
// Game message is a game, information about the game;
//
// optional
Game *Game `json:"game,omitempty"`
// Poll is a native poll, information about the poll;
//
// optional
Poll *Poll `json:"poll,omitempty"`
// Venue message is a venue, information about the venue.
// For backward compatibility, when this field is set, the location field
// will also be set;
//
// optional
Venue *Venue `json:"venue,omitempty"`
// Location message is a shared location, information about the location;
//
// optional
Location *Location `json:"location,omitempty"`
// NewChatMembers that were added to the group or supergroup
// and information about them (the bot itself may be one of these members);
//
// optional
NewChatMembers []User `json:"new_chat_members,omitempty"`
// LeftChatMember is a member was removed from the group,
// information about them (this member may be the bot itself);
//
// optional
LeftChatMember *User `json:"left_chat_member,omitempty"`
// NewChatTitle is a chat title was changed to this value;
//
// optional
NewChatTitle string `json:"new_chat_title,omitempty"`
// NewChatPhoto is a chat photo was change to this value;
//
// optional
NewChatPhoto []PhotoSize `json:"new_chat_photo,omitempty"`
// DeleteChatPhoto is a service message: the chat photo was deleted;
//
// optional
DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"`
// GroupChatCreated is a service message: the group has been created;
//
// optional
GroupChatCreated bool `json:"group_chat_created,omitempty"`
// SuperGroupChatCreated is a service message: the supergroup has been created.
// This field can't be received in a message coming through updates,
// because bot can't be a member of a supergroup when it is created.
// It can only be found in ReplyToMessage if someone replies to a very first message
// in a directly created supergroup;
//
// optional
SuperGroupChatCreated bool `json:"supergroup_chat_created,omitempty"`
// ChannelChatCreated is a service message: the channel has been created.
// This field can't be received in a message coming through updates,
// because bot can't be a member of a channel when it is created.
// It can only be found in ReplyToMessage
// if someone replies to a very first message in a channel;
//
// optional
ChannelChatCreated bool `json:"channel_chat_created,omitempty"`
// MessageAutoDeleteTimerChanged is a service message: auto-delete timer
// settings changed in the chat.
//
// optional
MessageAutoDeleteTimerChanged *MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed,omitempty"`
// MigrateToChatID is the group has been migrated to a supergroup with the specified identifier.
// This number may be greater than 32 bits and some programming languages
// may have difficulty/silent defects in interpreting it.
// But it is smaller than 52 bits, so a signed 64-bit integer
// or double-precision float type are safe for storing this identifier;
//
// optional
MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"`
// MigrateFromChatID is the supergroup has been migrated from a group with the specified identifier.
// This number may be greater than 32 bits and some programming languages
// may have difficulty/silent defects in interpreting it.
// But it is smaller than 52 bits, so a signed 64-bit integer
// or double-precision float type are safe for storing this identifier;
//
// optional
MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"`
// Specified message was pinned.
// Note that the Message object in this field will not contain
// further reply_to_message fields even if it itself is a reply.
//
// optional
PinnedMessage *Message `json:"pinned_message,omitempty"`
// Invoice message is an invoice for a payment;
//
// optional
Invoice *Invoice `json:"invoice,omitempty"`
// SuccessfulPayment message is a service message about a successful payment,
// information about the payment;
//
// optional
SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"`
// Message is a service message about a refunded payment, information about the payment
//
// optional
RefundedPayment *RefundedPayment `json:"refunded_payment,omitempty"`
// UsersShared is a service message: the users were shared with the bot
//
// optional
UsersShared *UsersShared `json:"users_shared,omitempty"`
// ChatShared is a service message: a chat was shared with the bot
//
// optional
ChatShared *ChatShared `json:"chat_shared,omitempty"`
// ConnectedWebsite is the domain name of the website on which the user has
// logged in;
//
// optional
ConnectedWebsite string `json:"connected_website,omitempty"`
// WriteAccessAllowed is a service message: the user allowed the bot
// added to the attachment menu to write messages
//
// optional
WriteAccessAllowed *WriteAccessAllowed `json:"write_access_allowed,omitempty"`
// PassportData is a Telegram Passport data;
//
// optional
PassportData *PassportData `json:"passport_data,omitempty"`
// ProximityAlertTriggered is a service message. A user in the chat
// triggered another user's proximity alert while sharing Live Location
//
// optional
ProximityAlertTriggered *ProximityAlertTriggered `json:"proximity_alert_triggered,omitempty"`
// BoostAdded is a service message: user boosted the chat
//
// optional
BoostAdded *ChatBoostAdded `json:"boost_added,omitempty"`
// Service message: chat background set
//
// optional
ChatBackgroundSet *ChatBackground `json:"chat_background_set,omitempty"`
// ForumTopicCreated is a service message: forum topic created
//
// optional
ForumTopicCreated *ForumTopicCreated `json:"forum_topic_created,omitempty"`
// ForumTopicClosed is a service message: forum topic edited
//
// optional
ForumTopicEdited *ForumTopicEdited `json:"forum_topic_edited,omitempty"`
// ForumTopicClosed is a service message: forum topic closed
//
// optional
ForumTopicClosed *ForumTopicClosed `json:"forum_topic_closed,omitempty"`
// ForumTopicReopened is a service message: forum topic reopened
//
// optional
ForumTopicReopened *ForumTopicReopened `json:"forum_topic_reopened,omitempty"`
// GeneralForumTopicHidden is a service message: the 'General' forum topic hidden
//
// optional
GeneralForumTopicHidden *GeneralForumTopicHidden `json:"general_forum_topic_hidden,omitempty"`
// GeneralForumTopicUnhidden is a service message: the 'General' forum topic unhidden
//
// optional
GeneralForumTopicUnhidden *GeneralForumTopicUnhidden `json:"general_forum_topic_unhidden,omitempty"`
// GiveawayCreated is as service message: a scheduled giveaway was created
//
// optional
GiveawayCreated *GiveawayCreated `json:"giveaway_created,omitempty"`
// Giveaway is a scheduled giveaway message
//
// optional
Giveaway *Giveaway `json:"giveaway,omitempty"`
// GiveawayWinners is a giveaway with public winners was completed
//
// optional
GiveawayWinners *GiveawayWinners `json:"giveaway_winners,omitempty"`
// GiveawayCompleted is a service message: a giveaway without public winners was completed
//
// optional
GiveawayCompleted *GiveawayCompleted `json:"giveaway_completed,omitempty"`
// VideoChatScheduled is a service message: video chat scheduled.
//
// optional
VideoChatScheduled *VideoChatScheduled `json:"video_chat_scheduled,omitempty"`
// VideoChatStarted is a service message: video chat started.
//
// optional
VideoChatStarted *VideoChatStarted `json:"video_chat_started,omitempty"`
// VideoChatEnded is a service message: video chat ended.
//
// optional
VideoChatEnded *VideoChatEnded `json:"video_chat_ended,omitempty"`
// VideoChatParticipantsInvited is a service message: new participants
// invited to a video chat.
//
// optional
VideoChatParticipantsInvited *VideoChatParticipantsInvited `json:"video_chat_participants_invited,omitempty"`
// WebAppData is a service message: data sent by a Web App.
//
// optional
WebAppData *WebAppData `json:"web_app_data,omitempty"`
// ReplyMarkup is the Inline keyboard attached to the message.
// login_url buttons are represented as ordinary url buttons.
//
// optional
ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"`
}
// Time converts the message timestamp into a Time.
func (m *Message) Time() time.Time {
return time.Unix(int64(m.Date), 0)
}
// IsCommand returns true if message starts with a "bot_command" entity.
func (m *Message) IsCommand() bool {
if m.Entities == nil || len(m.Entities) == 0 {
return false
}
entity := m.Entities[0]
return entity.Offset == 0 && entity.IsCommand()
}
// Command checks if the message was a command and if it was, returns the
// command. If the Message was not a command, it returns an empty string.
//
// If the command contains the at name syntax, it is removed. Use
// CommandWithAt() if you do not want that.
func (m *Message) Command() string {
command := m.CommandWithAt()
if i := strings.Index(command, "@"); i != -1 {
command = command[:i]
}
return command
}
// CommandWithAt checks if the message was a command and if it was, returns the
// command. If the Message was not a command, it returns an empty string.
//
// If the command contains the at name syntax, it is not removed. Use Command()
// if you want that.
func (m *Message) CommandWithAt() string {
if !m.IsCommand() {
return ""
}
// IsCommand() checks that the message begins with a bot_command entity
entity := m.Entities[0]
return m.Text[1:entity.Length]
}
// CommandArguments checks if the message was a command and if it was,
// returns all text after the command name. If the Message was not a
// command, it returns an empty string.
//
// Note: The first character after the command name is omitted:
// - "/foo bar baz" yields "bar baz", not " bar baz"
// - "/foo-bar baz" yields "bar baz", too
// Even though the latter is not a command conforming to the spec, the API
// marks "/foo" as command entity.
func (m *Message) CommandArguments() string {
if !m.IsCommand() {