-
Notifications
You must be signed in to change notification settings - Fork 910
/
configs.go
2568 lines (2031 loc) · 65.1 KB
/
configs.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 (
"bytes"
"fmt"
"io"
"net/url"
"os"
"strconv"
)
// Telegram constants
const (
// APIEndpoint is the endpoint for all API methods,
// with formatting for Sprintf.
APIEndpoint = "https://api.telegram.org/bot%s/%s"
// FileEndpoint is the endpoint for downloading a file from Telegram.
FileEndpoint = "https://api.telegram.org/file/bot%s/%s"
)
// Constant values for ChatActions
const (
ChatTyping = "typing"
ChatUploadPhoto = "upload_photo"
ChatRecordVideo = "record_video"
ChatUploadVideo = "upload_video"
ChatRecordVoice = "record_voice"
ChatUploadVoice = "upload_voice"
ChatUploadDocument = "upload_document"
ChatChooseSticker = "choose_sticker"
ChatFindLocation = "find_location"
ChatRecordVideoNote = "record_video_note"
ChatUploadVideoNote = "upload_video_note"
)
// API errors
const (
// ErrAPIForbidden happens when a token is bad
ErrAPIForbidden = "forbidden"
)
// Constant values for ParseMode in MessageConfig
const (
ModeMarkdown = "Markdown"
ModeMarkdownV2 = "MarkdownV2"
ModeHTML = "HTML"
)
// Constant values for update types
const (
// UpdateTypeMessage is new incoming message of any kind — text, photo, sticker, etc.
UpdateTypeMessage = "message"
// UpdateTypeEditedMessage is new version of a message that is known to the bot and was edited
UpdateTypeEditedMessage = "edited_message"
// UpdateTypeChannelPost is new incoming channel post of any kind — text, photo, sticker, etc.
UpdateTypeChannelPost = "channel_post"
// UpdateTypeEditedChannelPost is new version of a channel post that is known to the bot and was edited
UpdateTypeEditedChannelPost = "edited_channel_post"
// UpdateTypeInlineQuery is new incoming inline query
UpdateTypeInlineQuery = "inline_query"
// UpdateTypeChosenInlineResult i the result of an inline query that was chosen by a user and sent to their
// chat partner. Please see the documentation on the feedback collecting for
// details on how to enable these updates for your bot.
UpdateTypeChosenInlineResult = "chosen_inline_result"
// UpdateTypeCallbackQuery is new incoming callback query
UpdateTypeCallbackQuery = "callback_query"
// UpdateTypeShippingQuery is new incoming shipping query. Only for invoices with flexible price
UpdateTypeShippingQuery = "shipping_query"
// UpdateTypePreCheckoutQuery is new incoming pre-checkout query. Contains full information about checkout
UpdateTypePreCheckoutQuery = "pre_checkout_query"
// UpdateTypePoll is new poll state. Bots receive only updates about stopped polls and polls
// which are sent by the bot
UpdateTypePoll = "poll"
// UpdateTypePollAnswer is when user changed their answer in a non-anonymous poll. Bots receive new votes
// only in polls that were sent by the bot itself.
UpdateTypePollAnswer = "poll_answer"
// UpdateTypeMyChatMember is when 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.
UpdateTypeMyChatMember = "my_chat_member"
// UpdateTypeChatMember is when the bot must be an administrator in the chat and must explicitly specify
// this update in the list of allowed_updates to receive these updates.
UpdateTypeChatMember = "chat_member"
)
// Library errors
const (
ErrBadURL = "bad or empty url"
)
// Chattable is any config type that can be sent.
type Chattable interface {
params() (Params, error)
method() string
}
// Fileable is any config type that can be sent that includes a file.
type Fileable interface {
Chattable
files() []RequestFile
}
// RequestFile represents a file associated with a field name.
type RequestFile struct {
// The file field name.
Name string
// The file data to include.
Data RequestFileData
}
// RequestFileData represents the data to be used for a file.
type RequestFileData interface {
// NeedsUpload shows if the file needs to be uploaded.
NeedsUpload() bool
// UploadData gets the file name and an `io.Reader` for the file to be uploaded. This
// must only be called when the file needs to be uploaded.
UploadData() (string, io.Reader, error)
// SendData gets the file data to send when a file does not need to be uploaded. This
// must only be called when the file does not need to be uploaded.
SendData() string
}
// FileBytes contains information about a set of bytes to upload
// as a File.
type FileBytes struct {
Name string
Bytes []byte
}
func (fb FileBytes) NeedsUpload() bool {
return true
}
func (fb FileBytes) UploadData() (string, io.Reader, error) {
return fb.Name, bytes.NewReader(fb.Bytes), nil
}
func (fb FileBytes) SendData() string {
panic("FileBytes must be uploaded")
}
// FileReader contains information about a reader to upload as a File.
type FileReader struct {
Name string
Reader io.Reader
}
func (fr FileReader) NeedsUpload() bool {
return true
}
func (fr FileReader) UploadData() (string, io.Reader, error) {
return fr.Name, fr.Reader, nil
}
func (fr FileReader) SendData() string {
panic("FileReader must be uploaded")
}
// FilePath is a path to a local file.
type FilePath string
func (fp FilePath) NeedsUpload() bool {
return true
}
func (fp FilePath) UploadData() (string, io.Reader, error) {
fileHandle, err := os.Open(string(fp))
if err != nil {
return "", nil, err
}
name := fileHandle.Name()
return name, fileHandle, err
}
func (fp FilePath) SendData() string {
panic("FilePath must be uploaded")
}
// FileURL is a URL to use as a file for a request.
type FileURL string
func (fu FileURL) NeedsUpload() bool {
return false
}
func (fu FileURL) UploadData() (string, io.Reader, error) {
panic("FileURL cannot be uploaded")
}
func (fu FileURL) SendData() string {
return string(fu)
}
// FileID is an ID of a file already uploaded to Telegram.
type FileID string
func (fi FileID) NeedsUpload() bool {
return false
}
func (fi FileID) UploadData() (string, io.Reader, error) {
panic("FileID cannot be uploaded")
}
func (fi FileID) SendData() string {
return string(fi)
}
// fileAttach is an internal file type used for processed media groups.
type fileAttach string
func (fa fileAttach) NeedsUpload() bool {
return false
}
func (fa fileAttach) UploadData() (string, io.Reader, error) {
panic("fileAttach cannot be uploaded")
}
func (fa fileAttach) SendData() string {
return string(fa)
}
// LogOutConfig is a request to log out of the cloud Bot API server.
//
// Note that you may not log back in for at least 10 minutes.
type LogOutConfig struct{}
func (LogOutConfig) method() string {
return "logOut"
}
func (LogOutConfig) params() (Params, error) {
return nil, nil
}
// CloseConfig is a request to close the bot instance on a local server.
//
// Note that you may not close an instance for the first 10 minutes after the
// bot has started.
type CloseConfig struct{}
func (CloseConfig) method() string {
return "close"
}
func (CloseConfig) params() (Params, error) {
return nil, nil
}
// BaseChat is base type for all chat config types.
type BaseChat struct {
ChatID int64 // required
ChannelUsername string
ProtectContent bool
ReplyToMessageID int
ReplyMarkup interface{}
DisableNotification bool
AllowSendingWithoutReply bool
}
func (chat *BaseChat) params() (Params, error) {
params := make(Params)
params.AddFirstValid("chat_id", chat.ChatID, chat.ChannelUsername)
params.AddNonZero("reply_to_message_id", chat.ReplyToMessageID)
params.AddBool("disable_notification", chat.DisableNotification)
params.AddBool("allow_sending_without_reply", chat.AllowSendingWithoutReply)
params.AddBool("protect_content", chat.ProtectContent)
err := params.AddInterface("reply_markup", chat.ReplyMarkup)
return params, err
}
// BaseFile is a base type for all file config types.
type BaseFile struct {
BaseChat
File RequestFileData
}
func (file BaseFile) params() (Params, error) {
return file.BaseChat.params()
}
// BaseEdit is base type of all chat edits.
type BaseEdit struct {
ChatID int64
ChannelUsername string
MessageID int
InlineMessageID string
ReplyMarkup *InlineKeyboardMarkup
}
func (edit BaseEdit) params() (Params, error) {
params := make(Params)
if edit.InlineMessageID != "" {
params["inline_message_id"] = edit.InlineMessageID
} else {
params.AddFirstValid("chat_id", edit.ChatID, edit.ChannelUsername)
params.AddNonZero("message_id", edit.MessageID)
}
err := params.AddInterface("reply_markup", edit.ReplyMarkup)
return params, err
}
// MessageConfig contains information about a SendMessage request.
type MessageConfig struct {
BaseChat
Text string
ParseMode string
Entities []MessageEntity
DisableWebPagePreview bool
}
func (config MessageConfig) params() (Params, error) {
params, err := config.BaseChat.params()
if err != nil {
return params, err
}
params.AddNonEmpty("text", config.Text)
params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
params.AddNonEmpty("parse_mode", config.ParseMode)
err = params.AddInterface("entities", config.Entities)
return params, err
}
func (config MessageConfig) method() string {
return "sendMessage"
}
// ForwardConfig contains information about a ForwardMessage request.
type ForwardConfig struct {
BaseChat
FromChatID int64 // required
FromChannelUsername string
MessageID int // required
}
func (config ForwardConfig) params() (Params, error) {
params, err := config.BaseChat.params()
if err != nil {
return params, err
}
params.AddNonZero64("from_chat_id", config.FromChatID)
params.AddNonZero("message_id", config.MessageID)
return params, nil
}
func (config ForwardConfig) method() string {
return "forwardMessage"
}
// CopyMessageConfig contains information about a copyMessage request.
type CopyMessageConfig struct {
BaseChat
FromChatID int64
FromChannelUsername string
MessageID int
Caption string
ParseMode string
CaptionEntities []MessageEntity
}
func (config CopyMessageConfig) params() (Params, error) {
params, err := config.BaseChat.params()
if err != nil {
return params, err
}
params.AddFirstValid("from_chat_id", config.FromChatID, config.FromChannelUsername)
params.AddNonZero("message_id", config.MessageID)
params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode)
err = params.AddInterface("caption_entities", config.CaptionEntities)
return params, err
}
func (config CopyMessageConfig) method() string {
return "copyMessage"
}
// PhotoConfig contains information about a SendPhoto request.
type PhotoConfig struct {
BaseFile
Thumb RequestFileData
Caption string
ParseMode string
CaptionEntities []MessageEntity
}
func (config PhotoConfig) params() (Params, error) {
params, err := config.BaseFile.params()
if err != nil {
return params, err
}
params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode)
err = params.AddInterface("caption_entities", config.CaptionEntities)
return params, err
}
func (config PhotoConfig) method() string {
return "sendPhoto"
}
func (config PhotoConfig) files() []RequestFile {
files := []RequestFile{{
Name: "photo",
Data: config.File,
}}
if config.Thumb != nil {
files = append(files, RequestFile{
Name: "thumb",
Data: config.Thumb,
})
}
return files
}
// AudioConfig contains information about a SendAudio request.
type AudioConfig struct {
BaseFile
Thumb RequestFileData
Caption string
ParseMode string
CaptionEntities []MessageEntity
Duration int
Performer string
Title string
}
func (config AudioConfig) params() (Params, error) {
params, err := config.BaseChat.params()
if err != nil {
return params, err
}
params.AddNonZero("duration", config.Duration)
params.AddNonEmpty("performer", config.Performer)
params.AddNonEmpty("title", config.Title)
params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode)
err = params.AddInterface("caption_entities", config.CaptionEntities)
return params, err
}
func (config AudioConfig) method() string {
return "sendAudio"
}
func (config AudioConfig) files() []RequestFile {
files := []RequestFile{{
Name: "audio",
Data: config.File,
}}
if config.Thumb != nil {
files = append(files, RequestFile{
Name: "thumb",
Data: config.Thumb,
})
}
return files
}
// DocumentConfig contains information about a SendDocument request.
type DocumentConfig struct {
BaseFile
Thumb RequestFileData
Caption string
ParseMode string
CaptionEntities []MessageEntity
DisableContentTypeDetection bool
}
func (config DocumentConfig) params() (Params, error) {
params, err := config.BaseFile.params()
params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode)
params.AddBool("disable_content_type_detection", config.DisableContentTypeDetection)
return params, err
}
func (config DocumentConfig) method() string {
return "sendDocument"
}
func (config DocumentConfig) files() []RequestFile {
files := []RequestFile{{
Name: "document",
Data: config.File,
}}
if config.Thumb != nil {
files = append(files, RequestFile{
Name: "thumb",
Data: config.Thumb,
})
}
return files
}
// StickerConfig contains information about a SendSticker request.
type StickerConfig struct {
BaseFile
}
func (config StickerConfig) params() (Params, error) {
return config.BaseChat.params()
}
func (config StickerConfig) method() string {
return "sendSticker"
}
func (config StickerConfig) files() []RequestFile {
return []RequestFile{{
Name: "sticker",
Data: config.File,
}}
}
// VideoConfig contains information about a SendVideo request.
type VideoConfig struct {
BaseFile
Thumb RequestFileData
Duration int
Caption string
ParseMode string
CaptionEntities []MessageEntity
SupportsStreaming bool
}
func (config VideoConfig) params() (Params, error) {
params, err := config.BaseChat.params()
if err != nil {
return params, err
}
params.AddNonZero("duration", config.Duration)
params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode)
params.AddBool("supports_streaming", config.SupportsStreaming)
err = params.AddInterface("caption_entities", config.CaptionEntities)
return params, err
}
func (config VideoConfig) method() string {
return "sendVideo"
}
func (config VideoConfig) files() []RequestFile {
files := []RequestFile{{
Name: "video",
Data: config.File,
}}
if config.Thumb != nil {
files = append(files, RequestFile{
Name: "thumb",
Data: config.Thumb,
})
}
return files
}
// AnimationConfig contains information about a SendAnimation request.
type AnimationConfig struct {
BaseFile
Duration int
Thumb RequestFileData
Caption string
ParseMode string
CaptionEntities []MessageEntity
}
func (config AnimationConfig) params() (Params, error) {
params, err := config.BaseChat.params()
if err != nil {
return params, err
}
params.AddNonZero("duration", config.Duration)
params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode)
err = params.AddInterface("caption_entities", config.CaptionEntities)
return params, err
}
func (config AnimationConfig) method() string {
return "sendAnimation"
}
func (config AnimationConfig) files() []RequestFile {
files := []RequestFile{{
Name: "animation",
Data: config.File,
}}
if config.Thumb != nil {
files = append(files, RequestFile{
Name: "thumb",
Data: config.Thumb,
})
}
return files
}
// VideoNoteConfig contains information about a SendVideoNote request.
type VideoNoteConfig struct {
BaseFile
Thumb RequestFileData
Duration int
Length int
}
func (config VideoNoteConfig) params() (Params, error) {
params, err := config.BaseChat.params()
params.AddNonZero("duration", config.Duration)
params.AddNonZero("length", config.Length)
return params, err
}
func (config VideoNoteConfig) method() string {
return "sendVideoNote"
}
func (config VideoNoteConfig) files() []RequestFile {
files := []RequestFile{{
Name: "video_note",
Data: config.File,
}}
if config.Thumb != nil {
files = append(files, RequestFile{
Name: "thumb",
Data: config.Thumb,
})
}
return files
}
// VoiceConfig contains information about a SendVoice request.
type VoiceConfig struct {
BaseFile
Thumb RequestFileData
Caption string
ParseMode string
CaptionEntities []MessageEntity
Duration int
}
func (config VoiceConfig) params() (Params, error) {
params, err := config.BaseChat.params()
if err != nil {
return params, err
}
params.AddNonZero("duration", config.Duration)
params.AddNonEmpty("caption", config.Caption)
params.AddNonEmpty("parse_mode", config.ParseMode)
err = params.AddInterface("caption_entities", config.CaptionEntities)
return params, err
}
func (config VoiceConfig) method() string {
return "sendVoice"
}
func (config VoiceConfig) files() []RequestFile {
files := []RequestFile{{
Name: "voice",
Data: config.File,
}}
if config.Thumb != nil {
files = append(files, RequestFile{
Name: "thumb",
Data: config.Thumb,
})
}
return files
}
// LocationConfig contains information about a SendLocation request.
type LocationConfig struct {
BaseChat
Latitude float64 // required
Longitude float64 // required
HorizontalAccuracy float64 // optional
LivePeriod int // optional
Heading int // optional
ProximityAlertRadius int // optional
}
func (config LocationConfig) params() (Params, error) {
params, err := config.BaseChat.params()
params.AddNonZeroFloat("latitude", config.Latitude)
params.AddNonZeroFloat("longitude", config.Longitude)
params.AddNonZeroFloat("horizontal_accuracy", config.HorizontalAccuracy)
params.AddNonZero("live_period", config.LivePeriod)
params.AddNonZero("heading", config.Heading)
params.AddNonZero("proximity_alert_radius", config.ProximityAlertRadius)
return params, err
}
func (config LocationConfig) method() string {
return "sendLocation"
}
// EditMessageLiveLocationConfig allows you to update a live location.
type EditMessageLiveLocationConfig struct {
BaseEdit
Latitude float64 // required
Longitude float64 // required
HorizontalAccuracy float64 // optional
Heading int // optional
ProximityAlertRadius int // optional
}
func (config EditMessageLiveLocationConfig) params() (Params, error) {
params, err := config.BaseEdit.params()
params.AddNonZeroFloat("latitude", config.Latitude)
params.AddNonZeroFloat("longitude", config.Longitude)
params.AddNonZeroFloat("horizontal_accuracy", config.HorizontalAccuracy)
params.AddNonZero("heading", config.Heading)
params.AddNonZero("proximity_alert_radius", config.ProximityAlertRadius)
return params, err
}
func (config EditMessageLiveLocationConfig) method() string {
return "editMessageLiveLocation"
}
// StopMessageLiveLocationConfig stops updating a live location.
type StopMessageLiveLocationConfig struct {
BaseEdit
}
func (config StopMessageLiveLocationConfig) params() (Params, error) {
return config.BaseEdit.params()
}
func (config StopMessageLiveLocationConfig) method() string {
return "stopMessageLiveLocation"
}
// VenueConfig contains information about a SendVenue request.
type VenueConfig struct {
BaseChat
Latitude float64 // required
Longitude float64 // required
Title string // required
Address string // required
FoursquareID string
FoursquareType string
GooglePlaceID string
GooglePlaceType string
}
func (config VenueConfig) params() (Params, error) {
params, err := config.BaseChat.params()
params.AddNonZeroFloat("latitude", config.Latitude)
params.AddNonZeroFloat("longitude", config.Longitude)
params["title"] = config.Title
params["address"] = config.Address
params.AddNonEmpty("foursquare_id", config.FoursquareID)
params.AddNonEmpty("foursquare_type", config.FoursquareType)
params.AddNonEmpty("google_place_id", config.GooglePlaceID)
params.AddNonEmpty("google_place_type", config.GooglePlaceType)
return params, err
}
func (config VenueConfig) method() string {
return "sendVenue"
}
// ContactConfig allows you to send a contact.
type ContactConfig struct {
BaseChat
PhoneNumber string
FirstName string
LastName string
VCard string
}
func (config ContactConfig) params() (Params, error) {
params, err := config.BaseChat.params()
params["phone_number"] = config.PhoneNumber
params["first_name"] = config.FirstName
params.AddNonEmpty("last_name", config.LastName)
params.AddNonEmpty("vcard", config.VCard)
return params, err
}
func (config ContactConfig) method() string {
return "sendContact"
}
// SendPollConfig allows you to send a poll.
type SendPollConfig struct {
BaseChat
Question string
Options []string
IsAnonymous bool
Type string
AllowsMultipleAnswers bool
CorrectOptionID int64
Explanation string
ExplanationParseMode string
ExplanationEntities []MessageEntity
OpenPeriod int
CloseDate int
IsClosed bool
}
func (config SendPollConfig) params() (Params, error) {
params, err := config.BaseChat.params()
if err != nil {
return params, err
}
params["question"] = config.Question
if err = params.AddInterface("options", config.Options); err != nil {
return params, err
}
params["is_anonymous"] = strconv.FormatBool(config.IsAnonymous)
params.AddNonEmpty("type", config.Type)
params["allows_multiple_answers"] = strconv.FormatBool(config.AllowsMultipleAnswers)
params["correct_option_id"] = strconv.FormatInt(config.CorrectOptionID, 10)
params.AddBool("is_closed", config.IsClosed)
params.AddNonEmpty("explanation", config.Explanation)
params.AddNonEmpty("explanation_parse_mode", config.ExplanationParseMode)
params.AddNonZero("open_period", config.OpenPeriod)
params.AddNonZero("close_date", config.CloseDate)
err = params.AddInterface("explanation_entities", config.ExplanationEntities)
return params, err
}
func (SendPollConfig) method() string {
return "sendPoll"
}
// GameConfig allows you to send a game.
type GameConfig struct {
BaseChat
GameShortName string
}
func (config GameConfig) params() (Params, error) {
params, err := config.BaseChat.params()
params["game_short_name"] = config.GameShortName
return params, err
}
func (config GameConfig) method() string {
return "sendGame"
}
// SetGameScoreConfig allows you to update the game score in a chat.
type SetGameScoreConfig struct {
UserID int64
Score int
Force bool
DisableEditMessage bool
ChatID int64
ChannelUsername string
MessageID int
InlineMessageID string
}
func (config SetGameScoreConfig) params() (Params, error) {
params := make(Params)
params.AddNonZero64("user_id", config.UserID)
params.AddNonZero("scrore", config.Score)
params.AddBool("disable_edit_message", config.DisableEditMessage)
if config.InlineMessageID != "" {
params["inline_message_id"] = config.InlineMessageID
} else {
params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
params.AddNonZero("message_id", config.MessageID)
}
return params, nil
}
func (config SetGameScoreConfig) method() string {
return "setGameScore"
}
// GetGameHighScoresConfig allows you to fetch the high scores for a game.
type GetGameHighScoresConfig struct {
UserID int64
ChatID int64
ChannelUsername string
MessageID int
InlineMessageID string
}
func (config GetGameHighScoresConfig) params() (Params, error) {
params := make(Params)
params.AddNonZero64("user_id", config.UserID)
if config.InlineMessageID != "" {
params["inline_message_id"] = config.InlineMessageID
} else {
params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
params.AddNonZero("message_id", config.MessageID)
}
return params, nil
}
func (config GetGameHighScoresConfig) method() string {
return "getGameHighScores"
}
// ChatActionConfig contains information about a SendChatAction request.
type ChatActionConfig struct {
BaseChat
Action string // required
}
func (config ChatActionConfig) params() (Params, error) {
params, err := config.BaseChat.params()
params["action"] = config.Action
return params, err
}
func (config ChatActionConfig) method() string {
return "sendChatAction"
}
// EditMessageTextConfig allows you to modify the text in a message.
type EditMessageTextConfig struct {
BaseEdit
Text string
ParseMode string
Entities []MessageEntity
DisableWebPagePreview bool
}