configs.go (view raw)
1package tgbotapi
2
3import (
4 "encoding/json"
5 "io"
6 "net/url"
7 "strconv"
8)
9
10// Telegram constants
11const (
12 // APIEndpoint is the endpoint for all API methods,
13 // with formatting for Sprintf.
14 APIEndpoint = "https://api.telegram.org/bot%s/%s"
15 // FileEndpoint is the endpoint for downloading a file from Telegram.
16 FileEndpoint = "https://api.telegram.org/file/bot%s/%s"
17)
18
19// Constant values for ChatActions
20const (
21 ChatTyping = "typing"
22 ChatUploadPhoto = "upload_photo"
23 ChatRecordVideo = "record_video"
24 ChatUploadVideo = "upload_video"
25 ChatRecordAudio = "record_audio"
26 ChatUploadAudio = "upload_audio"
27 ChatUploadDocument = "upload_document"
28 ChatFindLocation = "find_location"
29)
30
31// API errors
32const (
33 // ErrAPIForbidden happens when a token is bad
34 ErrAPIForbidden = "forbidden"
35)
36
37// Constant values for ParseMode in MessageConfig
38const (
39 ModeMarkdown = "Markdown"
40 ModeHTML = "HTML"
41)
42
43// Library errors
44const (
45 // ErrBadFileType happens when you pass an unknown type
46 ErrBadFileType = "bad file type"
47 ErrBadURL = "bad or empty url"
48)
49
50// Chattable is any config type that can be sent.
51type Chattable interface {
52 values() (url.Values, error)
53 method() string
54}
55
56// Fileable is any config type that can be sent that includes a file.
57type Fileable interface {
58 Chattable
59 params() (map[string]string, error)
60 name() string
61 getFile() interface{}
62 useExistingFile() bool
63}
64
65// BaseChat is base type for all chat config types.
66type BaseChat struct {
67 ChatID int64 // required
68 ChannelUsername string
69 ReplyToMessageID int
70 ReplyMarkup interface{}
71 DisableNotification bool
72}
73
74// values returns url.Values representation of BaseChat
75func (chat *BaseChat) values() (url.Values, error) {
76 v := url.Values{}
77 if chat.ChannelUsername != "" {
78 v.Add("chat_id", chat.ChannelUsername)
79 } else {
80 v.Add("chat_id", strconv.FormatInt(chat.ChatID, 10))
81 }
82
83 if chat.ReplyToMessageID != 0 {
84 v.Add("reply_to_message_id", strconv.Itoa(chat.ReplyToMessageID))
85 }
86
87 if chat.ReplyMarkup != nil {
88 data, err := json.Marshal(chat.ReplyMarkup)
89 if err != nil {
90 return v, err
91 }
92
93 v.Add("reply_markup", string(data))
94 }
95
96 v.Add("disable_notification", strconv.FormatBool(chat.DisableNotification))
97
98 return v, nil
99}
100
101// BaseFile is a base type for all file config types.
102type BaseFile struct {
103 BaseChat
104 File interface{}
105 FileID string
106 UseExisting bool
107 MimeType string
108 FileSize int
109}
110
111// params returns a map[string]string representation of BaseFile.
112func (file BaseFile) params() (map[string]string, error) {
113 params := make(map[string]string)
114
115 if file.ChannelUsername != "" {
116 params["chat_id"] = file.ChannelUsername
117 } else {
118 params["chat_id"] = strconv.FormatInt(file.ChatID, 10)
119 }
120
121 if file.ReplyToMessageID != 0 {
122 params["reply_to_message_id"] = strconv.Itoa(file.ReplyToMessageID)
123 }
124
125 if file.ReplyMarkup != nil {
126 data, err := json.Marshal(file.ReplyMarkup)
127 if err != nil {
128 return params, err
129 }
130
131 params["reply_markup"] = string(data)
132 }
133
134 if file.MimeType != "" {
135 params["mime_type"] = file.MimeType
136 }
137
138 if file.FileSize > 0 {
139 params["file_size"] = strconv.Itoa(file.FileSize)
140 }
141
142 params["disable_notification"] = strconv.FormatBool(file.DisableNotification)
143
144 return params, nil
145}
146
147// getFile returns the file.
148func (file BaseFile) getFile() interface{} {
149 return file.File
150}
151
152// useExistingFile returns if the BaseFile has already been uploaded.
153func (file BaseFile) useExistingFile() bool {
154 return file.UseExisting
155}
156
157// BaseEdit is base type of all chat edits.
158type BaseEdit struct {
159 ChatID int64
160 ChannelUsername string
161 MessageID int
162 InlineMessageID string
163 ReplyMarkup *InlineKeyboardMarkup
164}
165
166func (edit BaseEdit) values() (url.Values, error) {
167 v := url.Values{}
168
169 if edit.InlineMessageID == "" {
170 if edit.ChannelUsername != "" {
171 v.Add("chat_id", edit.ChannelUsername)
172 } else {
173 v.Add("chat_id", strconv.FormatInt(edit.ChatID, 10))
174 }
175 v.Add("message_id", strconv.Itoa(edit.MessageID))
176 } else {
177 v.Add("inline_message_id", edit.InlineMessageID)
178 }
179
180 if edit.ReplyMarkup != nil {
181 data, err := json.Marshal(edit.ReplyMarkup)
182 if err != nil {
183 return v, err
184 }
185 v.Add("reply_markup", string(data))
186 }
187
188 return v, nil
189}
190
191// MessageConfig contains information about a SendMessage request.
192type MessageConfig struct {
193 BaseChat
194 Text string
195 ParseMode string
196 DisableWebPagePreview bool
197}
198
199// values returns a url.Values representation of MessageConfig.
200func (config MessageConfig) values() (url.Values, error) {
201 v, err := config.BaseChat.values()
202 if err != nil {
203 return v, err
204 }
205 v.Add("text", config.Text)
206 v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview))
207 if config.ParseMode != "" {
208 v.Add("parse_mode", config.ParseMode)
209 }
210
211 return v, nil
212}
213
214// method returns Telegram API method name for sending Message.
215func (config MessageConfig) method() string {
216 return "sendMessage"
217}
218
219// ForwardConfig contains information about a ForwardMessage request.
220type ForwardConfig struct {
221 BaseChat
222 FromChatID int64 // required
223 FromChannelUsername string
224 MessageID int // required
225}
226
227// values returns a url.Values representation of ForwardConfig.
228func (config ForwardConfig) values() (url.Values, error) {
229 v, err := config.BaseChat.values()
230 if err != nil {
231 return v, err
232 }
233 v.Add("from_chat_id", strconv.FormatInt(config.FromChatID, 10))
234 v.Add("message_id", strconv.Itoa(config.MessageID))
235 return v, nil
236}
237
238// method returns Telegram API method name for sending Forward.
239func (config ForwardConfig) method() string {
240 return "forwardMessage"
241}
242
243// PhotoConfig contains information about a SendPhoto request.
244type PhotoConfig struct {
245 BaseFile
246 Caption string
247 ParseMode string
248}
249
250// Params returns a map[string]string representation of PhotoConfig.
251func (config PhotoConfig) params() (map[string]string, error) {
252 params, _ := config.BaseFile.params()
253
254 if config.Caption != "" {
255 params["caption"] = config.Caption
256 }
257 if config.ParseMode != "" {
258 params["parse_mode"] = config.ParseMode
259 }
260
261 return params, nil
262}
263
264// Values returns a url.Values representation of PhotoConfig.
265func (config PhotoConfig) values() (url.Values, error) {
266 v, err := config.BaseChat.values()
267 if err != nil {
268 return v, err
269 }
270
271 v.Add(config.name(), config.FileID)
272 if config.Caption != "" {
273 v.Add("caption", config.Caption)
274 }
275 if config.ParseMode != "" {
276 v.Add("parse_mode", config.ParseMode)
277 }
278 return v, nil
279}
280
281// name returns the field name for the Photo.
282func (config PhotoConfig) name() string {
283 return "photo"
284}
285
286// method returns Telegram API method name for sending Photo.
287func (config PhotoConfig) method() string {
288 return "sendPhoto"
289}
290
291// AudioConfig contains information about a SendAudio request.
292type AudioConfig struct {
293 BaseFile
294 Caption string
295 Duration int
296 Performer string
297 Title string
298}
299
300// values returns a url.Values representation of AudioConfig.
301func (config AudioConfig) values() (url.Values, error) {
302 v, err := config.BaseChat.values()
303 if err != nil {
304 return v, err
305 }
306
307 v.Add(config.name(), config.FileID)
308 if config.Duration != 0 {
309 v.Add("duration", strconv.Itoa(config.Duration))
310 }
311
312 if config.Performer != "" {
313 v.Add("performer", config.Performer)
314 }
315 if config.Title != "" {
316 v.Add("title", config.Title)
317 }
318 if config.Caption != "" {
319 v.Add("caption", config.Caption)
320 }
321
322 return v, nil
323}
324
325// params returns a map[string]string representation of AudioConfig.
326func (config AudioConfig) params() (map[string]string, error) {
327 params, _ := config.BaseFile.params()
328
329 if config.Duration != 0 {
330 params["duration"] = strconv.Itoa(config.Duration)
331 }
332
333 if config.Performer != "" {
334 params["performer"] = config.Performer
335 }
336 if config.Title != "" {
337 params["title"] = config.Title
338 }
339 if config.Caption != "" {
340 params["caption"] = config.Caption
341 }
342
343 return params, nil
344}
345
346// name returns the field name for the Audio.
347func (config AudioConfig) name() string {
348 return "audio"
349}
350
351// method returns Telegram API method name for sending Audio.
352func (config AudioConfig) method() string {
353 return "sendAudio"
354}
355
356// DocumentConfig contains information about a SendDocument request.
357type DocumentConfig struct {
358 BaseFile
359 Caption string
360}
361
362// values returns a url.Values representation of DocumentConfig.
363func (config DocumentConfig) values() (url.Values, error) {
364 v, err := config.BaseChat.values()
365 if err != nil {
366 return v, err
367 }
368
369 v.Add(config.name(), config.FileID)
370 if config.Caption != "" {
371 v.Add("caption", config.Caption)
372 }
373
374 return v, nil
375}
376
377// params returns a map[string]string representation of DocumentConfig.
378func (config DocumentConfig) params() (map[string]string, error) {
379 params, _ := config.BaseFile.params()
380
381 if config.Caption != "" {
382 params["caption"] = config.Caption
383 }
384
385 return params, nil
386}
387
388// name returns the field name for the Document.
389func (config DocumentConfig) name() string {
390 return "document"
391}
392
393// method returns Telegram API method name for sending Document.
394func (config DocumentConfig) method() string {
395 return "sendDocument"
396}
397
398// StickerConfig contains information about a SendSticker request.
399type StickerConfig struct {
400 BaseFile
401}
402
403// values returns a url.Values representation of StickerConfig.
404func (config StickerConfig) values() (url.Values, error) {
405 v, err := config.BaseChat.values()
406 if err != nil {
407 return v, err
408 }
409
410 v.Add(config.name(), config.FileID)
411
412 return v, nil
413}
414
415// params returns a map[string]string representation of StickerConfig.
416func (config StickerConfig) params() (map[string]string, error) {
417 params, _ := config.BaseFile.params()
418
419 return params, nil
420}
421
422// name returns the field name for the Sticker.
423func (config StickerConfig) name() string {
424 return "sticker"
425}
426
427// method returns Telegram API method name for sending Sticker.
428func (config StickerConfig) method() string {
429 return "sendSticker"
430}
431
432// VideoConfig contains information about a SendVideo request.
433type VideoConfig struct {
434 BaseFile
435 Duration int
436 Caption string
437}
438
439// values returns a url.Values representation of VideoConfig.
440func (config VideoConfig) values() (url.Values, error) {
441 v, err := config.BaseChat.values()
442 if err != nil {
443 return v, err
444 }
445
446 v.Add(config.name(), config.FileID)
447 if config.Duration != 0 {
448 v.Add("duration", strconv.Itoa(config.Duration))
449 }
450 if config.Caption != "" {
451 v.Add("caption", config.Caption)
452 }
453
454 return v, nil
455}
456
457// params returns a map[string]string representation of VideoConfig.
458func (config VideoConfig) params() (map[string]string, error) {
459 params, _ := config.BaseFile.params()
460
461 if config.Caption != "" {
462 params["caption"] = config.Caption
463 }
464
465 return params, nil
466}
467
468// name returns the field name for the Video.
469func (config VideoConfig) name() string {
470 return "video"
471}
472
473// method returns Telegram API method name for sending Video.
474func (config VideoConfig) method() string {
475 return "sendVideo"
476}
477
478// VideoNoteConfig contains information about a SendVideoNote request.
479type VideoNoteConfig struct {
480 BaseFile
481 Duration int
482 Length int
483}
484
485// values returns a url.Values representation of VideoNoteConfig.
486func (config VideoNoteConfig) values() (url.Values, error) {
487 v, err := config.BaseChat.values()
488 if err != nil {
489 return v, err
490 }
491
492 v.Add(config.name(), config.FileID)
493 if config.Duration != 0 {
494 v.Add("duration", strconv.Itoa(config.Duration))
495 }
496
497 // Telegram API seems to have a bug, if no length is provided or it is 0, it will send an error response
498 if config.Length != 0 {
499 v.Add("length", strconv.Itoa(config.Length))
500 }
501
502 return v, nil
503}
504
505// params returns a map[string]string representation of VideoNoteConfig.
506func (config VideoNoteConfig) params() (map[string]string, error) {
507 params, _ := config.BaseFile.params()
508
509 if config.Length != 0 {
510 params["length"] = strconv.Itoa(config.Length)
511 }
512 if config.Duration != 0 {
513 params["duration"] = strconv.Itoa(config.Duration)
514 }
515
516 return params, nil
517}
518
519// name returns the field name for the VideoNote.
520func (config VideoNoteConfig) name() string {
521 return "video_note"
522}
523
524// method returns Telegram API method name for sending VideoNote.
525func (config VideoNoteConfig) method() string {
526 return "sendVideoNote"
527}
528
529// VoiceConfig contains information about a SendVoice request.
530type VoiceConfig struct {
531 BaseFile
532 Caption string
533 Duration int
534}
535
536// values returns a url.Values representation of VoiceConfig.
537func (config VoiceConfig) values() (url.Values, error) {
538 v, err := config.BaseChat.values()
539 if err != nil {
540 return v, err
541 }
542
543 v.Add(config.name(), config.FileID)
544 if config.Duration != 0 {
545 v.Add("duration", strconv.Itoa(config.Duration))
546 }
547 if config.Caption != "" {
548 v.Add("caption", config.Caption)
549 }
550
551 return v, nil
552}
553
554// params returns a map[string]string representation of VoiceConfig.
555func (config VoiceConfig) params() (map[string]string, error) {
556 params, _ := config.BaseFile.params()
557
558 if config.Duration != 0 {
559 params["duration"] = strconv.Itoa(config.Duration)
560 }
561 if config.Caption != "" {
562 params["caption"] = config.Caption
563 }
564
565 return params, nil
566}
567
568// name returns the field name for the Voice.
569func (config VoiceConfig) name() string {
570 return "voice"
571}
572
573// method returns Telegram API method name for sending Voice.
574func (config VoiceConfig) method() string {
575 return "sendVoice"
576}
577
578// LocationConfig contains information about a SendLocation request.
579type LocationConfig struct {
580 BaseChat
581 Latitude float64 // required
582 Longitude float64 // required
583}
584
585// values returns a url.Values representation of LocationConfig.
586func (config LocationConfig) values() (url.Values, error) {
587 v, err := config.BaseChat.values()
588 if err != nil {
589 return v, err
590 }
591
592 v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64))
593 v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))
594
595 return v, nil
596}
597
598// method returns Telegram API method name for sending Location.
599func (config LocationConfig) method() string {
600 return "sendLocation"
601}
602
603// VenueConfig contains information about a SendVenue request.
604type VenueConfig struct {
605 BaseChat
606 Latitude float64 // required
607 Longitude float64 // required
608 Title string // required
609 Address string // required
610 FoursquareID string
611}
612
613func (config VenueConfig) values() (url.Values, error) {
614 v, err := config.BaseChat.values()
615 if err != nil {
616 return v, err
617 }
618
619 v.Add("latitude", strconv.FormatFloat(config.Latitude, 'f', 6, 64))
620 v.Add("longitude", strconv.FormatFloat(config.Longitude, 'f', 6, 64))
621 v.Add("title", config.Title)
622 v.Add("address", config.Address)
623 if config.FoursquareID != "" {
624 v.Add("foursquare_id", config.FoursquareID)
625 }
626
627 return v, nil
628}
629
630func (config VenueConfig) method() string {
631 return "sendVenue"
632}
633
634// ContactConfig allows you to send a contact.
635type ContactConfig struct {
636 BaseChat
637 PhoneNumber string
638 FirstName string
639 LastName string
640}
641
642func (config ContactConfig) values() (url.Values, error) {
643 v, err := config.BaseChat.values()
644 if err != nil {
645 return v, err
646 }
647
648 v.Add("phone_number", config.PhoneNumber)
649 v.Add("first_name", config.FirstName)
650 v.Add("last_name", config.LastName)
651
652 return v, nil
653}
654
655func (config ContactConfig) method() string {
656 return "sendContact"
657}
658
659// GameConfig allows you to send a game.
660type GameConfig struct {
661 BaseChat
662 GameShortName string
663}
664
665func (config GameConfig) values() (url.Values, error) {
666 v, err := config.BaseChat.values()
667 if err != nil {
668 return v, err
669 }
670
671 v.Add("game_short_name", config.GameShortName)
672
673 return v, nil
674}
675
676func (config GameConfig) method() string {
677 return "sendGame"
678}
679
680// SetGameScoreConfig allows you to update the game score in a chat.
681type SetGameScoreConfig struct {
682 UserID int
683 Score int
684 Force bool
685 DisableEditMessage bool
686 ChatID int64
687 ChannelUsername string
688 MessageID int
689 InlineMessageID string
690}
691
692func (config SetGameScoreConfig) values() (url.Values, error) {
693 v := url.Values{}
694
695 v.Add("user_id", strconv.Itoa(config.UserID))
696 v.Add("score", strconv.Itoa(config.Score))
697 if config.InlineMessageID == "" {
698 if config.ChannelUsername == "" {
699 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
700 } else {
701 v.Add("chat_id", config.ChannelUsername)
702 }
703 v.Add("message_id", strconv.Itoa(config.MessageID))
704 } else {
705 v.Add("inline_message_id", config.InlineMessageID)
706 }
707 v.Add("disable_edit_message", strconv.FormatBool(config.DisableEditMessage))
708
709 return v, nil
710}
711
712func (config SetGameScoreConfig) method() string {
713 return "setGameScore"
714}
715
716// GetGameHighScoresConfig allows you to fetch the high scores for a game.
717type GetGameHighScoresConfig struct {
718 UserID int
719 ChatID int
720 ChannelUsername string
721 MessageID int
722 InlineMessageID string
723}
724
725func (config GetGameHighScoresConfig) values() (url.Values, error) {
726 v := url.Values{}
727
728 v.Add("user_id", strconv.Itoa(config.UserID))
729 if config.InlineMessageID == "" {
730 if config.ChannelUsername == "" {
731 v.Add("chat_id", strconv.Itoa(config.ChatID))
732 } else {
733 v.Add("chat_id", config.ChannelUsername)
734 }
735 v.Add("message_id", strconv.Itoa(config.MessageID))
736 } else {
737 v.Add("inline_message_id", config.InlineMessageID)
738 }
739
740 return v, nil
741}
742
743func (config GetGameHighScoresConfig) method() string {
744 return "getGameHighScores"
745}
746
747// ChatActionConfig contains information about a SendChatAction request.
748type ChatActionConfig struct {
749 BaseChat
750 Action string // required
751}
752
753// values returns a url.Values representation of ChatActionConfig.
754func (config ChatActionConfig) values() (url.Values, error) {
755 v, err := config.BaseChat.values()
756 if err != nil {
757 return v, err
758 }
759 v.Add("action", config.Action)
760 return v, nil
761}
762
763// method returns Telegram API method name for sending ChatAction.
764func (config ChatActionConfig) method() string {
765 return "sendChatAction"
766}
767
768// EditMessageTextConfig allows you to modify the text in a message.
769type EditMessageTextConfig struct {
770 BaseEdit
771 Text string
772 ParseMode string
773 DisableWebPagePreview bool
774}
775
776func (config EditMessageTextConfig) values() (url.Values, error) {
777 v, err := config.BaseEdit.values()
778 if err != nil {
779 return v, err
780 }
781
782 v.Add("text", config.Text)
783 v.Add("parse_mode", config.ParseMode)
784 v.Add("disable_web_page_preview", strconv.FormatBool(config.DisableWebPagePreview))
785
786 return v, nil
787}
788
789func (config EditMessageTextConfig) method() string {
790 return "editMessageText"
791}
792
793// EditMessageCaptionConfig allows you to modify the caption of a message.
794type EditMessageCaptionConfig struct {
795 BaseEdit
796 Caption string
797}
798
799func (config EditMessageCaptionConfig) values() (url.Values, error) {
800 v, _ := config.BaseEdit.values()
801
802 v.Add("caption", config.Caption)
803
804 return v, nil
805}
806
807func (config EditMessageCaptionConfig) method() string {
808 return "editMessageCaption"
809}
810
811// EditMessageReplyMarkupConfig allows you to modify the reply markup
812// of a message.
813type EditMessageReplyMarkupConfig struct {
814 BaseEdit
815}
816
817func (config EditMessageReplyMarkupConfig) values() (url.Values, error) {
818 return config.BaseEdit.values()
819}
820
821func (config EditMessageReplyMarkupConfig) method() string {
822 return "editMessageReplyMarkup"
823}
824
825// UserProfilePhotosConfig contains information about a
826// GetUserProfilePhotos request.
827type UserProfilePhotosConfig struct {
828 UserID int
829 Offset int
830 Limit int
831}
832
833// FileConfig has information about a file hosted on Telegram.
834type FileConfig struct {
835 FileID string
836}
837
838// UpdateConfig contains information about a GetUpdates request.
839type UpdateConfig struct {
840 Offset int
841 Limit int
842 Timeout int
843}
844
845// WebhookConfig contains information about a SetWebhook request.
846type WebhookConfig struct {
847 URL *url.URL
848 Certificate interface{}
849 MaxConnections int
850}
851
852// FileBytes contains information about a set of bytes to upload
853// as a File.
854type FileBytes struct {
855 Name string
856 Bytes []byte
857}
858
859// FileReader contains information about a reader to upload as a File.
860// If Size is -1, it will read the entire Reader into memory to
861// calculate a Size.
862type FileReader struct {
863 Name string
864 Reader io.Reader
865 Size int64
866}
867
868// InlineConfig contains information on making an InlineQuery response.
869type InlineConfig struct {
870 InlineQueryID string `json:"inline_query_id"`
871 Results []interface{} `json:"results"`
872 CacheTime int `json:"cache_time"`
873 IsPersonal bool `json:"is_personal"`
874 NextOffset string `json:"next_offset"`
875 SwitchPMText string `json:"switch_pm_text"`
876 SwitchPMParameter string `json:"switch_pm_parameter"`
877}
878
879// CallbackConfig contains information on making a CallbackQuery response.
880type CallbackConfig struct {
881 CallbackQueryID string `json:"callback_query_id"`
882 Text string `json:"text"`
883 ShowAlert bool `json:"show_alert"`
884 URL string `json:"url"`
885 CacheTime int `json:"cache_time"`
886}
887
888// ChatMemberConfig contains information about a user in a chat for use
889// with administrative functions such as kicking or unbanning a user.
890type ChatMemberConfig struct {
891 ChatID int64
892 SuperGroupUsername string
893 ChannelUsername string
894 UserID int
895}
896
897// KickChatMemberConfig contains extra fields to kick user
898type KickChatMemberConfig struct {
899 ChatMemberConfig
900 UntilDate int64
901}
902
903// RestrictChatMemberConfig contains fields to restrict members of chat
904type RestrictChatMemberConfig struct {
905 ChatMemberConfig
906 UntilDate int64
907 CanSendMessages *bool
908 CanSendMediaMessages *bool
909 CanSendOtherMessages *bool
910 CanAddWebPagePreviews *bool
911}
912
913// PromoteChatMemberConfig contains fields to promote members of chat
914type PromoteChatMemberConfig struct {
915 ChatMemberConfig
916 CanChangeInfo *bool
917 CanPostMessages *bool
918 CanEditMessages *bool
919 CanDeleteMessages *bool
920 CanInviteUsers *bool
921 CanRestrictMembers *bool
922 CanPinMessages *bool
923 CanPromoteMembers *bool
924}
925
926// ChatConfig contains information about getting information on a chat.
927type ChatConfig struct {
928 ChatID int64
929 SuperGroupUsername string
930}
931
932// ChatConfigWithUser contains information about getting information on
933// a specific user within a chat.
934type ChatConfigWithUser struct {
935 ChatID int64
936 SuperGroupUsername string
937 UserID int
938}
939
940// InvoiceConfig contains information for sendInvoice request.
941type InvoiceConfig struct {
942 BaseChat
943 Title string // required
944 Description string // required
945 Payload string // required
946 ProviderToken string // required
947 StartParameter string // required
948 Currency string // required
949 Prices *[]LabeledPrice // required
950 PhotoURL string
951 PhotoSize int
952 PhotoWidth int
953 PhotoHeight int
954 NeedName bool
955 NeedPhoneNumber bool
956 NeedEmail bool
957 NeedShippingAddress bool
958 IsFlexible bool
959}
960
961func (config InvoiceConfig) values() (url.Values, error) {
962 v, err := config.BaseChat.values()
963 if err != nil {
964 return v, err
965 }
966 v.Add("title", config.Title)
967 v.Add("description", config.Description)
968 v.Add("payload", config.Payload)
969 v.Add("provider_token", config.ProviderToken)
970 v.Add("start_parameter", config.StartParameter)
971 v.Add("currency", config.Currency)
972 data, err := json.Marshal(config.Prices)
973 if err != nil {
974 return v, err
975 }
976 v.Add("prices", string(data))
977 if config.PhotoURL != "" {
978 v.Add("photo_url", config.PhotoURL)
979 }
980 if config.PhotoSize != 0 {
981 v.Add("photo_size", strconv.Itoa(config.PhotoSize))
982 }
983 if config.PhotoWidth != 0 {
984 v.Add("photo_width", strconv.Itoa(config.PhotoWidth))
985 }
986 if config.PhotoHeight != 0 {
987 v.Add("photo_height", strconv.Itoa(config.PhotoHeight))
988 }
989 if config.NeedName != false {
990 v.Add("need_name", strconv.FormatBool(config.NeedName))
991 }
992 if config.NeedPhoneNumber != false {
993 v.Add("need_phone_number", strconv.FormatBool(config.NeedPhoneNumber))
994 }
995 if config.NeedEmail != false {
996 v.Add("need_email", strconv.FormatBool(config.NeedEmail))
997 }
998 if config.NeedShippingAddress != false {
999 v.Add("need_shipping_address", strconv.FormatBool(config.NeedShippingAddress))
1000 }
1001 if config.IsFlexible != false {
1002 v.Add("is_flexible", strconv.FormatBool(config.IsFlexible))
1003 }
1004
1005 return v, nil
1006}
1007
1008func (config InvoiceConfig) method() string {
1009 return "sendInvoice"
1010}
1011
1012// ShippingConfig contains information for answerShippingQuery request.
1013type ShippingConfig struct {
1014 ShippingQueryID string // required
1015 OK bool // required
1016 ShippingOptions *[]ShippingOption
1017 ErrorMessage string
1018}
1019
1020// PreCheckoutConfig conatins information for answerPreCheckoutQuery request.
1021type PreCheckoutConfig struct {
1022 PreCheckoutQueryID string // required
1023 OK bool // required
1024 ErrorMessage string
1025}
1026
1027// DeleteMessageConfig contains information of a message in a chat to delete.
1028type DeleteMessageConfig struct {
1029 ChatID int64
1030 MessageID int
1031}
1032
1033func (config DeleteMessageConfig) method() string {
1034 return "deleteMessage"
1035}
1036
1037func (config DeleteMessageConfig) values() (url.Values, error) {
1038 v := url.Values{}
1039
1040 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1041 v.Add("message_id", strconv.Itoa(config.MessageID))
1042
1043 return v, nil
1044}
1045
1046// PinChatMessageConfig contains information of a message in a chat to pin.
1047type PinChatMessageConfig struct {
1048 ChatID int64
1049 MessageID int
1050 DisableNotification bool
1051}
1052
1053func (config PinChatMessageConfig) method() string {
1054 return "pinChatMessage"
1055}
1056
1057func (config PinChatMessageConfig) values() (url.Values, error) {
1058 v := url.Values{}
1059
1060 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1061 v.Add("message_id", strconv.Itoa(config.MessageID))
1062 v.Add("disable_notification", strconv.FormatBool(config.DisableNotification))
1063
1064 return v, nil
1065}
1066
1067// UnpinChatMessageConfig contains information of chat to unpin.
1068type UnpinChatMessageConfig struct {
1069 ChatID int64
1070}
1071
1072func (config UnpinChatMessageConfig) method() string {
1073 return "unpinChatMessage"
1074}
1075
1076func (config UnpinChatMessageConfig) values() (url.Values, error) {
1077 v := url.Values{}
1078
1079 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1080
1081 return v, nil
1082}
1083
1084// SetChatTitleConfig contains information for change chat title.
1085type SetChatTitleConfig struct {
1086 ChatID int64
1087 Title string
1088}
1089
1090func (config SetChatTitleConfig) method() string {
1091 return "setChatTitle"
1092}
1093
1094func (config SetChatTitleConfig) values() (url.Values, error) {
1095 v := url.Values{}
1096
1097 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1098 v.Add("title", config.Title)
1099
1100 return v, nil
1101}
1102
1103// SetChatDescriptionConfig contains information for change chat description.
1104type SetChatDescriptionConfig struct {
1105 ChatID int64
1106 Description string
1107}
1108
1109func (config SetChatDescriptionConfig) method() string {
1110 return "setChatDescription"
1111}
1112
1113func (config SetChatDescriptionConfig) values() (url.Values, error) {
1114 v := url.Values{}
1115
1116 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1117 v.Add("description", config.Description)
1118
1119 return v, nil
1120}
1121
1122// SetChatPhotoConfig contains information for change chat photo
1123type SetChatPhotoConfig struct {
1124 BaseFile
1125}
1126
1127// name returns the field name for the Photo.
1128func (config SetChatPhotoConfig) name() string {
1129 return "photo"
1130}
1131
1132// method returns Telegram API method name for sending Photo.
1133func (config SetChatPhotoConfig) method() string {
1134 return "setChatPhoto"
1135}
1136
1137// DeleteChatPhotoConfig contains information for delete chat photo.
1138type DeleteChatPhotoConfig struct {
1139 ChatID int64
1140}
1141
1142func (config DeleteChatPhotoConfig) method() string {
1143 return "deleteChatPhoto"
1144}
1145
1146func (config DeleteChatPhotoConfig) values() (url.Values, error) {
1147 v := url.Values{}
1148
1149 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1150
1151 return v, nil
1152}