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