configs.go (view raw)
1package tgbotapi
2
3import (
4 "bytes"
5 "fmt"
6 "io"
7 "net/url"
8 "os"
9 "strconv"
10)
11
12// Telegram constants
13const (
14 // APIEndpoint is the endpoint for all API methods,
15 // with formatting for Sprintf.
16 APIEndpoint = "https://api.telegram.org/bot%s/%s"
17 // FileEndpoint is the endpoint for downloading a file from Telegram.
18 FileEndpoint = "https://api.telegram.org/file/bot%s/%s"
19)
20
21// Constant values for ChatActions
22const (
23 ChatTyping = "typing"
24 ChatUploadPhoto = "upload_photo"
25 ChatRecordVideo = "record_video"
26 ChatUploadVideo = "upload_video"
27 ChatRecordVoice = "record_voice"
28 ChatUploadVoice = "upload_voice"
29 ChatUploadDocument = "upload_document"
30 ChatChooseSticker = "choose_sticker"
31 ChatFindLocation = "find_location"
32 ChatRecordVideoNote = "record_video_note"
33 ChatUploadVideoNote = "upload_video_note"
34)
35
36// API errors
37const (
38 // ErrAPIForbidden happens when a token is bad
39 ErrAPIForbidden = "forbidden"
40)
41
42// Constant values for ParseMode in MessageConfig
43const (
44 ModeMarkdown = "Markdown"
45 ModeMarkdownV2 = "MarkdownV2"
46 ModeHTML = "HTML"
47)
48
49// Constant values for update types
50const (
51 // UpdateTypeMessage is new incoming message of any kind — text, photo, sticker, etc.
52 UpdateTypeMessage = "message"
53
54 // UpdateTypeEditedMessage is new version of a message that is known to the bot and was edited
55 UpdateTypeEditedMessage = "edited_message"
56
57 // UpdateTypeChannelPost is new incoming channel post of any kind — text, photo, sticker, etc.
58 UpdateTypeChannelPost = "channel_post"
59
60 // UpdateTypeEditedChannelPost is new version of a channel post that is known to the bot and was edited
61 UpdateTypeEditedChannelPost = "edited_channel_post"
62
63 // UpdateTypeInlineQuery is new incoming inline query
64 UpdateTypeInlineQuery = "inline_query"
65
66 // UpdateTypeChosenInlineResult i the result of an inline query that was chosen by a user and sent to their
67 // chat partner. Please see the documentation on the feedback collecting for
68 // details on how to enable these updates for your bot.
69 UpdateTypeChosenInlineResult = "chosen_inline_result"
70
71 // UpdateTypeCallbackQuery is new incoming callback query
72 UpdateTypeCallbackQuery = "callback_query"
73
74 // UpdateTypeShippingQuery is new incoming shipping query. Only for invoices with flexible price
75 UpdateTypeShippingQuery = "shipping_query"
76
77 // UpdateTypePreCheckoutQuery is new incoming pre-checkout query. Contains full information about checkout
78 UpdateTypePreCheckoutQuery = "pre_checkout_query"
79
80 // UpdateTypePoll is new poll state. Bots receive only updates about stopped polls and polls
81 // which are sent by the bot
82 UpdateTypePoll = "poll"
83
84 // UpdateTypePollAnswer is when user changed their answer in a non-anonymous poll. Bots receive new votes
85 // only in polls that were sent by the bot itself.
86 UpdateTypePollAnswer = "poll_answer"
87
88 // UpdateTypeMyChatMember is when the bot's chat member status was updated in a chat. For private chats, this
89 // update is received only when the bot is blocked or unblocked by the user.
90 UpdateTypeMyChatMember = "my_chat_member"
91
92 // UpdateTypeChatMember is when the bot must be an administrator in the chat and must explicitly specify
93 // this update in the list of allowed_updates to receive these updates.
94 UpdateTypeChatMember = "chat_member"
95)
96
97// Library errors
98const (
99 ErrBadURL = "bad or empty url"
100)
101
102// Chattable is any config type that can be sent.
103type Chattable interface {
104 params() (Params, error)
105 method() string
106}
107
108// Fileable is any config type that can be sent that includes a file.
109type Fileable interface {
110 Chattable
111 files() []RequestFile
112}
113
114// RequestFile represents a file associated with a field name.
115type RequestFile struct {
116 // The file field name.
117 Name string
118 // The file data to include.
119 Data RequestFileData
120}
121
122// RequestFileData represents the data to be used for a file.
123type RequestFileData interface {
124 // NeedsUpload shows if the file needs to be uploaded.
125 NeedsUpload() bool
126
127 // UploadData gets the file name and an `io.Reader` for the file to be uploaded. This
128 // must only be called when the file needs to be uploaded.
129 UploadData() (string, io.Reader, error)
130 // SendData gets the file data to send when a file does not need to be uploaded. This
131 // must only be called when the file does not need to be uploaded.
132 SendData() string
133}
134
135// FileBytes contains information about a set of bytes to upload
136// as a File.
137type FileBytes struct {
138 Name string
139 Bytes []byte
140}
141
142func (fb FileBytes) NeedsUpload() bool {
143 return true
144}
145
146func (fb FileBytes) UploadData() (string, io.Reader, error) {
147 return fb.Name, bytes.NewReader(fb.Bytes), nil
148}
149
150func (fb FileBytes) SendData() string {
151 panic("FileBytes must be uploaded")
152}
153
154// FileReader contains information about a reader to upload as a File.
155type FileReader struct {
156 Name string
157 Reader io.Reader
158}
159
160func (fr FileReader) NeedsUpload() bool {
161 return true
162}
163
164func (fr FileReader) UploadData() (string, io.Reader, error) {
165 return fr.Name, fr.Reader, nil
166}
167
168func (fr FileReader) SendData() string {
169 panic("FileReader must be uploaded")
170}
171
172// FilePath is a path to a local file.
173type FilePath string
174
175func (fp FilePath) NeedsUpload() bool {
176 return true
177}
178
179func (fp FilePath) UploadData() (string, io.Reader, error) {
180 fileHandle, err := os.Open(string(fp))
181 if err != nil {
182 return "", nil, err
183 }
184
185 name := fileHandle.Name()
186 return name, fileHandle, err
187}
188
189func (fp FilePath) SendData() string {
190 panic("FilePath must be uploaded")
191}
192
193// FileURL is a URL to use as a file for a request.
194type FileURL string
195
196func (fu FileURL) NeedsUpload() bool {
197 return false
198}
199
200func (fu FileURL) UploadData() (string, io.Reader, error) {
201 panic("FileURL cannot be uploaded")
202}
203
204func (fu FileURL) SendData() string {
205 return string(fu)
206}
207
208// FileID is an ID of a file already uploaded to Telegram.
209type FileID string
210
211func (fi FileID) NeedsUpload() bool {
212 return false
213}
214
215func (fi FileID) UploadData() (string, io.Reader, error) {
216 panic("FileID cannot be uploaded")
217}
218
219func (fi FileID) SendData() string {
220 return string(fi)
221}
222
223// fileAttach is an internal file type used for processed media groups.
224type fileAttach string
225
226func (fa fileAttach) NeedsUpload() bool {
227 return false
228}
229
230func (fa fileAttach) UploadData() (string, io.Reader, error) {
231 panic("fileAttach cannot be uploaded")
232}
233
234func (fa fileAttach) SendData() string {
235 return string(fa)
236}
237
238// LogOutConfig is a request to log out of the cloud Bot API server.
239//
240// Note that you may not log back in for at least 10 minutes.
241type LogOutConfig struct{}
242
243func (LogOutConfig) method() string {
244 return "logOut"
245}
246
247func (LogOutConfig) params() (Params, error) {
248 return nil, nil
249}
250
251// CloseConfig is a request to close the bot instance on a local server.
252//
253// Note that you may not close an instance for the first 10 minutes after the
254// bot has started.
255type CloseConfig struct{}
256
257func (CloseConfig) method() string {
258 return "close"
259}
260
261func (CloseConfig) params() (Params, error) {
262 return nil, nil
263}
264
265// BaseChat is base type for all chat config types.
266type BaseChat struct {
267 ChatID int64 // required
268 MessageThreadID int
269 ChannelUsername string
270 ProtectContent bool
271 ReplyToMessageID int
272 ReplyMarkup interface{}
273 DisableNotification bool
274 AllowSendingWithoutReply bool
275}
276
277func (chat *BaseChat) params() (Params, error) {
278 params := make(Params)
279
280 params.AddFirstValid("chat_id", chat.ChatID, chat.ChannelUsername)
281 params.AddNonZero("message_thread_id", chat.MessageThreadID)
282 params.AddNonZero("reply_to_message_id", chat.ReplyToMessageID)
283 params.AddBool("disable_notification", chat.DisableNotification)
284 params.AddBool("allow_sending_without_reply", chat.AllowSendingWithoutReply)
285 params.AddBool("protect_content", chat.ProtectContent)
286
287 err := params.AddInterface("reply_markup", chat.ReplyMarkup)
288
289 return params, err
290}
291
292// BaseFile is a base type for all file config types.
293type BaseFile struct {
294 BaseChat
295 File RequestFileData
296}
297
298func (file BaseFile) params() (Params, error) {
299 return file.BaseChat.params()
300}
301
302// BaseEdit is base type of all chat edits.
303type BaseEdit struct {
304 ChatID int64
305 ChannelUsername string
306 MessageID int
307 InlineMessageID string
308 ReplyMarkup *InlineKeyboardMarkup
309}
310
311func (edit BaseEdit) params() (Params, error) {
312 params := make(Params)
313
314 if edit.InlineMessageID != "" {
315 params["inline_message_id"] = edit.InlineMessageID
316 } else {
317 params.AddFirstValid("chat_id", edit.ChatID, edit.ChannelUsername)
318 params.AddNonZero("message_id", edit.MessageID)
319 }
320
321 err := params.AddInterface("reply_markup", edit.ReplyMarkup)
322
323 return params, err
324}
325
326// BaseSpoiler is base type of structures with spoilers.
327type BaseSpoiler struct {
328 HasSpoiler bool
329}
330
331func (spoiler BaseSpoiler) params() (Params, error) {
332 params := make(Params)
333
334 if spoiler.HasSpoiler {
335 params.AddBool("has_spoiler", true)
336 }
337
338 return params, nil
339}
340
341// MessageConfig contains information about a SendMessage request.
342type MessageConfig struct {
343 BaseChat
344 Text string
345 ParseMode string
346 Entities []MessageEntity
347 DisableWebPagePreview bool
348}
349
350func (config MessageConfig) params() (Params, error) {
351 params, err := config.BaseChat.params()
352 if err != nil {
353 return params, err
354 }
355
356 params.AddNonEmpty("text", config.Text)
357 params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
358 params.AddNonEmpty("parse_mode", config.ParseMode)
359 err = params.AddInterface("entities", config.Entities)
360
361 return params, err
362}
363
364func (config MessageConfig) method() string {
365 return "sendMessage"
366}
367
368// ForwardConfig contains information about a ForwardMessage request.
369type ForwardConfig struct {
370 BaseChat
371 FromChatID int64 // required
372 FromChannelUsername string
373 MessageID int // required
374}
375
376func (config ForwardConfig) params() (Params, error) {
377 params, err := config.BaseChat.params()
378 if err != nil {
379 return params, err
380 }
381
382 params.AddNonZero64("from_chat_id", config.FromChatID)
383 params.AddNonZero("message_id", config.MessageID)
384
385 return params, nil
386}
387
388func (config ForwardConfig) method() string {
389 return "forwardMessage"
390}
391
392// CopyMessageConfig contains information about a copyMessage request.
393type CopyMessageConfig struct {
394 BaseChat
395 FromChatID int64
396 FromChannelUsername string
397 MessageID int
398 Caption string
399 ParseMode string
400 CaptionEntities []MessageEntity
401}
402
403func (config CopyMessageConfig) params() (Params, error) {
404 params, err := config.BaseChat.params()
405 if err != nil {
406 return params, err
407 }
408
409 params.AddFirstValid("from_chat_id", config.FromChatID, config.FromChannelUsername)
410 params.AddNonZero("message_id", config.MessageID)
411 params.AddNonEmpty("caption", config.Caption)
412 params.AddNonEmpty("parse_mode", config.ParseMode)
413 err = params.AddInterface("caption_entities", config.CaptionEntities)
414
415 return params, err
416}
417
418func (config CopyMessageConfig) method() string {
419 return "copyMessage"
420}
421
422// PhotoConfig contains information about a SendPhoto request.
423type PhotoConfig struct {
424 BaseFile
425 BaseSpoiler
426 Thumb RequestFileData
427 Caption string
428 ParseMode string
429 CaptionEntities []MessageEntity
430}
431
432func (config PhotoConfig) params() (Params, error) {
433 params, err := config.BaseFile.params()
434 if err != nil {
435 return params, err
436 }
437
438 params.AddNonEmpty("caption", config.Caption)
439 params.AddNonEmpty("parse_mode", config.ParseMode)
440 err = params.AddInterface("caption_entities", config.CaptionEntities)
441 if err != nil {
442 return params, err
443 }
444
445 p1, err := config.BaseSpoiler.params()
446 if err != nil {
447 return params, err
448 }
449 params.Merge(p1)
450
451 return params, err
452}
453
454func (config PhotoConfig) method() string {
455 return "sendPhoto"
456}
457
458func (config PhotoConfig) files() []RequestFile {
459 files := []RequestFile{{
460 Name: "photo",
461 Data: config.File,
462 }}
463
464 if config.Thumb != nil {
465 files = append(files, RequestFile{
466 Name: "thumbnail",
467 Data: config.Thumb,
468 })
469 }
470
471 return files
472}
473
474// AudioConfig contains information about a SendAudio request.
475type AudioConfig struct {
476 BaseFile
477 Thumb RequestFileData
478 Caption string
479 ParseMode string
480 CaptionEntities []MessageEntity
481 Duration int
482 Performer string
483 Title string
484}
485
486func (config AudioConfig) params() (Params, error) {
487 params, err := config.BaseChat.params()
488 if err != nil {
489 return params, err
490 }
491
492 params.AddNonZero("duration", config.Duration)
493 params.AddNonEmpty("performer", config.Performer)
494 params.AddNonEmpty("title", config.Title)
495 params.AddNonEmpty("caption", config.Caption)
496 params.AddNonEmpty("parse_mode", config.ParseMode)
497 err = params.AddInterface("caption_entities", config.CaptionEntities)
498
499 return params, err
500}
501
502func (config AudioConfig) method() string {
503 return "sendAudio"
504}
505
506func (config AudioConfig) files() []RequestFile {
507 files := []RequestFile{{
508 Name: "audio",
509 Data: config.File,
510 }}
511
512 if config.Thumb != nil {
513 files = append(files, RequestFile{
514 Name: "thumbnail",
515 Data: config.Thumb,
516 })
517 }
518
519 return files
520}
521
522// DocumentConfig contains information about a SendDocument request.
523type DocumentConfig struct {
524 BaseFile
525 Thumb RequestFileData
526 Caption string
527 ParseMode string
528 CaptionEntities []MessageEntity
529 DisableContentTypeDetection bool
530}
531
532func (config DocumentConfig) params() (Params, error) {
533 params, err := config.BaseFile.params()
534
535 params.AddNonEmpty("caption", config.Caption)
536 params.AddNonEmpty("parse_mode", config.ParseMode)
537 params.AddBool("disable_content_type_detection", config.DisableContentTypeDetection)
538
539 return params, err
540}
541
542func (config DocumentConfig) method() string {
543 return "sendDocument"
544}
545
546func (config DocumentConfig) files() []RequestFile {
547 files := []RequestFile{{
548 Name: "document",
549 Data: config.File,
550 }}
551
552 if config.Thumb != nil {
553 files = append(files, RequestFile{
554 Name: "thumbnail",
555 Data: config.Thumb,
556 })
557 }
558
559 return files
560}
561
562// StickerConfig contains information about a SendSticker request.
563type StickerConfig struct {
564 //Emoji associated with the sticker; only for just uploaded stickers
565 Emoji string
566 BaseFile
567}
568
569func (config StickerConfig) params() (Params, error) {
570 params, err := config.BaseChat.params()
571 if err != nil {
572 return params, err
573 }
574 params.AddNonEmpty("emoji", config.Emoji)
575 return params, err
576}
577
578func (config StickerConfig) method() string {
579 return "sendSticker"
580}
581
582func (config StickerConfig) files() []RequestFile {
583 return []RequestFile{{
584 Name: "sticker",
585 Data: config.File,
586 }}
587}
588
589// VideoConfig contains information about a SendVideo request.
590type VideoConfig struct {
591 BaseFile
592 BaseSpoiler
593 Thumb RequestFileData
594 Duration int
595 Caption string
596 ParseMode string
597 CaptionEntities []MessageEntity
598 SupportsStreaming bool
599}
600
601func (config VideoConfig) params() (Params, error) {
602 params, err := config.BaseChat.params()
603 if err != nil {
604 return params, err
605 }
606
607 params.AddNonZero("duration", config.Duration)
608 params.AddNonEmpty("caption", config.Caption)
609 params.AddNonEmpty("parse_mode", config.ParseMode)
610 params.AddBool("supports_streaming", config.SupportsStreaming)
611 err = params.AddInterface("caption_entities", config.CaptionEntities)
612 if err != nil {
613 return params, err
614 }
615
616 p1, err := config.BaseSpoiler.params()
617 if err != nil {
618 return params, err
619 }
620 params.Merge(p1)
621
622 return params, err
623}
624
625func (config VideoConfig) method() string {
626 return "sendVideo"
627}
628
629func (config VideoConfig) files() []RequestFile {
630 files := []RequestFile{{
631 Name: "video",
632 Data: config.File,
633 }}
634
635 if config.Thumb != nil {
636 files = append(files, RequestFile{
637 Name: "thumbnail",
638 Data: config.Thumb,
639 })
640 }
641
642 return files
643}
644
645// AnimationConfig contains information about a SendAnimation request.
646type AnimationConfig struct {
647 BaseFile
648 BaseSpoiler
649 Duration int
650 Thumb RequestFileData
651 Caption string
652 ParseMode string
653 CaptionEntities []MessageEntity
654}
655
656func (config AnimationConfig) params() (Params, error) {
657 params, err := config.BaseChat.params()
658 if err != nil {
659 return params, err
660 }
661
662 params.AddNonZero("duration", config.Duration)
663 params.AddNonEmpty("caption", config.Caption)
664 params.AddNonEmpty("parse_mode", config.ParseMode)
665 err = params.AddInterface("caption_entities", config.CaptionEntities)
666 if err != nil {
667 return params, err
668 }
669
670 p1, err := config.BaseSpoiler.params()
671 if err != nil {
672 return params, err
673 }
674 params.Merge(p1)
675
676 return params, err
677}
678
679func (config AnimationConfig) method() string {
680 return "sendAnimation"
681}
682
683func (config AnimationConfig) files() []RequestFile {
684 files := []RequestFile{{
685 Name: "animation",
686 Data: config.File,
687 }}
688
689 if config.Thumb != nil {
690 files = append(files, RequestFile{
691 Name: "thumbnail",
692 Data: config.Thumb,
693 })
694 }
695
696 return files
697}
698
699// VideoNoteConfig contains information about a SendVideoNote request.
700type VideoNoteConfig struct {
701 BaseFile
702 Thumb RequestFileData
703 Duration int
704 Length int
705}
706
707func (config VideoNoteConfig) params() (Params, error) {
708 params, err := config.BaseChat.params()
709
710 params.AddNonZero("duration", config.Duration)
711 params.AddNonZero("length", config.Length)
712
713 return params, err
714}
715
716func (config VideoNoteConfig) method() string {
717 return "sendVideoNote"
718}
719
720func (config VideoNoteConfig) files() []RequestFile {
721 files := []RequestFile{{
722 Name: "video_note",
723 Data: config.File,
724 }}
725
726 if config.Thumb != nil {
727 files = append(files, RequestFile{
728 Name: "thumbnail",
729 Data: config.Thumb,
730 })
731 }
732
733 return files
734}
735
736// VoiceConfig contains information about a SendVoice request.
737type VoiceConfig struct {
738 BaseFile
739 Thumb RequestFileData
740 Caption string
741 ParseMode string
742 CaptionEntities []MessageEntity
743 Duration int
744}
745
746func (config VoiceConfig) params() (Params, error) {
747 params, err := config.BaseChat.params()
748 if err != nil {
749 return params, err
750 }
751
752 params.AddNonZero("duration", config.Duration)
753 params.AddNonEmpty("caption", config.Caption)
754 params.AddNonEmpty("parse_mode", config.ParseMode)
755 err = params.AddInterface("caption_entities", config.CaptionEntities)
756
757 return params, err
758}
759
760func (config VoiceConfig) method() string {
761 return "sendVoice"
762}
763
764func (config VoiceConfig) files() []RequestFile {
765 files := []RequestFile{{
766 Name: "voice",
767 Data: config.File,
768 }}
769
770 if config.Thumb != nil {
771 files = append(files, RequestFile{
772 Name: "thumbnail",
773 Data: config.Thumb,
774 })
775 }
776
777 return files
778}
779
780// LocationConfig contains information about a SendLocation request.
781type LocationConfig struct {
782 BaseChat
783 Latitude float64 // required
784 Longitude float64 // required
785 HorizontalAccuracy float64 // optional
786 LivePeriod int // optional
787 Heading int // optional
788 ProximityAlertRadius int // optional
789}
790
791func (config LocationConfig) params() (Params, error) {
792 params, err := config.BaseChat.params()
793
794 params.AddNonZeroFloat("latitude", config.Latitude)
795 params.AddNonZeroFloat("longitude", config.Longitude)
796 params.AddNonZeroFloat("horizontal_accuracy", config.HorizontalAccuracy)
797 params.AddNonZero("live_period", config.LivePeriod)
798 params.AddNonZero("heading", config.Heading)
799 params.AddNonZero("proximity_alert_radius", config.ProximityAlertRadius)
800
801 return params, err
802}
803
804func (config LocationConfig) method() string {
805 return "sendLocation"
806}
807
808// EditMessageLiveLocationConfig allows you to update a live location.
809type EditMessageLiveLocationConfig struct {
810 BaseEdit
811 Latitude float64 // required
812 Longitude float64 // required
813 HorizontalAccuracy float64 // optional
814 Heading int // optional
815 ProximityAlertRadius int // optional
816}
817
818func (config EditMessageLiveLocationConfig) params() (Params, error) {
819 params, err := config.BaseEdit.params()
820
821 params.AddNonZeroFloat("latitude", config.Latitude)
822 params.AddNonZeroFloat("longitude", config.Longitude)
823 params.AddNonZeroFloat("horizontal_accuracy", config.HorizontalAccuracy)
824 params.AddNonZero("heading", config.Heading)
825 params.AddNonZero("proximity_alert_radius", config.ProximityAlertRadius)
826
827 return params, err
828}
829
830func (config EditMessageLiveLocationConfig) method() string {
831 return "editMessageLiveLocation"
832}
833
834// StopMessageLiveLocationConfig stops updating a live location.
835type StopMessageLiveLocationConfig struct {
836 BaseEdit
837}
838
839func (config StopMessageLiveLocationConfig) params() (Params, error) {
840 return config.BaseEdit.params()
841}
842
843func (config StopMessageLiveLocationConfig) method() string {
844 return "stopMessageLiveLocation"
845}
846
847// VenueConfig contains information about a SendVenue request.
848type VenueConfig struct {
849 BaseChat
850 Latitude float64 // required
851 Longitude float64 // required
852 Title string // required
853 Address string // required
854 FoursquareID string
855 FoursquareType string
856 GooglePlaceID string
857 GooglePlaceType string
858}
859
860func (config VenueConfig) params() (Params, error) {
861 params, err := config.BaseChat.params()
862
863 params.AddNonZeroFloat("latitude", config.Latitude)
864 params.AddNonZeroFloat("longitude", config.Longitude)
865 params["title"] = config.Title
866 params["address"] = config.Address
867 params.AddNonEmpty("foursquare_id", config.FoursquareID)
868 params.AddNonEmpty("foursquare_type", config.FoursquareType)
869 params.AddNonEmpty("google_place_id", config.GooglePlaceID)
870 params.AddNonEmpty("google_place_type", config.GooglePlaceType)
871
872 return params, err
873}
874
875func (config VenueConfig) method() string {
876 return "sendVenue"
877}
878
879// ContactConfig allows you to send a contact.
880type ContactConfig struct {
881 BaseChat
882 PhoneNumber string
883 FirstName string
884 LastName string
885 VCard string
886}
887
888func (config ContactConfig) params() (Params, error) {
889 params, err := config.BaseChat.params()
890
891 params["phone_number"] = config.PhoneNumber
892 params["first_name"] = config.FirstName
893
894 params.AddNonEmpty("last_name", config.LastName)
895 params.AddNonEmpty("vcard", config.VCard)
896
897 return params, err
898}
899
900func (config ContactConfig) method() string {
901 return "sendContact"
902}
903
904// SendPollConfig allows you to send a poll.
905type SendPollConfig struct {
906 BaseChat
907 Question string
908 Options []string
909 IsAnonymous bool
910 Type string
911 AllowsMultipleAnswers bool
912 CorrectOptionID int64
913 Explanation string
914 ExplanationParseMode string
915 ExplanationEntities []MessageEntity
916 OpenPeriod int
917 CloseDate int
918 IsClosed bool
919}
920
921func (config SendPollConfig) params() (Params, error) {
922 params, err := config.BaseChat.params()
923 if err != nil {
924 return params, err
925 }
926
927 params["question"] = config.Question
928 if err = params.AddInterface("options", config.Options); err != nil {
929 return params, err
930 }
931 params["is_anonymous"] = strconv.FormatBool(config.IsAnonymous)
932 params.AddNonEmpty("type", config.Type)
933 params["allows_multiple_answers"] = strconv.FormatBool(config.AllowsMultipleAnswers)
934 params["correct_option_id"] = strconv.FormatInt(config.CorrectOptionID, 10)
935 params.AddBool("is_closed", config.IsClosed)
936 params.AddNonEmpty("explanation", config.Explanation)
937 params.AddNonEmpty("explanation_parse_mode", config.ExplanationParseMode)
938 params.AddNonZero("open_period", config.OpenPeriod)
939 params.AddNonZero("close_date", config.CloseDate)
940 err = params.AddInterface("explanation_entities", config.ExplanationEntities)
941
942 return params, err
943}
944
945func (SendPollConfig) method() string {
946 return "sendPoll"
947}
948
949// GameConfig allows you to send a game.
950type GameConfig struct {
951 BaseChat
952 GameShortName string
953}
954
955func (config GameConfig) params() (Params, error) {
956 params, err := config.BaseChat.params()
957
958 params["game_short_name"] = config.GameShortName
959
960 return params, err
961}
962
963func (config GameConfig) method() string {
964 return "sendGame"
965}
966
967// SetGameScoreConfig allows you to update the game score in a chat.
968type SetGameScoreConfig struct {
969 UserID int64
970 Score int
971 Force bool
972 DisableEditMessage bool
973 ChatID int64
974 ChannelUsername string
975 MessageID int
976 InlineMessageID string
977}
978
979func (config SetGameScoreConfig) params() (Params, error) {
980 params := make(Params)
981
982 params.AddNonZero64("user_id", config.UserID)
983 params.AddNonZero("scrore", config.Score)
984 params.AddBool("disable_edit_message", config.DisableEditMessage)
985
986 if config.InlineMessageID != "" {
987 params["inline_message_id"] = config.InlineMessageID
988 } else {
989 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
990 params.AddNonZero("message_id", config.MessageID)
991 }
992
993 return params, nil
994}
995
996func (config SetGameScoreConfig) method() string {
997 return "setGameScore"
998}
999
1000// GetGameHighScoresConfig allows you to fetch the high scores for a game.
1001type GetGameHighScoresConfig struct {
1002 UserID int64
1003 ChatID int64
1004 ChannelUsername string
1005 MessageID int
1006 InlineMessageID string
1007}
1008
1009func (config GetGameHighScoresConfig) params() (Params, error) {
1010 params := make(Params)
1011
1012 params.AddNonZero64("user_id", config.UserID)
1013
1014 if config.InlineMessageID != "" {
1015 params["inline_message_id"] = config.InlineMessageID
1016 } else {
1017 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1018 params.AddNonZero("message_id", config.MessageID)
1019 }
1020
1021 return params, nil
1022}
1023
1024func (config GetGameHighScoresConfig) method() string {
1025 return "getGameHighScores"
1026}
1027
1028// ChatActionConfig contains information about a SendChatAction request.
1029type ChatActionConfig struct {
1030 BaseChat
1031 MessageThreadID int
1032 Action string // required
1033}
1034
1035func (config ChatActionConfig) params() (Params, error) {
1036 params, err := config.BaseChat.params()
1037
1038 params["action"] = config.Action
1039 params.AddNonZero("message_thread_id", config.MessageThreadID)
1040
1041 return params, err
1042}
1043
1044func (config ChatActionConfig) method() string {
1045 return "sendChatAction"
1046}
1047
1048// EditMessageTextConfig allows you to modify the text in a message.
1049type EditMessageTextConfig struct {
1050 BaseEdit
1051 Text string
1052 ParseMode string
1053 Entities []MessageEntity
1054 DisableWebPagePreview bool
1055}
1056
1057func (config EditMessageTextConfig) params() (Params, error) {
1058 params, err := config.BaseEdit.params()
1059 if err != nil {
1060 return params, err
1061 }
1062
1063 params["text"] = config.Text
1064 params.AddNonEmpty("parse_mode", config.ParseMode)
1065 params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
1066 err = params.AddInterface("entities", config.Entities)
1067
1068 return params, err
1069}
1070
1071func (config EditMessageTextConfig) method() string {
1072 return "editMessageText"
1073}
1074
1075// EditMessageCaptionConfig allows you to modify the caption of a message.
1076type EditMessageCaptionConfig struct {
1077 BaseEdit
1078 Caption string
1079 ParseMode string
1080 CaptionEntities []MessageEntity
1081}
1082
1083func (config EditMessageCaptionConfig) params() (Params, error) {
1084 params, err := config.BaseEdit.params()
1085 if err != nil {
1086 return params, err
1087 }
1088
1089 params["caption"] = config.Caption
1090 params.AddNonEmpty("parse_mode", config.ParseMode)
1091 err = params.AddInterface("caption_entities", config.CaptionEntities)
1092
1093 return params, err
1094}
1095
1096func (config EditMessageCaptionConfig) method() string {
1097 return "editMessageCaption"
1098}
1099
1100// EditMessageMediaConfig allows you to make an editMessageMedia request.
1101type EditMessageMediaConfig struct {
1102 BaseEdit
1103
1104 Media interface{}
1105}
1106
1107func (EditMessageMediaConfig) method() string {
1108 return "editMessageMedia"
1109}
1110
1111func (config EditMessageMediaConfig) params() (Params, error) {
1112 params, err := config.BaseEdit.params()
1113 if err != nil {
1114 return params, err
1115 }
1116
1117 err = params.AddInterface("media", prepareInputMediaParam(config.Media, 0))
1118
1119 return params, err
1120}
1121
1122func (config EditMessageMediaConfig) files() []RequestFile {
1123 return prepareInputMediaFile(config.Media, 0)
1124}
1125
1126// EditMessageReplyMarkupConfig allows you to modify the reply markup
1127// of a message.
1128type EditMessageReplyMarkupConfig struct {
1129 BaseEdit
1130}
1131
1132func (config EditMessageReplyMarkupConfig) params() (Params, error) {
1133 return config.BaseEdit.params()
1134}
1135
1136func (config EditMessageReplyMarkupConfig) method() string {
1137 return "editMessageReplyMarkup"
1138}
1139
1140// StopPollConfig allows you to stop a poll sent by the bot.
1141type StopPollConfig struct {
1142 BaseEdit
1143}
1144
1145func (config StopPollConfig) params() (Params, error) {
1146 return config.BaseEdit.params()
1147}
1148
1149func (StopPollConfig) method() string {
1150 return "stopPoll"
1151}
1152
1153// UserProfilePhotosConfig contains information about a
1154// GetUserProfilePhotos request.
1155type UserProfilePhotosConfig struct {
1156 UserID int64
1157 Offset int
1158 Limit int
1159}
1160
1161func (UserProfilePhotosConfig) method() string {
1162 return "getUserProfilePhotos"
1163}
1164
1165func (config UserProfilePhotosConfig) params() (Params, error) {
1166 params := make(Params)
1167
1168 params.AddNonZero64("user_id", config.UserID)
1169 params.AddNonZero("offset", config.Offset)
1170 params.AddNonZero("limit", config.Limit)
1171
1172 return params, nil
1173}
1174
1175// FileConfig has information about a file hosted on Telegram.
1176type FileConfig struct {
1177 FileID string
1178}
1179
1180func (FileConfig) method() string {
1181 return "getFile"
1182}
1183
1184func (config FileConfig) params() (Params, error) {
1185 params := make(Params)
1186
1187 params["file_id"] = config.FileID
1188
1189 return params, nil
1190}
1191
1192// UpdateConfig contains information about a GetUpdates request.
1193type UpdateConfig struct {
1194 Offset int
1195 Limit int
1196 Timeout int
1197 AllowedUpdates []string
1198}
1199
1200func (UpdateConfig) method() string {
1201 return "getUpdates"
1202}
1203
1204func (config UpdateConfig) params() (Params, error) {
1205 params := make(Params)
1206
1207 params.AddNonZero("offset", config.Offset)
1208 params.AddNonZero("limit", config.Limit)
1209 params.AddNonZero("timeout", config.Timeout)
1210 params.AddInterface("allowed_updates", config.AllowedUpdates)
1211
1212 return params, nil
1213}
1214
1215// WebhookConfig contains information about a SetWebhook request.
1216type WebhookConfig struct {
1217 URL *url.URL
1218 Certificate RequestFileData
1219 IPAddress string
1220 MaxConnections int
1221 AllowedUpdates []string
1222 DropPendingUpdates bool
1223 SecretToken string
1224}
1225
1226func (config WebhookConfig) method() string {
1227 return "setWebhook"
1228}
1229
1230func (config WebhookConfig) params() (Params, error) {
1231 params := make(Params)
1232
1233 if config.URL != nil {
1234 params["url"] = config.URL.String()
1235 }
1236
1237 params.AddNonEmpty("ip_address", config.IPAddress)
1238 params.AddNonZero("max_connections", config.MaxConnections)
1239 err := params.AddInterface("allowed_updates", config.AllowedUpdates)
1240 params.AddBool("drop_pending_updates", config.DropPendingUpdates)
1241 params.AddNonEmpty("secret_token", config.SecretToken)
1242
1243 return params, err
1244}
1245
1246func (config WebhookConfig) files() []RequestFile {
1247 if config.Certificate != nil {
1248 return []RequestFile{{
1249 Name: "certificate",
1250 Data: config.Certificate,
1251 }}
1252 }
1253
1254 return nil
1255}
1256
1257// DeleteWebhookConfig is a helper to delete a webhook.
1258type DeleteWebhookConfig struct {
1259 DropPendingUpdates bool
1260}
1261
1262func (config DeleteWebhookConfig) method() string {
1263 return "deleteWebhook"
1264}
1265
1266func (config DeleteWebhookConfig) params() (Params, error) {
1267 params := make(Params)
1268
1269 params.AddBool("drop_pending_updates", config.DropPendingUpdates)
1270
1271 return params, nil
1272}
1273
1274// InlineConfig contains information on making an InlineQuery response.
1275type InlineConfig struct {
1276 InlineQueryID string `json:"inline_query_id"`
1277 Results []interface{} `json:"results"`
1278 CacheTime int `json:"cache_time"`
1279 IsPersonal bool `json:"is_personal"`
1280 NextOffset string `json:"next_offset"`
1281 SwitchPMText string `json:"switch_pm_text"`
1282 SwitchPMParameter string `json:"switch_pm_parameter"`
1283}
1284
1285func (config InlineConfig) method() string {
1286 return "answerInlineQuery"
1287}
1288
1289func (config InlineConfig) params() (Params, error) {
1290 params := make(Params)
1291
1292 params["inline_query_id"] = config.InlineQueryID
1293 params.AddNonZero("cache_time", config.CacheTime)
1294 params.AddBool("is_personal", config.IsPersonal)
1295 params.AddNonEmpty("next_offset", config.NextOffset)
1296 params.AddNonEmpty("switch_pm_text", config.SwitchPMText)
1297 params.AddNonEmpty("switch_pm_parameter", config.SwitchPMParameter)
1298 err := params.AddInterface("results", config.Results)
1299
1300 return params, err
1301}
1302
1303// AnswerWebAppQueryConfig is used to set the result of an interaction with a
1304// Web App and send a corresponding message on behalf of the user to the chat
1305// from which the query originated.
1306type AnswerWebAppQueryConfig struct {
1307 // WebAppQueryID is the unique identifier for the query to be answered.
1308 WebAppQueryID string `json:"web_app_query_id"`
1309 // Result is an InlineQueryResult object describing the message to be sent.
1310 Result interface{} `json:"result"`
1311}
1312
1313func (config AnswerWebAppQueryConfig) method() string {
1314 return "answerWebAppQuery"
1315}
1316
1317func (config AnswerWebAppQueryConfig) params() (Params, error) {
1318 params := make(Params)
1319
1320 params["web_app_query_id"] = config.WebAppQueryID
1321 err := params.AddInterface("result", config.Result)
1322
1323 return params, err
1324}
1325
1326// CallbackConfig contains information on making a CallbackQuery response.
1327type CallbackConfig struct {
1328 CallbackQueryID string `json:"callback_query_id"`
1329 Text string `json:"text"`
1330 ShowAlert bool `json:"show_alert"`
1331 URL string `json:"url"`
1332 CacheTime int `json:"cache_time"`
1333}
1334
1335func (config CallbackConfig) method() string {
1336 return "answerCallbackQuery"
1337}
1338
1339func (config CallbackConfig) params() (Params, error) {
1340 params := make(Params)
1341
1342 params["callback_query_id"] = config.CallbackQueryID
1343 params.AddNonEmpty("text", config.Text)
1344 params.AddBool("show_alert", config.ShowAlert)
1345 params.AddNonEmpty("url", config.URL)
1346 params.AddNonZero("cache_time", config.CacheTime)
1347
1348 return params, nil
1349}
1350
1351// ChatMemberConfig contains information about a user in a chat for use
1352// with administrative functions such as kicking or unbanning a user.
1353type ChatMemberConfig struct {
1354 ChatID int64
1355 SuperGroupUsername string
1356 ChannelUsername string
1357 UserID int64
1358}
1359
1360// UnbanChatMemberConfig allows you to unban a user.
1361type UnbanChatMemberConfig struct {
1362 ChatMemberConfig
1363 OnlyIfBanned bool
1364}
1365
1366func (config UnbanChatMemberConfig) method() string {
1367 return "unbanChatMember"
1368}
1369
1370func (config UnbanChatMemberConfig) params() (Params, error) {
1371 params := make(Params)
1372
1373 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1374 params.AddNonZero64("user_id", config.UserID)
1375 params.AddBool("only_if_banned", config.OnlyIfBanned)
1376
1377 return params, nil
1378}
1379
1380// BanChatMemberConfig contains extra fields to kick user.
1381type BanChatMemberConfig struct {
1382 ChatMemberConfig
1383 UntilDate int64
1384 RevokeMessages bool
1385}
1386
1387func (config BanChatMemberConfig) method() string {
1388 return "banChatMember"
1389}
1390
1391func (config BanChatMemberConfig) params() (Params, error) {
1392 params := make(Params)
1393
1394 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1395 params.AddNonZero64("user_id", config.UserID)
1396 params.AddNonZero64("until_date", config.UntilDate)
1397 params.AddBool("revoke_messages", config.RevokeMessages)
1398
1399 return params, nil
1400}
1401
1402// KickChatMemberConfig contains extra fields to ban user.
1403//
1404// This was renamed to BanChatMember in later versions of the Telegram Bot API.
1405type KickChatMemberConfig = BanChatMemberConfig
1406
1407// RestrictChatMemberConfig contains fields to restrict members of chat
1408type RestrictChatMemberConfig struct {
1409 ChatMemberConfig
1410 UntilDate int64
1411 UseIndependentChatPermissions bool
1412 Permissions *ChatPermissions
1413}
1414
1415func (config RestrictChatMemberConfig) method() string {
1416 return "restrictChatMember"
1417}
1418
1419func (config RestrictChatMemberConfig) params() (Params, error) {
1420 params := make(Params)
1421
1422 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1423 params.AddNonZero64("user_id", config.UserID)
1424 params.AddBool("use_independent_chat_permissions", config.UseIndependentChatPermissions)
1425
1426 err := params.AddInterface("permissions", config.Permissions)
1427 params.AddNonZero64("until_date", config.UntilDate)
1428
1429 return params, err
1430}
1431
1432// PromoteChatMemberConfig contains fields to promote members of chat
1433type PromoteChatMemberConfig struct {
1434 ChatMemberConfig
1435 IsAnonymous bool
1436 CanManageChat bool
1437 CanChangeInfo bool
1438 CanPostMessages bool
1439 CanEditMessages bool
1440 CanDeleteMessages bool
1441 CanManageVideoChats bool
1442 CanInviteUsers bool
1443 CanRestrictMembers bool
1444 CanPinMessages bool
1445 CanPromoteMembers bool
1446 CanManageTopics bool
1447}
1448
1449func (config PromoteChatMemberConfig) method() string {
1450 return "promoteChatMember"
1451}
1452
1453func (config PromoteChatMemberConfig) params() (Params, error) {
1454 params := make(Params)
1455
1456 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1457 params.AddNonZero64("user_id", config.UserID)
1458
1459 params.AddBool("is_anonymous", config.IsAnonymous)
1460 params.AddBool("can_manage_chat", config.CanManageChat)
1461 params.AddBool("can_change_info", config.CanChangeInfo)
1462 params.AddBool("can_post_messages", config.CanPostMessages)
1463 params.AddBool("can_edit_messages", config.CanEditMessages)
1464 params.AddBool("can_delete_messages", config.CanDeleteMessages)
1465 params.AddBool("can_manage_video_chats", config.CanManageVideoChats)
1466 params.AddBool("can_invite_users", config.CanInviteUsers)
1467 params.AddBool("can_restrict_members", config.CanRestrictMembers)
1468 params.AddBool("can_pin_messages", config.CanPinMessages)
1469 params.AddBool("can_promote_members", config.CanPromoteMembers)
1470 params.AddBool("can_manage_topics", config.CanManageTopics)
1471
1472 return params, nil
1473}
1474
1475// SetChatAdministratorCustomTitle sets the title of an administrative user
1476// promoted by the bot for a chat.
1477type SetChatAdministratorCustomTitle struct {
1478 ChatMemberConfig
1479 CustomTitle string
1480}
1481
1482func (SetChatAdministratorCustomTitle) method() string {
1483 return "setChatAdministratorCustomTitle"
1484}
1485
1486func (config SetChatAdministratorCustomTitle) params() (Params, error) {
1487 params := make(Params)
1488
1489 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
1490 params.AddNonZero64("user_id", config.UserID)
1491 params.AddNonEmpty("custom_title", config.CustomTitle)
1492
1493 return params, nil
1494}
1495
1496// BanChatSenderChatConfig bans a channel chat in a supergroup or a channel. The
1497// owner of the chat will not be able to send messages and join live streams on
1498// behalf of the chat, unless it is unbanned first. The bot must be an
1499// administrator in the supergroup or channel for this to work and must have the
1500// appropriate administrator rights.
1501type BanChatSenderChatConfig struct {
1502 ChatID int64
1503 ChannelUsername string
1504 SenderChatID int64
1505 UntilDate int
1506}
1507
1508func (config BanChatSenderChatConfig) method() string {
1509 return "banChatSenderChat"
1510}
1511
1512func (config BanChatSenderChatConfig) params() (Params, error) {
1513 params := make(Params)
1514
1515 _ = params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1516 params.AddNonZero64("sender_chat_id", config.SenderChatID)
1517 params.AddNonZero("until_date", config.UntilDate)
1518
1519 return params, nil
1520}
1521
1522// UnbanChatSenderChatConfig unbans a previously banned channel chat in a
1523// supergroup or channel. The bot must be an administrator for this to work and
1524// must have the appropriate administrator rights.
1525type UnbanChatSenderChatConfig struct {
1526 ChatID int64
1527 ChannelUsername string
1528 SenderChatID int64
1529}
1530
1531func (config UnbanChatSenderChatConfig) method() string {
1532 return "unbanChatSenderChat"
1533}
1534
1535func (config UnbanChatSenderChatConfig) params() (Params, error) {
1536 params := make(Params)
1537
1538 _ = params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1539 params.AddNonZero64("sender_chat_id", config.SenderChatID)
1540
1541 return params, nil
1542}
1543
1544// ChatConfig contains information about getting information on a chat.
1545type ChatConfig struct {
1546 ChatID int64
1547 SuperGroupUsername string
1548}
1549
1550func (config ChatConfig) params() (Params, error) {
1551 params := make(Params)
1552
1553 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1554
1555 return params, nil
1556}
1557
1558// ChatInfoConfig contains information about getting chat information.
1559type ChatInfoConfig struct {
1560 ChatConfig
1561}
1562
1563func (ChatInfoConfig) method() string {
1564 return "getChat"
1565}
1566
1567// ChatMemberCountConfig contains information about getting the number of users in a chat.
1568type ChatMemberCountConfig struct {
1569 ChatConfig
1570}
1571
1572func (ChatMemberCountConfig) method() string {
1573 return "getChatMembersCount"
1574}
1575
1576// ChatAdministratorsConfig contains information about getting chat administrators.
1577type ChatAdministratorsConfig struct {
1578 ChatConfig
1579}
1580
1581func (ChatAdministratorsConfig) method() string {
1582 return "getChatAdministrators"
1583}
1584
1585// SetChatPermissionsConfig allows you to set default permissions for the
1586// members in a group. The bot must be an administrator and have rights to
1587// restrict members.
1588type SetChatPermissionsConfig struct {
1589 ChatConfig
1590 UseIndependentChatPermissions bool
1591 Permissions *ChatPermissions
1592}
1593
1594func (SetChatPermissionsConfig) method() string {
1595 return "setChatPermissions"
1596}
1597
1598func (config SetChatPermissionsConfig) params() (Params, error) {
1599 params := make(Params)
1600
1601 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1602 params.AddBool("use_independent_chat_permissions", config.UseIndependentChatPermissions)
1603 err := params.AddInterface("permissions", config.Permissions)
1604
1605 return params, err
1606}
1607
1608// ChatInviteLinkConfig contains information about getting a chat link.
1609//
1610// Note that generating a new link will revoke any previous links.
1611type ChatInviteLinkConfig struct {
1612 ChatConfig
1613}
1614
1615func (ChatInviteLinkConfig) method() string {
1616 return "exportChatInviteLink"
1617}
1618
1619func (config ChatInviteLinkConfig) params() (Params, error) {
1620 params := make(Params)
1621
1622 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1623
1624 return params, nil
1625}
1626
1627// CreateChatInviteLinkConfig allows you to create an additional invite link for
1628// a chat. The bot must be an administrator in the chat for this to work and
1629// must have the appropriate admin rights. The link can be revoked using the
1630// RevokeChatInviteLinkConfig.
1631type CreateChatInviteLinkConfig struct {
1632 ChatConfig
1633 Name string
1634 ExpireDate int
1635 MemberLimit int
1636 CreatesJoinRequest bool
1637}
1638
1639func (CreateChatInviteLinkConfig) method() string {
1640 return "createChatInviteLink"
1641}
1642
1643func (config CreateChatInviteLinkConfig) params() (Params, error) {
1644 params := make(Params)
1645
1646 params.AddNonEmpty("name", config.Name)
1647 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1648 params.AddNonZero("expire_date", config.ExpireDate)
1649 params.AddNonZero("member_limit", config.MemberLimit)
1650 params.AddBool("creates_join_request", config.CreatesJoinRequest)
1651
1652 return params, nil
1653}
1654
1655// EditChatInviteLinkConfig allows you to edit a non-primary invite link created
1656// by the bot. The bot must be an administrator in the chat for this to work and
1657// must have the appropriate admin rights.
1658type EditChatInviteLinkConfig struct {
1659 ChatConfig
1660 InviteLink string
1661 Name string
1662 ExpireDate int
1663 MemberLimit int
1664 CreatesJoinRequest bool
1665}
1666
1667func (EditChatInviteLinkConfig) method() string {
1668 return "editChatInviteLink"
1669}
1670
1671func (config EditChatInviteLinkConfig) params() (Params, error) {
1672 params := make(Params)
1673
1674 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1675 params.AddNonEmpty("name", config.Name)
1676 params["invite_link"] = config.InviteLink
1677 params.AddNonZero("expire_date", config.ExpireDate)
1678 params.AddNonZero("member_limit", config.MemberLimit)
1679 params.AddBool("creates_join_request", config.CreatesJoinRequest)
1680
1681 return params, nil
1682}
1683
1684// RevokeChatInviteLinkConfig allows you to revoke an invite link created by the
1685// bot. If the primary link is revoked, a new link is automatically generated.
1686// The bot must be an administrator in the chat for this to work and must have
1687// the appropriate admin rights.
1688type RevokeChatInviteLinkConfig struct {
1689 ChatConfig
1690 InviteLink string
1691}
1692
1693func (RevokeChatInviteLinkConfig) method() string {
1694 return "revokeChatInviteLink"
1695}
1696
1697func (config RevokeChatInviteLinkConfig) params() (Params, error) {
1698 params := make(Params)
1699
1700 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1701 params["invite_link"] = config.InviteLink
1702
1703 return params, nil
1704}
1705
1706// ApproveChatJoinRequestConfig allows you to approve a chat join request.
1707type ApproveChatJoinRequestConfig struct {
1708 ChatConfig
1709 UserID int64
1710}
1711
1712func (ApproveChatJoinRequestConfig) method() string {
1713 return "approveChatJoinRequest"
1714}
1715
1716func (config ApproveChatJoinRequestConfig) params() (Params, error) {
1717 params := make(Params)
1718
1719 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1720 params.AddNonZero("user_id", int(config.UserID))
1721
1722 return params, nil
1723}
1724
1725// DeclineChatJoinRequest allows you to decline a chat join request.
1726type DeclineChatJoinRequest struct {
1727 ChatConfig
1728 UserID int64
1729}
1730
1731func (DeclineChatJoinRequest) method() string {
1732 return "declineChatJoinRequest"
1733}
1734
1735func (config DeclineChatJoinRequest) params() (Params, error) {
1736 params := make(Params)
1737
1738 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1739 params.AddNonZero("user_id", int(config.UserID))
1740
1741 return params, nil
1742}
1743
1744// LeaveChatConfig allows you to leave a chat.
1745type LeaveChatConfig struct {
1746 ChatID int64
1747 ChannelUsername string
1748}
1749
1750func (config LeaveChatConfig) method() string {
1751 return "leaveChat"
1752}
1753
1754func (config LeaveChatConfig) params() (Params, error) {
1755 params := make(Params)
1756
1757 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1758
1759 return params, nil
1760}
1761
1762// ChatConfigWithUser contains information about a chat and a user.
1763type ChatConfigWithUser struct {
1764 ChatID int64
1765 SuperGroupUsername string
1766 UserID int64
1767}
1768
1769func (config ChatConfigWithUser) params() (Params, error) {
1770 params := make(Params)
1771
1772 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1773 params.AddNonZero64("user_id", config.UserID)
1774
1775 return params, nil
1776}
1777
1778// GetChatMemberConfig is information about getting a specific member in a chat.
1779type GetChatMemberConfig struct {
1780 ChatConfigWithUser
1781}
1782
1783func (GetChatMemberConfig) method() string {
1784 return "getChatMember"
1785}
1786
1787// InvoiceConfig contains information for sendInvoice request.
1788type InvoiceConfig struct {
1789 BaseChat
1790 Title string // required
1791 Description string // required
1792 Payload string // required
1793 ProviderToken string // required
1794 Currency string // required
1795 Prices []LabeledPrice // required
1796 MaxTipAmount int
1797 SuggestedTipAmounts []int
1798 StartParameter string
1799 ProviderData string
1800 PhotoURL string
1801 PhotoSize int
1802 PhotoWidth int
1803 PhotoHeight int
1804 NeedName bool
1805 NeedPhoneNumber bool
1806 NeedEmail bool
1807 NeedShippingAddress bool
1808 SendPhoneNumberToProvider bool
1809 SendEmailToProvider bool
1810 IsFlexible bool
1811}
1812
1813func (config InvoiceConfig) params() (Params, error) {
1814 params, err := config.BaseChat.params()
1815 if err != nil {
1816 return params, err
1817 }
1818
1819 params["title"] = config.Title
1820 params["description"] = config.Description
1821 params["payload"] = config.Payload
1822 params["provider_token"] = config.ProviderToken
1823 params["currency"] = config.Currency
1824 if err = params.AddInterface("prices", config.Prices); err != nil {
1825 return params, err
1826 }
1827
1828 params.AddNonZero("max_tip_amount", config.MaxTipAmount)
1829 err = params.AddInterface("suggested_tip_amounts", config.SuggestedTipAmounts)
1830 params.AddNonEmpty("start_parameter", config.StartParameter)
1831 params.AddNonEmpty("provider_data", config.ProviderData)
1832 params.AddNonEmpty("photo_url", config.PhotoURL)
1833 params.AddNonZero("photo_size", config.PhotoSize)
1834 params.AddNonZero("photo_width", config.PhotoWidth)
1835 params.AddNonZero("photo_height", config.PhotoHeight)
1836 params.AddBool("need_name", config.NeedName)
1837 params.AddBool("need_phone_number", config.NeedPhoneNumber)
1838 params.AddBool("need_email", config.NeedEmail)
1839 params.AddBool("need_shipping_address", config.NeedShippingAddress)
1840 params.AddBool("is_flexible", config.IsFlexible)
1841 params.AddBool("send_phone_number_to_provider", config.SendPhoneNumberToProvider)
1842 params.AddBool("send_email_to_provider", config.SendEmailToProvider)
1843
1844 return params, err
1845}
1846
1847func (config InvoiceConfig) method() string {
1848 return "sendInvoice"
1849}
1850
1851// InvoiceLinkConfig contains information for createInvoiceLink method
1852type InvoiceLinkConfig struct {
1853 Title string //Required
1854 Description string //Required
1855 Payload string //Required
1856 ProviderToken string //Required
1857 Currency string //Required
1858 Prices []LabeledPrice //Required
1859 MaxTipAmount int
1860 SuggestedTipAmounts []int
1861 ProviderData string
1862 PhotoURL string
1863 PhotoSize int
1864 PhotoWidth int
1865 PhotoHeight int
1866 NeedName bool
1867 NeedPhoneNumber bool
1868 NeedEmail bool
1869 NeedShippingAddress bool
1870 SendPhoneNumberToProvider bool
1871 SendEmailToProvider bool
1872 IsFlexible bool
1873}
1874
1875func (config InvoiceLinkConfig) params() (Params, error) {
1876 params := make(Params)
1877
1878 params["title"] = config.Title
1879 params["description"] = config.Description
1880 params["payload"] = config.Payload
1881 params["provider_token"] = config.ProviderToken
1882 params["currency"] = config.Currency
1883 if err := params.AddInterface("prices", config.Prices); err != nil {
1884 return params, err
1885 }
1886
1887 params.AddNonZero("max_tip_amount", config.MaxTipAmount)
1888 err := params.AddInterface("suggested_tip_amounts", config.SuggestedTipAmounts)
1889 params.AddNonEmpty("provider_data", config.ProviderData)
1890 params.AddNonEmpty("photo_url", config.PhotoURL)
1891 params.AddNonZero("photo_size", config.PhotoSize)
1892 params.AddNonZero("photo_width", config.PhotoWidth)
1893 params.AddNonZero("photo_height", config.PhotoHeight)
1894 params.AddBool("need_name", config.NeedName)
1895 params.AddBool("need_phone_number", config.NeedPhoneNumber)
1896 params.AddBool("need_email", config.NeedEmail)
1897 params.AddBool("need_shipping_address", config.NeedShippingAddress)
1898 params.AddBool("send_phone_number_to_provider", config.SendPhoneNumberToProvider)
1899 params.AddBool("send_email_to_provider", config.SendEmailToProvider)
1900 params.AddBool("is_flexible", config.IsFlexible)
1901
1902 return params, err
1903}
1904
1905func (config InvoiceLinkConfig) method() string {
1906 return "createInvoiceLink"
1907}
1908
1909// ShippingConfig contains information for answerShippingQuery request.
1910type ShippingConfig struct {
1911 ShippingQueryID string // required
1912 OK bool // required
1913 ShippingOptions []ShippingOption
1914 ErrorMessage string
1915}
1916
1917func (config ShippingConfig) method() string {
1918 return "answerShippingQuery"
1919}
1920
1921func (config ShippingConfig) params() (Params, error) {
1922 params := make(Params)
1923
1924 params["shipping_query_id"] = config.ShippingQueryID
1925 params.AddBool("ok", config.OK)
1926 err := params.AddInterface("shipping_options", config.ShippingOptions)
1927 params.AddNonEmpty("error_message", config.ErrorMessage)
1928
1929 return params, err
1930}
1931
1932// PreCheckoutConfig contains information for answerPreCheckoutQuery request.
1933type PreCheckoutConfig struct {
1934 PreCheckoutQueryID string // required
1935 OK bool // required
1936 ErrorMessage string
1937}
1938
1939func (config PreCheckoutConfig) method() string {
1940 return "answerPreCheckoutQuery"
1941}
1942
1943func (config PreCheckoutConfig) params() (Params, error) {
1944 params := make(Params)
1945
1946 params["pre_checkout_query_id"] = config.PreCheckoutQueryID
1947 params.AddBool("ok", config.OK)
1948 params.AddNonEmpty("error_message", config.ErrorMessage)
1949
1950 return params, nil
1951}
1952
1953// DeleteMessageConfig contains information of a message in a chat to delete.
1954type DeleteMessageConfig struct {
1955 ChannelUsername string
1956 ChatID int64
1957 MessageID int
1958}
1959
1960func (config DeleteMessageConfig) method() string {
1961 return "deleteMessage"
1962}
1963
1964func (config DeleteMessageConfig) params() (Params, error) {
1965 params := make(Params)
1966
1967 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1968 params.AddNonZero("message_id", config.MessageID)
1969
1970 return params, nil
1971}
1972
1973// PinChatMessageConfig contains information of a message in a chat to pin.
1974type PinChatMessageConfig struct {
1975 ChatID int64
1976 ChannelUsername string
1977 MessageID int
1978 DisableNotification bool
1979}
1980
1981func (config PinChatMessageConfig) method() string {
1982 return "pinChatMessage"
1983}
1984
1985func (config PinChatMessageConfig) params() (Params, error) {
1986 params := make(Params)
1987
1988 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1989 params.AddNonZero("message_id", config.MessageID)
1990 params.AddBool("disable_notification", config.DisableNotification)
1991
1992 return params, nil
1993}
1994
1995// UnpinChatMessageConfig contains information of a chat message to unpin.
1996//
1997// If MessageID is not specified, it will unpin the most recent pin.
1998type UnpinChatMessageConfig struct {
1999 ChatID int64
2000 ChannelUsername string
2001 MessageID int
2002}
2003
2004func (config UnpinChatMessageConfig) method() string {
2005 return "unpinChatMessage"
2006}
2007
2008func (config UnpinChatMessageConfig) params() (Params, error) {
2009 params := make(Params)
2010
2011 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2012 params.AddNonZero("message_id", config.MessageID)
2013
2014 return params, nil
2015}
2016
2017// UnpinAllChatMessagesConfig contains information of all messages to unpin in
2018// a chat.
2019type UnpinAllChatMessagesConfig struct {
2020 ChatID int64
2021 ChannelUsername string
2022}
2023
2024func (config UnpinAllChatMessagesConfig) method() string {
2025 return "unpinAllChatMessages"
2026}
2027
2028func (config UnpinAllChatMessagesConfig) params() (Params, error) {
2029 params := make(Params)
2030
2031 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2032
2033 return params, nil
2034}
2035
2036// SetChatPhotoConfig allows you to set a group, supergroup, or channel's photo.
2037type SetChatPhotoConfig struct {
2038 BaseFile
2039}
2040
2041func (config SetChatPhotoConfig) method() string {
2042 return "setChatPhoto"
2043}
2044
2045func (config SetChatPhotoConfig) files() []RequestFile {
2046 return []RequestFile{{
2047 Name: "photo",
2048 Data: config.File,
2049 }}
2050}
2051
2052// DeleteChatPhotoConfig allows you to delete a group, supergroup, or channel's photo.
2053type DeleteChatPhotoConfig struct {
2054 ChatID int64
2055 ChannelUsername string
2056}
2057
2058func (config DeleteChatPhotoConfig) method() string {
2059 return "deleteChatPhoto"
2060}
2061
2062func (config DeleteChatPhotoConfig) params() (Params, error) {
2063 params := make(Params)
2064
2065 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2066
2067 return params, nil
2068}
2069
2070// SetChatTitleConfig allows you to set the title of something other than a private chat.
2071type SetChatTitleConfig struct {
2072 ChatID int64
2073 ChannelUsername string
2074
2075 Title string
2076}
2077
2078func (config SetChatTitleConfig) method() string {
2079 return "setChatTitle"
2080}
2081
2082func (config SetChatTitleConfig) params() (Params, error) {
2083 params := make(Params)
2084
2085 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2086 params["title"] = config.Title
2087
2088 return params, nil
2089}
2090
2091// SetChatDescriptionConfig allows you to set the description of a supergroup or channel.
2092type SetChatDescriptionConfig struct {
2093 ChatID int64
2094 ChannelUsername string
2095
2096 Description string
2097}
2098
2099func (config SetChatDescriptionConfig) method() string {
2100 return "setChatDescription"
2101}
2102
2103func (config SetChatDescriptionConfig) params() (Params, error) {
2104 params := make(Params)
2105
2106 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2107 params["description"] = config.Description
2108
2109 return params, nil
2110}
2111
2112// GetStickerSetConfig allows you to get the stickers in a set.
2113type GetStickerSetConfig struct {
2114 Name string
2115}
2116
2117func (config GetStickerSetConfig) method() string {
2118 return "getStickerSet"
2119}
2120
2121func (config GetStickerSetConfig) params() (Params, error) {
2122 params := make(Params)
2123
2124 params["name"] = config.Name
2125
2126 return params, nil
2127}
2128
2129// GetCustomEmojiStickersConfig get information about
2130// custom emoji stickers by their identifiers.
2131type GetCustomEmojiStickersConfig struct {
2132 CustomEmojiIDs []string
2133}
2134
2135func (config GetCustomEmojiStickersConfig) params() (Params, error) {
2136 params := make(Params)
2137
2138 params.AddInterface("custom_emoji_ids", config.CustomEmojiIDs)
2139
2140 return params, nil
2141}
2142
2143func (config GetCustomEmojiStickersConfig) method() string {
2144 return "getCustomEmojiStickers"
2145}
2146
2147// UploadStickerConfig allows you to upload a sticker for use in a set later.
2148type UploadStickerConfig struct {
2149 UserID int64
2150 Sticker RequestFile
2151 StickerFormat string
2152}
2153
2154func (config UploadStickerConfig) method() string {
2155 return "uploadStickerFile"
2156}
2157
2158func (config UploadStickerConfig) params() (Params, error) {
2159 params := make(Params)
2160
2161 params.AddNonZero64("user_id", config.UserID)
2162 params["sticker_format"] = config.StickerFormat
2163
2164 return params, nil
2165}
2166
2167func (config UploadStickerConfig) files() []RequestFile {
2168 return []RequestFile{{
2169 Name: "png_sticker",
2170 Data: config.PNGSticker,
2171 }}
2172}
2173
2174// NewStickerSetConfig allows creating a new sticker set.
2175//
2176// You must set either PNGSticker or TGSSticker.
2177type NewStickerSetConfig struct {
2178 UserID int64
2179 Name string
2180 Title string
2181 Stickers []InputSticker
2182 StickerFormat string
2183 StickerType string
2184 NeedsRepainting bool //optional; Pass True if stickers in the sticker set must be repainted to the color of text when used in messages, the accent color if used as emoji status, white on chat photos, or another appropriate color based on context; for custom emoji sticker sets only
2185}
2186
2187func (config NewStickerSetConfig) method() string {
2188 return "createNewStickerSet"
2189}
2190
2191func (config NewStickerSetConfig) params() (Params, error) {
2192 params := make(Params)
2193
2194 params.AddNonZero64("user_id", config.UserID)
2195 params["name"] = config.Name
2196 params["title"] = config.Title
2197 params["sticker_format"] = config.StickerFormat
2198
2199 params.AddBool("needs_repainting", config.NeedsRepainting)
2200 params.AddNonEmpty("sticker_type", string(config.StickerType))
2201 err := params.AddInterface("stickers", config.Stickers)
2202
2203 return params, err
2204}
2205
2206func (config NewStickerSetConfig) files() []RequestFile {
2207 if config.PNGSticker != nil {
2208 return []RequestFile{{
2209 Name: "png_sticker",
2210 Data: config.PNGSticker,
2211 }}
2212 }
2213
2214 return []RequestFile{{
2215 Name: "tgs_sticker",
2216 Data: config.TGSSticker,
2217 }}
2218}
2219
2220// AddStickerConfig allows you to add a sticker to a set.
2221type AddStickerConfig struct {
2222 UserID int64
2223 Name string
2224 Sticker InputSticker
2225}
2226
2227func (config AddStickerConfig) method() string {
2228 return "addStickerToSet"
2229}
2230
2231func (config AddStickerConfig) params() (Params, error) {
2232 params := make(Params)
2233
2234 params.AddNonZero64("user_id", config.UserID)
2235 params["name"] = config.Name
2236 err := params.AddInterface("sticker", config.Sticker)
2237 return params, err
2238}
2239
2240func (config AddStickerConfig) files() []RequestFile {
2241 if config.PNGSticker != nil {
2242 return []RequestFile{{
2243 Name: "png_sticker",
2244 Data: config.PNGSticker,
2245 }}
2246 }
2247
2248 return []RequestFile{{
2249 Name: "tgs_sticker",
2250 Data: config.TGSSticker,
2251 }}
2252
2253}
2254
2255// SetStickerPositionConfig allows you to change the position of a sticker in a set.
2256type SetStickerPositionConfig struct {
2257 Sticker string
2258 Position int
2259}
2260
2261func (config SetStickerPositionConfig) method() string {
2262 return "setStickerPositionInSet"
2263}
2264
2265func (config SetStickerPositionConfig) params() (Params, error) {
2266 params := make(Params)
2267
2268 params["sticker"] = config.Sticker
2269 params.AddNonZero("position", config.Position)
2270
2271 return params, nil
2272}
2273
2274// SetCustomEmojiStickerSetThumbnalConfig allows you to set the thumbnail of a custom emoji sticker set
2275type SetCustomEmojiStickerSetThumbnalConfig struct {
2276 Name string
2277 CustomEmojiID string
2278}
2279
2280func (config SetCustomEmojiStickerSetThumbnalConfig) method() string {
2281 return "setCustomEmojiStickerSetThumbnail"
2282}
2283
2284func (config SetCustomEmojiStickerSetThumbnalConfig) params() (Params, error) {
2285 params := make(Params)
2286
2287 params["name"] = config.Name
2288 params.AddNonEmpty("position", config.CustomEmojiID)
2289
2290 return params, nil
2291}
2292
2293// SetStickerSetTitle allows you to set the title of a created sticker set
2294type SetStickerSetTitleConfig struct {
2295 Name string
2296 Title string
2297}
2298
2299func (config SetStickerSetTitleConfig) method() string {
2300 return "setStickerSetTitle"
2301}
2302
2303func (config SetStickerSetTitleConfig) params() (Params, error) {
2304 params := make(Params)
2305
2306 params["name"] = config.Name
2307 params["title"] = config.Title
2308
2309 return params, nil
2310}
2311
2312// DeleteStickerSetConfig allows you to delete a sticker set that was created by the bot.
2313type DeleteStickerSetConfig struct {
2314 Name string
2315}
2316
2317func (config DeleteStickerSetConfig) method() string {
2318 return "deleteStickerSet"
2319}
2320
2321func (config DeleteStickerSetConfig) params() (Params, error) {
2322 params := make(Params)
2323
2324 params["name"] = config.Name
2325
2326 return params, nil
2327}
2328
2329// DeleteStickerConfig allows you to delete a sticker from a set.
2330type DeleteStickerConfig struct {
2331 Sticker string
2332}
2333
2334func (config DeleteStickerConfig) method() string {
2335 return "deleteStickerFromSet"
2336}
2337
2338func (config DeleteStickerConfig) params() (Params, error) {
2339 params := make(Params)
2340
2341 params["sticker"] = config.Sticker
2342
2343 return params, nil
2344}
2345
2346// SetStickerEmojiListConfig allows you to change the list of emoji assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot
2347type SetStickerEmojiListConfig struct {
2348 Sticker string
2349 EmojiList []string
2350}
2351
2352func (config SetStickerEmojiListConfig) method() string {
2353 return "setStickerEmojiList"
2354}
2355
2356func (config SetStickerEmojiListConfig) params() (Params, error) {
2357 params := make(Params)
2358
2359 params["sticker"] = config.Sticker
2360 err := params.AddInterface("emoji_list", config.EmojiList)
2361
2362 return params, err
2363}
2364
2365// SetStickerKeywordsConfig allows you to change search keywords assigned to a regular or custom emoji sticker. The sticker must belong to a sticker set created by the bot.
2366type SetStickerKeywordsConfig struct {
2367 Sticker string
2368 Keywords []string
2369}
2370
2371func (config SetStickerKeywordsConfig) method() string {
2372 return "setStickerKeywords"
2373}
2374
2375func (config SetStickerKeywordsConfig) params() (Params, error) {
2376 params := make(Params)
2377
2378 params["sticker"] = config.Sticker
2379 err := params.AddInterface("keywords", config.Keywords)
2380
2381 return params, err
2382}
2383
2384// SetStickerMaskPositionConfig allows you to change the mask position of a mask sticker. The sticker must belong to a sticker set that was created by the bot
2385type SetStickerMaskPositionConfig struct {
2386 Sticker string
2387 MaskPosition *MaskPosition
2388}
2389
2390func (config SetStickerMaskPositionConfig) method() string {
2391 return "setStickerMaskPosition"
2392}
2393
2394func (config SetStickerMaskPositionConfig) params() (Params, error) {
2395 params := make(Params)
2396
2397 params["sticker"] = config.Sticker
2398 err := params.AddInterface("keywords", config.MaskPosition)
2399
2400 return params, err
2401}
2402
2403// SetStickerSetThumbConfig allows you to set the thumbnail for a sticker set.
2404type SetStickerSetThumbConfig struct {
2405 Name string
2406 UserID int64
2407 Thumb RequestFileData
2408}
2409
2410func (config SetStickerSetThumbConfig) method() string {
2411 return "setStickerSetThumbnail"
2412}
2413
2414func (config SetStickerSetThumbConfig) params() (Params, error) {
2415 params := make(Params)
2416
2417 params["name"] = config.Name
2418 params.AddNonZero64("user_id", config.UserID)
2419
2420 return params, nil
2421}
2422
2423func (config SetStickerSetThumbConfig) files() []RequestFile {
2424 return []RequestFile{{
2425 Name: "thumbnail",
2426 Data: config.Thumb,
2427 }}
2428}
2429
2430// SetChatStickerSetConfig allows you to set the sticker set for a supergroup.
2431type SetChatStickerSetConfig struct {
2432 ChatID int64
2433 SuperGroupUsername string
2434
2435 StickerSetName string
2436}
2437
2438func (config SetChatStickerSetConfig) method() string {
2439 return "setChatStickerSet"
2440}
2441
2442func (config SetChatStickerSetConfig) params() (Params, error) {
2443 params := make(Params)
2444
2445 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2446 params["sticker_set_name"] = config.StickerSetName
2447
2448 return params, nil
2449}
2450
2451// DeleteChatStickerSetConfig allows you to remove a supergroup's sticker set.
2452type DeleteChatStickerSetConfig struct {
2453 ChatID int64
2454 SuperGroupUsername string
2455}
2456
2457func (config DeleteChatStickerSetConfig) method() string {
2458 return "deleteChatStickerSet"
2459}
2460
2461func (config DeleteChatStickerSetConfig) params() (Params, error) {
2462 params := make(Params)
2463
2464 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2465
2466 return params, nil
2467}
2468
2469// GetForumTopicIconStickersConfig allows you to get custom emoji stickers,
2470// which can be used as a forum topic icon by any user.
2471type GetForumTopicIconStickersConfig struct{}
2472
2473func (config GetForumTopicIconStickersConfig) method() string {
2474 return "getForumTopicIconStickers"
2475}
2476
2477func (config GetForumTopicIconStickersConfig) params() (Params, error) {
2478 return nil, nil
2479}
2480
2481// BaseForum is a base type for all forum config types.
2482type BaseForum struct {
2483 ChatID int64
2484 SuperGroupUsername string
2485}
2486
2487func (config BaseForum) params() (Params, error) {
2488 params := make(Params)
2489
2490 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2491
2492 return params, nil
2493}
2494
2495// CreateForumTopicConfig allows you to create a topic
2496// in a forum supergroup chat.
2497type CreateForumTopicConfig struct {
2498 BaseForum
2499 Name string
2500 IconColor int
2501 IconCustomEmojiID string
2502}
2503
2504func (config CreateForumTopicConfig) method() string {
2505 return "createForumTopic"
2506}
2507
2508func (config CreateForumTopicConfig) params() (Params, error) {
2509 params := make(Params)
2510
2511 params.AddNonEmpty("name", config.Name)
2512 params.AddNonZero("icon_color", config.IconColor)
2513 params.AddNonEmpty("icon_custom_emoji_id", config.IconCustomEmojiID)
2514
2515 p1, _ := config.BaseForum.params()
2516 params.Merge(p1)
2517
2518 return params, nil
2519}
2520
2521// EditForumTopicConfig allows you to edit
2522// name and icon of a topic in a forum supergroup chat.
2523type EditForumTopicConfig struct {
2524 BaseForum
2525 MessageThreadID int
2526 Name string
2527 IconCustomEmojiID string
2528}
2529
2530func (config EditForumTopicConfig) method() string {
2531 return "editForumTopic"
2532}
2533
2534func (config EditForumTopicConfig) params() (Params, error) {
2535 params := make(Params)
2536
2537 params.AddNonZero("message_thread_id", config.MessageThreadID)
2538 params.AddNonEmpty("name", config.Name)
2539 params.AddNonEmpty("icon_custom_emoji_id", config.IconCustomEmojiID)
2540
2541 p1, _ := config.BaseForum.params()
2542 params.Merge(p1)
2543
2544 return params, nil
2545}
2546
2547// CloseForumTopicConfig allows you to close
2548// an open topic in a forum supergroup chat.
2549type CloseForumTopicConfig struct {
2550 BaseForum
2551 MessageThreadID int
2552}
2553
2554func (config CloseForumTopicConfig) method() string {
2555 return "closeForumTopic"
2556}
2557
2558func (config CloseForumTopicConfig) params() (Params, error) {
2559 params := make(Params)
2560
2561 params.AddNonZero("message_thread_id", config.MessageThreadID)
2562
2563 p1, _ := config.BaseForum.params()
2564 params.Merge(p1)
2565
2566 return params, nil
2567}
2568
2569// ReopenForumTopicConfig allows you to reopen
2570// an closed topic in a forum supergroup chat.
2571type ReopenForumTopicConfig struct {
2572 BaseForum
2573 MessageThreadID int
2574}
2575
2576func (config ReopenForumTopicConfig) method() string {
2577 return "reopenForumTopic"
2578}
2579
2580func (config ReopenForumTopicConfig) params() (Params, error) {
2581 params := make(Params)
2582
2583 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2584 params.AddNonZero("message_thread_id", config.MessageThreadID)
2585
2586 p1, _ := config.BaseForum.params()
2587 params.Merge(p1)
2588
2589 return params, nil
2590}
2591
2592// DeleteForumTopicConfig allows you to delete a forum topic
2593// along with all its messages in a forum supergroup chat.
2594type DeleteForumTopicConfig struct {
2595 BaseForum
2596 MessageThreadID int
2597}
2598
2599func (config DeleteForumTopicConfig) method() string {
2600 return "deleteForumTopic"
2601}
2602
2603func (config DeleteForumTopicConfig) params() (Params, error) {
2604 params := make(Params)
2605
2606 params.AddNonZero("message_thread_id", config.MessageThreadID)
2607
2608 p1, _ := config.BaseForum.params()
2609 params.Merge(p1)
2610
2611 return params, nil
2612}
2613
2614// UnpinAllForumTopicMessagesConfig allows you to clear the list
2615// of pinned messages in a forum topic.
2616type UnpinAllForumTopicMessagesConfig struct {
2617 BaseForum
2618 MessageThreadID int
2619}
2620
2621func (config UnpinAllForumTopicMessagesConfig) method() string {
2622 return "unpinAllForumTopicMessages"
2623}
2624
2625func (config UnpinAllForumTopicMessagesConfig) params() (Params, error) {
2626 params := make(Params)
2627
2628 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2629 params.AddNonZero("message_thread_id", config.MessageThreadID)
2630
2631 p1, _ := config.BaseForum.params()
2632 params.Merge(p1)
2633
2634 return params, nil
2635}
2636
2637// UnpinAllForumTopicMessagesConfig allows you to edit the name of
2638// the 'General' topic in a forum supergroup chat.
2639// The bot must be an administrator in the chat for this to work
2640// and must have can_manage_topics administrator rights. Returns True on success.
2641type EditGeneralForumTopicConfig struct {
2642 BaseForum
2643 Name string
2644}
2645
2646func (config EditGeneralForumTopicConfig) method() string {
2647 return "editGeneralForumTopic"
2648}
2649
2650func (config EditGeneralForumTopicConfig) params() (Params, error) {
2651 params := make(Params)
2652
2653 params.AddNonEmpty("name", config.Name)
2654
2655 p1, _ := config.BaseForum.params()
2656 params.Merge(p1)
2657
2658 return params, nil
2659}
2660
2661// CloseGeneralForumTopicConfig allows you to to close an open 'General' topic
2662// in a forum supergroup chat. The bot must be an administrator in the chat
2663// for this to work and must have the can_manage_topics administrator rights.
2664// Returns True on success.
2665type CloseGeneralForumTopicConfig struct{ BaseForum }
2666
2667func (config CloseGeneralForumTopicConfig) method() string {
2668 return "closeGeneralForumTopic"
2669}
2670
2671// CloseGeneralForumTopicConfig allows you to reopen a closed 'General' topic
2672// in a forum supergroup chat. The bot must be an administrator in the chat
2673// for this to work and must have the can_manage_topics administrator rights.
2674// The topic will be automatically unhidden if it was hidden.
2675// Returns True on success.
2676type ReopenGeneralForumTopicConfig struct{ BaseForum }
2677
2678func (config ReopenGeneralForumTopicConfig) method() string {
2679 return "reopenGeneralForumTopic"
2680}
2681
2682// HideGeneralForumTopicConfig allows you to hide the 'General' topic
2683// in a forum supergroup chat. The bot must be an administrator in the chat
2684// for this to work and must have the can_manage_topics administrator rights.
2685// The topic will be automatically closed if it was open.
2686// Returns True on success.
2687type HideGeneralForumTopicConfig struct{ BaseForum }
2688
2689func (config HideGeneralForumTopicConfig) method() string {
2690 return "hideGeneralForumTopic"
2691}
2692
2693// UnhideGeneralForumTopicConfig allows you to unhide the 'General' topic
2694// in a forum supergroup chat. The bot must be an administrator in the chat
2695// for this to work and must have the can_manage_topics administrator rights.
2696// Returns True on success.
2697type UnhideGeneralForumTopicConfig struct{ BaseForum }
2698
2699func (config UnhideGeneralForumTopicConfig) method() string {
2700 return "unhideGeneralForumTopic"
2701}
2702
2703// MediaGroupConfig allows you to send a group of media.
2704//
2705// Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo).
2706type MediaGroupConfig struct {
2707 BaseChat
2708 Media []interface{}
2709}
2710
2711func (config MediaGroupConfig) method() string {
2712 return "sendMediaGroup"
2713}
2714
2715func (config MediaGroupConfig) params() (Params, error) {
2716 params, err := config.BaseChat.params()
2717 if err != nil {
2718 return nil, err
2719 }
2720
2721 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2722 params.AddBool("disable_notification", config.DisableNotification)
2723 params.AddNonZero("reply_to_message_id", config.ReplyToMessageID)
2724
2725 err = params.AddInterface("media", prepareInputMediaForParams(config.Media))
2726
2727 return params, err
2728}
2729
2730func (config MediaGroupConfig) files() []RequestFile {
2731 return prepareInputMediaForFiles(config.Media)
2732}
2733
2734// DiceConfig contains information about a sendDice request.
2735type DiceConfig struct {
2736 BaseChat
2737 // Emoji on which the dice throw animation is based.
2738 // Currently, must be one of 🎲, 🎯, 🏀, ⚽, 🎳, or 🎰.
2739 // Dice can have values 1-6 for 🎲, 🎯, and 🎳, values 1-5 for 🏀 and ⚽,
2740 // and values 1-64 for 🎰.
2741 // Defaults to “🎲”
2742 Emoji string
2743}
2744
2745func (config DiceConfig) method() string {
2746 return "sendDice"
2747}
2748
2749func (config DiceConfig) params() (Params, error) {
2750 params, err := config.BaseChat.params()
2751 if err != nil {
2752 return params, err
2753 }
2754
2755 params.AddNonEmpty("emoji", config.Emoji)
2756
2757 return params, err
2758}
2759
2760// GetMyCommandsConfig gets a list of the currently registered commands.
2761type GetMyCommandsConfig struct {
2762 Scope *BotCommandScope
2763 LanguageCode string
2764}
2765
2766func (config GetMyCommandsConfig) method() string {
2767 return "getMyCommands"
2768}
2769
2770func (config GetMyCommandsConfig) params() (Params, error) {
2771 params := make(Params)
2772
2773 err := params.AddInterface("scope", config.Scope)
2774 params.AddNonEmpty("language_code", config.LanguageCode)
2775
2776 return params, err
2777}
2778
2779// SetMyCommandsConfig sets a list of commands the bot understands.
2780type SetMyCommandsConfig struct {
2781 Commands []BotCommand
2782 Scope *BotCommandScope
2783 LanguageCode string
2784}
2785
2786func (config SetMyCommandsConfig) method() string {
2787 return "setMyCommands"
2788}
2789
2790func (config SetMyCommandsConfig) params() (Params, error) {
2791 params := make(Params)
2792
2793 if err := params.AddInterface("commands", config.Commands); err != nil {
2794 return params, err
2795 }
2796 err := params.AddInterface("scope", config.Scope)
2797 params.AddNonEmpty("language_code", config.LanguageCode)
2798
2799 return params, err
2800}
2801
2802type DeleteMyCommandsConfig struct {
2803 Scope *BotCommandScope
2804 LanguageCode string
2805}
2806
2807func (config DeleteMyCommandsConfig) method() string {
2808 return "deleteMyCommands"
2809}
2810
2811func (config DeleteMyCommandsConfig) params() (Params, error) {
2812 params := make(Params)
2813
2814 err := params.AddInterface("scope", config.Scope)
2815 params.AddNonEmpty("language_code", config.LanguageCode)
2816
2817 return params, err
2818}
2819
2820// GetMyDescriptionConfig get the current bot description for the given user language
2821type GetMyDescriptionConfig struct {
2822 LanguageCode string
2823}
2824
2825func (config GetMyDescriptionConfig) method() string {
2826 return "getMyDescription"
2827}
2828
2829func (config GetMyDescriptionConfig) params() (Params, error) {
2830 params := make(Params)
2831
2832 params.AddNonEmpty("language_code", config.LanguageCode)
2833
2834 return params, nil
2835}
2836
2837// SetMyDescroptionConfig sets the bot's description, which is shown in the chat with the bot if the chat is empty
2838type SetMyDescriptionConfig struct {
2839 // Pass an empty string to remove the dedicated description for the given language.
2840 Description string
2841 //If empty, the description will be applied to all users for whose language there is no dedicated description.
2842 LanguageCode string
2843}
2844
2845func (config SetMyDescriptionConfig) method() string {
2846 return "setMyDescription"
2847}
2848
2849func (config SetMyDescriptionConfig) params() (Params, error) {
2850 params := make(Params)
2851
2852 params.AddNonEmpty("description", config.Description)
2853 params.AddNonEmpty("language_code", config.LanguageCode)
2854
2855 return params, nil
2856}
2857
2858// GetMyShortDescriptionConfig get the current bot short description for the given user language
2859type GetMyShortDescriptionConfig struct {
2860 LanguageCode string
2861}
2862
2863func (config GetMyShortDescriptionConfig) method() string {
2864 return "getMyShortDescription"
2865}
2866
2867func (config GetMyShortDescriptionConfig) params() (Params, error) {
2868 params := make(Params)
2869
2870 params.AddNonEmpty("language_code", config.LanguageCode)
2871
2872 return params, nil
2873}
2874
2875// SetMyDescroptionConfig sets the bot's short description, which is shown on the bot's profile page and is sent together with the link when users share the bot.
2876type SetMyShortDescriptionConfig struct {
2877 // New short description for the bot; 0-120 characters.
2878 //
2879 //Pass an empty string to remove the dedicated short description for the given language.
2880 ShortDescription string
2881 //A two-letter ISO 639-1 language code.
2882 //
2883 //If empty, the short description will be applied to all users for whose language there is no dedicated short description.
2884 LanguageCode string
2885}
2886
2887func (config SetMyShortDescriptionConfig) method() string {
2888 return "setMyDescription"
2889}
2890
2891func (config SetMyShortDescriptionConfig) params() (Params, error) {
2892 params := make(Params)
2893
2894 params.AddNonEmpty("short_description", config.ShortDescription)
2895 params.AddNonEmpty("language_code", config.LanguageCode)
2896
2897 return params, nil
2898}
2899
2900// SetChatMenuButtonConfig changes the bot's menu button in a private chat,
2901// or the default menu button.
2902type SetChatMenuButtonConfig struct {
2903 ChatID int64
2904 ChannelUsername string
2905
2906 MenuButton *MenuButton
2907}
2908
2909func (config SetChatMenuButtonConfig) method() string {
2910 return "setChatMenuButton"
2911}
2912
2913func (config SetChatMenuButtonConfig) params() (Params, error) {
2914 params := make(Params)
2915
2916 if err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername); err != nil {
2917 return params, err
2918 }
2919 err := params.AddInterface("menu_button", config.MenuButton)
2920
2921 return params, err
2922}
2923
2924type GetChatMenuButtonConfig struct {
2925 ChatID int64
2926 ChannelUsername string
2927}
2928
2929func (config GetChatMenuButtonConfig) method() string {
2930 return "getChatMenuButton"
2931}
2932
2933func (config GetChatMenuButtonConfig) params() (Params, error) {
2934 params := make(Params)
2935
2936 err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2937
2938 return params, err
2939}
2940
2941type SetMyDefaultAdministratorRightsConfig struct {
2942 Rights ChatAdministratorRights
2943 ForChannels bool
2944}
2945
2946func (config SetMyDefaultAdministratorRightsConfig) method() string {
2947 return "setMyDefaultAdministratorRights"
2948}
2949
2950func (config SetMyDefaultAdministratorRightsConfig) params() (Params, error) {
2951 params := make(Params)
2952
2953 err := params.AddInterface("rights", config.Rights)
2954 params.AddBool("for_channels", config.ForChannels)
2955
2956 return params, err
2957}
2958
2959type GetMyDefaultAdministratorRightsConfig struct {
2960 ForChannels bool
2961}
2962
2963func (config GetMyDefaultAdministratorRightsConfig) method() string {
2964 return "getMyDefaultAdministratorRights"
2965}
2966
2967func (config GetMyDefaultAdministratorRightsConfig) params() (Params, error) {
2968 params := make(Params)
2969
2970 params.AddBool("for_channels", config.ForChannels)
2971
2972 return params, nil
2973}
2974
2975// prepareInputMediaParam evaluates a single InputMedia and determines if it
2976// needs to be modified for a successful upload. If it returns nil, then the
2977// value does not need to be included in the params. Otherwise, it will return
2978// the same type as was originally provided.
2979//
2980// The idx is used to calculate the file field name. If you only have a single
2981// file, 0 may be used. It is formatted into "attach://file-%d" for the primary
2982// media and "attach://file-%d-thumb" for thumbnails.
2983//
2984// It is expected to be used in conjunction with prepareInputMediaFile.
2985func prepareInputMediaParam(inputMedia interface{}, idx int) interface{} {
2986 switch m := inputMedia.(type) {
2987 case InputMediaPhoto:
2988 if m.Media.NeedsUpload() {
2989 m.Media = fileAttach(fmt.Sprintf("attach://file-%d", idx))
2990 }
2991
2992 return m
2993 case InputMediaVideo:
2994 if m.Media.NeedsUpload() {
2995 m.Media = fileAttach(fmt.Sprintf("attach://file-%d", idx))
2996 }
2997
2998 if m.Thumb != nil && m.Thumb.NeedsUpload() {
2999 m.Thumb = fileAttach(fmt.Sprintf("attach://file-%d-thumb", idx))
3000 }
3001
3002 return m
3003 case InputMediaAudio:
3004 if m.Media.NeedsUpload() {
3005 m.Media = fileAttach(fmt.Sprintf("attach://file-%d", idx))
3006 }
3007
3008 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3009 m.Thumb = fileAttach(fmt.Sprintf("attach://file-%d-thumb", idx))
3010 }
3011
3012 return m
3013 case InputMediaDocument:
3014 if m.Media.NeedsUpload() {
3015 m.Media = fileAttach(fmt.Sprintf("attach://file-%d", idx))
3016 }
3017
3018 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3019 m.Thumb = fileAttach(fmt.Sprintf("attach://file-%d-thumb", idx))
3020 }
3021
3022 return m
3023 }
3024
3025 return nil
3026}
3027
3028// prepareInputMediaFile generates an array of RequestFile to provide for
3029// Fileable's files method. It returns an array as a single InputMedia may have
3030// multiple files, for the primary media and a thumbnail.
3031//
3032// The idx parameter is used to generate file field names. It uses the names
3033// "file-%d" for the main file and "file-%d-thumb" for the thumbnail.
3034//
3035// It is expected to be used in conjunction with prepareInputMediaParam.
3036func prepareInputMediaFile(inputMedia interface{}, idx int) []RequestFile {
3037 files := []RequestFile{}
3038
3039 switch m := inputMedia.(type) {
3040 case InputMediaPhoto:
3041 if m.Media.NeedsUpload() {
3042 files = append(files, RequestFile{
3043 Name: fmt.Sprintf("file-%d", idx),
3044 Data: m.Media,
3045 })
3046 }
3047 case InputMediaVideo:
3048 if m.Media.NeedsUpload() {
3049 files = append(files, RequestFile{
3050 Name: fmt.Sprintf("file-%d", idx),
3051 Data: m.Media,
3052 })
3053 }
3054
3055 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3056 files = append(files, RequestFile{
3057 Name: fmt.Sprintf("file-%d", idx),
3058 Data: m.Thumb,
3059 })
3060 }
3061 case InputMediaDocument:
3062 if m.Media.NeedsUpload() {
3063 files = append(files, RequestFile{
3064 Name: fmt.Sprintf("file-%d", idx),
3065 Data: m.Media,
3066 })
3067 }
3068
3069 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3070 files = append(files, RequestFile{
3071 Name: fmt.Sprintf("file-%d", idx),
3072 Data: m.Thumb,
3073 })
3074 }
3075 case InputMediaAudio:
3076 if m.Media.NeedsUpload() {
3077 files = append(files, RequestFile{
3078 Name: fmt.Sprintf("file-%d", idx),
3079 Data: m.Media,
3080 })
3081 }
3082
3083 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3084 files = append(files, RequestFile{
3085 Name: fmt.Sprintf("file-%d", idx),
3086 Data: m.Thumb,
3087 })
3088 }
3089 }
3090
3091 return files
3092}
3093
3094// prepareInputMediaForParams calls prepareInputMediaParam for each item
3095// provided and returns a new array with the correct params for a request.
3096//
3097// It is expected that files will get data from the associated function,
3098// prepareInputMediaForFiles.
3099func prepareInputMediaForParams(inputMedia []interface{}) []interface{} {
3100 newMedia := make([]interface{}, len(inputMedia))
3101 copy(newMedia, inputMedia)
3102
3103 for idx, media := range inputMedia {
3104 if param := prepareInputMediaParam(media, idx); param != nil {
3105 newMedia[idx] = param
3106 }
3107 }
3108
3109 return newMedia
3110}
3111
3112// prepareInputMediaForFiles calls prepareInputMediaFile for each item
3113// provided and returns a new array with the correct files for a request.
3114//
3115// It is expected that params will get data from the associated function,
3116// prepareInputMediaForParams.
3117func prepareInputMediaForFiles(inputMedia []interface{}) []RequestFile {
3118 files := []RequestFile{}
3119
3120 for idx, media := range inputMedia {
3121 if file := prepareInputMediaFile(media, idx); file != nil {
3122 files = append(files, file...)
3123 }
3124 }
3125
3126 return files
3127}