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 ParseMode string
798}
799
800func (config EditMessageCaptionConfig) values() (url.Values, error) {
801 v, _ := config.BaseEdit.values()
802
803 v.Add("caption", config.Caption)
804 v.Add("parse_mode", config.ParseMode)
805
806 return v, nil
807}
808
809func (config EditMessageCaptionConfig) method() string {
810 return "editMessageCaption"
811}
812
813// EditMessageReplyMarkupConfig allows you to modify the reply markup
814// of a message.
815type EditMessageReplyMarkupConfig struct {
816 BaseEdit
817}
818
819func (config EditMessageReplyMarkupConfig) values() (url.Values, error) {
820 return config.BaseEdit.values()
821}
822
823func (config EditMessageReplyMarkupConfig) method() string {
824 return "editMessageReplyMarkup"
825}
826
827// UserProfilePhotosConfig contains information about a
828// GetUserProfilePhotos request.
829type UserProfilePhotosConfig struct {
830 UserID int
831 Offset int
832 Limit int
833}
834
835// FileConfig has information about a file hosted on Telegram.
836type FileConfig struct {
837 FileID string
838}
839
840// UpdateConfig contains information about a GetUpdates request.
841type UpdateConfig struct {
842 Offset int
843 Limit int
844 Timeout int
845}
846
847// WebhookConfig contains information about a SetWebhook request.
848type WebhookConfig struct {
849 URL *url.URL
850 Certificate interface{}
851 MaxConnections int
852}
853
854// FileBytes contains information about a set of bytes to upload
855// as a File.
856type FileBytes struct {
857 Name string
858 Bytes []byte
859}
860
861// FileReader contains information about a reader to upload as a File.
862// If Size is -1, it will read the entire Reader into memory to
863// calculate a Size.
864type FileReader struct {
865 Name string
866 Reader io.Reader
867 Size int64
868}
869
870// InlineConfig contains information on making an InlineQuery response.
871type InlineConfig struct {
872 InlineQueryID string `json:"inline_query_id"`
873 Results []interface{} `json:"results"`
874 CacheTime int `json:"cache_time"`
875 IsPersonal bool `json:"is_personal"`
876 NextOffset string `json:"next_offset"`
877 SwitchPMText string `json:"switch_pm_text"`
878 SwitchPMParameter string `json:"switch_pm_parameter"`
879}
880
881// CallbackConfig contains information on making a CallbackQuery response.
882type CallbackConfig struct {
883 CallbackQueryID string `json:"callback_query_id"`
884 Text string `json:"text"`
885 ShowAlert bool `json:"show_alert"`
886 URL string `json:"url"`
887 CacheTime int `json:"cache_time"`
888}
889
890// ChatMemberConfig contains information about a user in a chat for use
891// with administrative functions such as kicking or unbanning a user.
892type ChatMemberConfig struct {
893 ChatID int64
894 SuperGroupUsername string
895 ChannelUsername string
896 UserID int
897}
898
899// KickChatMemberConfig contains extra fields to kick user
900type KickChatMemberConfig struct {
901 ChatMemberConfig
902 UntilDate int64
903}
904
905// RestrictChatMemberConfig contains fields to restrict members of chat
906type RestrictChatMemberConfig struct {
907 ChatMemberConfig
908 UntilDate int64
909 CanSendMessages *bool
910 CanSendMediaMessages *bool
911 CanSendOtherMessages *bool
912 CanAddWebPagePreviews *bool
913}
914
915// PromoteChatMemberConfig contains fields to promote members of chat
916type PromoteChatMemberConfig struct {
917 ChatMemberConfig
918 CanChangeInfo *bool
919 CanPostMessages *bool
920 CanEditMessages *bool
921 CanDeleteMessages *bool
922 CanInviteUsers *bool
923 CanRestrictMembers *bool
924 CanPinMessages *bool
925 CanPromoteMembers *bool
926}
927
928// ChatConfig contains information about getting information on a chat.
929type ChatConfig struct {
930 ChatID int64
931 SuperGroupUsername string
932}
933
934// ChatConfigWithUser contains information about getting information on
935// a specific user within a chat.
936type ChatConfigWithUser struct {
937 ChatID int64
938 SuperGroupUsername string
939 UserID int
940}
941
942// InvoiceConfig contains information for sendInvoice request.
943type InvoiceConfig struct {
944 BaseChat
945 Title string // required
946 Description string // required
947 Payload string // required
948 ProviderToken string // required
949 StartParameter string // required
950 Currency string // required
951 Prices *[]LabeledPrice // required
952 PhotoURL string
953 PhotoSize int
954 PhotoWidth int
955 PhotoHeight int
956 NeedName bool
957 NeedPhoneNumber bool
958 NeedEmail bool
959 NeedShippingAddress bool
960 IsFlexible bool
961}
962
963func (config InvoiceConfig) values() (url.Values, error) {
964 v, err := config.BaseChat.values()
965 if err != nil {
966 return v, err
967 }
968 v.Add("title", config.Title)
969 v.Add("description", config.Description)
970 v.Add("payload", config.Payload)
971 v.Add("provider_token", config.ProviderToken)
972 v.Add("start_parameter", config.StartParameter)
973 v.Add("currency", config.Currency)
974 data, err := json.Marshal(config.Prices)
975 if err != nil {
976 return v, err
977 }
978 v.Add("prices", string(data))
979 if config.PhotoURL != "" {
980 v.Add("photo_url", config.PhotoURL)
981 }
982 if config.PhotoSize != 0 {
983 v.Add("photo_size", strconv.Itoa(config.PhotoSize))
984 }
985 if config.PhotoWidth != 0 {
986 v.Add("photo_width", strconv.Itoa(config.PhotoWidth))
987 }
988 if config.PhotoHeight != 0 {
989 v.Add("photo_height", strconv.Itoa(config.PhotoHeight))
990 }
991 if config.NeedName != false {
992 v.Add("need_name", strconv.FormatBool(config.NeedName))
993 }
994 if config.NeedPhoneNumber != false {
995 v.Add("need_phone_number", strconv.FormatBool(config.NeedPhoneNumber))
996 }
997 if config.NeedEmail != false {
998 v.Add("need_email", strconv.FormatBool(config.NeedEmail))
999 }
1000 if config.NeedShippingAddress != false {
1001 v.Add("need_shipping_address", strconv.FormatBool(config.NeedShippingAddress))
1002 }
1003 if config.IsFlexible != false {
1004 v.Add("is_flexible", strconv.FormatBool(config.IsFlexible))
1005 }
1006
1007 return v, nil
1008}
1009
1010func (config InvoiceConfig) method() string {
1011 return "sendInvoice"
1012}
1013
1014// ShippingConfig contains information for answerShippingQuery request.
1015type ShippingConfig struct {
1016 ShippingQueryID string // required
1017 OK bool // required
1018 ShippingOptions *[]ShippingOption
1019 ErrorMessage string
1020}
1021
1022// PreCheckoutConfig conatins information for answerPreCheckoutQuery request.
1023type PreCheckoutConfig struct {
1024 PreCheckoutQueryID string // required
1025 OK bool // required
1026 ErrorMessage string
1027}
1028
1029// DeleteMessageConfig contains information of a message in a chat to delete.
1030type DeleteMessageConfig struct {
1031 ChatID int64
1032 MessageID int
1033}
1034
1035func (config DeleteMessageConfig) method() string {
1036 return "deleteMessage"
1037}
1038
1039func (config DeleteMessageConfig) values() (url.Values, error) {
1040 v := url.Values{}
1041
1042 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1043 v.Add("message_id", strconv.Itoa(config.MessageID))
1044
1045 return v, nil
1046}
1047
1048// PinChatMessageConfig contains information of a message in a chat to pin.
1049type PinChatMessageConfig struct {
1050 ChatID int64
1051 MessageID int
1052 DisableNotification bool
1053}
1054
1055func (config PinChatMessageConfig) method() string {
1056 return "pinChatMessage"
1057}
1058
1059func (config PinChatMessageConfig) values() (url.Values, error) {
1060 v := url.Values{}
1061
1062 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1063 v.Add("message_id", strconv.Itoa(config.MessageID))
1064 v.Add("disable_notification", strconv.FormatBool(config.DisableNotification))
1065
1066 return v, nil
1067}
1068
1069// UnpinChatMessageConfig contains information of chat to unpin.
1070type UnpinChatMessageConfig struct {
1071 ChatID int64
1072}
1073
1074func (config UnpinChatMessageConfig) method() string {
1075 return "unpinChatMessage"
1076}
1077
1078func (config UnpinChatMessageConfig) values() (url.Values, error) {
1079 v := url.Values{}
1080
1081 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1082
1083 return v, nil
1084}
1085
1086// SetChatTitleConfig contains information for change chat title.
1087type SetChatTitleConfig struct {
1088 ChatID int64
1089 Title string
1090}
1091
1092func (config SetChatTitleConfig) method() string {
1093 return "setChatTitle"
1094}
1095
1096func (config SetChatTitleConfig) values() (url.Values, error) {
1097 v := url.Values{}
1098
1099 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1100 v.Add("title", config.Title)
1101
1102 return v, nil
1103}
1104
1105// SetChatDescriptionConfig contains information for change chat description.
1106type SetChatDescriptionConfig struct {
1107 ChatID int64
1108 Description string
1109}
1110
1111func (config SetChatDescriptionConfig) method() string {
1112 return "setChatDescription"
1113}
1114
1115func (config SetChatDescriptionConfig) values() (url.Values, error) {
1116 v := url.Values{}
1117
1118 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1119 v.Add("description", config.Description)
1120
1121 return v, nil
1122}
1123
1124// SetChatPhotoConfig contains information for change chat photo
1125type SetChatPhotoConfig struct {
1126 BaseFile
1127}
1128
1129// name returns the field name for the Photo.
1130func (config SetChatPhotoConfig) name() string {
1131 return "photo"
1132}
1133
1134// method returns Telegram API method name for sending Photo.
1135func (config SetChatPhotoConfig) method() string {
1136 return "setChatPhoto"
1137}
1138
1139// DeleteChatPhotoConfig contains information for delete chat photo.
1140type DeleteChatPhotoConfig struct {
1141 ChatID int64
1142}
1143
1144func (config DeleteChatPhotoConfig) method() string {
1145 return "deleteChatPhoto"
1146}
1147
1148func (config DeleteChatPhotoConfig) values() (url.Values, error) {
1149 v := url.Values{}
1150
1151 v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
1152
1153 return v, nil
1154}