configs.go (view raw)
1package tgbotapi
2
3import (
4 "io"
5 "net/url"
6)
7
8// Telegram constants
9const (
10 // APIEndpoint is the endpoint for all API methods,
11 // with formatting for Sprintf.
12 APIEndpoint = "https://api.telegram.org/bot%s/%s"
13 // FileEndpoint is the endpoint for downloading a file from Telegram.
14 FileEndpoint = "https://api.telegram.org/file/bot%s/%s"
15)
16
17// Constant values for ChatActions
18const (
19 ChatTyping = "typing"
20 ChatUploadPhoto = "upload_photo"
21 ChatRecordVideo = "record_video"
22 ChatUploadVideo = "upload_video"
23 ChatRecordAudio = "record_audio"
24 ChatUploadAudio = "upload_audio"
25 ChatUploadDocument = "upload_document"
26 ChatFindLocation = "find_location"
27)
28
29// API errors
30const (
31 // ErrAPIForbidden happens when a token is bad
32 ErrAPIForbidden = "forbidden"
33)
34
35// Constant values for ParseMode in MessageConfig
36const (
37 ModeMarkdown = "Markdown"
38 ModeHTML = "HTML"
39)
40
41// Library errors
42const (
43 // ErrBadFileType happens when you pass an unknown type
44 ErrBadFileType = "bad file type"
45 ErrBadURL = "bad or empty url"
46)
47
48// Chattable is any config type that can be sent.
49type Chattable interface {
50 params() (Params, error)
51 method() string
52}
53
54// Fileable is any config type that can be sent that includes a file.
55type Fileable interface {
56 Chattable
57 name() string
58 getFile() interface{}
59 useExistingFile() bool
60}
61
62// BaseChat is base type for all chat config types.
63type BaseChat struct {
64 ChatID int64 // required
65 ChannelUsername string
66 ReplyToMessageID int
67 ReplyMarkup interface{}
68 DisableNotification bool
69}
70
71func (chat *BaseChat) params() (Params, error) {
72 params := make(Params)
73
74 params.AddFirstValid("chat_id", chat.ChatID, chat.ChannelUsername)
75 params.AddNonZero("reply_to_message_id", chat.ReplyToMessageID)
76 params.AddBool("disable_notification", chat.DisableNotification)
77
78 err := params.AddInterface("reply_markup", chat.ReplyMarkup)
79
80 return params, err
81}
82
83// BaseFile is a base type for all file config types.
84type BaseFile struct {
85 BaseChat
86 File interface{}
87 FileID string
88 UseExisting bool
89 MimeType string
90 FileSize int
91}
92
93func (file BaseFile) params() (Params, error) {
94 params, err := file.BaseChat.params()
95
96 params.AddNonEmpty("mime_type", file.MimeType)
97 params.AddNonZero("file_size", file.FileSize)
98
99 return params, err
100}
101
102func (file BaseFile) getFile() interface{} {
103 return file.File
104}
105
106func (file BaseFile) useExistingFile() bool {
107 return file.UseExisting
108}
109
110// BaseEdit is base type of all chat edits.
111type BaseEdit struct {
112 ChatID int64
113 ChannelUsername string
114 MessageID int
115 InlineMessageID string
116 ReplyMarkup *InlineKeyboardMarkup
117}
118
119func (edit BaseEdit) params() (Params, error) {
120 params := make(Params)
121
122 if edit.InlineMessageID != "" {
123 params["inline_message_id"] = edit.InlineMessageID
124 } else {
125 params.AddFirstValid("chat_id", edit.ChatID, edit.ChannelUsername)
126 params.AddNonZero("message_id", edit.MessageID)
127 }
128
129 err := params.AddInterface("reply_markup", edit.ReplyMarkup)
130
131 return params, err
132}
133
134// MessageConfig contains information about a SendMessage request.
135type MessageConfig struct {
136 BaseChat
137 Text string
138 ParseMode string
139 DisableWebPagePreview bool
140}
141
142func (config MessageConfig) params() (Params, error) {
143 params, err := config.BaseChat.params()
144 if err != nil {
145 return params, err
146 }
147
148 params.AddNonEmpty("text", config.Text)
149 params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
150 params.AddNonEmpty("parse_mode", config.ParseMode)
151
152 return params, nil
153}
154
155func (config MessageConfig) method() string {
156 return "sendMessage"
157}
158
159// ForwardConfig contains information about a ForwardMessage request.
160type ForwardConfig struct {
161 BaseChat
162 FromChatID int64 // required
163 FromChannelUsername string
164 MessageID int // required
165}
166
167func (config ForwardConfig) params() (Params, error) {
168 params, err := config.BaseChat.params()
169 if err != nil {
170 return params, err
171 }
172
173 params.AddNonZero64("from_chat_id", config.FromChatID)
174 params.AddNonZero("message_id", config.MessageID)
175
176 return params, nil
177}
178
179func (config ForwardConfig) method() string {
180 return "forwardMessage"
181}
182
183// PhotoConfig contains information about a SendPhoto request.
184type PhotoConfig struct {
185 BaseFile
186 Caption string
187 ParseMode string
188}
189
190func (config PhotoConfig) params() (Params, error) {
191 params, err := config.BaseFile.params()
192
193 params.AddNonEmpty(config.name(), config.FileID)
194 params.AddNonEmpty("caption", config.Caption)
195 params.AddNonEmpty("parse_mode", config.ParseMode)
196
197 return params, err
198}
199
200func (config PhotoConfig) name() string {
201 return "photo"
202}
203
204func (config PhotoConfig) method() string {
205 return "sendPhoto"
206}
207
208// AudioConfig contains information about a SendAudio request.
209type AudioConfig struct {
210 BaseFile
211 Caption string
212 ParseMode string
213 Duration int
214 Performer string
215 Title string
216}
217
218func (config AudioConfig) params() (Params, error) {
219 params, err := config.BaseChat.params()
220 if err != nil {
221 return params, err
222 }
223
224 params.AddNonEmpty(config.name(), config.FileID)
225 params.AddNonZero("duration", config.Duration)
226 params.AddNonEmpty("performer", config.Performer)
227 params.AddNonEmpty("title", config.Title)
228 params.AddNonEmpty("caption", config.Caption)
229 params.AddNonEmpty("parse_mode", config.ParseMode)
230
231 return params, nil
232}
233
234func (config AudioConfig) name() string {
235 return "audio"
236}
237
238func (config AudioConfig) method() string {
239 return "sendAudio"
240}
241
242// DocumentConfig contains information about a SendDocument request.
243type DocumentConfig struct {
244 BaseFile
245 Caption string
246 ParseMode string
247}
248
249func (config DocumentConfig) params() (Params, error) {
250 params, err := config.BaseFile.params()
251
252 params.AddNonEmpty(config.name(), config.FileID)
253 params.AddNonEmpty("caption", config.Caption)
254 params.AddNonEmpty("parse_mode", config.ParseMode)
255
256 return params, err
257}
258
259func (config DocumentConfig) name() string {
260 return "document"
261}
262
263func (config DocumentConfig) method() string {
264 return "sendDocument"
265}
266
267// StickerConfig contains information about a SendSticker request.
268type StickerConfig struct {
269 BaseFile
270}
271
272func (config StickerConfig) params() (Params, error) {
273 params, err := config.BaseChat.params()
274
275 params.AddNonEmpty(config.name(), config.FileID)
276
277 return params, err
278}
279
280func (config StickerConfig) name() string {
281 return "sticker"
282}
283
284func (config StickerConfig) method() string {
285 return "sendSticker"
286}
287
288// VideoConfig contains information about a SendVideo request.
289type VideoConfig struct {
290 BaseFile
291 Duration int
292 Caption string
293 ParseMode string
294 SupportsStreaming bool
295}
296
297func (config VideoConfig) params() (Params, error) {
298 params, err := config.BaseChat.params()
299
300 params.AddNonEmpty(config.name(), config.FileID)
301 params.AddNonZero("duration", config.Duration)
302 params.AddNonEmpty("caption", config.Caption)
303 params.AddNonEmpty("parse_mode", config.ParseMode)
304 params.AddBool("supports_streaming", config.SupportsStreaming)
305
306 return params, err
307}
308
309func (config VideoConfig) name() string {
310 return "video"
311}
312
313func (config VideoConfig) method() string {
314 return "sendVideo"
315}
316
317// AnimationConfig contains information about a SendAnimation request.
318type AnimationConfig struct {
319 BaseFile
320 Duration int
321 Caption string
322 ParseMode string
323}
324
325func (config AnimationConfig) params() (Params, error) {
326 params, err := config.BaseChat.params()
327
328 params.AddNonEmpty(config.name(), config.FileID)
329 params.AddNonZero("duration", config.Duration)
330 params.AddNonEmpty("caption", config.Caption)
331 params.AddNonEmpty("parse_mode", config.ParseMode)
332
333 return params, err
334}
335
336func (config AnimationConfig) name() string {
337 return "animation"
338}
339
340func (config AnimationConfig) method() string {
341 return "sendAnimation"
342}
343
344// VideoNoteConfig contains information about a SendVideoNote request.
345type VideoNoteConfig struct {
346 BaseFile
347 Duration int
348 Length int
349}
350
351func (config VideoNoteConfig) params() (Params, error) {
352 params, err := config.BaseChat.params()
353
354 params.AddNonEmpty(config.name(), config.FileID)
355 params.AddNonZero("duration", config.Duration)
356 params.AddNonZero("length", config.Length)
357
358 return params, err
359}
360
361func (config VideoNoteConfig) name() string {
362 return "video_note"
363}
364
365func (config VideoNoteConfig) method() string {
366 return "sendVideoNote"
367}
368
369// VoiceConfig contains information about a SendVoice request.
370type VoiceConfig struct {
371 BaseFile
372 Caption string
373 ParseMode string
374 Duration int
375}
376
377func (config VoiceConfig) params() (Params, error) {
378 params, err := config.BaseChat.params()
379
380 params.AddNonEmpty(config.name(), config.FileID)
381 params.AddNonZero("duration", config.Duration)
382 params.AddNonEmpty("caption", config.Caption)
383 params.AddNonEmpty("parse_mode", config.ParseMode)
384
385 return params, err
386}
387
388func (config VoiceConfig) name() string {
389 return "voice"
390}
391
392func (config VoiceConfig) method() string {
393 return "sendVoice"
394}
395
396// LocationConfig contains information about a SendLocation request.
397type LocationConfig struct {
398 BaseChat
399 Latitude float64 // required
400 Longitude float64 // required
401 LivePeriod int // optional
402}
403
404func (config LocationConfig) params() (Params, error) {
405 params, err := config.BaseChat.params()
406
407 params.AddNonZeroFloat("latitude", config.Latitude)
408 params.AddNonZeroFloat("longitude", config.Longitude)
409 params.AddNonZero("live_period", config.LivePeriod)
410
411 return params, err
412}
413
414func (config LocationConfig) method() string {
415 return "sendLocation"
416}
417
418// EditMessageLiveLocationConfig allows you to update a live location.
419type EditMessageLiveLocationConfig struct {
420 BaseEdit
421 Latitude float64 // required
422 Longitude float64 // required
423}
424
425func (config EditMessageLiveLocationConfig) params() (Params, error) {
426 params, err := config.BaseEdit.params()
427
428 params.AddNonZeroFloat("latitude", config.Latitude)
429 params.AddNonZeroFloat("longitude", config.Longitude)
430
431 return params, err
432}
433
434func (config EditMessageLiveLocationConfig) method() string {
435 return "editMessageLiveLocation"
436}
437
438// StopMessageLiveLocationConfig stops updating a live location.
439type StopMessageLiveLocationConfig struct {
440 BaseEdit
441}
442
443func (config StopMessageLiveLocationConfig) params() (Params, error) {
444 return config.BaseEdit.params()
445}
446
447func (config StopMessageLiveLocationConfig) method() string {
448 return "stopMessageLiveLocation"
449}
450
451// VenueConfig contains information about a SendVenue request.
452type VenueConfig struct {
453 BaseChat
454 Latitude float64 // required
455 Longitude float64 // required
456 Title string // required
457 Address string // required
458 FoursquareID string
459}
460
461func (config VenueConfig) params() (Params, error) {
462 params, err := config.BaseChat.params()
463
464 params.AddNonZeroFloat("latitude", config.Latitude)
465 params.AddNonZeroFloat("longitude", config.Longitude)
466 params["title"] = config.Title
467 params["address"] = config.Address
468 params.AddNonEmpty("foursquare_id", config.FoursquareID)
469
470 return params, err
471}
472
473func (config VenueConfig) method() string {
474 return "sendVenue"
475}
476
477// ContactConfig allows you to send a contact.
478type ContactConfig struct {
479 BaseChat
480 PhoneNumber string
481 FirstName string
482 LastName string
483 VCard string
484}
485
486func (config ContactConfig) params() (Params, error) {
487 params, err := config.BaseChat.params()
488
489 params["phone_number"] = config.PhoneNumber
490 params["first_name"] = config.FirstName
491
492 params.AddNonEmpty("last_name", config.LastName)
493 params.AddNonEmpty("vcard", config.VCard)
494
495 return params, err
496}
497
498func (config ContactConfig) method() string {
499 return "sendContact"
500}
501
502// SendPollConfig allows you to send a poll.
503type SendPollConfig struct {
504 BaseChat
505 Question string
506 Options []string
507}
508
509func (config SendPollConfig) params() (Params, error) {
510 params, err := config.BaseChat.params()
511 if err != nil {
512 return params, err
513 }
514
515 params["question"] = config.Question
516 err = params.AddInterface("options", config.Options)
517
518 return params, err
519}
520
521func (SendPollConfig) method() string {
522 return "sendPoll"
523}
524
525// GameConfig allows you to send a game.
526type GameConfig struct {
527 BaseChat
528 GameShortName string
529}
530
531func (config GameConfig) params() (Params, error) {
532 params, err := config.BaseChat.params()
533
534 params["game_short_name"] = config.GameShortName
535
536 return params, err
537}
538
539func (config GameConfig) method() string {
540 return "sendGame"
541}
542
543// SetGameScoreConfig allows you to update the game score in a chat.
544type SetGameScoreConfig struct {
545 UserID int
546 Score int
547 Force bool
548 DisableEditMessage bool
549 ChatID int64
550 ChannelUsername string
551 MessageID int
552 InlineMessageID string
553}
554
555func (config SetGameScoreConfig) params() (Params, error) {
556 params := make(Params)
557
558 params.AddNonZero("user_id", config.UserID)
559 params.AddNonZero("scrore", config.Score)
560 params.AddBool("disable_edit_message", config.DisableEditMessage)
561
562 if config.InlineMessageID != "" {
563 params["inline_message_id"] = config.InlineMessageID
564 } else {
565 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
566 params.AddNonZero("message_id", config.MessageID)
567 }
568
569 return params, nil
570}
571
572func (config SetGameScoreConfig) method() string {
573 return "setGameScore"
574}
575
576// GetGameHighScoresConfig allows you to fetch the high scores for a game.
577type GetGameHighScoresConfig struct {
578 UserID int
579 ChatID int
580 ChannelUsername string
581 MessageID int
582 InlineMessageID string
583}
584
585func (config GetGameHighScoresConfig) params() (Params, error) {
586 params := make(Params)
587
588 params.AddNonZero("user_id", config.UserID)
589
590 if config.InlineMessageID != "" {
591 params["inline_message_id"] = config.InlineMessageID
592 } else {
593 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
594 params.AddNonZero("message_id", config.MessageID)
595 }
596
597 return params, nil
598}
599
600func (config GetGameHighScoresConfig) method() string {
601 return "getGameHighScores"
602}
603
604// ChatActionConfig contains information about a SendChatAction request.
605type ChatActionConfig struct {
606 BaseChat
607 Action string // required
608}
609
610func (config ChatActionConfig) params() (Params, error) {
611 params, err := config.BaseChat.params()
612
613 params["action"] = config.Action
614
615 return params, err
616}
617
618func (config ChatActionConfig) method() string {
619 return "sendChatAction"
620}
621
622// EditMessageTextConfig allows you to modify the text in a message.
623type EditMessageTextConfig struct {
624 BaseEdit
625 Text string
626 ParseMode string
627 DisableWebPagePreview bool
628}
629
630func (config EditMessageTextConfig) params() (Params, error) {
631 params, err := config.BaseEdit.params()
632
633 params["text"] = config.Text
634 params.AddNonEmpty("parse_mode", config.ParseMode)
635 params.AddBool("disable_web_page_preview", config.DisableWebPagePreview)
636
637 return params, err
638}
639
640func (config EditMessageTextConfig) method() string {
641 return "editMessageText"
642}
643
644// EditMessageCaptionConfig allows you to modify the caption of a message.
645type EditMessageCaptionConfig struct {
646 BaseEdit
647 Caption string
648 ParseMode string
649}
650
651func (config EditMessageCaptionConfig) params() (Params, error) {
652 params, err := config.BaseEdit.params()
653
654 params["caption"] = config.Caption
655 params.AddNonEmpty("parse_mode", config.ParseMode)
656
657 return params, err
658}
659
660func (config EditMessageCaptionConfig) method() string {
661 return "editMessageCaption"
662}
663
664// EditMessageMediaConfig contains information about editing a message's media.
665type EditMessageMediaConfig struct {
666 BaseEdit
667
668 Media interface{}
669}
670
671func (EditMessageMediaConfig) method() string {
672 return "editMessageMedia"
673}
674
675func (config EditMessageMediaConfig) params() (Params, error) {
676 params, err := config.BaseEdit.params()
677
678 params.AddInterface("media", config.Media)
679
680 return params, err
681}
682
683// EditMessageReplyMarkupConfig allows you to modify the reply markup
684// of a message.
685type EditMessageReplyMarkupConfig struct {
686 BaseEdit
687}
688
689func (config EditMessageReplyMarkupConfig) params() (Params, error) {
690 return config.BaseEdit.params()
691}
692
693func (config EditMessageReplyMarkupConfig) method() string {
694 return "editMessageReplyMarkup"
695}
696
697// StopPollConfig allows you to stop a poll sent by the bot.
698type StopPollConfig struct {
699 BaseEdit
700}
701
702func (config StopPollConfig) params() (Params, error) {
703 return config.BaseEdit.params()
704}
705
706func (StopPollConfig) method() string {
707 return "stopPoll"
708}
709
710// UserProfilePhotosConfig contains information about a
711// GetUserProfilePhotos request.
712type UserProfilePhotosConfig struct {
713 UserID int
714 Offset int
715 Limit int
716}
717
718func (UserProfilePhotosConfig) method() string {
719 return "getUserProfilePhotos"
720}
721
722func (config UserProfilePhotosConfig) params() (Params, error) {
723 params := make(Params)
724
725 params.AddNonZero("user_id", config.UserID)
726 params.AddNonZero("offset", config.Offset)
727 params.AddNonZero("limit", config.Limit)
728
729 return params, nil
730}
731
732// FileConfig has information about a file hosted on Telegram.
733type FileConfig struct {
734 FileID string
735}
736
737func (FileConfig) method() string {
738 return "getFile"
739}
740
741func (config FileConfig) params() (Params, error) {
742 params := make(Params)
743
744 params["file_id"] = config.FileID
745
746 return params, nil
747}
748
749// UpdateConfig contains information about a GetUpdates request.
750type UpdateConfig struct {
751 Offset int
752 Limit int
753 Timeout int
754}
755
756func (UpdateConfig) method() string {
757 return "getUpdates"
758}
759
760func (config UpdateConfig) params() (Params, error) {
761 params := make(Params)
762
763 params.AddNonZero("offset", config.Offset)
764 params.AddNonZero("limit", config.Limit)
765 params.AddNonZero("timeout", config.Timeout)
766
767 return params, nil
768}
769
770// WebhookConfig contains information about a SetWebhook request.
771type WebhookConfig struct {
772 URL *url.URL
773 Certificate interface{}
774 MaxConnections int
775 AllowedUpdates []string
776}
777
778func (config WebhookConfig) method() string {
779 return "setWebhook"
780}
781
782func (config WebhookConfig) params() (Params, error) {
783 params := make(Params)
784
785 if config.URL != nil {
786 params["url"] = config.URL.String()
787 }
788
789 params.AddNonZero("max_connections", config.MaxConnections)
790 params.AddInterface("allowed_updates", config.AllowedUpdates)
791
792 return params, nil
793}
794
795func (config WebhookConfig) name() string {
796 return "certificate"
797}
798
799func (config WebhookConfig) getFile() interface{} {
800 return config.Certificate
801}
802
803func (config WebhookConfig) useExistingFile() bool {
804 return config.URL != nil
805}
806
807// RemoveWebhookConfig is a helper to remove a webhook.
808type RemoveWebhookConfig struct {
809}
810
811func (config RemoveWebhookConfig) method() string {
812 return "setWebhook"
813}
814
815func (config RemoveWebhookConfig) params() (Params, error) {
816 return nil, nil
817}
818
819// FileBytes contains information about a set of bytes to upload
820// as a File.
821type FileBytes struct {
822 Name string
823 Bytes []byte
824}
825
826// FileReader contains information about a reader to upload as a File.
827// If Size is -1, it will read the entire Reader into memory to
828// calculate a Size.
829type FileReader struct {
830 Name string
831 Reader io.Reader
832 Size int64
833}
834
835// InlineConfig contains information on making an InlineQuery response.
836type InlineConfig struct {
837 InlineQueryID string `json:"inline_query_id"`
838 Results []interface{} `json:"results"`
839 CacheTime int `json:"cache_time"`
840 IsPersonal bool `json:"is_personal"`
841 NextOffset string `json:"next_offset"`
842 SwitchPMText string `json:"switch_pm_text"`
843 SwitchPMParameter string `json:"switch_pm_parameter"`
844}
845
846func (config InlineConfig) method() string {
847 return "answerInlineQuery"
848}
849
850func (config InlineConfig) params() (Params, error) {
851 params := make(Params)
852
853 params["inline_query_id"] = config.InlineQueryID
854 params.AddNonZero("cache_time", config.CacheTime)
855 params.AddBool("is_personal", config.IsPersonal)
856 params.AddNonEmpty("next_offset", config.NextOffset)
857 params.AddNonEmpty("switch_pm_text", config.SwitchPMText)
858 params.AddNonEmpty("switch_pm_parameter", config.SwitchPMParameter)
859
860 if err := params.AddInterface("results", config.Results); err != nil {
861 return params, err
862 }
863
864 return params, nil
865}
866
867// CallbackConfig contains information on making a CallbackQuery response.
868type CallbackConfig struct {
869 CallbackQueryID string `json:"callback_query_id"`
870 Text string `json:"text"`
871 ShowAlert bool `json:"show_alert"`
872 URL string `json:"url"`
873 CacheTime int `json:"cache_time"`
874}
875
876func (config CallbackConfig) method() string {
877 return "answerCallbackQuery"
878}
879
880func (config CallbackConfig) params() (Params, error) {
881 params := make(Params)
882
883 params["callback_query_id"] = config.CallbackQueryID
884 params.AddNonEmpty("text", config.Text)
885 params.AddBool("show_alert", config.ShowAlert)
886 params.AddNonEmpty("url", config.URL)
887 params.AddNonZero("cache_time", config.CacheTime)
888
889 return params, nil
890}
891
892// ChatMemberConfig contains information about a user in a chat for use
893// with administrative functions such as kicking or unbanning a user.
894type ChatMemberConfig struct {
895 ChatID int64
896 SuperGroupUsername string
897 ChannelUsername string
898 UserID int
899}
900
901// UnbanChatMemberConfig allows you to unban a user.
902type UnbanChatMemberConfig struct {
903 ChatMemberConfig
904}
905
906func (config UnbanChatMemberConfig) method() string {
907 return "unbanChatMember"
908}
909
910func (config UnbanChatMemberConfig) params() (Params, error) {
911 params := make(Params)
912
913 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
914 params.AddNonZero("user_id", config.UserID)
915
916 return params, nil
917}
918
919// KickChatMemberConfig contains extra fields to kick user
920type KickChatMemberConfig struct {
921 ChatMemberConfig
922 UntilDate int64
923}
924
925func (config KickChatMemberConfig) method() string {
926 return "kickChatMember"
927}
928
929func (config KickChatMemberConfig) params() (Params, error) {
930 params := make(Params)
931
932 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
933 params.AddNonZero("user_id", config.UserID)
934 params.AddNonZero64("until_date", config.UntilDate)
935
936 return params, nil
937}
938
939// RestrictChatMemberConfig contains fields to restrict members of chat
940type RestrictChatMemberConfig struct {
941 ChatMemberConfig
942 UntilDate int64
943 CanSendMessages *bool
944 CanSendMediaMessages *bool
945 CanSendOtherMessages *bool
946 CanAddWebPagePreviews *bool
947}
948
949func (config RestrictChatMemberConfig) method() string {
950 return "restrictChatMember"
951}
952
953func (config RestrictChatMemberConfig) params() (Params, error) {
954 params := make(Params)
955
956 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
957 params.AddNonZero("user_id", config.UserID)
958
959 params.AddNonNilBool("can_send_messages", config.CanSendMessages)
960 params.AddNonNilBool("can_send_media_messages", config.CanSendMediaMessages)
961 params.AddNonNilBool("can_send_other_messages", config.CanSendOtherMessages)
962 params.AddNonNilBool("can_add_web_page_previews", config.CanAddWebPagePreviews)
963 params.AddNonZero64("until_date", config.UntilDate)
964
965 return params, nil
966}
967
968// PromoteChatMemberConfig contains fields to promote members of chat
969type PromoteChatMemberConfig struct {
970 ChatMemberConfig
971 CanChangeInfo *bool
972 CanPostMessages *bool
973 CanEditMessages *bool
974 CanDeleteMessages *bool
975 CanInviteUsers *bool
976 CanRestrictMembers *bool
977 CanPinMessages *bool
978 CanPromoteMembers *bool
979}
980
981func (config PromoteChatMemberConfig) method() string {
982 return "promoteChatMember"
983}
984
985func (config PromoteChatMemberConfig) params() (Params, error) {
986 params := make(Params)
987
988 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
989 params.AddNonZero("user_id", config.UserID)
990
991 params.AddNonNilBool("can_change_info", config.CanChangeInfo)
992 params.AddNonNilBool("can_post_messages", config.CanPostMessages)
993 params.AddNonNilBool("can_edit_messages", config.CanEditMessages)
994 params.AddNonNilBool("can_delete_messages", config.CanDeleteMessages)
995 params.AddNonNilBool("can_invite_users", config.CanInviteUsers)
996 params.AddNonNilBool("can_restrict_members", config.CanRestrictMembers)
997 params.AddNonNilBool("can_pin_messages", config.CanPinMessages)
998 params.AddNonNilBool("can_promote_members", config.CanPromoteMembers)
999
1000 return params, nil
1001}
1002
1003// ChatConfig contains information about getting information on a chat.
1004type ChatConfig struct {
1005 ChatID int64
1006 SuperGroupUsername string
1007}
1008
1009func (config ChatConfig) params() (Params, error) {
1010 params := make(Params)
1011
1012 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1013
1014 return params, nil
1015}
1016
1017// ChatInfoConfig contains information about getting chat information.
1018type ChatInfoConfig struct {
1019 ChatConfig
1020}
1021
1022func (ChatInfoConfig) method() string {
1023 return "getChat"
1024}
1025
1026// ChatMemberCountConfig contains information about getting the number of users in a chat.
1027type ChatMemberCountConfig struct {
1028 ChatConfig
1029}
1030
1031func (ChatMemberCountConfig) method() string {
1032 return "getChatMembersCount"
1033}
1034
1035// ChatAdministratorsConfig contains information about getting chat administrators.
1036type ChatAdministratorsConfig struct {
1037 ChatConfig
1038}
1039
1040func (ChatAdministratorsConfig) method() string {
1041 return "getChatAdministrators"
1042}
1043
1044// ChatInviteLinkConfig contains information about getting a chat link.
1045//
1046// Note that generating a new link will revoke any previous links.
1047type ChatInviteLinkConfig struct {
1048 ChatConfig
1049}
1050
1051func (ChatInviteLinkConfig) method() string {
1052 return "exportChatInviteLink"
1053}
1054
1055func (config ChatInviteLinkConfig) params() (Params, error) {
1056 params := make(Params)
1057
1058 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1059
1060 return params, nil
1061}
1062
1063// LeaveChatConfig allows you to leave a chat.
1064type LeaveChatConfig struct {
1065 ChatID int64
1066 ChannelUsername string
1067}
1068
1069func (config LeaveChatConfig) method() string {
1070 return "leaveChat"
1071}
1072
1073func (config LeaveChatConfig) params() (Params, error) {
1074 params := make(Params)
1075
1076 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1077
1078 return params, nil
1079}
1080
1081// ChatConfigWithUser contains information about a chat and a user.
1082type ChatConfigWithUser struct {
1083 ChatID int64
1084 SuperGroupUsername string
1085 UserID int
1086}
1087
1088func (config ChatConfigWithUser) params() (Params, error) {
1089 params := make(Params)
1090
1091 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1092 params.AddNonZero("user_id", config.UserID)
1093
1094 return params, nil
1095}
1096
1097// GetChatMemberConfig is information about getting a specific member in a chat.
1098type GetChatMemberConfig struct {
1099 ChatConfigWithUser
1100}
1101
1102func (GetChatMemberConfig) method() string {
1103 return "getChatMember"
1104}
1105
1106// InvoiceConfig contains information for sendInvoice request.
1107type InvoiceConfig struct {
1108 BaseChat
1109 Title string // required
1110 Description string // required
1111 Payload string // required
1112 ProviderToken string // required
1113 StartParameter string // required
1114 Currency string // required
1115 Prices []LabeledPrice // required
1116 ProviderData string
1117 PhotoURL string
1118 PhotoSize int
1119 PhotoWidth int
1120 PhotoHeight int
1121 NeedName bool
1122 NeedPhoneNumber bool
1123 NeedEmail bool
1124 NeedShippingAddress bool
1125 SendPhoneNumberToProvider bool
1126 SendEmailToProvider bool
1127 IsFlexible bool
1128}
1129
1130func (config InvoiceConfig) params() (Params, error) {
1131 params, err := config.BaseChat.params()
1132 if err != nil {
1133 return params, err
1134 }
1135
1136 params["title"] = config.Title
1137 params["description"] = config.Description
1138 params["payload"] = config.Payload
1139 params["provider_token"] = config.ProviderToken
1140 params["start_parameter"] = config.StartParameter
1141 params["currency"] = config.Currency
1142
1143 if err = params.AddInterface("prices", config.Prices); err != nil {
1144 return params, err
1145 }
1146
1147 params.AddNonEmpty("provider_data", config.ProviderData)
1148 params.AddNonEmpty("photo_url", config.PhotoURL)
1149 params.AddNonZero("photo_size", config.PhotoSize)
1150 params.AddNonZero("photo_width", config.PhotoWidth)
1151 params.AddNonZero("photo_height", config.PhotoHeight)
1152 params.AddBool("need_name", config.NeedName)
1153 params.AddBool("need_phone_number", config.NeedPhoneNumber)
1154 params.AddBool("need_email", config.NeedEmail)
1155 params.AddBool("need_shipping_address", config.NeedShippingAddress)
1156 params.AddBool("is_flexible", config.IsFlexible)
1157 params.AddBool("send_phone_number_to_provider", config.SendPhoneNumberToProvider)
1158 params.AddBool("send_email_to_provider", config.SendEmailToProvider)
1159
1160 return params, nil
1161}
1162
1163func (config InvoiceConfig) method() string {
1164 return "sendInvoice"
1165}
1166
1167// ShippingConfig contains information for answerShippingQuery request.
1168type ShippingConfig struct {
1169 ShippingQueryID string // required
1170 OK bool // required
1171 ShippingOptions []ShippingOption
1172 ErrorMessage string
1173}
1174
1175// PreCheckoutConfig conatins information for answerPreCheckoutQuery request.
1176type PreCheckoutConfig struct {
1177 PreCheckoutQueryID string // required
1178 OK bool // required
1179 ErrorMessage string
1180}
1181
1182// DeleteMessageConfig contains information of a message in a chat to delete.
1183type DeleteMessageConfig struct {
1184 ChatID int64
1185 MessageID int
1186}
1187
1188func (config DeleteMessageConfig) method() string {
1189 return "deleteMessage"
1190}
1191
1192func (config DeleteMessageConfig) params() (Params, error) {
1193 params := make(Params)
1194
1195 params.AddNonZero64("chat_id", config.ChatID)
1196 params.AddNonZero("message_id", config.MessageID)
1197
1198 return params, nil
1199}
1200
1201// PinChatMessageConfig contains information of a message in a chat to pin.
1202type PinChatMessageConfig struct {
1203 ChatID int64
1204 ChannelUsername string
1205 MessageID int
1206 DisableNotification bool
1207}
1208
1209func (config PinChatMessageConfig) method() string {
1210 return "pinChatMessage"
1211}
1212
1213func (config PinChatMessageConfig) params() (Params, error) {
1214 params := make(Params)
1215
1216 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1217 params.AddNonZero("message_id", config.MessageID)
1218 params.AddBool("disable_notification", config.DisableNotification)
1219
1220 return params, nil
1221}
1222
1223// UnpinChatMessageConfig contains information of chat to unpin.
1224type UnpinChatMessageConfig struct {
1225 ChatID int64
1226 ChannelUsername string
1227}
1228
1229func (config UnpinChatMessageConfig) method() string {
1230 return "unpinChatMessage"
1231}
1232
1233func (config UnpinChatMessageConfig) params() (Params, error) {
1234 params := make(Params)
1235
1236 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1237
1238 return params, nil
1239}
1240
1241// SetChatPhotoConfig allows you to set a group, supergroup, or channel's photo.
1242type SetChatPhotoConfig struct {
1243 BaseFile
1244}
1245
1246func (config SetChatPhotoConfig) method() string {
1247 return "setChatPhoto"
1248}
1249
1250func (config SetChatPhotoConfig) name() string {
1251 return "photo"
1252}
1253
1254func (config SetChatPhotoConfig) getFile() interface{} {
1255 return config.File
1256}
1257
1258func (config SetChatPhotoConfig) useExistingFile() bool {
1259 return config.UseExisting
1260}
1261
1262// DeleteChatPhotoConfig allows you to delete a group, supergroup, or channel's photo.
1263type DeleteChatPhotoConfig struct {
1264 ChatID int64
1265 ChannelUsername string
1266}
1267
1268func (config DeleteChatPhotoConfig) method() string {
1269 return "deleteChatPhoto"
1270}
1271
1272func (config DeleteChatPhotoConfig) params() (Params, error) {
1273 params := make(Params)
1274
1275 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1276
1277 return params, nil
1278}
1279
1280// SetChatTitleConfig allows you to set the title of something other than a private chat.
1281type SetChatTitleConfig struct {
1282 ChatID int64
1283 ChannelUsername string
1284
1285 Title string
1286}
1287
1288func (config SetChatTitleConfig) method() string {
1289 return "setChatTitle"
1290}
1291
1292func (config SetChatTitleConfig) params() (Params, error) {
1293 params := make(Params)
1294
1295 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1296 params["title"] = config.Title
1297
1298 return params, nil
1299}
1300
1301// SetChatDescriptionConfig allows you to set the description of a supergroup or channel.
1302type SetChatDescriptionConfig struct {
1303 ChatID int64
1304 ChannelUsername string
1305
1306 Description string
1307}
1308
1309func (config SetChatDescriptionConfig) method() string {
1310 return "setChatDescription"
1311}
1312
1313func (config SetChatDescriptionConfig) params() (Params, error) {
1314 params := make(Params)
1315
1316 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1317 params["description"] = config.Description
1318
1319 return params, nil
1320}
1321
1322// GetStickerSetConfig allows you to get the stickers in a set.
1323type GetStickerSetConfig struct {
1324 Name string
1325}
1326
1327func (config GetStickerSetConfig) method() string {
1328 return "getStickerSet"
1329}
1330
1331func (config GetStickerSetConfig) params() (Params, error) {
1332 params := make(Params)
1333
1334 params["name"] = config.Name
1335
1336 return params, nil
1337}
1338
1339// UploadStickerConfig allows you to upload a sticker for use in a set later.
1340type UploadStickerConfig struct {
1341 UserID int64
1342 PNGSticker interface{}
1343}
1344
1345func (config UploadStickerConfig) method() string {
1346 return "uploadStickerFile"
1347}
1348
1349func (config UploadStickerConfig) params() (Params, error) {
1350 params := make(Params)
1351
1352 params.AddNonZero64("user_id", config.UserID)
1353
1354 return params, nil
1355}
1356
1357func (config UploadStickerConfig) name() string {
1358 return "png_sticker"
1359}
1360
1361func (config UploadStickerConfig) getFile() interface{} {
1362 return config.PNGSticker
1363}
1364
1365func (config UploadStickerConfig) useExistingFile() bool {
1366 return false
1367}
1368
1369// NewStickerSetConfig allows creating a new sticker set.
1370type NewStickerSetConfig struct {
1371 UserID int64
1372 Name string
1373 Title string
1374 PNGSticker interface{}
1375 Emojis string
1376 ContainsMasks bool
1377 MaskPosition *MaskPosition
1378}
1379
1380func (config NewStickerSetConfig) method() string {
1381 return "createNewStickerSet"
1382}
1383
1384func (config NewStickerSetConfig) params() (Params, error) {
1385 params := make(Params)
1386
1387 params.AddNonZero64("user_id", config.UserID)
1388 params["name"] = config.Name
1389 params["title"] = config.Title
1390
1391 if sticker, ok := config.PNGSticker.(string); ok {
1392 params[config.name()] = sticker
1393 }
1394
1395 params["emojis"] = config.Emojis
1396
1397 params.AddBool("contains_masks", config.ContainsMasks)
1398
1399 err := params.AddInterface("mask_position", config.MaskPosition)
1400
1401 return params, err
1402}
1403
1404func (config NewStickerSetConfig) getFile() interface{} {
1405 return config.PNGSticker
1406}
1407
1408func (config NewStickerSetConfig) name() string {
1409 return "png_sticker"
1410}
1411
1412func (config NewStickerSetConfig) useExistingFile() bool {
1413 _, ok := config.PNGSticker.(string)
1414
1415 return ok
1416}
1417
1418// AddStickerConfig allows you to add a sticker to a set.
1419type AddStickerConfig struct {
1420 UserID int64
1421 Name string
1422 PNGSticker interface{}
1423 Emojis string
1424 MaskPosition *MaskPosition
1425}
1426
1427func (config AddStickerConfig) method() string {
1428 return "addStickerToSet"
1429}
1430
1431func (config AddStickerConfig) params() (Params, error) {
1432 params := make(Params)
1433
1434 params.AddNonZero64("user_id", config.UserID)
1435 params["name"] = config.Name
1436 params["emojis"] = config.Emojis
1437
1438 if sticker, ok := config.PNGSticker.(string); ok {
1439 params[config.name()] = sticker
1440 }
1441
1442 err := params.AddInterface("mask_position", config.MaskPosition)
1443
1444 return params, err
1445}
1446
1447func (config AddStickerConfig) name() string {
1448 return "png_sticker"
1449}
1450
1451func (config AddStickerConfig) getFile() interface{} {
1452 return config.PNGSticker
1453}
1454
1455func (config AddStickerConfig) useExistingFile() bool {
1456 return false
1457}
1458
1459// SetStickerPositionConfig allows you to change the position of a sticker in a set.
1460type SetStickerPositionConfig struct {
1461 Sticker string
1462 Position int
1463}
1464
1465func (config SetStickerPositionConfig) method() string {
1466 return "setStickerPositionInSet"
1467}
1468
1469func (config SetStickerPositionConfig) params() (Params, error) {
1470 params := make(Params)
1471
1472 params["sticker"] = config.Sticker
1473 params.AddNonZero("position", config.Position)
1474
1475 return params, nil
1476}
1477
1478// DeleteStickerConfig allows you to delete a sticker from a set.
1479type DeleteStickerConfig struct {
1480 Sticker string
1481}
1482
1483func (config DeleteStickerConfig) method() string {
1484 return "deleteStickerFromSet"
1485}
1486
1487func (config DeleteStickerConfig) params() (Params, error) {
1488 params := make(Params)
1489
1490 params["sticker"] = config.Sticker
1491
1492 return params, nil
1493}
1494
1495// SetChatStickerSetConfig allows you to set the sticker set for a supergroup.
1496type SetChatStickerSetConfig struct {
1497 ChatID int64
1498 SuperGroupUsername string
1499
1500 StickerSetName string
1501}
1502
1503func (config SetChatStickerSetConfig) method() string {
1504 return "setChatStickerSet"
1505}
1506
1507func (config SetChatStickerSetConfig) params() (Params, error) {
1508 params := make(Params)
1509
1510 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1511 params["sticker_set_name"] = config.StickerSetName
1512
1513 return params, nil
1514}
1515
1516// DeleteChatStickerSetConfig allows you to remove a supergroup's sticker set.
1517type DeleteChatStickerSetConfig struct {
1518 ChatID int64
1519 SuperGroupUsername string
1520}
1521
1522func (config DeleteChatStickerSetConfig) method() string {
1523 return "deleteChatStickerSet"
1524}
1525
1526func (config DeleteChatStickerSetConfig) params() (Params, error) {
1527 params := make(Params)
1528
1529 params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
1530
1531 return params, nil
1532}
1533
1534// MediaGroupConfig allows you to send a group of media.
1535//
1536// Media consist of InputMedia items (InputMediaPhoto, InputMediaVideo).
1537type MediaGroupConfig struct {
1538 ChatID int64
1539 ChannelUsername string
1540
1541 Media []interface{}
1542 DisableNotification bool
1543 ReplyToMessageID int
1544}
1545
1546func (config MediaGroupConfig) method() string {
1547 return "sendMediaGroup"
1548}
1549
1550func (config MediaGroupConfig) params() (Params, error) {
1551 params := make(Params)
1552
1553 params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername)
1554 if err := params.AddInterface("media", config.Media); err != nil {
1555 return params, nil
1556 }
1557 params.AddBool("disable_notification", config.DisableNotification)
1558 params.AddNonZero("reply_to_message_id", config.ReplyToMessageID)
1559
1560 return params, nil
1561}