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