configs.go (view raw)
1package tgbotapi
2
3import (
4 "fmt"
5 "io"
6 "net/url"
7 "strconv"
8)
9
10// Telegram constants
11const (
12 // APIEndpoint is the endpoint for all API methods,
13 // with formatting for Sprintf.
14 APIEndpoint = "https://api.telegram.org/bot%s/%s"
15 // FileEndpoint is the endpoint for downloading a file from Telegram.
16 FileEndpoint = "https://api.telegram.org/file/bot%s/%s"
17)
18
19// Constant values for ChatActions
20const (
21 ChatTyping = "typing"
22 ChatUploadPhoto = "upload_photo"
23 ChatRecordVideo = "record_video"
24 ChatUploadVideo = "upload_video"
25 ChatRecordAudio = "record_audio"
26 ChatUploadAudio = "upload_audio"
27 ChatUploadDocument = "upload_document"
28 ChatFindLocation = "find_location"
29 ChatRecordVideoNote = "record_video_note"
30 ChatUploadVideoNote = "upload_video_note"
31)
32
33// API errors
34const (
35 // ErrAPIForbidden happens when a token is bad
36 ErrAPIForbidden = "forbidden"
37)
38
39// Constant values for ParseMode in MessageConfig
40const (
41 ModeMarkdown = "Markdown"
42 ModeMarkdownV2 = "MarkdownV2"
43 ModeHTML = "HTML"
44)
45
46// Library errors
47const (
48 // ErrBadFileType happens when you pass an unknown type
49 ErrBadFileType = "bad file type"
50 ErrBadURL = "bad or empty url"
51)
52
53// Chattable is any config type that can be sent.
54type Chattable interface {
55 params() (Params, error)
56 method() string
57}
58
59// RequestFile represents a file associated with a request. May involve
60// uploading a file, or passing an existing ID.
61type RequestFile struct {
62 // The multipart upload field name.
63 Name string
64 // The file to upload.
65 File interface{}
66}
67
68// Fileable is any config type that can be sent that includes a file.
69type Fileable interface {
70 Chattable
71 files() []RequestFile
72}
73
74// BaseChat is base type for all chat config types.
75type BaseChat struct {
76 ChatID int64 // required
77 ChannelUsername string
78 ReplyToMessageID int
79 ReplyMarkup interface{}
80 DisableNotification bool
81}
82
83func (chat *BaseChat) params() (Params, error) {
84 params := make(Params)
85
86 params.AddFirstValid("chat_id", chat.ChatID, chat.ChannelUsername)
87 params.AddNonZero("reply_to_message_id", chat.ReplyToMessageID)
88 params.AddBool("disable_notification", chat.DisableNotification)
89
90 err := params.AddInterface("reply_markup", chat.ReplyMarkup)
91
92 return params, err
93}
94
95// BaseFile is a base type for all file config types.
96type BaseFile struct {
97 BaseChat
98 File interface{}
99}
100
101func (file BaseFile) params() (Params, error) {
102 return file.BaseChat.params()
103}
104
105// BaseEdit is base type of all chat edits.
106type BaseEdit struct {
107 ChatID int64
108 ChannelUsername string
109 MessageID int
110 InlineMessageID string
111 ReplyMarkup *InlineKeyboardMarkup
112}
113
114func (edit BaseEdit) params() (Params, error) {
115 params := make(Params)
116
117 if edit.InlineMessageID != "" {
118 params["inline_message_id"] = edit.InlineMessageID
119 } else {
120 params.AddFirstValid("chat_id", edit.ChatID, edit.ChannelUsername)
121 params.AddNonZero("message_id", edit.MessageID)
122 }
123
124 err := params.AddInterface("reply_markup", edit.ReplyMarkup)
125
126 return params, err
127}
128
129// MessageConfig contains information about a SendMessage request.
130type MessageConfig struct {
131 BaseChat
132 Text string
133 ParseMode string
134 DisableWebPagePreview bool
135}
136
137func (config MessageConfig) params() (Params, error) {
138 params, err := config.BaseChat.params()
139 if err != nil {
140 return params, err
141 }
142
143 params.AddNonEmpty("text", config.Text)
144 params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
145 params.AddNonEmpty("parse_mode", config.ParseMode)
146
147 return params, nil
148}
149
150func (config MessageConfig) method() string {
151 return "sendMessage"
152}
153
154// ForwardConfig contains information about a ForwardMessage request.
155type ForwardConfig struct {
156 BaseChat
157 FromChatID int64 // required
158 FromChannelUsername string
159 MessageID int // required
160}
161
162func (config ForwardConfig) params() (Params, error) {
163 params, err := config.BaseChat.params()
164 if err != nil {
165 return params, err
166 }
167
168 params.AddNonZero64("from_chat_id", config.FromChatID)
169 params.AddNonZero("message_id", config.MessageID)
170
171 return params, nil
172}
173
174func (config ForwardConfig) method() string {
175 return "forwardMessage"
176}
177
178// PhotoConfig contains information about a SendPhoto request.
179type PhotoConfig struct {
180 BaseFile
181 Thumb interface{}
182 Caption string
183 ParseMode string
184}
185
186func (config PhotoConfig) params() (Params, error) {
187 params, err := config.BaseFile.params()
188
189 params.AddNonEmpty("caption", config.Caption)
190 params.AddNonEmpty("parse_mode", config.ParseMode)
191
192 return params, err
193}
194
195func (config PhotoConfig) method() string {
196 return "sendPhoto"
197}
198
199func (config PhotoConfig) files() []RequestFile {
200 files := []RequestFile{{
201 Name: "photo",
202 File: config.File,
203 }}
204
205 if config.Thumb != nil {
206 files = append(files, RequestFile{
207 Name: "thumb",
208 File: config.Thumb,
209 })
210 }
211
212 return files
213}
214
215// AudioConfig contains information about a SendAudio request.
216type AudioConfig struct {
217 BaseFile
218 Thumb interface{}
219 Caption string
220 ParseMode string
221 Duration int
222 Performer string
223 Title string
224}
225
226func (config AudioConfig) params() (Params, error) {
227 params, err := config.BaseChat.params()
228 if err != nil {
229 return params, err
230 }
231
232 params.AddNonZero("duration", config.Duration)
233 params.AddNonEmpty("performer", config.Performer)
234 params.AddNonEmpty("title", config.Title)
235 params.AddNonEmpty("caption", config.Caption)
236 params.AddNonEmpty("parse_mode", config.ParseMode)
237
238 return params, nil
239}
240
241func (config AudioConfig) method() string {
242 return "sendAudio"
243}
244
245func (config AudioConfig) files() []RequestFile {
246 files := []RequestFile{{
247 Name: "audio",
248 File: config.File,
249 }}
250
251 if config.Thumb != nil {
252 files = append(files, RequestFile{
253 Name: "thumb",
254 File: config.Thumb,
255 })
256 }
257
258 return files
259}
260
261// DocumentConfig contains information about a SendDocument request.
262type DocumentConfig struct {
263 BaseFile
264 Thumb interface{}
265 Caption string
266 ParseMode string
267}
268
269func (config DocumentConfig) params() (Params, error) {
270 params, err := config.BaseFile.params()
271
272 params.AddNonEmpty("caption", config.Caption)
273 params.AddNonEmpty("parse_mode", config.ParseMode)
274
275 return params, err
276}
277
278func (config DocumentConfig) method() string {
279 return "sendDocument"
280}
281
282func (config DocumentConfig) files() []RequestFile {
283 files := []RequestFile{{
284 Name: "document",
285 File: config.File,
286 }}
287
288 if config.Thumb != nil {
289 files = append(files, RequestFile{
290 Name: "thumb",
291 File: config.Thumb,
292 })
293 }
294
295 return files
296}
297
298// StickerConfig contains information about a SendSticker request.
299type StickerConfig struct {
300 BaseFile
301}
302
303func (config StickerConfig) params() (Params, error) {
304 return config.BaseChat.params()
305}
306
307func (config StickerConfig) method() string {
308 return "sendSticker"
309}
310
311func (config StickerConfig) files() []RequestFile {
312 return []RequestFile{{
313 Name: "sticker",
314 File: config.File,
315 }}
316}
317
318// VideoConfig contains information about a SendVideo request.
319type VideoConfig struct {
320 BaseFile
321 Thumb interface{}
322 Duration int
323 Caption string
324 ParseMode string
325 SupportsStreaming bool
326}
327
328func (config VideoConfig) params() (Params, error) {
329 params, err := config.BaseChat.params()
330
331 params.AddNonZero("duration", config.Duration)
332 params.AddNonEmpty("caption", config.Caption)
333 params.AddNonEmpty("parse_mode", config.ParseMode)
334 params.AddBool("supports_streaming", config.SupportsStreaming)
335
336 return params, err
337}
338
339func (config VideoConfig) method() string {
340 return "sendVideo"
341}
342
343func (config VideoConfig) files() []RequestFile {
344 files := []RequestFile{{
345 Name: "video",
346 File: config.File,
347 }}
348
349 if config.Thumb != nil {
350 files = append(files, RequestFile{
351 Name: "thumb",
352 File: config.Thumb,
353 })
354 }
355
356 return files
357}
358
359// AnimationConfig contains information about a SendAnimation request.
360type AnimationConfig struct {
361 BaseFile
362 Duration int
363 Thumb interface{}
364 Caption string
365 ParseMode string
366}
367
368func (config AnimationConfig) params() (Params, error) {
369 params, err := config.BaseChat.params()
370
371 params.AddNonZero("duration", config.Duration)
372 params.AddNonEmpty("caption", config.Caption)
373 params.AddNonEmpty("parse_mode", config.ParseMode)
374
375 return params, err
376}
377
378func (config AnimationConfig) name() string {
379 return "animation"
380}
381
382func (config AnimationConfig) method() string {
383 return "sendAnimation"
384}
385
386func (config AnimationConfig) files() []RequestFile {
387 files := []RequestFile{{
388 Name: "animation",
389 File: config.File,
390 }}
391
392 if config.Thumb != nil {
393 files = append(files, RequestFile{
394 Name: "thumb",
395 File: config.Thumb,
396 })
397 }
398
399 return files
400}
401
402// VideoNoteConfig contains information about a SendVideoNote request.
403type VideoNoteConfig struct {
404 BaseFile
405 Thumb interface{}
406 Duration int
407 Length int
408}
409
410func (config VideoNoteConfig) params() (Params, error) {
411 params, err := config.BaseChat.params()
412
413 params.AddNonZero("duration", config.Duration)
414 params.AddNonZero("length", config.Length)
415
416 return params, err
417}
418
419func (config VideoNoteConfig) method() string {
420 return "sendVideoNote"
421}
422
423func (config VideoNoteConfig) files() []RequestFile {
424 files := []RequestFile{{
425 Name: "video_note",
426 File: config.File,
427 }}
428
429 if config.Thumb != nil {
430 files = append(files, RequestFile{
431 Name: "thumb",
432 File: config.Thumb,
433 })
434 }
435
436 return files
437}
438
439// VoiceConfig contains information about a SendVoice request.
440type VoiceConfig struct {
441 BaseFile
442 Thumb interface{}
443 Caption string
444 ParseMode string
445 Duration int
446}
447
448func (config VoiceConfig) params() (Params, error) {
449 params, err := config.BaseChat.params()
450
451 params.AddNonZero("duration", config.Duration)
452 params.AddNonEmpty("caption", config.Caption)
453 params.AddNonEmpty("parse_mode", config.ParseMode)
454
455 return params, err
456}
457
458func (config VoiceConfig) method() string {
459 return "sendVoice"
460}
461
462func (config VoiceConfig) files() []RequestFile {
463 files := []RequestFile{{
464 Name: "voice",
465 File: config.File,
466 }}
467
468 if config.Thumb != nil {
469 files = append(files, RequestFile{
470 Name: "thumb",
471 File: config.Thumb,
472 })
473 }
474
475 return files
476}
477
478// LocationConfig contains information about a SendLocation request.
479type LocationConfig struct {
480 BaseChat
481 Latitude float64 // required
482 Longitude float64 // required
483 LivePeriod int // optional
484}
485
486func (config LocationConfig) params() (Params, error) {
487 params, err := config.BaseChat.params()
488
489 params.AddNonZeroFloat("latitude", config.Latitude)
490 params.AddNonZeroFloat("longitude", config.Longitude)
491 params.AddNonZero("live_period", config.LivePeriod)
492
493 return params, err
494}
495
496func (config LocationConfig) method() string {
497 return "sendLocation"
498}
499
500// EditMessageLiveLocationConfig allows you to update a live location.
501type EditMessageLiveLocationConfig struct {
502 BaseEdit
503 Latitude float64 // required
504 Longitude float64 // required
505}
506
507func (config EditMessageLiveLocationConfig) params() (Params, error) {
508 params, err := config.BaseEdit.params()
509
510 params.AddNonZeroFloat("latitude", config.Latitude)
511 params.AddNonZeroFloat("longitude", config.Longitude)
512
513 return params, err
514}
515
516func (config EditMessageLiveLocationConfig) method() string {
517 return "editMessageLiveLocation"
518}
519
520// StopMessageLiveLocationConfig stops updating a live location.
521type StopMessageLiveLocationConfig struct {
522 BaseEdit
523}
524
525func (config StopMessageLiveLocationConfig) params() (Params, error) {
526 return config.BaseEdit.params()
527}
528
529func (config StopMessageLiveLocationConfig) method() string {
530 return "stopMessageLiveLocation"
531}
532
533// VenueConfig contains information about a SendVenue request.
534type VenueConfig struct {
535 BaseChat
536 Latitude float64 // required
537 Longitude float64 // required
538 Title string // required
539 Address string // required
540 FoursquareID string
541}
542
543func (config VenueConfig) params() (Params, error) {
544 params, err := config.BaseChat.params()
545
546 params.AddNonZeroFloat("latitude", config.Latitude)
547 params.AddNonZeroFloat("longitude", config.Longitude)
548 params["title"] = config.Title
549 params["address"] = config.Address
550 params.AddNonEmpty("foursquare_id", config.FoursquareID)
551
552 return params, err
553}
554
555func (config VenueConfig) method() string {
556 return "sendVenue"
557}
558
559// ContactConfig allows you to send a contact.
560type ContactConfig struct {
561 BaseChat
562 PhoneNumber string
563 FirstName string
564 LastName string
565 VCard string
566}
567
568func (config ContactConfig) params() (Params, error) {
569 params, err := config.BaseChat.params()
570
571 params["phone_number"] = config.PhoneNumber
572 params["first_name"] = config.FirstName
573
574 params.AddNonEmpty("last_name", config.LastName)
575 params.AddNonEmpty("vcard", config.VCard)
576
577 return params, err
578}
579
580func (config ContactConfig) method() string {
581 return "sendContact"
582}
583
584// SendPollConfig allows you to send a poll.
585type SendPollConfig struct {
586 BaseChat
587 Question string
588 Options []string
589 IsAnonymous bool
590 Type string
591 AllowsMultipleAnswers bool
592 CorrectOptionID int64
593 Explanation string
594 ExplanationParseMode string
595 OpenPeriod int
596 CloseDate int
597 IsClosed bool
598}
599
600func (config SendPollConfig) params() (Params, error) {
601 params, err := config.BaseChat.params()
602 if err != nil {
603 return params, err
604 }
605
606 params["question"] = config.Question
607 err = params.AddInterface("options", config.Options)
608 params["is_anonymous"] = strconv.FormatBool(config.IsAnonymous)
609 params.AddNonEmpty("type", config.Type)
610 params["allows_multiple_answers"] = strconv.FormatBool(config.AllowsMultipleAnswers)
611 params["correct_option_id"] = strconv.FormatInt(config.CorrectOptionID, 10)
612 params.AddBool("is_closed", config.IsClosed)
613 params.AddNonEmpty("explanation", config.Explanation)
614 params.AddNonEmpty("explanation_parse_mode", config.ExplanationParseMode)
615 params.AddNonZero("open_period", config.OpenPeriod)
616 params.AddNonZero("close_date", config.CloseDate)
617
618 return params, err
619}
620
621func (SendPollConfig) method() string {
622 return "sendPoll"
623}
624
625// GameConfig allows you to send a game.
626type GameConfig struct {
627 BaseChat
628 GameShortName string
629}
630
631func (config GameConfig) params() (Params, error) {
632 params, err := config.BaseChat.params()
633
634 params["game_short_name"] = config.GameShortName
635
636 return params, err
637}
638
639func (config GameConfig) method() string {
640 return "sendGame"
641}
642
643// SetGameScoreConfig allows you to update the game score in a chat.
644type SetGameScoreConfig struct {
645 UserID int
646 Score int
647 Force bool
648 DisableEditMessage bool
649 ChatID int64
650 ChannelUsername string
651 MessageID int
652 InlineMessageID string
653}
654
655func (config SetGameScoreConfig) params() (Params, error) {
656 params := make(Params)
657
658 params.AddNonZero("user_id", config.UserID)
659 params.AddNonZero("scrore", config.Score)
660 params.AddBool("disable_edit_message", config.DisableEditMessage)
661
662 if config.InlineMessageID != "" {
663 params["inline_message_id"] = config.InlineMessageID
664 } else {
665 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
666 params.AddNonZero("message_id", config.MessageID)
667 }
668
669 return params, nil
670}
671
672func (config SetGameScoreConfig) method() string {
673 return "setGameScore"
674}
675
676// GetGameHighScoresConfig allows you to fetch the high scores for a game.
677type GetGameHighScoresConfig struct {
678 UserID int
679 ChatID int
680 ChannelUsername string
681 MessageID int
682 InlineMessageID string
683}
684
685func (config GetGameHighScoresConfig) params() (Params, error) {
686 params := make(Params)
687
688 params.AddNonZero("user_id", config.UserID)
689
690 if config.InlineMessageID != "" {
691 params["inline_message_id"] = config.InlineMessageID
692 } else {
693 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
694 params.AddNonZero("message_id", config.MessageID)
695 }
696
697 return params, nil
698}
699
700func (config GetGameHighScoresConfig) method() string {
701 return "getGameHighScores"
702}
703
704// ChatActionConfig contains information about a SendChatAction request.
705type ChatActionConfig struct {
706 BaseChat
707 Action string // required
708}
709
710func (config ChatActionConfig) params() (Params, error) {
711 params, err := config.BaseChat.params()
712
713 params["action"] = config.Action
714
715 return params, err
716}
717
718func (config ChatActionConfig) method() string {
719 return "sendChatAction"
720}
721
722// EditMessageTextConfig allows you to modify the text in a message.
723type EditMessageTextConfig struct {
724 BaseEdit
725 Text string
726 ParseMode string
727 DisableWebPagePreview bool
728}
729
730func (config EditMessageTextConfig) params() (Params, error) {
731 params, err := config.BaseEdit.params()
732
733 params["text"] = config.Text
734 params.AddNonEmpty("parse_mode", config.ParseMode)
735 params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
736
737 return params, err
738}
739
740func (config EditMessageTextConfig) method() string {
741 return "editMessageText"
742}
743
744// EditMessageCaptionConfig allows you to modify the caption of a message.
745type EditMessageCaptionConfig struct {
746 BaseEdit
747 Caption string
748 ParseMode string
749}
750
751func (config EditMessageCaptionConfig) params() (Params, error) {
752 params, err := config.BaseEdit.params()
753
754 params["caption"] = config.Caption
755 params.AddNonEmpty("parse_mode", config.ParseMode)
756
757 return params, err
758}
759
760func (config EditMessageCaptionConfig) method() string {
761 return "editMessageCaption"
762}
763
764// EditMessageMediaConfig allows you to make an editMessageMedia request.
765type EditMessageMediaConfig struct {
766 BaseEdit
767
768 Media interface{}
769}
770
771func (config EditMessageMediaConfig) files() []RequestFile {
772 return []RequestFile{
773 {
774 Name: "media",
775 File: config.Media,
776 },
777 }
778}
779
780func (EditMessageMediaConfig) method() string {
781 return "editMessageMedia"
782}
783
784func (config EditMessageMediaConfig) params() (Params, error) {
785 return config.BaseEdit.params()
786}
787
788// EditMessageReplyMarkupConfig allows you to modify the reply markup
789// of a message.
790type EditMessageReplyMarkupConfig struct {
791 BaseEdit
792}
793
794func (config EditMessageReplyMarkupConfig) params() (Params, error) {
795 return config.BaseEdit.params()
796}
797
798func (config EditMessageReplyMarkupConfig) method() string {
799 return "editMessageReplyMarkup"
800}
801
802// StopPollConfig allows you to stop a poll sent by the bot.
803type StopPollConfig struct {
804 BaseEdit
805}
806
807func (config StopPollConfig) params() (Params, error) {
808 return config.BaseEdit.params()
809}
810
811func (StopPollConfig) method() string {
812 return "stopPoll"
813}
814
815// UserProfilePhotosConfig contains information about a
816// GetUserProfilePhotos request.
817type UserProfilePhotosConfig struct {
818 UserID int
819 Offset int
820 Limit int
821}
822
823func (UserProfilePhotosConfig) method() string {
824 return "getUserProfilePhotos"
825}
826
827func (config UserProfilePhotosConfig) params() (Params, error) {
828 params := make(Params)
829
830 params.AddNonZero("user_id", config.UserID)
831 params.AddNonZero("offset", config.Offset)
832 params.AddNonZero("limit", config.Limit)
833
834 return params, nil
835}
836
837// FileConfig has information about a file hosted on Telegram.
838type FileConfig struct {
839 FileID string
840}
841
842func (FileConfig) method() string {
843 return "getFile"
844}
845
846func (config FileConfig) params() (Params, error) {
847 params := make(Params)
848
849 params["file_id"] = config.FileID
850
851 return params, nil
852}
853
854// UpdateConfig contains information about a GetUpdates request.
855type UpdateConfig struct {
856 Offset int
857 Limit int
858 Timeout int
859}
860
861func (UpdateConfig) method() string {
862 return "getUpdates"
863}
864
865func (config UpdateConfig) params() (Params, error) {
866 params := make(Params)
867
868 params.AddNonZero("offset", config.Offset)
869 params.AddNonZero("limit", config.Limit)
870 params.AddNonZero("timeout", config.Timeout)
871
872 return params, nil
873}
874
875// WebhookConfig contains information about a SetWebhook request.
876type WebhookConfig struct {
877 URL *url.URL
878 Certificate interface{}
879 MaxConnections int
880 AllowedUpdates []string
881}
882
883func (config WebhookConfig) method() string {
884 return "setWebhook"
885}
886
887func (config WebhookConfig) params() (Params, error) {
888 params := make(Params)
889
890 if config.URL != nil {
891 params["url"] = config.URL.String()
892 }
893
894 params.AddNonZero("max_connections", config.MaxConnections)
895 params.AddInterface("allowed_updates", config.AllowedUpdates)
896
897 return params, nil
898}
899
900func (config WebhookConfig) name() string {
901 return "certificate"
902}
903
904// RemoveWebhookConfig is a helper to remove a webhook.
905type RemoveWebhookConfig struct {
906}
907
908func (config RemoveWebhookConfig) method() string {
909 return "setWebhook"
910}
911
912func (config RemoveWebhookConfig) params() (Params, error) {
913 return nil, nil
914}
915
916// FileBytes contains information about a set of bytes to upload
917// as a File.
918type FileBytes struct {
919 Name string
920 Bytes []byte
921}
922
923// FileReader contains information about a reader to upload as a File.
924// If Size is -1, it will read the entire Reader into memory to
925// calculate a Size.
926type FileReader struct {
927 Name string
928 Reader io.Reader
929 Size int64
930}
931
932// FileURL is a URL to use as a file for a request.
933type FileURL string
934
935// FileID is an ID of a file already uploaded to Telegram.
936type FileID string
937
938// InlineConfig contains information on making an InlineQuery response.
939type InlineConfig struct {
940 InlineQueryID string `json:"inline_query_id"`
941 Results []interface{} `json:"results"`
942 CacheTime int `json:"cache_time"`
943 IsPersonal bool `json:"is_personal"`
944 NextOffset string `json:"next_offset"`
945 SwitchPMText string `json:"switch_pm_text"`
946 SwitchPMParameter string `json:"switch_pm_parameter"`
947}
948
949func (config InlineConfig) method() string {
950 return "answerInlineQuery"
951}
952
953func (config InlineConfig) params() (Params, error) {
954 params := make(Params)
955
956 params["inline_query_id"] = config.InlineQueryID
957 params.AddNonZero("cache_time", config.CacheTime)
958 params.AddBool("is_personal", config.IsPersonal)
959 params.AddNonEmpty("next_offset", config.NextOffset)
960 params.AddNonEmpty("switch_pm_text", config.SwitchPMText)
961 params.AddNonEmpty("switch_pm_parameter", config.SwitchPMParameter)
962
963 if err := params.AddInterface("results", config.Results); err != nil {
964 return params, err
965 }
966
967 return params, nil
968}
969
970// CallbackConfig contains information on making a CallbackQuery response.
971type CallbackConfig struct {
972 CallbackQueryID string `json:"callback_query_id"`
973 Text string `json:"text"`
974 ShowAlert bool `json:"show_alert"`
975 URL string `json:"url"`
976 CacheTime int `json:"cache_time"`
977}
978
979func (config CallbackConfig) method() string {
980 return "answerCallbackQuery"
981}
982
983func (config CallbackConfig) params() (Params, error) {
984 params := make(Params)
985
986 params["callback_query_id"] = config.CallbackQueryID
987 params.AddNonEmpty("text", config.Text)
988 params.AddBool("show_alert", config.ShowAlert)
989 params.AddNonEmpty("url", config.URL)
990 params.AddNonZero("cache_time", config.CacheTime)
991
992 return params, nil
993}
994
995// ChatMemberConfig contains information about a user in a chat for use
996// with administrative functions such as kicking or unbanning a user.
997type ChatMemberConfig struct {
998 ChatID int64
999 SuperGroupUsername string
1000 ChannelUsername string
1001 UserID int
1002}
1003
1004// UnbanChatMemberConfig allows you to unban a user.
1005type UnbanChatMemberConfig struct {
1006 ChatMemberConfig
1007}
1008
1009func (config UnbanChatMemberConfig) method() string {
1010 return "unbanChatMember"
1011}
1012
1013func (config UnbanChatMemberConfig) params() (Params, error) {
1014 params := make(Params)
1015
1016 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1017 params.AddNonZero("user_id", config.UserID)
1018
1019 return params, nil
1020}
1021
1022// KickChatMemberConfig contains extra fields to kick user
1023type KickChatMemberConfig struct {
1024 ChatMemberConfig
1025 UntilDate int64
1026}
1027
1028func (config KickChatMemberConfig) method() string {
1029 return "kickChatMember"
1030}
1031
1032func (config KickChatMemberConfig) params() (Params, error) {
1033 params := make(Params)
1034
1035 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1036 params.AddNonZero("user_id", config.UserID)
1037 params.AddNonZero64("until_date", config.UntilDate)
1038
1039 return params, nil
1040}
1041
1042// RestrictChatMemberConfig contains fields to restrict members of chat
1043type RestrictChatMemberConfig struct {
1044 ChatMemberConfig
1045 UntilDate int64
1046 Permissions *ChatPermissions
1047}
1048
1049func (config RestrictChatMemberConfig) method() string {
1050 return "restrictChatMember"
1051}
1052
1053func (config RestrictChatMemberConfig) params() (Params, error) {
1054 params := make(Params)
1055
1056 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1057 params.AddNonZero("user_id", config.UserID)
1058
1059 if err := params.AddInterface("permissions", config.Permissions); err != nil {
1060 return params, err
1061 }
1062 params.AddNonZero64("until_date", config.UntilDate)
1063
1064 return params, nil
1065}
1066
1067// PromoteChatMemberConfig contains fields to promote members of chat
1068type PromoteChatMemberConfig struct {
1069 ChatMemberConfig
1070 CanChangeInfo bool
1071 CanPostMessages bool
1072 CanEditMessages bool
1073 CanDeleteMessages bool
1074 CanInviteUsers bool
1075 CanRestrictMembers bool
1076 CanPinMessages bool
1077 CanPromoteMembers bool
1078}
1079
1080func (config PromoteChatMemberConfig) method() string {
1081 return "promoteChatMember"
1082}
1083
1084func (config PromoteChatMemberConfig) params() (Params, error) {
1085 params := make(Params)
1086
1087 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1088 params.AddNonZero("user_id", config.UserID)
1089
1090 params.AddBool("can_change_info", config.CanChangeInfo)
1091 params.AddBool("can_post_messages", config.CanPostMessages)
1092 params.AddBool("can_edit_messages", config.CanEditMessages)
1093 params.AddBool("can_delete_messages", config.CanDeleteMessages)
1094 params.AddBool("can_invite_users", config.CanInviteUsers)
1095 params.AddBool("can_restrict_members", config.CanRestrictMembers)
1096 params.AddBool("can_pin_messages", config.CanPinMessages)
1097 params.AddBool("can_promote_members", config.CanPromoteMembers)
1098
1099 return params, nil
1100}
1101
1102// SetChatAdministratorCustomTitle sets the title of an administrative user
1103// promoted by the bot for a chat.
1104type SetChatAdministratorCustomTitle struct {
1105 ChatMemberConfig
1106 CustomTitle string
1107}
1108
1109func (SetChatAdministratorCustomTitle) method() string {
1110 return "setChatAdministratorCustomTitle"
1111}
1112
1113func (config SetChatAdministratorCustomTitle) params() (Params, error) {
1114 params := make(Params)
1115
1116 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1117 params.AddNonZero("user_id", config.UserID)
1118 params.AddNonEmpty("custom_title", config.CustomTitle)
1119
1120 return params, nil
1121}
1122
1123// ChatConfig contains information about getting information on a chat.
1124type ChatConfig struct {
1125 ChatID int64
1126 SuperGroupUsername string
1127}
1128
1129func (config ChatConfig) params() (Params, error) {
1130 params := make(Params)
1131
1132 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1133
1134 return params, nil
1135}
1136
1137// ChatInfoConfig contains information about getting chat information.
1138type ChatInfoConfig struct {
1139 ChatConfig
1140}
1141
1142func (ChatInfoConfig) method() string {
1143 return "getChat"
1144}
1145
1146// ChatMemberCountConfig contains information about getting the number of users in a chat.
1147type ChatMemberCountConfig struct {
1148 ChatConfig
1149}
1150
1151func (ChatMemberCountConfig) method() string {
1152 return "getChatMembersCount"
1153}
1154
1155// ChatAdministratorsConfig contains information about getting chat administrators.
1156type ChatAdministratorsConfig struct {
1157 ChatConfig
1158}
1159
1160func (ChatAdministratorsConfig) method() string {
1161 return "getChatAdministrators"
1162}
1163
1164// SetChatPermissionsConfig allows you to set default permissions for the
1165// members in a group. The bot must be an administrator and have rights to
1166// restrict members.
1167type SetChatPermissionsConfig struct {
1168 ChatConfig
1169 Permissions *ChatPermissions
1170}
1171
1172func (SetChatPermissionsConfig) method() string {
1173 return "setChatPermissions"
1174}
1175
1176func (config SetChatPermissionsConfig) params() (Params, error) {
1177 params := make(Params)
1178
1179 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1180 params.AddInterface("permissions", config.Permissions)
1181
1182 return params, nil
1183}
1184
1185// ChatInviteLinkConfig contains information about getting a chat link.
1186//
1187// Note that generating a new link will revoke any previous links.
1188type ChatInviteLinkConfig struct {
1189 ChatConfig
1190}
1191
1192func (ChatInviteLinkConfig) method() string {
1193 return "exportChatInviteLink"
1194}
1195
1196func (config ChatInviteLinkConfig) params() (Params, error) {
1197 params := make(Params)
1198
1199 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1200
1201 return params, nil
1202}
1203
1204// LeaveChatConfig allows you to leave a chat.
1205type LeaveChatConfig struct {
1206 ChatID int64
1207 ChannelUsername string
1208}
1209
1210func (config LeaveChatConfig) method() string {
1211 return "leaveChat"
1212}
1213
1214func (config LeaveChatConfig) params() (Params, error) {
1215 params := make(Params)
1216
1217 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1218
1219 return params, nil
1220}
1221
1222// ChatConfigWithUser contains information about a chat and a user.
1223type ChatConfigWithUser struct {
1224 ChatID int64
1225 SuperGroupUsername string
1226 UserID int
1227}
1228
1229func (config ChatConfigWithUser) params() (Params, error) {
1230 params := make(Params)
1231
1232 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1233 params.AddNonZero("user_id", config.UserID)
1234
1235 return params, nil
1236}
1237
1238// GetChatMemberConfig is information about getting a specific member in a chat.
1239type GetChatMemberConfig struct {
1240 ChatConfigWithUser
1241}
1242
1243func (GetChatMemberConfig) method() string {
1244 return "getChatMember"
1245}
1246
1247// InvoiceConfig contains information for sendInvoice request.
1248type InvoiceConfig struct {
1249 BaseChat
1250 Title string // required
1251 Description string // required
1252 Payload string // required
1253 ProviderToken string // required
1254 StartParameter string // required
1255 Currency string // required
1256 Prices []LabeledPrice // required
1257 ProviderData string
1258 PhotoURL string
1259 PhotoSize int
1260 PhotoWidth int
1261 PhotoHeight int
1262 NeedName bool
1263 NeedPhoneNumber bool
1264 NeedEmail bool
1265 NeedShippingAddress bool
1266 SendPhoneNumberToProvider bool
1267 SendEmailToProvider bool
1268 IsFlexible bool
1269}
1270
1271func (config InvoiceConfig) params() (Params, error) {
1272 params, err := config.BaseChat.params()
1273 if err != nil {
1274 return params, err
1275 }
1276
1277 params["title"] = config.Title
1278 params["description"] = config.Description
1279 params["payload"] = config.Payload
1280 params["provider_token"] = config.ProviderToken
1281 params["start_parameter"] = config.StartParameter
1282 params["currency"] = config.Currency
1283
1284 if err = params.AddInterface("prices", config.Prices); err != nil {
1285 return params, err
1286 }
1287
1288 params.AddNonEmpty("provider_data", config.ProviderData)
1289 params.AddNonEmpty("photo_url", config.PhotoURL)
1290 params.AddNonZero("photo_size", config.PhotoSize)
1291 params.AddNonZero("photo_width", config.PhotoWidth)
1292 params.AddNonZero("photo_height", config.PhotoHeight)
1293 params.AddBool("need_name", config.NeedName)
1294 params.AddBool("need_phone_number", config.NeedPhoneNumber)
1295 params.AddBool("need_email", config.NeedEmail)
1296 params.AddBool("need_shipping_address", config.NeedShippingAddress)
1297 params.AddBool("is_flexible", config.IsFlexible)
1298 params.AddBool("send_phone_number_to_provider", config.SendPhoneNumberToProvider)
1299 params.AddBool("send_email_to_provider", config.SendEmailToProvider)
1300
1301 return params, nil
1302}
1303
1304func (config InvoiceConfig) method() string {
1305 return "sendInvoice"
1306}
1307
1308// ShippingConfig contains information for answerShippingQuery request.
1309type ShippingConfig struct {
1310 ShippingQueryID string // required
1311 OK bool // required
1312 ShippingOptions []ShippingOption
1313 ErrorMessage string
1314}
1315
1316// PreCheckoutConfig conatins information for answerPreCheckoutQuery request.
1317type PreCheckoutConfig struct {
1318 PreCheckoutQueryID string // required
1319 OK bool // required
1320 ErrorMessage string
1321}
1322
1323// DeleteMessageConfig contains information of a message in a chat to delete.
1324type DeleteMessageConfig struct {
1325 ChannelUsername string
1326 ChatID int64
1327 MessageID int
1328}
1329
1330func (config DeleteMessageConfig) method() string {
1331 return "deleteMessage"
1332}
1333
1334func (config DeleteMessageConfig) params() (Params, error) {
1335 params := make(Params)
1336
1337 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1338 params.AddNonZero("message_id", config.MessageID)
1339
1340 return params, nil
1341}
1342
1343// PinChatMessageConfig contains information of a message in a chat to pin.
1344type PinChatMessageConfig struct {
1345 ChatID int64
1346 ChannelUsername string
1347 MessageID int
1348 DisableNotification bool
1349}
1350
1351func (config PinChatMessageConfig) method() string {
1352 return "pinChatMessage"
1353}
1354
1355func (config PinChatMessageConfig) params() (Params, error) {
1356 params := make(Params)
1357
1358 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1359 params.AddNonZero("message_id", config.MessageID)
1360 params.AddBool("disable_notification", config.DisableNotification)
1361
1362 return params, nil
1363}
1364
1365// UnpinChatMessageConfig contains information of chat to unpin.
1366type UnpinChatMessageConfig struct {
1367 ChatID int64
1368 ChannelUsername string
1369}
1370
1371func (config UnpinChatMessageConfig) method() string {
1372 return "unpinChatMessage"
1373}
1374
1375func (config UnpinChatMessageConfig) params() (Params, error) {
1376 params := make(Params)
1377
1378 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1379
1380 return params, nil
1381}
1382
1383// SetChatPhotoConfig allows you to set a group, supergroup, or channel's photo.
1384type SetChatPhotoConfig struct {
1385 BaseFile
1386}
1387
1388func (config SetChatPhotoConfig) method() string {
1389 return "setChatPhoto"
1390}
1391
1392func (config SetChatPhotoConfig) files() []RequestFile {
1393 return []RequestFile{{
1394 Name: "photo",
1395 File: config.File,
1396 }}
1397}
1398
1399// DeleteChatPhotoConfig allows you to delete a group, supergroup, or channel's photo.
1400type DeleteChatPhotoConfig struct {
1401 ChatID int64
1402 ChannelUsername string
1403}
1404
1405func (config DeleteChatPhotoConfig) method() string {
1406 return "deleteChatPhoto"
1407}
1408
1409func (config DeleteChatPhotoConfig) params() (Params, error) {
1410 params := make(Params)
1411
1412 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1413
1414 return params, nil
1415}
1416
1417// SetChatTitleConfig allows you to set the title of something other than a private chat.
1418type SetChatTitleConfig struct {
1419 ChatID int64
1420 ChannelUsername string
1421
1422 Title string
1423}
1424
1425func (config SetChatTitleConfig) method() string {
1426 return "setChatTitle"
1427}
1428
1429func (config SetChatTitleConfig) params() (Params, error) {
1430 params := make(Params)
1431
1432 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1433 params["title"] = config.Title
1434
1435 return params, nil
1436}
1437
1438// SetChatDescriptionConfig allows you to set the description of a supergroup or channel.
1439type SetChatDescriptionConfig struct {
1440 ChatID int64
1441 ChannelUsername string
1442
1443 Description string
1444}
1445
1446func (config SetChatDescriptionConfig) method() string {
1447 return "setChatDescription"
1448}
1449
1450func (config SetChatDescriptionConfig) params() (Params, error) {
1451 params := make(Params)
1452
1453 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1454 params["description"] = config.Description
1455
1456 return params, nil
1457}
1458
1459// GetStickerSetConfig allows you to get the stickers in a set.
1460type GetStickerSetConfig struct {
1461 Name string
1462}
1463
1464func (config GetStickerSetConfig) method() string {
1465 return "getStickerSet"
1466}
1467
1468func (config GetStickerSetConfig) params() (Params, error) {
1469 params := make(Params)
1470
1471 params["name"] = config.Name
1472
1473 return params, nil
1474}
1475
1476// UploadStickerConfig allows you to upload a sticker for use in a set later.
1477type UploadStickerConfig struct {
1478 UserID int64
1479 PNGSticker interface{}
1480}
1481
1482func (config UploadStickerConfig) method() string {
1483 return "uploadStickerFile"
1484}
1485
1486func (config UploadStickerConfig) params() (Params, error) {
1487 params := make(Params)
1488
1489 params.AddNonZero64("user_id", config.UserID)
1490
1491 return params, nil
1492}
1493
1494func (config UploadStickerConfig) files() []RequestFile {
1495 return []RequestFile{
1496 {
1497 Name: "png_sticker",
1498 File: config.PNGSticker,
1499 },
1500 }
1501}
1502
1503// NewStickerSetConfig allows creating a new sticker set.
1504//
1505// You must set either PNGSticker or TGSSticker.
1506type NewStickerSetConfig struct {
1507 UserID int64
1508 Name string
1509 Title string
1510 PNGSticker interface{}
1511 TGSSticker interface{}
1512 Emojis string
1513 ContainsMasks bool
1514 MaskPosition *MaskPosition
1515}
1516
1517func (config NewStickerSetConfig) method() string {
1518 return "createNewStickerSet"
1519}
1520
1521func (config NewStickerSetConfig) params() (Params, error) {
1522 params := make(Params)
1523
1524 params.AddNonZero64("user_id", config.UserID)
1525 params["name"] = config.Name
1526 params["title"] = config.Title
1527
1528 params["emojis"] = config.Emojis
1529
1530 params.AddBool("contains_masks", config.ContainsMasks)
1531
1532 err := params.AddInterface("mask_position", config.MaskPosition)
1533
1534 return params, err
1535}
1536
1537func (config NewStickerSetConfig) files() []RequestFile {
1538 if config.PNGSticker != nil {
1539 return []RequestFile{{
1540 Name: "png_sticker",
1541 File: config.PNGSticker,
1542 }}
1543 }
1544
1545 return []RequestFile{{
1546 Name: "tgs_sticker",
1547 File: config.TGSSticker,
1548 }}
1549}
1550
1551// AddStickerConfig allows you to add a sticker to a set.
1552type AddStickerConfig struct {
1553 UserID int64
1554 Name string
1555 PNGSticker interface{}
1556 TGSSticker interface{}
1557 Emojis string
1558 MaskPosition *MaskPosition
1559}
1560
1561func (config AddStickerConfig) method() string {
1562 return "addStickerToSet"
1563}
1564
1565func (config AddStickerConfig) params() (Params, error) {
1566 params := make(Params)
1567
1568 params.AddNonZero64("user_id", config.UserID)
1569 params["name"] = config.Name
1570 params["emojis"] = config.Emojis
1571
1572 err := params.AddInterface("mask_position", config.MaskPosition)
1573
1574 return params, err
1575}
1576
1577func (config AddStickerConfig) files() []RequestFile {
1578 if config.PNGSticker != nil {
1579 return []RequestFile{{
1580 Name: "png_sticker",
1581 File: config.PNGSticker,
1582 }}
1583 }
1584
1585 return []RequestFile{{
1586 Name: "tgs_sticker",
1587 File: config.TGSSticker,
1588 }}
1589
1590}
1591
1592// SetStickerPositionConfig allows you to change the position of a sticker in a set.
1593type SetStickerPositionConfig struct {
1594 Sticker string
1595 Position int
1596}
1597
1598func (config SetStickerPositionConfig) method() string {
1599 return "setStickerPositionInSet"
1600}
1601
1602func (config SetStickerPositionConfig) params() (Params, error) {
1603 params := make(Params)
1604
1605 params["sticker"] = config.Sticker
1606 params.AddNonZero("position", config.Position)
1607
1608 return params, nil
1609}
1610
1611// DeleteStickerConfig allows you to delete a sticker from a set.
1612type DeleteStickerConfig struct {
1613 Sticker string
1614}
1615
1616func (config DeleteStickerConfig) method() string {
1617 return "deleteStickerFromSet"
1618}
1619
1620func (config DeleteStickerConfig) params() (Params, error) {
1621 params := make(Params)
1622
1623 params["sticker"] = config.Sticker
1624
1625 return params, nil
1626}
1627
1628// SetStickerSetThumbConfig allows you to set the thumbnail for a sticker set.
1629type SetStickerSetThumbConfig struct {
1630 Name string
1631 UserID int
1632 Thumb interface{}
1633}
1634
1635func (config SetStickerSetThumbConfig) method() string {
1636 return "setStickerSetThumb"
1637}
1638
1639func (config SetStickerSetThumbConfig) params() (Params, error) {
1640 params := make(Params)
1641
1642 params["name"] = config.Name
1643 params.AddNonZero("user_id", config.UserID)
1644
1645 if thumb, ok := config.Thumb.(string); ok {
1646 params["thumb"] = thumb
1647 }
1648
1649 return params, nil
1650}
1651
1652func (config SetStickerSetThumbConfig) name() string {
1653 return "thumb"
1654}
1655
1656// SetChatStickerSetConfig allows you to set the sticker set for a supergroup.
1657type SetChatStickerSetConfig struct {
1658 ChatID int64
1659 SuperGroupUsername string
1660
1661 StickerSetName string
1662}
1663
1664func (config SetChatStickerSetConfig) method() string {
1665 return "setChatStickerSet"
1666}
1667
1668func (config SetChatStickerSetConfig) params() (Params, error) {
1669 params := make(Params)
1670
1671 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1672 params["sticker_set_name"] = config.StickerSetName
1673
1674 return params, nil
1675}
1676
1677// DeleteChatStickerSetConfig allows you to remove a supergroup's sticker set.
1678type DeleteChatStickerSetConfig struct {
1679 ChatID int64
1680 SuperGroupUsername string
1681}
1682
1683func (config DeleteChatStickerSetConfig) method() string {
1684 return "deleteChatStickerSet"
1685}
1686
1687func (config DeleteChatStickerSetConfig) params() (Params, error) {
1688 params := make(Params)
1689
1690 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1691
1692 return params, nil
1693}
1694
1695// MediaGroupConfig allows you to send a group of media.
1696//
1697// Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo).
1698type MediaGroupConfig struct {
1699 ChatID int64
1700 ChannelUsername string
1701
1702 Media []interface{}
1703 DisableNotification bool
1704 ReplyToMessageID int
1705}
1706
1707func (config MediaGroupConfig) method() string {
1708 return "sendMediaGroup"
1709}
1710
1711func (config MediaGroupConfig) params() (Params, error) {
1712 params := make(Params)
1713
1714 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1715 params.AddBool("disable_notification", config.DisableNotification)
1716 params.AddNonZero("reply_to_message_id", config.ReplyToMessageID)
1717
1718 newMedia := make([]interface{}, len(config.Media))
1719 copy(newMedia, config.Media)
1720
1721 for idx, media := range config.Media {
1722 switch m := media.(type) {
1723 case InputMediaPhoto:
1724 switch m.Media.(type) {
1725 case string, FileBytes, FileReader:
1726 m.Media = fmt.Sprintf("attach://file-%d", idx)
1727 newMedia[idx] = m
1728 }
1729 case InputMediaVideo:
1730 switch m.Media.(type) {
1731 case string, FileBytes, FileReader:
1732 m.Media = fmt.Sprintf("attach://file-%d", idx)
1733 newMedia[idx] = m
1734 }
1735 }
1736 }
1737
1738 params.AddInterface("media", newMedia)
1739
1740 return params, nil
1741}
1742
1743func (config MediaGroupConfig) files() []RequestFile {
1744 files := []RequestFile{}
1745
1746 for idx, media := range config.Media {
1747 switch m := media.(type) {
1748 case InputMediaPhoto:
1749 switch f := m.Media.(type) {
1750 case string, FileBytes, FileReader:
1751 files = append(files, RequestFile{
1752 Name: fmt.Sprintf("file-%d", idx),
1753 File: f,
1754 })
1755 }
1756 case InputMediaVideo:
1757 switch f := m.Media.(type) {
1758 case string, FileBytes, FileReader:
1759 files = append(files, RequestFile{
1760 Name: fmt.Sprintf("file-%d", idx),
1761 File: f,
1762 })
1763 }
1764 }
1765 }
1766
1767 return files
1768}
1769
1770// DiceConfig allows you to send a random dice roll to Telegram.
1771//
1772// Emoji may be one of the following: 🎲 (1-6), 🎯 (1-6), 🏀 (1-5).
1773type DiceConfig struct {
1774 BaseChat
1775
1776 Emoji string
1777}
1778
1779func (config DiceConfig) method() string {
1780 return "sendDice"
1781}
1782
1783func (config DiceConfig) params() (Params, error) {
1784 params, err := config.BaseChat.params()
1785 if err != nil {
1786 return params, err
1787 }
1788
1789 params.AddNonEmpty("emoji", config.Emoji)
1790
1791 return params, err
1792}
1793
1794// GetMyCommandsConfig gets a list of the currently registered commands.
1795type GetMyCommandsConfig struct{}
1796
1797func (config GetMyCommandsConfig) method() string {
1798 return "getMyCommands"
1799}
1800
1801func (config GetMyCommandsConfig) params() (Params, error) {
1802 return make(Params), nil
1803}
1804
1805// SetMyCommandsConfig sets a list of commands the bot understands.
1806type SetMyCommandsConfig struct {
1807 commands []BotCommand
1808}
1809
1810func (config SetMyCommandsConfig) method() string {
1811 return "setMyCommands"
1812}
1813
1814func (config SetMyCommandsConfig) params() (Params, error) {
1815 params := make(Params)
1816
1817 err := params.AddInterface("commands", config.commands)
1818
1819 return params, err
1820}