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