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