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 StickerType string
2183 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
2184}
2185
2186func (config NewStickerSetConfig) method() string {
2187 return "createNewStickerSet"
2188}
2189
2190func (config NewStickerSetConfig) params() (Params, error) {
2191 params := make(Params)
2192
2193 params.AddNonZero64("user_id", config.UserID)
2194 params["name"] = config.Name
2195 params["title"] = config.Title
2196
2197 params.AddBool("needs_repainting", config.NeedsRepainting)
2198 params.AddNonEmpty("sticker_type", string(config.StickerType))
2199 err := params.AddInterface("stickers", config.Stickers)
2200
2201 return params, err
2202}
2203
2204func (config NewStickerSetConfig) files() []RequestFile {
2205 if config.PNGSticker != nil {
2206 return []RequestFile{{
2207 Name: "png_sticker",
2208 Data: config.PNGSticker,
2209 }}
2210 }
2211
2212 return []RequestFile{{
2213 Name: "tgs_sticker",
2214 Data: config.TGSSticker,
2215 }}
2216}
2217
2218// AddStickerConfig allows you to add a sticker to a set.
2219type AddStickerConfig struct {
2220 UserID int64
2221 Name string
2222 Sticker InputSticker
2223}
2224
2225func (config AddStickerConfig) method() string {
2226 return "addStickerToSet"
2227}
2228
2229func (config AddStickerConfig) params() (Params, error) {
2230 params := make(Params)
2231
2232 params.AddNonZero64("user_id", config.UserID)
2233 params["name"] = config.Name
2234 err := params.AddInterface("sticker", config.Sticker)
2235 return params, err
2236}
2237
2238func (config AddStickerConfig) files() []RequestFile {
2239 if config.PNGSticker != nil {
2240 return []RequestFile{{
2241 Name: "png_sticker",
2242 Data: config.PNGSticker,
2243 }}
2244 }
2245
2246 return []RequestFile{{
2247 Name: "tgs_sticker",
2248 Data: config.TGSSticker,
2249 }}
2250
2251}
2252
2253// SetStickerPositionConfig allows you to change the position of a sticker in a set.
2254type SetStickerPositionConfig struct {
2255 Sticker string
2256 Position int
2257}
2258
2259func (config SetStickerPositionConfig) method() string {
2260 return "setStickerPositionInSet"
2261}
2262
2263func (config SetStickerPositionConfig) params() (Params, error) {
2264 params := make(Params)
2265
2266 params["sticker"] = config.Sticker
2267 params.AddNonZero("position", config.Position)
2268
2269 return params, nil
2270}
2271
2272// SetCustomEmojiStickerSetThumbnalConfig allows you to set the thumbnail of a custom emoji sticker set
2273type SetCustomEmojiStickerSetThumbnalConfig struct {
2274 Name string
2275 CustomEmojiID string
2276}
2277
2278func (config SetCustomEmojiStickerSetThumbnalConfig) method() string {
2279 return "setCustomEmojiStickerSetThumbnail"
2280}
2281
2282func (config SetCustomEmojiStickerSetThumbnalConfig) params() (Params, error) {
2283 params := make(Params)
2284
2285 params["name"] = config.Name
2286 params.AddNonEmpty("position", config.CustomEmojiID)
2287
2288 return params, nil
2289}
2290
2291// SetStickerSetTitle allows you to set the title of a created sticker set
2292type SetStickerSetTitleConfig struct {
2293 Name string
2294 Title string
2295}
2296
2297func (config SetStickerSetTitleConfig) method() string {
2298 return "setStickerSetTitle"
2299}
2300
2301func (config SetStickerSetTitleConfig) params() (Params, error) {
2302 params := make(Params)
2303
2304 params["name"] = config.Name
2305 params["title"] = config.Title
2306
2307 return params, nil
2308}
2309
2310// DeleteStickerSetConfig allows you to delete a sticker set that was created by the bot.
2311type DeleteStickerSetConfig struct {
2312 Name string
2313}
2314
2315func (config DeleteStickerSetConfig) method() string {
2316 return "deleteStickerSet"
2317}
2318
2319func (config DeleteStickerSetConfig) params() (Params, error) {
2320 params := make(Params)
2321
2322 params["name"] = config.Name
2323
2324 return params, nil
2325}
2326
2327// DeleteStickerConfig allows you to delete a sticker from a set.
2328type DeleteStickerConfig struct {
2329 Sticker string
2330}
2331
2332func (config DeleteStickerConfig) method() string {
2333 return "deleteStickerFromSet"
2334}
2335
2336func (config DeleteStickerConfig) params() (Params, error) {
2337 params := make(Params)
2338
2339 params["sticker"] = config.Sticker
2340
2341 return params, nil
2342}
2343
2344// 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
2345type SetStickerEmojiListConfig struct {
2346 Sticker string
2347 EmojiList []string
2348}
2349
2350func (config SetStickerEmojiListConfig) method() string {
2351 return "setStickerEmojiList"
2352}
2353
2354func (config SetStickerEmojiListConfig) params() (Params, error) {
2355 params := make(Params)
2356
2357 params["sticker"] = config.Sticker
2358 err := params.AddInterface("emoji_list", config.EmojiList)
2359
2360 return params, err
2361}
2362
2363// 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.
2364type SetStickerKeywordsConfig struct {
2365 Sticker string
2366 Keywords []string
2367}
2368
2369func (config SetStickerKeywordsConfig) method() string {
2370 return "setStickerKeywords"
2371}
2372
2373func (config SetStickerKeywordsConfig) params() (Params, error) {
2374 params := make(Params)
2375
2376 params["sticker"] = config.Sticker
2377 err := params.AddInterface("keywords", config.Keywords)
2378
2379 return params, err
2380}
2381
2382// 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
2383type SetStickerMaskPositionConfig struct {
2384 Sticker string
2385 MaskPosition *MaskPosition
2386}
2387
2388func (config SetStickerMaskPositionConfig) method() string {
2389 return "setStickerMaskPosition"
2390}
2391
2392func (config SetStickerMaskPositionConfig) params() (Params, error) {
2393 params := make(Params)
2394
2395 params["sticker"] = config.Sticker
2396 err := params.AddInterface("keywords", config.MaskPosition)
2397
2398 return params, err
2399}
2400
2401// SetStickerSetThumbConfig allows you to set the thumbnail for a sticker set.
2402type SetStickerSetThumbConfig struct {
2403 Name string
2404 UserID int64
2405 Thumb RequestFileData
2406}
2407
2408func (config SetStickerSetThumbConfig) method() string {
2409 return "setStickerSetThumbnail"
2410}
2411
2412func (config SetStickerSetThumbConfig) params() (Params, error) {
2413 params := make(Params)
2414
2415 params["name"] = config.Name
2416 params.AddNonZero64("user_id", config.UserID)
2417
2418 return params, nil
2419}
2420
2421func (config SetStickerSetThumbConfig) files() []RequestFile {
2422 return []RequestFile{{
2423 Name: "thumbnail",
2424 Data: config.Thumb,
2425 }}
2426}
2427
2428// SetChatStickerSetConfig allows you to set the sticker set for a supergroup.
2429type SetChatStickerSetConfig struct {
2430 ChatID int64
2431 SuperGroupUsername string
2432
2433 StickerSetName string
2434}
2435
2436func (config SetChatStickerSetConfig) method() string {
2437 return "setChatStickerSet"
2438}
2439
2440func (config SetChatStickerSetConfig) params() (Params, error) {
2441 params := make(Params)
2442
2443 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2444 params["sticker_set_name"] = config.StickerSetName
2445
2446 return params, nil
2447}
2448
2449// DeleteChatStickerSetConfig allows you to remove a supergroup's sticker set.
2450type DeleteChatStickerSetConfig struct {
2451 ChatID int64
2452 SuperGroupUsername string
2453}
2454
2455func (config DeleteChatStickerSetConfig) method() string {
2456 return "deleteChatStickerSet"
2457}
2458
2459func (config DeleteChatStickerSetConfig) params() (Params, error) {
2460 params := make(Params)
2461
2462 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2463
2464 return params, nil
2465}
2466
2467// GetForumTopicIconStickersConfig allows you to get custom emoji stickers,
2468// which can be used as a forum topic icon by any user.
2469type GetForumTopicIconStickersConfig struct{}
2470
2471func (config GetForumTopicIconStickersConfig) method() string {
2472 return "getForumTopicIconStickers"
2473}
2474
2475func (config GetForumTopicIconStickersConfig) params() (Params, error) {
2476 return nil, nil
2477}
2478
2479// BaseForum is a base type for all forum config types.
2480type BaseForum struct {
2481 ChatID int64
2482 SuperGroupUsername string
2483}
2484
2485func (config BaseForum) params() (Params, error) {
2486 params := make(Params)
2487
2488 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2489
2490 return params, nil
2491}
2492
2493// CreateForumTopicConfig allows you to create a topic
2494// in a forum supergroup chat.
2495type CreateForumTopicConfig struct {
2496 BaseForum
2497 Name string
2498 IconColor int
2499 IconCustomEmojiID string
2500}
2501
2502func (config CreateForumTopicConfig) method() string {
2503 return "createForumTopic"
2504}
2505
2506func (config CreateForumTopicConfig) params() (Params, error) {
2507 params := make(Params)
2508
2509 params.AddNonEmpty("name", config.Name)
2510 params.AddNonZero("icon_color", config.IconColor)
2511 params.AddNonEmpty("icon_custom_emoji_id", config.IconCustomEmojiID)
2512
2513 p1, _ := config.BaseForum.params()
2514 params.Merge(p1)
2515
2516 return params, nil
2517}
2518
2519// EditForumTopicConfig allows you to edit
2520// name and icon of a topic in a forum supergroup chat.
2521type EditForumTopicConfig struct {
2522 BaseForum
2523 MessageThreadID int
2524 Name string
2525 IconCustomEmojiID string
2526}
2527
2528func (config EditForumTopicConfig) method() string {
2529 return "editForumTopic"
2530}
2531
2532func (config EditForumTopicConfig) params() (Params, error) {
2533 params := make(Params)
2534
2535 params.AddNonZero("message_thread_id", config.MessageThreadID)
2536 params.AddNonEmpty("name", config.Name)
2537 params.AddNonEmpty("icon_custom_emoji_id", config.IconCustomEmojiID)
2538
2539 p1, _ := config.BaseForum.params()
2540 params.Merge(p1)
2541
2542 return params, nil
2543}
2544
2545// CloseForumTopicConfig allows you to close
2546// an open topic in a forum supergroup chat.
2547type CloseForumTopicConfig struct {
2548 BaseForum
2549 MessageThreadID int
2550}
2551
2552func (config CloseForumTopicConfig) method() string {
2553 return "closeForumTopic"
2554}
2555
2556func (config CloseForumTopicConfig) params() (Params, error) {
2557 params := make(Params)
2558
2559 params.AddNonZero("message_thread_id", config.MessageThreadID)
2560
2561 p1, _ := config.BaseForum.params()
2562 params.Merge(p1)
2563
2564 return params, nil
2565}
2566
2567// ReopenForumTopicConfig allows you to reopen
2568// an closed topic in a forum supergroup chat.
2569type ReopenForumTopicConfig struct {
2570 BaseForum
2571 MessageThreadID int
2572}
2573
2574func (config ReopenForumTopicConfig) method() string {
2575 return "reopenForumTopic"
2576}
2577
2578func (config ReopenForumTopicConfig) params() (Params, error) {
2579 params := make(Params)
2580
2581 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2582 params.AddNonZero("message_thread_id", config.MessageThreadID)
2583
2584 p1, _ := config.BaseForum.params()
2585 params.Merge(p1)
2586
2587 return params, nil
2588}
2589
2590// DeleteForumTopicConfig allows you to delete a forum topic
2591// along with all its messages in a forum supergroup chat.
2592type DeleteForumTopicConfig struct {
2593 BaseForum
2594 MessageThreadID int
2595}
2596
2597func (config DeleteForumTopicConfig) method() string {
2598 return "deleteForumTopic"
2599}
2600
2601func (config DeleteForumTopicConfig) params() (Params, error) {
2602 params := make(Params)
2603
2604 params.AddNonZero("message_thread_id", config.MessageThreadID)
2605
2606 p1, _ := config.BaseForum.params()
2607 params.Merge(p1)
2608
2609 return params, nil
2610}
2611
2612// UnpinAllForumTopicMessagesConfig allows you to clear the list
2613// of pinned messages in a forum topic.
2614type UnpinAllForumTopicMessagesConfig struct {
2615 BaseForum
2616 MessageThreadID int
2617}
2618
2619func (config UnpinAllForumTopicMessagesConfig) method() string {
2620 return "unpinAllForumTopicMessages"
2621}
2622
2623func (config UnpinAllForumTopicMessagesConfig) params() (Params, error) {
2624 params := make(Params)
2625
2626 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
2627 params.AddNonZero("message_thread_id", config.MessageThreadID)
2628
2629 p1, _ := config.BaseForum.params()
2630 params.Merge(p1)
2631
2632 return params, nil
2633}
2634
2635// UnpinAllForumTopicMessagesConfig allows you to edit the name of
2636// the 'General' topic in a forum supergroup chat.
2637// The bot must be an administrator in the chat for this to work
2638// and must have can_manage_topics administrator rights. Returns True on success.
2639type EditGeneralForumTopicConfig struct {
2640 BaseForum
2641 Name string
2642}
2643
2644func (config EditGeneralForumTopicConfig) method() string {
2645 return "editGeneralForumTopic"
2646}
2647
2648func (config EditGeneralForumTopicConfig) params() (Params, error) {
2649 params := make(Params)
2650
2651 params.AddNonEmpty("name", config.Name)
2652
2653 p1, _ := config.BaseForum.params()
2654 params.Merge(p1)
2655
2656 return params, nil
2657}
2658
2659// CloseGeneralForumTopicConfig allows you to to close an open 'General' topic
2660// in a forum supergroup chat. The bot must be an administrator in the chat
2661// for this to work and must have the can_manage_topics administrator rights.
2662// Returns True on success.
2663type CloseGeneralForumTopicConfig struct{ BaseForum }
2664
2665func (config CloseGeneralForumTopicConfig) method() string {
2666 return "closeGeneralForumTopic"
2667}
2668
2669// CloseGeneralForumTopicConfig allows you to reopen a closed 'General' topic
2670// in a forum supergroup chat. The bot must be an administrator in the chat
2671// for this to work and must have the can_manage_topics administrator rights.
2672// The topic will be automatically unhidden if it was hidden.
2673// Returns True on success.
2674type ReopenGeneralForumTopicConfig struct{ BaseForum }
2675
2676func (config ReopenGeneralForumTopicConfig) method() string {
2677 return "reopenGeneralForumTopic"
2678}
2679
2680// HideGeneralForumTopicConfig allows you to hide the 'General' topic
2681// in a forum supergroup chat. The bot must be an administrator in the chat
2682// for this to work and must have the can_manage_topics administrator rights.
2683// The topic will be automatically closed if it was open.
2684// Returns True on success.
2685type HideGeneralForumTopicConfig struct{ BaseForum }
2686
2687func (config HideGeneralForumTopicConfig) method() string {
2688 return "hideGeneralForumTopic"
2689}
2690
2691// UnhideGeneralForumTopicConfig allows you to unhide the 'General' topic
2692// in a forum supergroup chat. The bot must be an administrator in the chat
2693// for this to work and must have the can_manage_topics administrator rights.
2694// Returns True on success.
2695type UnhideGeneralForumTopicConfig struct{ BaseForum }
2696
2697func (config UnhideGeneralForumTopicConfig) method() string {
2698 return "unhideGeneralForumTopic"
2699}
2700
2701// MediaGroupConfig allows you to send a group of media.
2702//
2703// Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo).
2704type MediaGroupConfig struct {
2705 BaseChat
2706 Media []interface{}
2707}
2708
2709func (config MediaGroupConfig) method() string {
2710 return "sendMediaGroup"
2711}
2712
2713func (config MediaGroupConfig) params() (Params, error) {
2714 params, err := config.BaseChat.params()
2715 if err != nil {
2716 return nil, err
2717 }
2718
2719 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2720 params.AddBool("disable_notification", config.DisableNotification)
2721 params.AddNonZero("reply_to_message_id", config.ReplyToMessageID)
2722
2723 err = params.AddInterface("media", prepareInputMediaForParams(config.Media))
2724
2725 return params, err
2726}
2727
2728func (config MediaGroupConfig) files() []RequestFile {
2729 return prepareInputMediaForFiles(config.Media)
2730}
2731
2732// DiceConfig contains information about a sendDice request.
2733type DiceConfig struct {
2734 BaseChat
2735 // Emoji on which the dice throw animation is based.
2736 // Currently, must be one of 🎲, 🎯, 🏀, ⚽, 🎳, or 🎰.
2737 // Dice can have values 1-6 for 🎲, 🎯, and 🎳, values 1-5 for 🏀 and ⚽,
2738 // and values 1-64 for 🎰.
2739 // Defaults to “🎲”
2740 Emoji string
2741}
2742
2743func (config DiceConfig) method() string {
2744 return "sendDice"
2745}
2746
2747func (config DiceConfig) params() (Params, error) {
2748 params, err := config.BaseChat.params()
2749 if err != nil {
2750 return params, err
2751 }
2752
2753 params.AddNonEmpty("emoji", config.Emoji)
2754
2755 return params, err
2756}
2757
2758// GetMyCommandsConfig gets a list of the currently registered commands.
2759type GetMyCommandsConfig struct {
2760 Scope *BotCommandScope
2761 LanguageCode string
2762}
2763
2764func (config GetMyCommandsConfig) method() string {
2765 return "getMyCommands"
2766}
2767
2768func (config GetMyCommandsConfig) params() (Params, error) {
2769 params := make(Params)
2770
2771 err := params.AddInterface("scope", config.Scope)
2772 params.AddNonEmpty("language_code", config.LanguageCode)
2773
2774 return params, err
2775}
2776
2777// SetMyCommandsConfig sets a list of commands the bot understands.
2778type SetMyCommandsConfig struct {
2779 Commands []BotCommand
2780 Scope *BotCommandScope
2781 LanguageCode string
2782}
2783
2784func (config SetMyCommandsConfig) method() string {
2785 return "setMyCommands"
2786}
2787
2788func (config SetMyCommandsConfig) params() (Params, error) {
2789 params := make(Params)
2790
2791 if err := params.AddInterface("commands", config.Commands); err != nil {
2792 return params, err
2793 }
2794 err := params.AddInterface("scope", config.Scope)
2795 params.AddNonEmpty("language_code", config.LanguageCode)
2796
2797 return params, err
2798}
2799
2800type DeleteMyCommandsConfig struct {
2801 Scope *BotCommandScope
2802 LanguageCode string
2803}
2804
2805func (config DeleteMyCommandsConfig) method() string {
2806 return "deleteMyCommands"
2807}
2808
2809func (config DeleteMyCommandsConfig) params() (Params, error) {
2810 params := make(Params)
2811
2812 err := params.AddInterface("scope", config.Scope)
2813 params.AddNonEmpty("language_code", config.LanguageCode)
2814
2815 return params, err
2816}
2817
2818// GetMyDescriptionConfig get the current bot description for the given user language
2819type GetMyDescriptionConfig struct {
2820 LanguageCode string
2821}
2822
2823func (config GetMyDescriptionConfig) method() string {
2824 return "getMyDescription"
2825}
2826
2827func (config GetMyDescriptionConfig) params() (Params, error) {
2828 params := make(Params)
2829
2830 params.AddNonEmpty("language_code", config.LanguageCode)
2831
2832 return params, nil
2833}
2834
2835// SetMyDescroptionConfig sets the bot's description, which is shown in the chat with the bot if the chat is empty
2836type SetMyDescriptionConfig struct {
2837 // Pass an empty string to remove the dedicated description for the given language.
2838 Description string
2839 //If empty, the description will be applied to all users for whose language there is no dedicated description.
2840 LanguageCode string
2841}
2842
2843func (config SetMyDescriptionConfig) method() string {
2844 return "setMyDescription"
2845}
2846
2847func (config SetMyDescriptionConfig) params() (Params, error) {
2848 params := make(Params)
2849
2850 params.AddNonEmpty("description", config.Description)
2851 params.AddNonEmpty("language_code", config.LanguageCode)
2852
2853 return params, nil
2854}
2855
2856// GetMyShortDescriptionConfig get the current bot short description for the given user language
2857type GetMyShortDescriptionConfig struct {
2858 LanguageCode string
2859}
2860
2861func (config GetMyShortDescriptionConfig) method() string {
2862 return "getMyShortDescription"
2863}
2864
2865func (config GetMyShortDescriptionConfig) params() (Params, error) {
2866 params := make(Params)
2867
2868 params.AddNonEmpty("language_code", config.LanguageCode)
2869
2870 return params, nil
2871}
2872
2873// 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.
2874type SetMyShortDescriptionConfig struct {
2875 // New short description for the bot; 0-120 characters.
2876 //
2877 //Pass an empty string to remove the dedicated short description for the given language.
2878 ShortDescription string
2879 //A two-letter ISO 639-1 language code.
2880 //
2881 //If empty, the short description will be applied to all users for whose language there is no dedicated short description.
2882 LanguageCode string
2883}
2884
2885func (config SetMyShortDescriptionConfig) method() string {
2886 return "setMyDescription"
2887}
2888
2889func (config SetMyShortDescriptionConfig) params() (Params, error) {
2890 params := make(Params)
2891
2892 params.AddNonEmpty("short_description", config.ShortDescription)
2893 params.AddNonEmpty("language_code", config.LanguageCode)
2894
2895 return params, nil
2896}
2897
2898// SetChatMenuButtonConfig changes the bot's menu button in a private chat,
2899// or the default menu button.
2900type SetChatMenuButtonConfig struct {
2901 ChatID int64
2902 ChannelUsername string
2903
2904 MenuButton *MenuButton
2905}
2906
2907func (config SetChatMenuButtonConfig) method() string {
2908 return "setChatMenuButton"
2909}
2910
2911func (config SetChatMenuButtonConfig) params() (Params, error) {
2912 params := make(Params)
2913
2914 if err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername); err != nil {
2915 return params, err
2916 }
2917 err := params.AddInterface("menu_button", config.MenuButton)
2918
2919 return params, err
2920}
2921
2922type GetChatMenuButtonConfig struct {
2923 ChatID int64
2924 ChannelUsername string
2925}
2926
2927func (config GetChatMenuButtonConfig) method() string {
2928 return "getChatMenuButton"
2929}
2930
2931func (config GetChatMenuButtonConfig) params() (Params, error) {
2932 params := make(Params)
2933
2934 err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
2935
2936 return params, err
2937}
2938
2939type SetMyDefaultAdministratorRightsConfig struct {
2940 Rights ChatAdministratorRights
2941 ForChannels bool
2942}
2943
2944func (config SetMyDefaultAdministratorRightsConfig) method() string {
2945 return "setMyDefaultAdministratorRights"
2946}
2947
2948func (config SetMyDefaultAdministratorRightsConfig) params() (Params, error) {
2949 params := make(Params)
2950
2951 err := params.AddInterface("rights", config.Rights)
2952 params.AddBool("for_channels", config.ForChannels)
2953
2954 return params, err
2955}
2956
2957type GetMyDefaultAdministratorRightsConfig struct {
2958 ForChannels bool
2959}
2960
2961func (config GetMyDefaultAdministratorRightsConfig) method() string {
2962 return "getMyDefaultAdministratorRights"
2963}
2964
2965func (config GetMyDefaultAdministratorRightsConfig) params() (Params, error) {
2966 params := make(Params)
2967
2968 params.AddBool("for_channels", config.ForChannels)
2969
2970 return params, nil
2971}
2972
2973// prepareInputMediaParam evaluates a single InputMedia and determines if it
2974// needs to be modified for a successful upload. If it returns nil, then the
2975// value does not need to be included in the params. Otherwise, it will return
2976// the same type as was originally provided.
2977//
2978// The idx is used to calculate the file field name. If you only have a single
2979// file, 0 may be used. It is formatted into "attach://file-%d" for the primary
2980// media and "attach://file-%d-thumb" for thumbnails.
2981//
2982// It is expected to be used in conjunction with prepareInputMediaFile.
2983func prepareInputMediaParam(inputMedia interface{}, idx int) interface{} {
2984 switch m := inputMedia.(type) {
2985 case InputMediaPhoto:
2986 if m.Media.NeedsUpload() {
2987 m.Media = fileAttach(fmt.Sprintf("attach://file-%d", idx))
2988 }
2989
2990 return m
2991 case InputMediaVideo:
2992 if m.Media.NeedsUpload() {
2993 m.Media = fileAttach(fmt.Sprintf("attach://file-%d", idx))
2994 }
2995
2996 if m.Thumb != nil && m.Thumb.NeedsUpload() {
2997 m.Thumb = fileAttach(fmt.Sprintf("attach://file-%d-thumb", idx))
2998 }
2999
3000 return m
3001 case InputMediaAudio:
3002 if m.Media.NeedsUpload() {
3003 m.Media = fileAttach(fmt.Sprintf("attach://file-%d", idx))
3004 }
3005
3006 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3007 m.Thumb = fileAttach(fmt.Sprintf("attach://file-%d-thumb", idx))
3008 }
3009
3010 return m
3011 case InputMediaDocument:
3012 if m.Media.NeedsUpload() {
3013 m.Media = fileAttach(fmt.Sprintf("attach://file-%d", idx))
3014 }
3015
3016 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3017 m.Thumb = fileAttach(fmt.Sprintf("attach://file-%d-thumb", idx))
3018 }
3019
3020 return m
3021 }
3022
3023 return nil
3024}
3025
3026// prepareInputMediaFile generates an array of RequestFile to provide for
3027// Fileable's files method. It returns an array as a single InputMedia may have
3028// multiple files, for the primary media and a thumbnail.
3029//
3030// The idx parameter is used to generate file field names. It uses the names
3031// "file-%d" for the main file and "file-%d-thumb" for the thumbnail.
3032//
3033// It is expected to be used in conjunction with prepareInputMediaParam.
3034func prepareInputMediaFile(inputMedia interface{}, idx int) []RequestFile {
3035 files := []RequestFile{}
3036
3037 switch m := inputMedia.(type) {
3038 case InputMediaPhoto:
3039 if m.Media.NeedsUpload() {
3040 files = append(files, RequestFile{
3041 Name: fmt.Sprintf("file-%d", idx),
3042 Data: m.Media,
3043 })
3044 }
3045 case InputMediaVideo:
3046 if m.Media.NeedsUpload() {
3047 files = append(files, RequestFile{
3048 Name: fmt.Sprintf("file-%d", idx),
3049 Data: m.Media,
3050 })
3051 }
3052
3053 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3054 files = append(files, RequestFile{
3055 Name: fmt.Sprintf("file-%d", idx),
3056 Data: m.Thumb,
3057 })
3058 }
3059 case InputMediaDocument:
3060 if m.Media.NeedsUpload() {
3061 files = append(files, RequestFile{
3062 Name: fmt.Sprintf("file-%d", idx),
3063 Data: m.Media,
3064 })
3065 }
3066
3067 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3068 files = append(files, RequestFile{
3069 Name: fmt.Sprintf("file-%d", idx),
3070 Data: m.Thumb,
3071 })
3072 }
3073 case InputMediaAudio:
3074 if m.Media.NeedsUpload() {
3075 files = append(files, RequestFile{
3076 Name: fmt.Sprintf("file-%d", idx),
3077 Data: m.Media,
3078 })
3079 }
3080
3081 if m.Thumb != nil && m.Thumb.NeedsUpload() {
3082 files = append(files, RequestFile{
3083 Name: fmt.Sprintf("file-%d", idx),
3084 Data: m.Thumb,
3085 })
3086 }
3087 }
3088
3089 return files
3090}
3091
3092// prepareInputMediaForParams calls prepareInputMediaParam for each item
3093// provided and returns a new array with the correct params for a request.
3094//
3095// It is expected that files will get data from the associated function,
3096// prepareInputMediaForFiles.
3097func prepareInputMediaForParams(inputMedia []interface{}) []interface{} {
3098 newMedia := make([]interface{}, len(inputMedia))
3099 copy(newMedia, inputMedia)
3100
3101 for idx, media := range inputMedia {
3102 if param := prepareInputMediaParam(media, idx); param != nil {
3103 newMedia[idx] = param
3104 }
3105 }
3106
3107 return newMedia
3108}
3109
3110// prepareInputMediaForFiles calls prepareInputMediaFile for each item
3111// provided and returns a new array with the correct files for a request.
3112//
3113// It is expected that params will get data from the associated function,
3114// prepareInputMediaForParams.
3115func prepareInputMediaForFiles(inputMedia []interface{}) []RequestFile {
3116 files := []RequestFile{}
3117
3118 for idx, media := range inputMedia {
3119 if file := prepareInputMediaFile(media, idx); file != nil {
3120 files = append(files, file...)
3121 }
3122 }
3123
3124 return files
3125}