-
Notifications
You must be signed in to change notification settings - Fork 11
/
types_gen_ext.go
1604 lines (1390 loc) · 42.8 KB
/
types_gen_ext.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 tg
import (
"encoding/json"
"fmt"
"strconv"
"time"
)
type ChatID int64
var _ PeerID = (ChatID)(0)
func (id ChatID) PeerID() string {
return strconv.FormatInt(int64(id), 10)
}
// ChatType represents enum of possible chat types.
type ChatType int8
const (
// ChatTypePrivate represents one-to-one chat.
ChatTypePrivate ChatType = iota + 1
// ChatTypeGroup represents group chats.
ChatTypeGroup
// ChatTypeSupergroup supergroup chats.
ChatTypeSupergroup
// ChatTypeChannel represents channels
ChatTypeChannel
// ChatTypeSender for a private chat with the inline query sender
ChatTypeSender
)
func (chatType ChatType) String() string {
if chatType < ChatTypePrivate || chatType > ChatTypeSender {
return "unknown"
}
return [...]string{"private", "group", "supergroup", "channel", "sender"}[chatType-1]
}
func (chatType ChatType) MarshalJSON() ([]byte, error) {
return json.Marshal(chatType.String())
}
func (chatType *ChatType) UnmarshalJSON(b []byte) error {
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
switch s {
case "private":
*chatType = ChatTypePrivate
case "group":
*chatType = ChatTypeGroup
case "supergroup":
*chatType = ChatTypeSupergroup
case "channel":
*chatType = ChatTypeChannel
case "sender":
*chatType = ChatTypeSender
default:
return fmt.Errorf("unknown chat type: %s", s)
}
return nil
}
// ChatAction type of action to broadcast via sendChatAction.
type ChatAction int8
const (
ChatActionTyping ChatAction = iota + 1
ChatActionUploadPhoto
ChatActionRecordVideo
ChatActionUploadVideo
ChatActionRecordVoice
ChatActionUploadVoice
ChatActionUploadDocument
ChatActionChooseSticker
ChatActionFindLocation
ChatActionRecordVideoNote
ChatActionUploadVideoNote
)
func (action ChatAction) String() string {
if action < ChatActionTyping || action > ChatActionUploadVideoNote {
return "unknown"
}
return [...]string{
"typing",
"upload_photo",
"record_video",
"upload_video",
"record_voice",
"upload_voice",
"upload_document",
"choose_sticker",
"find_location",
"record_video_note",
"upload_video_note",
}[action-1]
}
// UserID it's unique identifier for Telegram user or bot.
type UserID int64
var _ PeerID = (UserID)(0)
func (id UserID) PeerID() string {
return strconv.FormatInt(int64(id), 10)
}
// Username represents a Telegram username.
type Username string
// PeerID implements [Peer] interface.
func (un Username) PeerID() string {
return "@" + string(un)
}
// Link returns a public link with username.
func (un Username) Link() string {
return "https://t.me/" + string(un)
}
// DeepLink returns a deep link with username.
func (un Username) DeepLink() string {
return "tg://resolve?domain=" + string(un)
}
// PeerID represents generic Telegram peer.
//
// Known implementations:
// - [UserID]
// - [ChatID]
// - [Username]
// - [Chat]
// - [User]
type PeerID interface {
PeerID() string
}
type FileID string
// FileArg it's union type for different ways of sending files.
type FileArg struct {
// Send already uploaded file by its file_id.
FileID FileID
// Send remote file by URL.
URL string
// Upload file
Upload InputFile
addr string
}
// NewFileArgUpload creates a new FileArg for uploading a file by content.
func NewFileArgUpload(file InputFile) FileArg {
return FileArg{
Upload: file,
}
}
// NewFileArgURL creates a new FileArg for sending a file by URL.
func NewFileArgURL(url string) FileArg {
return FileArg{
URL: url,
}
}
// NewFileArgID creates a new FileArg for sending a file by file_id.
func NewFileArgID(id FileID) FileArg {
return FileArg{
FileID: id,
}
}
func (arg FileArg) MarshalJSON() ([]byte, error) {
str := arg.getRef()
if str != "" {
return json.Marshal(str)
}
return nil, fmt.Errorf("FileArg is not json serializable")
}
// isRef returns true if FileArg is just reference
func (arg *FileArg) isRef() bool {
return arg.FileID != "" || arg.URL != "" || arg.addr != ""
}
// getRef returns text representation of reference
func (arg *FileArg) getRef() string {
if arg.FileID != "" {
return string(arg.FileID)
} else if arg.URL != "" {
return arg.URL
} else if arg.addr != "" {
return arg.addr
}
return ""
}
//go:generate go run github.com/mr-linch/go-tg-gen@latest -types-output types_gen.go
func (chat Chat) PeerID() string {
return chat.ID.PeerID()
}
func (user User) PeerID() string {
return user.ID.PeerID()
}
// InputMedia generic interface for InputMedia*.
//
// Known implementations:
// - [InputMediaPhoto]
// - [InputMediaVideo]
// - [InputMediaAudio]
// - [InputMediaDocument]
// - [InputMediaAnimation]
type InputMedia interface {
getMedia() (media *FileArg, thumb *InputFile)
}
type CallbackGame struct{}
// ReplyMarkup generic for keyboards.
//
// Known implementations:
// - [ReplyKeyboardMarkup]
// - [InlineKeyboardMarkup]
// - [ReplyKeyboardRemove]
// - [ForceReply]
type ReplyMarkup interface {
isReplyMarkup()
}
var _ ReplyMarkup = (*InlineKeyboardMarkup)(nil)
// NewInlineKeyboardMarkup creates a new InlineKeyboardMarkup.
func NewInlineKeyboardMarkup(rows ...[]InlineKeyboardButton) InlineKeyboardMarkup {
return InlineKeyboardMarkup{
InlineKeyboard: rows,
}
}
func (markup InlineKeyboardMarkup) Ptr() *InlineKeyboardMarkup {
return &markup
}
// NewInlineButtonURL create inline button
// with http(s):// or tg:// URL to be opened when the button is pressed.
func NewInlineKeyboardButtonURL(text string, url string) InlineKeyboardButton {
return InlineKeyboardButton{
Text: text,
URL: url,
}
}
// NewInlineKeyboardButtonCallback creates a new InlineKeyboardButton with specified callback data.
// Query should have length 1-64 bytes.
func NewInlineKeyboardButtonCallback(text string, query string) InlineKeyboardButton {
return InlineKeyboardButton{
Text: text,
CallbackData: query,
}
}
type CallbackDataEncoder[T any] interface {
Encode(data T) (string, error)
}
// NewInlineKeyboardButtonWebApp creates a button that open a web app.
func NewInlineKeyboardButtonWebApp(text string, webApp WebAppInfo) InlineKeyboardButton {
return InlineKeyboardButton{
Text: text,
WebApp: &webApp,
}
}
// InlineKeyboardMarkup represents button that open web page with auth data.
func NewInlineKeyboardButtonLoginURL(text string, loginURL LoginURL) InlineKeyboardButton {
return InlineKeyboardButton{
Text: text,
LoginURL: &loginURL,
}
}
// NewInlineKeyboardButtonSwitchInlineQuery represents button that
//
// will prompt the user to select one of their chats,
//
// open that chat and insert the bot's username and the specified inline query in the input field.
func NewInlineKeyboardButtonSwitchInlineQuery(text string, query string) InlineKeyboardButton {
return InlineKeyboardButton{
Text: text,
SwitchInlineQuery: query,
}
}
// NewInlineKeyboardButtonSwitchInlineQueryCurrentChat represents button that
// will insert the bot's username and the specified inline query in the current chat's input field
func NewInlineKeyboardButtonSwitchInlineQueryCurrentChat(text string, query string) InlineKeyboardButton {
return InlineKeyboardButton{
Text: text,
SwitchInlineQueryCurrentChat: query,
}
}
// NewInlineKeyboardButtonCallbackGame represents the button which open a game.
func NewInlineKeyboardButtonCallbackGame(text string) InlineKeyboardButton {
return InlineKeyboardButton{
Text: text,
CallbackGame: &CallbackGame{},
}
}
// NewInlineKeyboardButtonPay represents a Pay button.
// NOTE: This type of button must always be the first button in the first row and can only be used in invoice messages
func NewInlineKeyboardButtonPay(text string) InlineKeyboardButton {
return InlineKeyboardButton{
Text: text,
Pay: true,
}
}
func (markup InlineKeyboardMarkup) isReplyMarkup() {}
// NewReplyKeyboardMarkup creates a new ReplyKeyboardMarkup.
func NewReplyKeyboardMarkup(rows ...[]KeyboardButton) *ReplyKeyboardMarkup {
return &ReplyKeyboardMarkup{
Keyboard: rows,
}
}
var _ ReplyMarkup = (*ReplyKeyboardMarkup)(nil)
// WithResizeKeyboard requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons).
// Defaults to false, in which case the custom keyboard is always of the same height as the app's standard keyboard.
func (markup *ReplyKeyboardMarkup) WithResizeKeyboardMarkup() *ReplyKeyboardMarkup {
markup.ResizeKeyboard = true
return markup
}
// WithOneTimeKeyboard requests clients to hide the keyboard as soon as it's been used.
// The keyboard will still be available, but clients will automatically display the
// usual letter-keyboard in the chat - the user can press a special button in
// the input field to see the custom keyboard again.
// Defaults to false.
func (markup *ReplyKeyboardMarkup) WithOneTimeKeyboardMarkup() *ReplyKeyboardMarkup {
markup.OneTimeKeyboard = true
return markup
}
// WithInputFieldPlaceholder sets the placeholder to be shown in the input field when the keyboard is active;
// 1-64 characters
func (markup *ReplyKeyboardMarkup) WithInputFieldPlaceholder(placeholder string) *ReplyKeyboardMarkup {
markup.InputFieldPlaceholder = placeholder
return markup
}
// Use this parameter if you want to show the keyboard to specific users only.
func (markup *ReplyKeyboardMarkup) WithSelective() *ReplyKeyboardMarkup {
markup.Selective = true
return markup
}
// NewKeyboardButton creates a plain reply keyboard button.
func NewKeyboardButton(text string) KeyboardButton {
return KeyboardButton{
Text: text,
}
}
// NewKeyboardButtonRequestContact creates a reply keyboard button that request a contact from user.
// Available in private chats only.
func NewKeyboardButtonRequestContact(text string) KeyboardButton {
return KeyboardButton{
Text: text,
RequestContact: true,
}
}
// NewKeyboardButtonRequestLocation creates a reply keyboard button that request a location from user.
// Available in private chats only.
func NewKeyboardButtonRequestLocation(text string) KeyboardButton {
return KeyboardButton{
Text: text,
RequestLocation: true,
}
}
// NewKeyboardButtonRequestPoll creates a reply keyboard button that request a poll from user.
// Available in private chats only.
func NewKeyboardButtonRequestPoll(text string, poll KeyboardButtonPollType) KeyboardButton {
return KeyboardButton{
Text: text,
RequestPoll: &poll,
}
}
// NewKeyboardButtonWebApp create a reply keyboard button that open a web app.
func NewKeyboardButtonWebApp(text string, webApp WebAppInfo) KeyboardButton {
return KeyboardButton{
Text: text,
WebApp: &webApp,
}
}
// NewKeyboardButtonRequestUsers creates a reply keyboard button that request a user from user.
// Available in private chats only.
func NewKeyboardButtonRequestUsers(text string, config KeyboardButtonRequestUsers) KeyboardButton {
return KeyboardButton{
Text: text,
RequestUsers: &config,
}
}
// NewKeyboardButtonRequestChats creates a reply keyboard button that request a chat from user.
// Available in private chats only.
func NewKeyboardButtonRequestChat(text string, config KeyboardButtonRequestChat) KeyboardButton {
return KeyboardButton{
Text: text,
RequestChat: &config,
}
}
func (markup ReplyKeyboardMarkup) isReplyMarkup() {}
var _ ReplyMarkup = (*ReplyKeyboardRemove)(nil)
// NewReplyKeyboardRemove creates a new ReplyKeyboardRemove.
func NewReplyKeyboardRemove() *ReplyKeyboardRemove {
return &ReplyKeyboardRemove{
RemoveKeyboard: true,
}
}
// WithSelective set it if you want to remove the keyboard for specific users only.
func (markup *ReplyKeyboardRemove) WithSelective() *ReplyKeyboardRemove {
markup.Selective = true
return markup
}
func (markup ReplyKeyboardRemove) isReplyMarkup() {}
var _ ReplyMarkup = (*ForceReply)(nil)
// NewForceReply creates a new ForceReply.
func NewForceReply() *ForceReply {
return &ForceReply{
ForceReply: true,
}
}
// WithSelective set it if you want to force reply for specific users only.
func (markup *ForceReply) WithSelective() *ForceReply {
markup.Selective = true
return markup
}
// WithInputFieldPlaceholder sets the placeholder to be shown in the input field when the reply is active;
// 1-64 characters
func (markup *ForceReply) WithInputFieldPlaceholder(placeholder string) *ForceReply {
markup.InputFieldPlaceholder = placeholder
return markup
}
func (markup ForceReply) isReplyMarkup() {}
// NewButtonRow it's generic helper for create keyboards in functional way.
func NewButtonRow[T Button](buttons ...T) []T {
return buttons
}
// Button define generic button interface
type Button interface {
InlineKeyboardButton | KeyboardButton
}
// ButtonLayout it's build for fixed width keyboards.
type ButtonLayout[T Button] struct {
buttons [][]T
rowWidth int
}
// NewButtonColumn returns keyboard from a single column of Button.
func NewButtonColumn[T Button](buttons ...T) [][]T {
result := make([][]T, 0, len(buttons))
for _, button := range buttons {
result = append(result, []T{button})
}
return result
}
// NewButtonLayout creates layout with specified width.
// Buttons will be added via Insert method.
func NewButtonLayout[T Button](rowWidth int, buttons ...T) *ButtonLayout[T] {
layout := &ButtonLayout[T]{
rowWidth: rowWidth,
buttons: make([][]T, 0),
}
return layout.Insert(buttons...)
}
// Keyboard returns result of building.
func (layout *ButtonLayout[T]) Keyboard() [][]T {
return layout.buttons
}
// Insert buttons to last row if possible, or create new and insert.
func (layout *ButtonLayout[T]) Insert(buttons ...T) *ButtonLayout[T] {
for _, button := range buttons {
layout.insert(button)
}
return layout
}
func (layout *ButtonLayout[T]) insert(button T) *ButtonLayout[T] {
if len(layout.buttons) > 0 && len(layout.buttons[len(layout.buttons)-1]) < layout.rowWidth {
layout.buttons[len(layout.buttons)-1] = append(layout.buttons[len(layout.buttons)-1], button)
} else {
layout.buttons = append(layout.buttons, []T{button})
}
return layout
}
// Add accepts any number of buttons,
// always starts adding from a new row
// and adds a row when it reaches the set width.
func (layout *ButtonLayout[T]) Add(buttons ...T) *ButtonLayout[T] {
row := make([]T, 0, layout.rowWidth)
for _, button := range buttons {
if len(row) == layout.rowWidth {
layout.buttons = append(layout.buttons, row)
row = make([]T, 0, layout.rowWidth)
}
row = append(row, button)
}
if len(row) > 0 {
layout.buttons = append(layout.buttons, row)
}
return layout
}
// Row add new row with no respect for row width
func (layout *ButtonLayout[T]) Row(buttons ...T) *ButtonLayout[T] {
layout.buttons = append(layout.buttons, buttons)
return layout
}
// InlineQueryResult it's a generic interface for all inline query results.
//
// Known implementations:
// - [InlineQueryResultCachedAudio]
// - [InlineQueryResultCachedDocument]
// - [InlineQueryResultCachedGIF]
// - [InlineQueryResultCachedMPEG4GIF]
// - [InlineQueryResultCachedPhoto]
// - [InlineQueryResultCachedSticker]
// - [InlineQueryResultCachedVideo]
// - [InlineQueryResultCachedVoice]
// - [InlineQueryResultAudio]
// - [InlineQueryResultDocument]
// - [InlineQueryResultGIF]
// - [InlineQueryResultMPEG4GIF]
// - [InlineQueryResultPhoto]
// - [InlineQueryResultVideo]
// - [InlineQueryResultVoice]
// - [InlineQueryResultArticle]
// - [InlineQueryResultContact]
// - [InlineQueryResultGame]
// - [InlineQueryResultLocation]
// - [InlineQueryResultVenue]
type InlineQueryResult interface {
isInlineQueryResult()
json.Marshaler
}
func (InlineQueryResultCachedAudio) isInlineQueryResult() {}
func (result InlineQueryResultCachedAudio) MarshalJSON() ([]byte, error) {
result.Type = "audio"
type alias InlineQueryResultCachedAudio
return json.Marshal(alias(result))
}
func (InlineQueryResultCachedDocument) isInlineQueryResult() {}
func (result InlineQueryResultCachedDocument) MarshalJSON() ([]byte, error) {
result.Type = "document"
type alias InlineQueryResultCachedDocument
return json.Marshal(alias(result))
}
func (InlineQueryResultCachedGIF) isInlineQueryResult() {}
func (result InlineQueryResultCachedGIF) MarshalJSON() ([]byte, error) {
result.Type = "gif"
type alias InlineQueryResultCachedGIF
return json.Marshal(alias(result))
}
func (InlineQueryResultCachedMPEG4GIF) isInlineQueryResult() {}
func (result InlineQueryResultCachedMPEG4GIF) MarshalJSON() ([]byte, error) {
result.Type = "mpeg4_gif"
type alias InlineQueryResultCachedMPEG4GIF
return json.Marshal(alias(result))
}
func (InlineQueryResultCachedPhoto) isInlineQueryResult() {}
func (result InlineQueryResultCachedPhoto) MarshalJSON() ([]byte, error) {
result.Type = "photo"
type alias InlineQueryResultCachedPhoto
return json.Marshal(alias(result))
}
func (InlineQueryResultCachedSticker) isInlineQueryResult() {}
func (result InlineQueryResultCachedSticker) MarshalJSON() ([]byte, error) {
result.Type = "sticker"
type alias InlineQueryResultCachedSticker
return json.Marshal(alias(result))
}
func (InlineQueryResultCachedVideo) isInlineQueryResult() {}
func (result InlineQueryResultCachedVideo) MarshalJSON() ([]byte, error) {
result.Type = "video"
type alias InlineQueryResultCachedVideo
return json.Marshal(alias(result))
}
func (InlineQueryResultCachedVoice) isInlineQueryResult() {}
func (result InlineQueryResultCachedVoice) MarshalJSON() ([]byte, error) {
result.Type = "voice"
type alias InlineQueryResultCachedVoice
return json.Marshal(alias(result))
}
func (InlineQueryResultAudio) isInlineQueryResult() {}
func (result InlineQueryResultAudio) MarshalJSON() ([]byte, error) {
result.Type = "audio"
type alias InlineQueryResultAudio
return json.Marshal(alias(result))
}
func (InlineQueryResultDocument) isInlineQueryResult() {}
func (result InlineQueryResultDocument) MarshalJSON() ([]byte, error) {
result.Type = "document"
type alias InlineQueryResultDocument
return json.Marshal(alias(result))
}
func (InlineQueryResultGIF) isInlineQueryResult() {}
func (result InlineQueryResultGIF) MarshalJSON() ([]byte, error) {
result.Type = "gif"
type alias InlineQueryResultGIF
return json.Marshal(alias(result))
}
func (InlineQueryResultMPEG4GIF) isInlineQueryResult() {}
func (result InlineQueryResultMPEG4GIF) MarshalJSON() ([]byte, error) {
result.Type = "mpeg4_gif"
type alias InlineQueryResultMPEG4GIF
return json.Marshal(alias(result))
}
func (InlineQueryResultPhoto) isInlineQueryResult() {}
func (result InlineQueryResultPhoto) MarshalJSON() ([]byte, error) {
result.Type = "photo"
type alias InlineQueryResultPhoto
return json.Marshal(alias(result))
}
func (InlineQueryResultVideo) isInlineQueryResult() {}
func (result InlineQueryResultVideo) MarshalJSON() ([]byte, error) {
result.Type = "video"
type alias InlineQueryResultVideo
return json.Marshal(alias(result))
}
func (InlineQueryResultVoice) isInlineQueryResult() {}
func (result InlineQueryResultVoice) MarshalJSON() ([]byte, error) {
result.Type = "voice"
type alias InlineQueryResultVoice
return json.Marshal(alias(result))
}
func (InlineQueryResultArticle) isInlineQueryResult() {}
func (result InlineQueryResultArticle) MarshalJSON() ([]byte, error) {
result.Type = "article"
type alias InlineQueryResultArticle
return json.Marshal(alias(result))
}
func (InlineQueryResultContact) isInlineQueryResult() {}
func (result InlineQueryResultContact) MarshalJSON() ([]byte, error) {
result.Type = "contact"
type alias InlineQueryResultContact
return json.Marshal(alias(result))
}
func (InlineQueryResultGame) isInlineQueryResult() {}
func (result InlineQueryResultGame) MarshalJSON() ([]byte, error) {
result.Type = "game"
type alias InlineQueryResultGame
return json.Marshal(alias(result))
}
func (InlineQueryResultLocation) isInlineQueryResult() {}
func (result InlineQueryResultLocation) MarshalJSON() ([]byte, error) {
result.Type = "location"
type alias InlineQueryResultLocation
return json.Marshal(alias(result))
}
func (InlineQueryResultVenue) isInlineQueryResult() {}
func (result InlineQueryResultVenue) MarshalJSON() ([]byte, error) {
result.Type = "venue"
type alias InlineQueryResultVenue
return json.Marshal(alias(result))
}
// InputMessageContent it's generic interface for all types of input message content.
//
// Known implementations:
// - [InputTextMessageContent]
// - [InputLocationMessageContent]
// - [InputVenueMessageContent]
// - [InputContactMessageContent]
// - [InputInvoiceMessageContent]
type InputMessageContent interface {
isInputMessageContent()
}
func (content InputTextMessageContent) isInputMessageContent() {}
func (content InputLocationMessageContent) isInputMessageContent() {}
func (content InputVenueMessageContent) isInputMessageContent() {}
func (content InputContactMessageContent) isInputMessageContent() {}
func (content InputInvoiceMessageContent) isInputMessageContent() {}
func (media *InputMediaPhoto) getMedia() (*FileArg, *InputFile) {
return &media.Media, nil
}
func (media *InputMediaVideo) getMedia() (*FileArg, *InputFile) {
return &media.Media, media.Thumbnail
}
func (media *InputMediaAudio) getMedia() (*FileArg, *InputFile) {
return &media.Media, media.Thumbnail
}
func (media *InputMediaDocument) getMedia() (*FileArg, *InputFile) {
return &media.Media, media.Thumbnail
}
func (media *InputMediaAnimation) getMedia() (*FileArg, *InputFile) {
return &media.Media, media.Thumbnail
}
func (media *InputMediaPhoto) MarshalJSON() ([]byte, error) {
media.Type = "photo"
type alias InputMediaPhoto
return json.Marshal(alias(*media))
}
func (media *InputMediaVideo) MarshalJSON() ([]byte, error) {
media.Type = "video"
type alias InputMediaVideo
return json.Marshal(alias(*media))
}
func (media *InputMediaAudio) MarshalJSON() ([]byte, error) {
media.Type = "audio"
type alias InputMediaAudio
return json.Marshal(alias(*media))
}
func (media *InputMediaDocument) MarshalJSON() ([]byte, error) {
media.Type = "document"
type alias InputMediaDocument
return json.Marshal(alias(*media))
}
func (media *InputMediaAnimation) MarshalJSON() ([]byte, error) {
media.Type = "animation"
type alias InputMediaAnimation
return json.Marshal(alias(*media))
}
// BotCommandScope it's generic interface for all types of bot command scope.
//
// Known implementations:
// - [BotCommandScopeDefault]
// - [BotCommandScopeAllPrivateChats]
// - [BotCommandScopeAllGroupChats]
// - [BotCommandScopeAllChatAdministrators]
// - [BotCommandScopeChat]
// - [BotCommandScopeChatAdministrators]
// - [BotCommandScopeChatMember]
type BotCommandScope interface {
isBotCommandScope()
json.Marshaler
}
func (BotCommandScopeDefault) isBotCommandScope() {}
func (scope BotCommandScopeDefault) MarshalJSON() ([]byte, error) {
scope.Type = "default"
type alias BotCommandScopeDefault
return json.Marshal(alias(scope))
}
func (BotCommandScopeAllPrivateChats) isBotCommandScope() {}
func (scope BotCommandScopeAllPrivateChats) MarshalJSON() ([]byte, error) {
scope.Type = "all_private_chats"
type alias BotCommandScopeAllPrivateChats
return json.Marshal(alias(scope))
}
func (BotCommandScopeAllGroupChats) isBotCommandScope() {}
func (scope BotCommandScopeAllGroupChats) MarshalJSON() ([]byte, error) {
scope.Type = "all_group_chats"
type alias BotCommandScopeAllGroupChats
return json.Marshal(alias(scope))
}
func (BotCommandScopeAllChatAdministrators) isBotCommandScope() {}
func (scope BotCommandScopeAllChatAdministrators) MarshalJSON() ([]byte, error) {
scope.Type = "all_chat_administrators"
type alias BotCommandScopeAllChatAdministrators
return json.Marshal(alias(scope))
}
func (BotCommandScopeChat) isBotCommandScope() {}
func (scope BotCommandScopeChat) MarshalJSON() ([]byte, error) {
scope.Type = "chat"
type alias BotCommandScopeChat
return json.Marshal(alias(scope))
}
func (BotCommandScopeChatAdministrators) isBotCommandScope() {}
func (scope BotCommandScopeChatAdministrators) MarshalJSON() ([]byte, error) {
scope.Type = "chat_administrators"
type alias BotCommandScopeChatAdministrators
return json.Marshal(alias(scope))
}
func (BotCommandScopeChatMember) isBotCommandScope() {}
func (scope BotCommandScopeChatMember) MarshalJSON() ([]byte, error) {
scope.Type = "chat_member"
type alias BotCommandScopeChatMember
return json.Marshal(alias(scope))
}
// MenuButton it's generic interface for all types of menu button.
//
// Known implementations:
// - [MenuButtonDefault]
// - [MenuButtonCommands]
// - [MenubuttonWebApp]
type MenuButton interface {
isMenuButton()
json.Marshaler
}
func (MenuButtonDefault) isMenuButton() {}
func (button MenuButtonDefault) MarshalJSON() ([]byte, error) {
button.Type = "default"
type alias MenuButtonDefault
return json.Marshal(alias(button))
}
func (MenuButtonCommands) isMenuButton() {}
func (button MenuButtonCommands) MarshalJSON() ([]byte, error) {
button.Type = "commands"
type alias MenuButtonCommands
return json.Marshal(alias(button))
}
func (MenuButtonWebApp) isMenuButton() {}
func (button MenuButtonWebApp) MarshalJSON() ([]byte, error) {
button.Type = "web_app"
type alias MenuButtonWebApp
return json.Marshal(alias(button))
}
// MenuButtonOneOf contains one of MenuButton implementations.
// It's used for proper JSON marshaling.
type MenuButtonOneOf struct {
Default *MenuButtonDefault
Commands *MenuButtonCommands
WebApp *MenuButtonWebApp
}
func (button *MenuButtonOneOf) UnmarshalJSON(v []byte) error {
var partial struct {
Type string `json:"type"`
}
if err := json.Unmarshal(v, &partial); err != nil {
return fmt.Errorf("unmarshal MenuButtonOneOf partial: %w", err)
}
switch partial.Type {
case "default":
button.Default = &MenuButtonDefault{}
return json.Unmarshal(v, button.Default)
case "commands":
button.Commands = &MenuButtonCommands{}
return json.Unmarshal(v, button.Commands)
case "web_app":
button.WebApp = &MenuButtonWebApp{}
return json.Unmarshal(v, button.WebApp)
default:
return fmt.Errorf("unknown MenuButtonOneOf type: %s", partial.Type)
}
}
// MessageType it's type for describe content of Message.
type MessageType int
const (
MessageTypeUnknown MessageType = iota
MessageTypeText
MessageTypeAnimation
MessageTypeAudio
MessageTypeDocument
MessageTypePhoto
MessageTypeSticker
MessageTypeVideo
MessageTypeVideoNote
MessageTypeVoice
MessageTypeContact
MessageTypeDice
MessageTypeGame
MessageTypePoll
MessageTypeVenue
MessageTypeLocation
MessageTypeNewChatMembers
MessageTypeLeftChatMember
MessageTypeNewChatTitle
MessageTypeNewChatPhoto
MessageTypeDeleteChatPhoto
MessageTypeGroupChatCreated
MessageTypeSupergroupChatCreated
MessageTypeChannelChatCreated
MessageTypeMessageAutoDeleteTimerChanged
MessageTypeMigrateToChatID
MessageTypeMigrateFromChatID
MessageTypePinnedMessage
MessageTypeInvoice
MessageTypeSuccessfulPayment
MessageTypeUsersShared
MessageTypeChatShared
MessageTypeConnectedWebsite
MessageTypePassportData
MessageTypeProximityAlertTriggered
MessageTypeVideoChatScheduled
MessageTypeVideoChatStarted
MessageTypeVideoChatEnded
MessageTypeVideoChatParticipantsInvited
MessageTypeWebAppData
)
func (msg *Message) Type() MessageType {
switch {
case msg.Text != "":
return MessageTypeText
case msg.Animation != nil:
return MessageTypeAnimation
case msg.Audio != nil:
return MessageTypeAudio
case msg.Document != nil:
return MessageTypeDocument
case msg.Photo != nil:
return MessageTypePhoto
case msg.Sticker != nil:
return MessageTypeSticker
case msg.Video != nil:
return MessageTypeVideo
case msg.VideoNote != nil:
return MessageTypeVideoNote
case msg.Voice != nil:
return MessageTypeVoice
case msg.Contact != nil:
return MessageTypeContact
case msg.Dice != nil:
return MessageTypeDice
case msg.Game != nil:
return MessageTypeGame
case msg.Poll != nil:
return MessageTypePoll
case msg.Venue != nil: