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