From 67c5217394180c54527b5fc2a756dac724f9ed04 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Sun, 26 Jul 2020 23:07:24 -0500 Subject: [PATCH 1/8] Attempt to use GitHub Actions. --- .github/workflows/test.yml | 28 ++++++++++++++++++++++++++++ .travis.yml | 6 ------ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..fc48c2f --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Test + +on: [push, pull_request] + +jobs: + build: + name: Test + runs-on: ubuntu-latest + steps: + - name: Set up Go 1.x + uses: actions/setup-go@v2 + with: + go-version: ^1.14 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Build + run: go build -v . + + - name: Test + run: go test -coverprofile=coverage.out -covermode=atomic -v . + + - name: Upload coverage report + uses: codecov/codecov-action@v1 + with: + file: ./coverage.out diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 712ce95..0000000 --- a/.travis.yml +++ /dev/null @@ -1,6 +0,0 @@ -language: go - -go: - - '1.13' - - '1.14' - - tip From e6e2a9f3ef2b66d3edaa3719146477442c65f97e Mon Sep 17 00:00:00 2001 From: Syfaro Date: Thu, 5 Nov 2020 13:48:39 -0500 Subject: [PATCH 2/8] Update Go version, fix duplicate runs. --- .github/workflows/test.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc48c2f..48b2859 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,6 +1,11 @@ name: Test -on: [push, pull_request] +on: + push: + branches: + - master + - develop + pull_request: jobs: build: @@ -10,7 +15,7 @@ jobs: - name: Set up Go 1.x uses: actions/setup-go@v2 with: - go-version: ^1.14 + go-version: ^1.15 id: go - name: Check out code into the Go module directory From b52a9399c92a1a24fc855d079b382aab6ec7884d Mon Sep 17 00:00:00 2001 From: Syfaro Date: Thu, 5 Nov 2020 13:58:19 -0500 Subject: [PATCH 3/8] Fix Imgur issue. --- bot_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bot_test.go b/bot_test.go index 3229a8e..b490d8d 100644 --- a/bot_test.go +++ b/bot_test.go @@ -526,9 +526,8 @@ func TestSendWithMediaGroup(t *testing.T) { bot, _ := getBot(t) cfg := NewMediaGroup(ChatID, []interface{}{ - NewInputMediaPhoto("https://i.imgur.com/unQLJIb.jpg"), - NewInputMediaPhoto("https://i.imgur.com/J5qweNZ.jpg"), - NewInputMediaVideo("https://i.imgur.com/F6RmI24.mp4"), + NewInputMediaPhoto("https://github.com/go-telegram-bot-api/telegram-bot-api/raw/0a3a1c8716c4cd8d26a262af9f12dcbab7f3f28c/tests/image.jpg"), + NewInputMediaVideo("https://github.com/go-telegram-bot-api/telegram-bot-api/raw/0a3a1c8716c4cd8d26a262af9f12dcbab7f3f28c/tests/video.mp4"), }) messages, err := bot.SendMediaGroup(cfg) @@ -540,7 +539,7 @@ func TestSendWithMediaGroup(t *testing.T) { t.Error() } - if len(messages) != 3 { + if len(messages) != 2 { t.Error() } } From ac5306ce0c6d68946d7d5a029c0338e758b5fc96 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Thu, 5 Nov 2020 16:53:37 -0500 Subject: [PATCH 4/8] Updates for Bot API 5.0. --- bot_test.go | 8 +- configs.go | 245 ++++++++++++++++++++++++++++++++++++++++---------- types.go | 244 +++++++++++++++++++++++++++++++------------------ types_test.go | 2 +- 4 files changed, 358 insertions(+), 141 deletions(-) diff --git a/bot_test.go b/bot_test.go index b490d8d..db0c335 100644 --- a/bot_test.go +++ b/bot_test.go @@ -477,7 +477,7 @@ func TestSetWebhookWithCert(t *testing.T) { time.Sleep(time.Second * 2) - bot.Request(RemoveWebhookConfig{}) + bot.Request(DeleteWebhookConfig{}) wh := NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, "tests/cert.pem") _, err := bot.Request(wh) @@ -491,7 +491,7 @@ func TestSetWebhookWithCert(t *testing.T) { t.Error(err) } - bot.Request(RemoveWebhookConfig{}) + bot.Request(DeleteWebhookConfig{}) } func TestSetWebhookWithoutCert(t *testing.T) { @@ -499,7 +499,7 @@ func TestSetWebhookWithoutCert(t *testing.T) { time.Sleep(time.Second * 2) - bot.Request(RemoveWebhookConfig{}) + bot.Request(DeleteWebhookConfig{}) wh := NewWebhook("https://example.com/tgbotapi-test/" + bot.Token) _, err := bot.Request(wh) @@ -519,7 +519,7 @@ func TestSetWebhookWithoutCert(t *testing.T) { t.Errorf("failed to set webhook: %s", info.LastErrorMessage) } - bot.Request(RemoveWebhookConfig{}) + bot.Request(DeleteWebhookConfig{}) } func TestSendWithMediaGroup(t *testing.T) { diff --git a/configs.go b/configs.go index 939522b..bd07203 100644 --- a/configs.go +++ b/configs.go @@ -63,13 +63,41 @@ type Fileable interface { useExistingFile() bool } +// LogOutConfig is a request to log out of the cloud Bot API server. +// +// Note that you may not log back in for at least 10 minutes. +type LogOutConfig struct{} + +func (LogOutConfig) method() string { + return "logOut" +} + +func (LogOutConfig) params() (Params, error) { + return nil, nil +} + +// CloseConfig is a request to close the bot instance on a local server. +// +// Note that you may not close an instance for the first 10 minutes after the +// bot has started. +type CloseConfig struct{} + +func (CloseConfig) method() string { + return "close" +} + +func (CloseConfig) params() (Params, error) { + return nil, nil +} + // BaseChat is base type for all chat config types. type BaseChat struct { - ChatID int64 // required - ChannelUsername string - ReplyToMessageID int - ReplyMarkup interface{} - DisableNotification bool + ChatID int64 // required + ChannelUsername string + ReplyToMessageID int + ReplyMarkup interface{} + DisableNotification bool + AllowSendingWithoutReply bool } func (chat *BaseChat) params() (Params, error) { @@ -78,6 +106,7 @@ func (chat *BaseChat) params() (Params, error) { params.AddFirstValid("chat_id", chat.ChatID, chat.ChannelUsername) params.AddNonZero("reply_to_message_id", chat.ReplyToMessageID) params.AddBool("disable_notification", chat.DisableNotification) + params.AddBool("allow_sending_without_reply", chat.AllowSendingWithoutReply) err := params.AddInterface("reply_markup", chat.ReplyMarkup) @@ -140,6 +169,7 @@ type MessageConfig struct { BaseChat Text string ParseMode string + Entities []MessageEntity DisableWebPagePreview bool } @@ -152,8 +182,9 @@ func (config MessageConfig) params() (Params, error) { params.AddNonEmpty("text", config.Text) params.AddBool("disable_web_page_preview", config.DisableWebPagePreview) params.AddNonEmpty("parse_mode", config.ParseMode) + err = params.AddInterface("entities", config.Entities) - return params, nil + return params, err } func (config MessageConfig) method() string { @@ -184,19 +215,50 @@ func (config ForwardConfig) method() string { return "forwardMessage" } +// CopyMessageConfig contains information about a copyMessage request. +type CopyMessageConfig struct { + BaseChat + FromChatID int64 + FromChannelUsername string + MessageID int + Caption string + ParseMode string + CaptionEntities []MessageEntity +} + +func (config CopyMessageConfig) params() (Params, error) { + params, err := config.BaseChat.params() + if err != nil { + return params, err + } + + params.AddFirstValid("from_chat_id", config.FromChatID, config.FromChannelUsername) + params.AddNonZero("message_id", config.MessageID) + params.AddNonEmpty("caption", config.Caption) + params.AddNonEmpty("parse_mode", config.ParseMode) + err = params.AddInterface("caption_entities", config.CaptionEntities) + + return params, err +} + // PhotoConfig contains information about a SendPhoto request. type PhotoConfig struct { BaseFile - Caption string - ParseMode string + Caption string + ParseMode string + CaptionEntities []MessageEntity } func (config PhotoConfig) params() (Params, error) { params, err := config.BaseFile.params() + if err != nil { + return params, err + } params.AddNonEmpty(config.name(), config.FileID) params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("parse_mode", config.ParseMode) + err = params.AddInterface("caption_entities", config.CaptionEntities) return params, err } @@ -212,11 +274,12 @@ func (config PhotoConfig) method() string { // AudioConfig contains information about a SendAudio request. type AudioConfig struct { BaseFile - Caption string - ParseMode string - Duration int - Performer string - Title string + Caption string + ParseMode string + CaptionEntities []MessageEntity + Duration int + Performer string + Title string } func (config AudioConfig) params() (Params, error) { @@ -231,8 +294,9 @@ func (config AudioConfig) params() (Params, error) { params.AddNonEmpty("title", config.Title) params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("parse_mode", config.ParseMode) + err = params.AddInterface("caption_entities", config.CaptionEntities) - return params, nil + return params, err } func (config AudioConfig) name() string { @@ -246,8 +310,10 @@ func (config AudioConfig) method() string { // DocumentConfig contains information about a SendDocument request. type DocumentConfig struct { BaseFile - Caption string - ParseMode string + Caption string + ParseMode string + CaptionEntities []MessageEntity + DisableContentTypeDetection bool } func (config DocumentConfig) params() (Params, error) { @@ -256,6 +322,7 @@ func (config DocumentConfig) params() (Params, error) { params.AddNonEmpty(config.name(), config.FileID) params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("parse_mode", config.ParseMode) + params.AddBool("disable_content_type_detection", config.DisableContentTypeDetection) return params, err } @@ -295,17 +362,22 @@ type VideoConfig struct { Duration int Caption string ParseMode string + CaptionEntities []MessageEntity SupportsStreaming bool } func (config VideoConfig) params() (Params, error) { params, err := config.BaseChat.params() + if err != nil { + return params, err + } params.AddNonEmpty(config.name(), config.FileID) params.AddNonZero("duration", config.Duration) params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("parse_mode", config.ParseMode) params.AddBool("supports_streaming", config.SupportsStreaming) + err = params.AddInterface("caption_entities", config.CaptionEntities) return params, err } @@ -321,18 +393,23 @@ func (config VideoConfig) method() string { // AnimationConfig contains information about a SendAnimation request. type AnimationConfig struct { BaseFile - Duration int - Caption string - ParseMode string + Duration int + Caption string + ParseMode string + CaptionEntities []MessageEntity } func (config AnimationConfig) params() (Params, error) { params, err := config.BaseChat.params() + if err != nil { + return params, err + } params.AddNonEmpty(config.name(), config.FileID) params.AddNonZero("duration", config.Duration) params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("parse_mode", config.ParseMode) + err = params.AddInterface("caption_entities", config.CaptionEntities) return params, err } @@ -373,18 +450,23 @@ func (config VideoNoteConfig) method() string { // VoiceConfig contains information about a SendVoice request. type VoiceConfig struct { BaseFile - Caption string - ParseMode string - Duration int + Caption string + ParseMode string + CaptionEntities []MessageEntity + Duration int } func (config VoiceConfig) params() (Params, error) { params, err := config.BaseChat.params() + if err != nil { + return params, err + } params.AddNonEmpty(config.name(), config.FileID) params.AddNonZero("duration", config.Duration) params.AddNonEmpty("caption", config.Caption) params.AddNonEmpty("parse_mode", config.ParseMode) + err = params.AddInterface("caption_entities", config.CaptionEntities) return params, err } @@ -400,9 +482,12 @@ func (config VoiceConfig) method() string { // LocationConfig contains information about a SendLocation request. type LocationConfig struct { BaseChat - Latitude float64 // required - Longitude float64 // required - LivePeriod int // optional + Latitude float64 // required + Longitude float64 // required + HorizontalAccuracy float64 // optional + LivePeriod int // optional + Heading int // optional + ProximityAlertRadius int // optional } func (config LocationConfig) params() (Params, error) { @@ -410,7 +495,10 @@ func (config LocationConfig) params() (Params, error) { params.AddNonZeroFloat("latitude", config.Latitude) params.AddNonZeroFloat("longitude", config.Longitude) + params.AddNonZeroFloat("horizontal_accuracy", config.HorizontalAccuracy) params.AddNonZero("live_period", config.LivePeriod) + params.AddNonZero("heading", config.Heading) + params.AddNonZero("proximity_alert_radius", config.ProximityAlertRadius) return params, err } @@ -422,8 +510,11 @@ func (config LocationConfig) method() string { // EditMessageLiveLocationConfig allows you to update a live location. type EditMessageLiveLocationConfig struct { BaseEdit - Latitude float64 // required - Longitude float64 // required + Latitude float64 // required + Longitude float64 // required + HorizontalAccuracy float64 // optional + Heading int // optional + ProximityAlertRadius int // optional } func (config EditMessageLiveLocationConfig) params() (Params, error) { @@ -431,6 +522,9 @@ func (config EditMessageLiveLocationConfig) params() (Params, error) { params.AddNonZeroFloat("latitude", config.Latitude) params.AddNonZeroFloat("longitude", config.Longitude) + params.AddNonZeroFloat("horizontal_accuracy", config.HorizontalAccuracy) + params.AddNonZero("heading", config.Heading) + params.AddNonZero("proximity_alert_radius", config.ProximityAlertRadius) return params, err } @@ -455,11 +549,14 @@ func (config StopMessageLiveLocationConfig) method() string { // VenueConfig contains information about a SendVenue request. type VenueConfig struct { BaseChat - Latitude float64 // required - Longitude float64 // required - Title string // required - Address string // required - FoursquareID string + Latitude float64 // required + Longitude float64 // required + Title string // required + Address string // required + FoursquareID string + FoursquareType string + GooglePlaceID string + GooglePlaceType string } func (config VenueConfig) params() (Params, error) { @@ -470,6 +567,9 @@ func (config VenueConfig) params() (Params, error) { params["title"] = config.Title params["address"] = config.Address params.AddNonEmpty("foursquare_id", config.FoursquareID) + params.AddNonEmpty("foursquare_type", config.FoursquareType) + params.AddNonEmpty("google_place_id", config.GooglePlaceID) + params.AddNonEmpty("google_place_type", config.GooglePlaceType) return params, err } @@ -514,6 +614,7 @@ type SendPollConfig struct { CorrectOptionID int64 Explanation string ExplanationParseMode string + ExplanationEntities []MessageEntity OpenPeriod int CloseDate int IsClosed bool @@ -526,7 +627,9 @@ func (config SendPollConfig) params() (Params, error) { } params["question"] = config.Question - err = params.AddInterface("options", config.Options) + if err = params.AddInterface("options", config.Options); err != nil { + return params, err + } params["is_anonymous"] = strconv.FormatBool(config.IsAnonymous) params.AddNonEmpty("type", config.Type) params["allows_multiple_answers"] = strconv.FormatBool(config.AllowsMultipleAnswers) @@ -536,6 +639,7 @@ func (config SendPollConfig) params() (Params, error) { params.AddNonEmpty("explanation_parse_mode", config.ExplanationParseMode) params.AddNonZero("open_period", config.OpenPeriod) params.AddNonZero("close_date", config.CloseDate) + err = params.AddInterface("explanation_entities", config.ExplanationEntities) return params, err } @@ -646,15 +750,20 @@ type EditMessageTextConfig struct { BaseEdit Text string ParseMode string + Entities []MessageEntity DisableWebPagePreview bool } func (config EditMessageTextConfig) params() (Params, error) { params, err := config.BaseEdit.params() + if err != nil { + return params, err + } params["text"] = config.Text params.AddNonEmpty("parse_mode", config.ParseMode) params.AddBool("disable_web_page_preview", config.DisableWebPagePreview) + err = params.AddInterface("entities", config.Entities) return params, err } @@ -666,15 +775,20 @@ func (config EditMessageTextConfig) method() string { // EditMessageCaptionConfig allows you to modify the caption of a message. type EditMessageCaptionConfig struct { BaseEdit - Caption string - ParseMode string + Caption string + ParseMode string + CaptionEntities []MessageEntity } func (config EditMessageCaptionConfig) params() (Params, error) { params, err := config.BaseEdit.params() + if err != nil { + return params, err + } params["caption"] = config.Caption params.AddNonEmpty("parse_mode", config.ParseMode) + err = params.AddInterface("caption_entities", config.CaptionEntities) return params, err } @@ -791,10 +905,12 @@ func (config UpdateConfig) params() (Params, error) { // WebhookConfig contains information about a SetWebhook request. type WebhookConfig struct { - URL *url.URL - Certificate interface{} - MaxConnections int - AllowedUpdates []string + URL *url.URL + Certificate interface{} + IPAddress string + MaxConnections int + AllowedUpdates []string + DropPendingUpdates bool } func (config WebhookConfig) method() string { @@ -808,8 +924,10 @@ func (config WebhookConfig) params() (Params, error) { params["url"] = config.URL.String() } + params.AddNonEmpty("ip_address", config.IPAddress) params.AddNonZero("max_connections", config.MaxConnections) params.AddInterface("allowed_updates", config.AllowedUpdates) + params.AddBool("drop_pending_updates", config.DropPendingUpdates) return params, nil } @@ -826,16 +944,21 @@ func (config WebhookConfig) useExistingFile() bool { return config.URL != nil } -// RemoveWebhookConfig is a helper to remove a webhook. -type RemoveWebhookConfig struct { +// DeleteWebhookConfig is a helper to delete a webhook. +type DeleteWebhookConfig struct { + DropPendingUpdates bool } -func (config RemoveWebhookConfig) method() string { - return "setWebhook" +func (config DeleteWebhookConfig) method() string { + return "deleteWebhook" } -func (config RemoveWebhookConfig) params() (Params, error) { - return nil, nil +func (config DeleteWebhookConfig) params() (Params, error) { + params := make(Params) + + params.AddBool("drop_pending_updates", config.DropPendingUpdates) + + return params, nil } // FileBytes contains information about a set of bytes to upload @@ -923,6 +1046,7 @@ type ChatMemberConfig struct { // UnbanChatMemberConfig allows you to unban a user. type UnbanChatMemberConfig struct { ChatMemberConfig + OnlyIfBanned bool } func (config UnbanChatMemberConfig) method() string { @@ -934,6 +1058,7 @@ func (config UnbanChatMemberConfig) params() (Params, error) { params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) params.AddNonZero("user_id", config.UserID) + params.AddBool("only_if_banned", config.OnlyIfBanned) return params, nil } @@ -986,6 +1111,7 @@ func (config RestrictChatMemberConfig) params() (Params, error) { // PromoteChatMemberConfig contains fields to promote members of chat type PromoteChatMemberConfig struct { ChatMemberConfig + IsAnonymous bool CanChangeInfo bool CanPostMessages bool CanEditMessages bool @@ -1006,6 +1132,7 @@ func (config PromoteChatMemberConfig) params() (Params, error) { params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) params.AddNonZero("user_id", config.UserID) + params.AddBool("is_anonymous", config.IsAnonymous) params.AddBool("can_change_info", config.CanChangeInfo) params.AddBool("can_post_messages", config.CanPostMessages) params.AddBool("can_edit_messages", config.CanEditMessages) @@ -1281,10 +1408,13 @@ func (config PinChatMessageConfig) params() (Params, error) { return params, nil } -// UnpinChatMessageConfig contains information of chat to unpin. +// UnpinChatMessageConfig contains information of a chat message to unpin. +// +// If MessageID is not specified, it will unpin the most recent pin. type UnpinChatMessageConfig struct { ChatID int64 ChannelUsername string + MessageID int } func (config UnpinChatMessageConfig) method() string { @@ -1294,6 +1424,26 @@ func (config UnpinChatMessageConfig) method() string { func (config UnpinChatMessageConfig) params() (Params, error) { params := make(Params) + params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + params.AddNonZero("message_id", config.MessageID) + + return params, nil +} + +// UnpinAllChatMessagesConfig contains information of all messages to unpin in +// a chat. +type UnpinAllChatMessagesConfig struct { + ChatID int64 + ChannelUsername string +} + +func (config UnpinAllChatMessagesConfig) method() string { + return "unpinAllChatMessages" +} + +func (config UnpinAllChatMessagesConfig) params() (Params, error) { + params := make(Params) + params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) return params, nil @@ -1680,7 +1830,8 @@ func (config MediaGroupConfig) params() (Params, error) { // DiceConfig allows you to send a random dice roll to Telegram. // -// Emoji may be one of the following: 🎲 (1-6), 🎯 (1-6), πŸ€ (1-5). +// Emoji may be one of the following: 🎲 (1-6), 🎯 (1-6), πŸ€ (1-5), ⚽ (1-5), +// 🎰 (1-64). type DiceConfig struct { BaseChat diff --git a/types.go b/types.go index 95a871d..6e74d1a 100644 --- a/types.go +++ b/types.go @@ -121,6 +121,7 @@ type Chat struct { LastName string `json:"last_name,omitempty"` // optional AllMembersAreAdmins bool `json:"all_members_are_administrators,omitempty"` // deprecated, optional Photo *ChatPhoto `json:"photo,omitempty"` // optional + Bio string `json:"bio,omitempty"` // optional Description string `json:"description,omitempty"` // optional InviteLink string `json:"invite_link,omitempty"` // optional PinnedMessage *Message `json:"pinned_message,omitempty"` // optional @@ -128,6 +129,8 @@ type Chat struct { SlowModeDelay int `json:"slow_mode_delay,omitempty"` // optional StickerSetName string `json:"sticker_set_name,omitempty"` // optional CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` // optional + LinkedChatID int `json:"linked_chat_id,omitempty"` // optional + Location *ChatLocation `json:"location"` // optional } // IsPrivate returns if the Chat is a private conversation. @@ -158,55 +161,57 @@ func (c Chat) ChatConfig() ChatConfig { // Message is returned by almost every request, and contains data about // almost anything. type Message struct { - MessageID int `json:"message_id"` - From *User `json:"from,omitempty"` // optional - Date int `json:"date"` - Chat *Chat `json:"chat"` - ForwardFrom *User `json:"forward_from,omitempty"` // optional - ForwardFromChat *Chat `json:"forward_from_chat,omitempty"` // optional - ForwardFromMessageID int `json:"forward_from_message_id,omitempty"` // optional - ForwardSignature string `json:"forward_signature,omitempty"` // optional - ForwardSenderName string `json:"forward_sender_name,omitempty"` // optional - ForwardDate int `json:"forward_date,omitempty"` // optional - ReplyToMessage *Message `json:"reply_to_message,omitempty"` // optional - ViaBot *User `json:"via_bot"` // optional - EditDate int `json:"edit_date,omitempty"` // optional - MediaGroupID string `json:"media_group_id,omitempty"` // optional - AuthorSignature string `json:"author_signature,omitempty"` // optional - Text string `json:"text,omitempty"` // optional - Entities []MessageEntity `json:"entities,omitempty"` // optional - CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` // optional - Audio *Audio `json:"audio,omitempty"` // optional - Document *Document `json:"document,omitempty"` // optional - Animation *ChatAnimation `json:"animation,omitempty"` // optional - Game *Game `json:"game,omitempty"` // optional - Photo []PhotoSize `json:"photo,omitempty"` // optional - Sticker *Sticker `json:"sticker,omitempty"` // optional - Video *Video `json:"video,omitempty"` // optional - VideoNote *VideoNote `json:"video_note,omitempty"` // optional - Voice *Voice `json:"voice,omitempty"` // optional - Caption string `json:"caption,omitempty"` // optional - Contact *Contact `json:"contact,omitempty"` // optional - Location *Location `json:"location,omitempty"` // optional - Venue *Venue `json:"venue,omitempty"` // optional - Poll *Poll `json:"poll,omitempty"` // optional - Dice *Dice `json:"dice,omitempty"` // optional - NewChatMembers []User `json:"new_chat_members,omitempty"` // optional - LeftChatMember *User `json:"left_chat_member,omitempty"` // optional - NewChatTitle string `json:"new_chat_title,omitempty"` // optional - NewChatPhoto []PhotoSize `json:"new_chat_photo,omitempty"` // optional - DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"` // optional - GroupChatCreated bool `json:"group_chat_created,omitempty"` // optional - SuperGroupChatCreated bool `json:"supergroup_chat_created,omitempty"` // optional - ChannelChatCreated bool `json:"channel_chat_created,omitempty"` // optional - MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` // optional - MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"` // optional - PinnedMessage *Message `json:"pinned_message,omitempty"` // optional - Invoice *Invoice `json:"invoice,omitempty"` // optional - SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"` // optional - ConnectedWebsite string `json:"connected_website,omitempty"` // optional - PassportData *PassportData `json:"passport_data,omitempty"` // optional - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // optional + MessageID int `json:"message_id"` + From *User `json:"from,omitempty"` // optional + SenderChat *Chat `json:"sender_chat,omitempty"` // optional + Date int `json:"date"` + Chat *Chat `json:"chat"` + ForwardFrom *User `json:"forward_from,omitempty"` // optional + ForwardFromChat *Chat `json:"forward_from_chat,omitempty"` // optional + ForwardFromMessageID int `json:"forward_from_message_id,omitempty"` // optional + ForwardSignature string `json:"forward_signature,omitempty"` // optional + ForwardSenderName string `json:"forward_sender_name,omitempty"` // optional + ForwardDate int `json:"forward_date,omitempty"` // optional + ReplyToMessage *Message `json:"reply_to_message,omitempty"` // optional + ViaBot *User `json:"via_bot"` // optional + EditDate int `json:"edit_date,omitempty"` // optional + MediaGroupID string `json:"media_group_id,omitempty"` // optional + AuthorSignature string `json:"author_signature,omitempty"` // optional + Text string `json:"text,omitempty"` // optional + Entities []MessageEntity `json:"entities,omitempty"` // optional + Audio *Audio `json:"audio,omitempty"` // optional + Document *Document `json:"document,omitempty"` // optional + Animation *ChatAnimation `json:"animation,omitempty"` // optional + Photo []PhotoSize `json:"photo,omitempty"` // optional + Sticker *Sticker `json:"sticker,omitempty"` // optional + Video *Video `json:"video,omitempty"` // optional + VideoNote *VideoNote `json:"video_note,omitempty"` // optional + Voice *Voice `json:"voice,omitempty"` // optional + Caption string `json:"caption,omitempty"` // optional + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` // optional + Contact *Contact `json:"contact,omitempty"` // optional + Dice *Dice `json:"dice,omitempty"` // optional + Game *Game `json:"game,omitempty"` // optional + Poll *Poll `json:"poll,omitempty"` // optional + Venue *Venue `json:"venue,omitempty"` // optional + Location *Location `json:"location,omitempty"` // optional + NewChatMembers []User `json:"new_chat_members,omitempty"` // optional + LeftChatMember *User `json:"left_chat_member,omitempty"` // optional + NewChatTitle string `json:"new_chat_title,omitempty"` // optional + NewChatPhoto []PhotoSize `json:"new_chat_photo,omitempty"` // optional + DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"` // optional + GroupChatCreated bool `json:"group_chat_created,omitempty"` // optional + SuperGroupChatCreated bool `json:"supergroup_chat_created,omitempty"` // optional + ChannelChatCreated bool `json:"channel_chat_created,omitempty"` // optional + MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` // optional + MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"` // optional + PinnedMessage *Message `json:"pinned_message,omitempty"` // optional + Invoice *Invoice `json:"invoice,omitempty"` // optional + SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"` // optional + ConnectedWebsite string `json:"connected_website,omitempty"` // optional + PassportData *PassportData `json:"passport_data,omitempty"` // optional + ProximityAlertTriggered *ProximityAlertTriggered `json:"proximity_alert_triggered"` // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // optional } // Time converts the message timestamp into a Time. @@ -363,6 +368,7 @@ type Audio struct { Duration int `json:"duration"` Performer string `json:"performer,omitempty"` // optional Title string `json:"title,omitempty"` // optional + FileName string `json:"file_name,omitempty"` // optional MimeType string `json:"mime_type,omitempty"` // optional FileSize int `json:"file_size,omitempty"` // optional } @@ -427,6 +433,7 @@ type Video struct { Height int `json:"height"` Duration int `json:"duration"` Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional + FileName string `json:"file_name,omitempty"` // optional MimeType string `json:"mime_type,omitempty"` // optional FileSize int `json:"file_size,omitempty"` // optional } @@ -463,16 +470,23 @@ type Contact struct { // Location contains information about a place. type Location struct { - Longitude float64 `json:"longitude"` - Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + Latitude float64 `json:"latitude"` + HorizontalAccuracy float64 `json:"horizontal_accuracy"` // optional + LivePeriod int `json:"live_period"` // optional + Heading int `json:"heading"` // optional + ProximityAlertRadius int `json:"proximity_alert_radius"` // optional } // Venue contains information about a venue, including its Location. type Venue struct { - Location Location `json:"location"` - Title string `json:"title"` - Address string `json:"address"` - FoursquareID string `json:"foursquare_id,omitempty"` // optional + Location Location `json:"location"` + Title string `json:"title"` + Address string `json:"address"` + FoursquareID string `json:"foursquare_id,omitempty"` // optional + FoursquareType string `json:"foursquare_type,omitempty"` // optional + GooglePlaceID string `json:"google_place_id,omitempty"` // optional + GooglePlaceType string `json:"google_place_type,omitempty"` // optional } // PollOption contains information about one answer option in a poll. @@ -510,6 +524,14 @@ type Dice struct { Value int `json:"value"` } +// ProximityAlertTriggered represents a service message sent when a user in the +// chat triggers a proximity alert sent by another user. +type ProximityAlertTriggered struct { + Traveler User `json:"traveler"` + Watcher User `json:"watcher"` + Distance int `json:"distance"` +} + // UserProfilePhotos contains a set of user profile photos. type UserProfilePhotos struct { TotalCount int `json:"total_count"` @@ -620,6 +642,7 @@ type ChatMember struct { User *User `json:"user"` Status string `json:"status"` CustomTitle string `json:"custom_title,omitempty"` // optional + IsAnonymous bool `json:"is_anonymous"` // optional UntilDate int64 `json:"until_date,omitempty"` // optional CanBeEdited bool `json:"can_be_edited,omitempty"` // optional CanPostMessages bool `json:"can_post_messages,omitempty"` // optional @@ -685,12 +708,14 @@ type CallbackGame struct{} // WebhookInfo is information about a currently set webhook. type WebhookInfo struct { - URL string `json:"url"` - HasCustomCertificate bool `json:"has_custom_certificate"` - PendingUpdateCount int `json:"pending_update_count"` - LastErrorDate int `json:"last_error_date"` // optional - LastErrorMessage string `json:"last_error_message"` // optional - MaxConnections int `json:"max_connections"` // optional + URL string `json:"url"` + HasCustomCertificate bool `json:"has_custom_certificate"` + PendingUpdateCount int `json:"pending_update_count"` + IPAddress string `json:"ip_address"` // optional + LastErrorDate int `json:"last_error_date"` // optional + LastErrorMessage string `json:"last_error_message"` // optional + MaxConnections int `json:"max_connections"` // optional + AllowedUpdates []string `json:"allowed_updates"` // optional } // IsSet returns true if a webhook is currently set. @@ -734,6 +759,8 @@ type InlineQueryResultPhoto struct { Title string `json:"title"` Description string `json:"description"` Caption string `json:"caption"` + ParseMode string `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -747,6 +774,7 @@ type InlineQueryResultCachedPhoto struct { Description string `json:"description"` Caption string `json:"caption"` ParseMode string `json:"parse_mode"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -763,6 +791,8 @@ type InlineQueryResultGIF struct { Duration int `json:"gif_duration,omitempty"` Title string `json:"title,omitempty"` Caption string `json:"caption,omitempty"` + ParseMode string `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -776,6 +806,7 @@ type InlineQueryResultCachedGIF struct { Caption string `json:"caption"` ParseMode string `json:"parse_mode"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -791,6 +822,8 @@ type InlineQueryResultMPEG4GIF struct { ThumbMimeType string `json:"thumb_mime_type"` Title string `json:"title"` Caption string `json:"caption"` + ParseMode string `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -804,6 +837,7 @@ type InlineQueryResultCachedMpeg4Gif struct { Title string `json:"title"` Caption string `json:"caption"` ParseMode string `json:"parse_mode"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -817,6 +851,8 @@ type InlineQueryResultVideo struct { ThumbURL string `json:"thumb_url"` Title string `json:"title"` Caption string `json:"caption"` + ParseMode string `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` Width int `json:"video_width"` Height int `json:"video_height"` Duration int `json:"video_duration"` @@ -834,6 +870,7 @@ type InlineQueryResultCachedVideo struct { Description string `json:"description"` Caption string `json:"caption"` ParseMode string `json:"parse_mode"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -844,7 +881,6 @@ type InlineQueryResultCachedSticker struct { ID string `json:"id"` // required StickerID string `json:"sticker_file_id"` // required Title string `json:"title"` // required - ParseMode string `json:"parse_mode"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -856,6 +892,8 @@ type InlineQueryResultAudio struct { URL string `json:"audio_url"` // required Title string `json:"title"` // required Caption string `json:"caption"` + ParseMode string `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` Performer string `json:"performer"` Duration int `json:"audio_duration"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` @@ -869,6 +907,7 @@ type InlineQueryResultCachedAudio struct { AudioID string `json:"audio_file_id"` // required Caption string `json:"caption"` ParseMode string `json:"parse_mode"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -880,6 +919,8 @@ type InlineQueryResultVoice struct { URL string `json:"voice_url"` // required Title string `json:"title"` // required Caption string `json:"caption"` + ParseMode string `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` Duration int `json:"voice_duration"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` @@ -893,6 +934,7 @@ type InlineQueryResultCachedVoice struct { Title string `json:"title"` // required Caption string `json:"caption"` ParseMode string `json:"parse_mode"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } @@ -903,6 +945,8 @@ type InlineQueryResultDocument struct { ID string `json:"id"` // required Title string `json:"title"` // required Caption string `json:"caption"` + ParseMode string `json:"parse_mode,omitempty"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` URL string `json:"document_url"` // required MimeType string `json:"mime_type"` // required Description string `json:"description"` @@ -922,23 +966,27 @@ type InlineQueryResultCachedDocument struct { Caption string `json:"caption"` Description string `json:"description"` ParseMode string `json:"parse_mode"` + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` } // InlineQueryResultLocation is an inline query response location. type InlineQueryResultLocation struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - Latitude float64 `json:"latitude"` // required - Longitude float64 `json:"longitude"` // required - LivePeriod int `json:"live_period"` // optional - Title string `json:"title"` // required - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` - ThumbURL string `json:"thumb_url"` - ThumbWidth int `json:"thumb_width"` - ThumbHeight int `json:"thumb_height"` + Type string `json:"type"` // required + ID string `json:"id"` // required + Latitude float64 `json:"latitude"` // required + Longitude float64 `json:"longitude"` // required + LivePeriod int `json:"live_period"` // optional + Title string `json:"title"` // required + HorizontalAccuracy float64 `json:"horizontal_accuracy,omitempty"` + Heading int `json:"heading"` + ProximityAlertRadius int `json:"proximity_alert_radius"` + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + InputMessageContent interface{} `json:"input_message_content,omitempty"` + ThumbURL string `json:"thumb_url"` + ThumbWidth int `json:"thumb_width"` + ThumbHeight int `json:"thumb_height"` } // InlineQueryResultContact is an inline query response contact. @@ -964,8 +1012,10 @@ type InlineQueryResultVenue struct { Longitude float64 `json:"longitude"` // required Title string `json:"title"` // required Address string `json:"address"` // required - FoursquareID string `json:"foursquare_id"` - FoursquareType string `json:"foursquare_type"` + FoursquareID string `json:"foursquare_id,omitempty"` + FoursquareType string `json:"foursquare_type,omitempty"` + GooglePlaceID string `json:"google_place_id,omitempty"` + GooglePlaceType string `json:"google_place_type,omitempty"` ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` InputMessageContent interface{} `json:"input_message_content,omitempty"` ThumbURL string `json:"thumb_url"` @@ -993,26 +1043,34 @@ type ChosenInlineResult struct { // InputTextMessageContent contains text for displaying // as an inline query result. type InputTextMessageContent struct { - Text string `json:"message_text"` - ParseMode string `json:"parse_mode"` - DisableWebPagePreview bool `json:"disable_web_page_preview"` + Text string `json:"message_text"` + ParseMode string `json:"parse_mode"` + Entities []MessageEntity `json:"entities,omitempty"` + DisableWebPagePreview bool `json:"disable_web_page_preview"` } // InputLocationMessageContent contains a location for displaying // as an inline query result. type InputLocationMessageContent struct { - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + HorizontalAccuracy float64 `json:"horizontal_accuracy"` + LivePeriod int `json:"live_period"` + Heading int `json:"heading"` + ProximityAlertRadius int `json:"proximity_alert_radius"` } // InputVenueMessageContent contains a venue for displaying // as an inline query result. type InputVenueMessageContent struct { - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` - Title string `json:"title"` - Address string `json:"address"` - FoursquareID string `json:"foursquare_id"` + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` + Title string `json:"title"` + Address string `json:"address"` + FoursquareID string `json:"foursquare_id"` + FoursquareType string `json:"foursquare_type"` + GooglePlaceID string `json:"google_place_id"` + GooglePlaceType string `json:"google_place_type"` } // InputContactMessageContent contains a contact for displaying @@ -1104,6 +1162,12 @@ type StickerSet struct { Thumb *PhotoSize `json:"thumb"` } +// ChatLocation represents a location to which a chat is connected. +type ChatLocation struct { + Location Location `json:"location"` + Address string `json:"address"` +} + // BotCommand represents Telegram's understanding of a command. type BotCommand struct { Command string `json:"command"` @@ -1112,10 +1176,11 @@ type BotCommand struct { // BaseInputMedia is a base type for the InputMedia types. type BaseInputMedia struct { - Type string `json:"type"` - Media string `json:"media"` - Caption string `json:"caption"` - ParseMode string `json:"parse_mode"` + Type string `json:"type"` + Media string `json:"media"` + Caption string `json:"caption"` + ParseMode string `json:"parse_mode"` + CaptionEntities []MessageEntity `json:"caption_entities"` } // InputMediaPhoto is a photo to send as part of a media group. @@ -1151,6 +1216,7 @@ type InputMediaAudio struct { // InputMediaDocument is a audio to send as part of a media group. type InputMediaDocument struct { BaseInputMedia + DisableContentTypeDetection bool `json:"disable_content_type_detection,omitempty"` } // Error is an error containing extra information returned by the Telegram API. diff --git a/types_test.go b/types_test.go index 401cb6a..afe1fa0 100644 --- a/types_test.go +++ b/types_test.go @@ -311,7 +311,7 @@ var ( _ Chattable = PhotoConfig{} _ Chattable = PinChatMessageConfig{} _ Chattable = PromoteChatMemberConfig{} - _ Chattable = RemoveWebhookConfig{} + _ Chattable = DeleteWebhookConfig{} _ Chattable = RestrictChatMemberConfig{} _ Chattable = SendPollConfig{} _ Chattable = SetChatDescriptionConfig{} From 366879b110471d989da64a46eb02ae12dd618082 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Thu, 5 Nov 2020 23:29:48 -0500 Subject: [PATCH 5/8] Merge branch 'master' into develop --- README.md | 2 +- bot.go | 53 +- bot_test.go | 48 +- configs.go | 102 +- helpers.go | 38 +- helpers_test.go | 18 + types.go | 3026 ++++++++++++++++++++++++++++++++++++----------- types_test.go | 2 + 8 files changed, 2494 insertions(+), 795 deletions(-) diff --git a/README.md b/README.md index 02cab2d..536077f 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![GoDoc](https://godoc.org/github.com/go-telegram-bot-api/telegram-bot-api?status.svg)](http://godoc.org/github.com/go-telegram-bot-api/telegram-bot-api) [![Travis](https://travis-ci.org/go-telegram-bot-api/telegram-bot-api.svg)](https://travis-ci.org/go-telegram-bot-api/telegram-bot-api) -All methods are fairly self explanatory, and reading the godoc page should +All methods are fairly self explanatory, and reading the [godoc](http://godoc.org/github.com/go-telegram-bot-api/telegram-bot-api) page should explain everything. If something isn't clear, open an issue or submit a pull request. diff --git a/bot.go b/bot.go index b028f9d..a78e635 100644 --- a/bot.go +++ b/bot.go @@ -18,14 +18,20 @@ import ( "github.com/technoweenie/multipartstreamer" ) +// HTTPClient is the type needed for the bot to perform HTTP requests. +type HTTPClient interface { + Do(req *http.Request) (*http.Response, error) + PostForm(url string, data url.Values) (*http.Response, error) +} + // BotAPI allows you to interact with the Telegram Bot API. type BotAPI struct { Token string `json:"token"` Debug bool `json:"debug"` Buffer int `json:"buffer"` - Self User `json:"-"` - Client *http.Client `json:"-"` + Self User `json:"-"` + Client HTTPClient `json:"-"` shutdownChannel chan interface{} apiEndpoint string @@ -35,21 +41,29 @@ type BotAPI struct { // // It requires a token, provided by @BotFather on Telegram. func NewBotAPI(token string) (*BotAPI, error) { - return NewBotAPIWithClient(token, &http.Client{}) + return NewBotAPIWithClient(token, APIEndpoint, &http.Client{}) +} + +// NewBotAPIWithAPIEndpoint creates a new BotAPI instance +// and allows you to pass API endpoint. +// +// It requires a token, provided by @BotFather on Telegram and API endpoint. +func NewBotAPIWithAPIEndpoint(token, apiEndpoint string) (*BotAPI, error) { + return NewBotAPIWithClient(token, apiEndpoint, &http.Client{}) } // NewBotAPIWithClient creates a new BotAPI instance // and allows you to pass a http.Client. // -// It requires a token, provided by @BotFather on Telegram. -func NewBotAPIWithClient(token string, client *http.Client) (*BotAPI, error) { +// It requires a token, provided by @BotFather on Telegram and API endpoint. +func NewBotAPIWithClient(token, apiEndpoint string, client HTTPClient) (*BotAPI, error) { bot := &BotAPI{ Token: token, Client: client, Buffer: 100, shutdownChannel: make(chan interface{}), - apiEndpoint: APIEndpoint, + apiEndpoint: apiEndpoint, } self, err := bot.GetMe() @@ -413,6 +427,7 @@ func (bot *BotAPI) GetUpdatesChan(config UpdateConfig) UpdatesChannel { for { select { case <-bot.shutdownChannel: + close(ch) return default: } @@ -451,21 +466,35 @@ func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel { ch := make(chan Update, bot.Buffer) http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) { - ch <- bot.HandleUpdate(w, r) + update, err := bot.HandleUpdate(r) + if err != nil { + errMsg, _ := json.Marshal(map[string]string{"error": err.Error()}) + w.WriteHeader(http.StatusBadRequest) + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write(errMsg) + return + } + + ch <- *update }) return ch } // HandleUpdate parses and returns update received via webhook -func (bot *BotAPI) HandleUpdate(res http.ResponseWriter, req *http.Request) Update { - bytes, _ := ioutil.ReadAll(req.Body) - req.Body.Close() +func (bot *BotAPI) HandleUpdate(r *http.Request) (*Update, error) { + if r.Method != http.MethodPost { + err := errors.New("wrong HTTP method required POST") + return nil, err + } var update Update - json.Unmarshal(bytes, &update) + err := json.NewDecoder(r.Body).Decode(&update) + if err != nil { + return nil, err + } - return update + return &update, nil } // WriteToHTTPResponse writes the request to the HTTP ResponseWriter. diff --git a/bot_test.go b/bot_test.go index b490d8d..013baf5 100644 --- a/bot_test.go +++ b/bot_test.go @@ -23,10 +23,25 @@ const ( ExistingStickerFileID = "BQADAgADcwADjMcoCbdl-6eB--YPAg" ) +type testLogger struct { + t *testing.T +} + +func (t testLogger) Println(v ...interface{}) { + t.t.Log(v...) +} + +func (t testLogger) Printf(format string, v ...interface{}) { + t.t.Logf(format, v...) +} + func getBot(t *testing.T) (*BotAPI, error) { bot, err := NewBotAPI(TestToken) bot.Debug = true + logger := testLogger{t} + SetLogger(logger) + if err != nil { t.Error(err) } @@ -417,6 +432,32 @@ func TestSendWithExistingStickerAndKeyboardHide(t *testing.T) { } } +func TestSendWithDice(t *testing.T) { + bot, _ := getBot(t) + + msg := NewDice(ChatID) + _, err := bot.Send(msg) + + if err != nil { + t.Error(err) + t.Fail() + } + +} + +func TestSendWithDiceWithEmoji(t *testing.T) { + bot, _ := getBot(t) + + msg := NewDiceWithEmoji(ChatID, "πŸ€") + _, err := bot.Send(msg) + + if err != nil { + t.Error(err) + t.Fail() + } + +} + func TestGetFile(t *testing.T) { bot, _ := getBot(t) @@ -634,7 +675,12 @@ func ExampleWebhookHandler() { } http.HandleFunc("/"+bot.Token, func(w http.ResponseWriter, r *http.Request) { - log.Printf("%+v\n", bot.HandleUpdate(w, r)) + update, err := bot.HandleUpdate(r) + if err != nil { + log.Printf("%+v\n", err.Error()) + } else { + log.Printf("%+v\n", *update) + } }) go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) diff --git a/configs.go b/configs.go index 939522b..9427554 100644 --- a/configs.go +++ b/configs.go @@ -831,7 +831,7 @@ type RemoveWebhookConfig struct { } func (config RemoveWebhookConfig) method() string { - return "setWebhook" + return "deleteWebhook" } func (config RemoveWebhookConfig) params() (Params, error) { @@ -878,12 +878,9 @@ func (config InlineConfig) params() (Params, error) { params.AddNonEmpty("next_offset", config.NextOffset) params.AddNonEmpty("switch_pm_text", config.SwitchPMText) params.AddNonEmpty("switch_pm_parameter", config.SwitchPMParameter) + err := params.AddInterface("results", config.Results) - if err := params.AddInterface("results", config.Results); err != nil { - return params, err - } - - return params, nil + return params, err } // CallbackConfig contains information on making a CallbackQuery response. @@ -975,12 +972,10 @@ func (config RestrictChatMemberConfig) params() (Params, error) { params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) params.AddNonZero("user_id", config.UserID) - if err := params.AddInterface("permissions", config.Permissions); err != nil { - return params, err - } + err := params.AddInterface("permissions", config.Permissions) params.AddNonZero64("until_date", config.UntilDate) - return params, nil + return params, err } // PromoteChatMemberConfig contains fields to promote members of chat @@ -1200,10 +1195,7 @@ func (config InvoiceConfig) params() (Params, error) { params["start_parameter"] = config.StartParameter params["currency"] = config.Currency - if err = params.AddInterface("prices", config.Prices); err != nil { - return params, err - } - + err = params.AddInterface("prices", config.Prices) params.AddNonEmpty("provider_data", config.ProviderData) params.AddNonEmpty("photo_url", config.PhotoURL) params.AddNonZero("photo_size", config.PhotoSize) @@ -1217,7 +1209,7 @@ func (config InvoiceConfig) params() (Params, error) { params.AddBool("send_phone_number_to_provider", config.SendPhoneNumberToProvider) params.AddBool("send_email_to_provider", config.SendEmailToProvider) - return params, nil + return params, err } func (config InvoiceConfig) method() string { @@ -1232,6 +1224,21 @@ type ShippingConfig struct { ErrorMessage string } +func (config ShippingConfig) method() string { + return "answerShippingQuery" +} + +func (config ShippingConfig) params() (Params, error) { + params := make(Params) + + params["shipping_query_id"] = config.ShippingQueryID + params.AddBool("ok", config.OK) + err := params.AddInterface("shipping_options", config.ShippingOptions) + params.AddNonEmpty("error_message", config.ErrorMessage) + + return params, err +} + // PreCheckoutConfig conatins information for answerPreCheckoutQuery request. type PreCheckoutConfig struct { PreCheckoutQueryID string // required @@ -1239,6 +1246,20 @@ type PreCheckoutConfig struct { ErrorMessage string } +func (config PreCheckoutConfig) method() string { + return "answerPreCheckoutQuery" +} + +func (config PreCheckoutConfig) params() (Params, error) { + params := make(Params) + + params["pre_checkout_query_id"] = config.PreCheckoutQueryID + params.AddBool("ok", config.OK) + params.AddNonEmpty("error_message", config.ErrorMessage) + + return params, nil +} + // DeleteMessageConfig contains information of a message in a chat to delete. type DeleteMessageConfig struct { ChannelUsername string @@ -1678,30 +1699,6 @@ func (config MediaGroupConfig) params() (Params, error) { return params, nil } -// DiceConfig allows you to send a random dice roll to Telegram. -// -// Emoji may be one of the following: 🎲 (1-6), 🎯 (1-6), πŸ€ (1-5). -type DiceConfig struct { - BaseChat - - Emoji string -} - -func (config DiceConfig) method() string { - return "sendDice" -} - -func (config DiceConfig) params() (Params, error) { - params, err := config.BaseChat.params() - if err != nil { - return params, err - } - - params.AddNonEmpty("emoji", config.Emoji) - - return params, err -} - // GetMyCommandsConfig gets a list of the currently registered commands. type GetMyCommandsConfig struct{} @@ -1710,7 +1707,7 @@ func (config GetMyCommandsConfig) method() string { } func (config GetMyCommandsConfig) params() (Params, error) { - return make(Params), nil + return nil, nil } // SetMyCommandsConfig sets a list of commands the bot understands. @@ -1729,3 +1726,28 @@ func (config SetMyCommandsConfig) params() (Params, error) { return params, err } + +// DiceConfig contains information about a sendDice request. +type DiceConfig struct { + BaseChat + // Emoji on which the dice throw animation is based. + // Currently, must be one of β€œπŸŽ²β€, β€œπŸŽ―β€, or β€œπŸ€β€. + // Dice can have values 1-6 for β€œπŸŽ²β€ and β€œπŸŽ―β€, and values 1-5 for β€œπŸ€β€. + // Defaults to β€œπŸŽ²β€ + Emoji string +} + +func (config DiceConfig) method() string { + return "sendDice" +} + +func (config DiceConfig) params() (Params, error) { + params, err := config.BaseChat.params() + if err != nil { + return params, err + } + + params.AddNonEmpty("emoji", config.Emoji) + + return params, err +} diff --git a/helpers.go b/helpers.go index 1e95367..cd61a94 100644 --- a/helpers.go +++ b/helpers.go @@ -29,7 +29,8 @@ func NewDeleteMessage(chatID int64, messageID int) DeleteMessageConfig { // NewMessageToChannel creates a new Message that is sent to a channel // by username. // -// username is the username of the channel, text is the message text. +// username is the username of the channel, text is the message text, +// and the username should be in the form of `@username`. func NewMessageToChannel(username string, text string) MessageConfig { return MessageConfig{ BaseChat: BaseChat{ @@ -540,12 +541,12 @@ func NewInlineQueryResultMPEG4GIF(id, url string) InlineQueryResultMPEG4GIF { } } -// NewInlineQueryResultCachedMPEG4GIF create a new inline query with cached photo. -func NewInlineQueryResultCachedMPEG4GIF(id, MPEG4GifID string) InlineQueryResultCachedMpeg4Gif { - return InlineQueryResultCachedMpeg4Gif{ - Type: "mpeg4_gif", - ID: id, - MGifID: MPEG4GifID, +// NewInlineQueryResultCachedMPEG4GIF create a new inline query with cached MPEG4 GIF. +func NewInlineQueryResultCachedMPEG4GIF(id, MPEG4GifID string) InlineQueryResultCachedMPEG4GIF { + return InlineQueryResultCachedMPEG4GIF{ + Type: "mpeg4_gif", + ID: id, + MPEG4FileID: MPEG4GifID, } } @@ -700,6 +701,18 @@ func NewEditMessageText(chatID int64, messageID int, text string) EditMessageTex } } +// NewEditMessageTextAndMarkup allows you to edit the text and replymarkup of a message. +func NewEditMessageTextAndMarkup(chatID int64, messageID int, text string, replyMarkup InlineKeyboardMarkup) EditMessageTextConfig { + return EditMessageTextConfig{ + BaseEdit: BaseEdit{ + ChatID: chatID, + MessageID: messageID, + ReplyMarkup: &replyMarkup, + }, + Text: text, + } +} + // NewEditMessageCaption allows you to edit the caption of a message. func NewEditMessageCaption(chatID int64, messageID int, caption string) EditMessageCaptionConfig { return EditMessageCaptionConfig{ @@ -723,17 +736,6 @@ func NewEditMessageReplyMarkup(chatID int64, messageID int, replyMarkup InlineKe } } -// NewHideKeyboard hides the keyboard, with the option for being selective -// or hiding for everyone. -func NewHideKeyboard(selective bool) ReplyKeyboardHide { - log.Println("NewHideKeyboard is deprecated, please use NewRemoveKeyboard") - - return ReplyKeyboardHide{ - HideKeyboard: true, - Selective: selective, - } -} - // NewRemoveKeyboard hides the keyboard, with the option for being selective // or hiding for everyone. func NewRemoveKeyboard(selective bool) ReplyKeyboardRemove { diff --git a/helpers_test.go b/helpers_test.go index 2fc678c..9a712dc 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -174,3 +174,21 @@ func TestNewEditMessageReplyMarkup(t *testing.T) { } } + +func TestNewDice(t *testing.T) { + dice := NewDice(42) + + if dice.ChatID != 42 || + dice.Emoji != "" { + t.Fail() + } +} + +func TestNewDiceWithEmoji(t *testing.T) { + dice := NewDiceWithEmoji(42, "πŸ€") + + if dice.ChatID != 42 || + dice.Emoji != "πŸ€" { + t.Fail() + } +} diff --git a/types.go b/types.go index 95a871d..19fb01e 100644 --- a/types.go +++ b/types.go @@ -19,26 +19,83 @@ type APIResponse struct { Parameters *ResponseParameters `json:"parameters,omitempty"` } -// ResponseParameters are various errors that can be returned in APIResponse. -type ResponseParameters struct { - MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` // optional - RetryAfter int `json:"retry_after,omitempty"` // optional +// Error is an error containing extra information returned by the Telegram API. +type Error struct { + Code int + Message string + ResponseParameters +} + +// Error message string. +func (e Error) Error() string { + return e.Message } // Update is an update response, from GetUpdates. type Update struct { - UpdateID int `json:"update_id"` - Message *Message `json:"message,omitempty"` - EditedMessage *Message `json:"edited_message,omitempty"` - ChannelPost *Message `json:"channel_post,omitempty"` - EditedChannelPost *Message `json:"edited_channel_post,omitempty"` - InlineQuery *InlineQuery `json:"inline_query,omitempty"` + // UpdateID is the update's unique identifier. + // Update identifiers start from a certain positive number and increase + // sequentially. + // This ID becomes especially handy if you're using Webhooks, + // since it allows you to ignore repeated updates or to restore + // the correct update sequence, should they get out of order. + // If there are no new updates for at least a week, then identifier + // of the next update will be chosen randomly instead of sequentially. + UpdateID int `json:"update_id"` + // Message new incoming message of any kind β€” text, photo, sticker, etc. + // + // optional + Message *Message `json:"message,omitempty"` + // EditedMessage new version of a message that is known to the bot and was + // edited + // + // optional + EditedMessage *Message `json:"edited_message,omitempty"` + // ChannelPost new version of a message that is known to the bot and was + // edited + // + // optional + ChannelPost *Message `json:"channel_post,omitempty"` + // EditedChannelPost new incoming channel post of any kind β€” text, photo, + // sticker, etc. + // + // optional + EditedChannelPost *Message `json:"edited_channel_post,omitempty"` + // InlineQuery new incoming inline query + // + // optional + InlineQuery *InlineQuery `json:"inline_query,omitempty"` + // ChosenInlineResult is the result of an inline query + // that was chosen by a user and sent to their chat partner. + // Please see our documentation on the feedback collecting + // for details on how to enable these updates for your bot. + // + // optional ChosenInlineResult *ChosenInlineResult `json:"chosen_inline_result,omitempty"` - CallbackQuery *CallbackQuery `json:"callback_query,omitempty"` - ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"` - PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"` - Poll *Poll `json:"poll,omitempty"` - PollAnswer *PollAnswer `json:"poll_answer,omitempty"` + // CallbackQuery new incoming callback query + // + // optional + CallbackQuery *CallbackQuery `json:"callback_query,omitempty"` + // ShippingQuery new incoming shipping query. Only for invoices with + // flexible price + // + // optional + ShippingQuery *ShippingQuery `json:"shipping_query,omitempty"` + // PreCheckoutQuery new incoming pre-checkout query. Contains full + // information about checkout + // + // optional + PreCheckoutQuery *PreCheckoutQuery `json:"pre_checkout_query,omitempty"` + // Pool new poll state. Bots receive only updates about stopped polls and + // polls, which are sent by the bot + // + // optional + Poll *Poll `json:"poll,omitempty"` + // PollAnswer user changed their answer in a non-anonymous poll. Bots + // receive new votes only in polls that were sent by the bot itself. + // + // optional + PollAnswer *PollAnswer `json:"poll_answer,omitempty"` } // UpdatesChannel is the channel for getting updates. @@ -51,17 +108,44 @@ func (ch UpdatesChannel) Clear() { } } -// User is a user on Telegram. +// User represents a Telegram user or bot. type User struct { - ID int `json:"id"` - FirstName string `json:"first_name"` - LastName string `json:"last_name,omitempty"` // optional - UserName string `json:"username,omitempty"` // optional - LanguageCode string `json:"language_code,omitempty"` // optional - IsBot bool `json:"is_bot,omitempty"` // optional - CanJoinGroups bool `json:"can_join_groups,omitempty"` // optional - CanReadAllGroupMessages bool `json:"can_read_all_group_messages,omitempty"` // optional - SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"` // optional + // ID is a unique identifier for this user or bot + ID int `json:"id"` + // IsBot true, if this user is a bot + // + // optional + IsBot bool `json:"is_bot,omitempty"` + // FirstName user's or bot's first name + FirstName string `json:"first_name"` + // LastName user's or bot's last name + // + // optional + LastName string `json:"last_name,omitempty"` + // UserName user's or bot's username + // + // optional + UserName string `json:"username,omitempty"` + // LanguageCode IETF language tag of the user's language + // more info: https://en.wikipedia.org/wiki/IETF_language_tag + // + // optional + LanguageCode string `json:"language_code,omitempty"` + // CanJoinGroups is true, if the bot can be invited to groups. + // Returned only in getMe. + // + // optional + CanJoinGroups bool `json:"can_join_groups,omitempty"` + // CanReadAllGroupMessages is true, if privacy mode is disabled for the bot. + // Returned only in getMe. + // + // optional + CanReadAllGroupMessages bool `json:"can_read_all_group_messages,omitempty"` + // SupportsInlineQueries is true, if the bot supports inline queries. + // Returned only in getMe. + // + // optional + SupportsInlineQueries bool `json:"supports_inline_queries,omitempty"` } // String displays a simple text version of a user. @@ -90,44 +174,65 @@ type GroupChat struct { Title string `json:"title"` } -// ChatPhoto represents a chat photo. -type ChatPhoto struct { - SmallFileID string `json:"small_file_id"` - SmallFileUniqueID string `json:"small_file_unique_id"` - BigFileID string `json:"big_file_id"` - BigFileUniqueID string `json:"big_file_unique_id"` -} - -// ChatPermissions describes actions that a non-administrator user is -// allowed to take in a chat. All fields are optional. -type ChatPermissions struct { - CanSendMessages bool `json:"can_send_messages"` - CanSendMediaMessages bool `json:"can_send_media_messages"` - CanSendPolls bool `json:"can_send_polls"` - CanSendOtherMessages bool `json:"can_send_other_messages"` - CanAddWebPagePreviews bool `json:"can_add_web_page_previews"` - CanChangeInfo bool `json:"can_change_info"` - CanInviteUsers bool `json:"can_invite_users"` - CanPinMessages bool `json:"can_pin_messages"` -} - -// Chat contains information about the place a message was sent. +// Chat represents a chat. type Chat struct { - ID int64 `json:"id"` - Type string `json:"type"` - Title string `json:"title,omitempty"` // optional - UserName string `json:"username,omitempty"` // optional - FirstName string `json:"first_name,omitempty"` // optional - LastName string `json:"last_name,omitempty"` // optional - AllMembersAreAdmins bool `json:"all_members_are_administrators,omitempty"` // deprecated, optional - Photo *ChatPhoto `json:"photo,omitempty"` // optional - Description string `json:"description,omitempty"` // optional - InviteLink string `json:"invite_link,omitempty"` // optional - PinnedMessage *Message `json:"pinned_message,omitempty"` // optional - Permissions *ChatPermissions `json:"permissions,omitempty"` // optional - SlowModeDelay int `json:"slow_mode_delay,omitempty"` // optional - StickerSetName string `json:"sticker_set_name,omitempty"` // optional - CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` // optional + // ID is a unique identifier for this chat + ID int64 `json:"id"` + // Type of chat, can be either β€œprivate”, β€œgroup”, β€œsupergroup” or β€œchannel” + Type string `json:"type"` + // Title for supergroups, channels and group chats + // + // optional + Title string `json:"title,omitempty"` + // UserName for private chats, supergroups and channels if available + // + // optional + UserName string `json:"username,omitempty"` + // FirstName of the other party in a private chat + // + // optional + FirstName string `json:"first_name,omitempty"` + // LastName of the other party in a private chat + // + // optional + LastName string `json:"last_name,omitempty"` + // Photo is a chat photo + Photo *ChatPhoto `json:"photo"` + // Description for groups, supergroups and channel chats + // + // optional + Description string `json:"description,omitempty"` + // InviteLink is a chat invite link, for groups, supergroups and channel chats. + // Each administrator in a chat generates their own invite links, + // so the bot must first generate the link using exportChatInviteLink + // + // optional + InviteLink string `json:"invite_link,omitempty"` + // PinnedMessage is the pinned message, for groups, supergroups and channels + // + // optional + PinnedMessage *Message `json:"pinned_message,omitempty"` + // Permissions is default chat member permissions, for groups and + // supergroups. Returned only in getChat. + // + // optional + Permissions *ChatPermissions `json:"permissions,omitempty"` + // SlowModeDelay is for supergroups, the minimum allowed delay between + // consecutive messages sent by each unpriviledged user. Returned only in + // getChat. + // + // optional + SlowModeDelay int `json:"slow_mode_delay,omitempty"` + // StickerSetName is for supergroups, name of group sticker set.Returned + // only in getChat. + // + // optional + StickerSetName string `json:"sticker_set_name,omitempty"` + // CanSetStickerSet is true, if the bot can change the group sticker set. + // Returned only in getChat. + // + // optional + CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` } // IsPrivate returns if the Chat is a private conversation. @@ -155,58 +260,231 @@ func (c Chat) ChatConfig() ChatConfig { return ChatConfig{ChatID: c.ID} } -// Message is returned by almost every request, and contains data about -// almost anything. +// Message represents a message. type Message struct { - MessageID int `json:"message_id"` - From *User `json:"from,omitempty"` // optional - Date int `json:"date"` - Chat *Chat `json:"chat"` - ForwardFrom *User `json:"forward_from,omitempty"` // optional - ForwardFromChat *Chat `json:"forward_from_chat,omitempty"` // optional - ForwardFromMessageID int `json:"forward_from_message_id,omitempty"` // optional - ForwardSignature string `json:"forward_signature,omitempty"` // optional - ForwardSenderName string `json:"forward_sender_name,omitempty"` // optional - ForwardDate int `json:"forward_date,omitempty"` // optional - ReplyToMessage *Message `json:"reply_to_message,omitempty"` // optional - ViaBot *User `json:"via_bot"` // optional - EditDate int `json:"edit_date,omitempty"` // optional - MediaGroupID string `json:"media_group_id,omitempty"` // optional - AuthorSignature string `json:"author_signature,omitempty"` // optional - Text string `json:"text,omitempty"` // optional - Entities []MessageEntity `json:"entities,omitempty"` // optional - CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` // optional - Audio *Audio `json:"audio,omitempty"` // optional - Document *Document `json:"document,omitempty"` // optional - Animation *ChatAnimation `json:"animation,omitempty"` // optional - Game *Game `json:"game,omitempty"` // optional - Photo []PhotoSize `json:"photo,omitempty"` // optional - Sticker *Sticker `json:"sticker,omitempty"` // optional - Video *Video `json:"video,omitempty"` // optional - VideoNote *VideoNote `json:"video_note,omitempty"` // optional - Voice *Voice `json:"voice,omitempty"` // optional - Caption string `json:"caption,omitempty"` // optional - Contact *Contact `json:"contact,omitempty"` // optional - Location *Location `json:"location,omitempty"` // optional - Venue *Venue `json:"venue,omitempty"` // optional - Poll *Poll `json:"poll,omitempty"` // optional - Dice *Dice `json:"dice,omitempty"` // optional - NewChatMembers []User `json:"new_chat_members,omitempty"` // optional - LeftChatMember *User `json:"left_chat_member,omitempty"` // optional - NewChatTitle string `json:"new_chat_title,omitempty"` // optional - NewChatPhoto []PhotoSize `json:"new_chat_photo,omitempty"` // optional - DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"` // optional - GroupChatCreated bool `json:"group_chat_created,omitempty"` // optional - SuperGroupChatCreated bool `json:"supergroup_chat_created,omitempty"` // optional - ChannelChatCreated bool `json:"channel_chat_created,omitempty"` // optional - MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` // optional - MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"` // optional - PinnedMessage *Message `json:"pinned_message,omitempty"` // optional - Invoice *Invoice `json:"invoice,omitempty"` // optional - SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"` // optional - ConnectedWebsite string `json:"connected_website,omitempty"` // optional - PassportData *PassportData `json:"passport_data,omitempty"` // optional - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` // optional + // MessageID is a unique message identifier inside this chat + MessageID int `json:"message_id"` + // From is a sender, empty for messages sent to channels; + // + // optional + From *User `json:"from,omitempty"` + // Date of the message was sent in Unix time + Date int `json:"date"` + // Chat is the conversation the message belongs to + Chat *Chat `json:"chat"` + // ForwardFrom for forwarded messages, sender of the original message; + // + // optional + ForwardFrom *User `json:"forward_from,omitempty"` + // ForwardFromChat for messages forwarded from channels, + // information about the original channel; + // + // optional + ForwardFromChat *Chat `json:"forward_from_chat,omitempty"` + // ForwardFromMessageID for messages forwarded from channels, + // identifier of the original message in the channel; + // + // optional + ForwardFromMessageID int `json:"forward_from_message_id,omitempty"` + // ForwardSignature for messages forwarded from channels, signature of the + // post author if present + // + // optional + ForwardSignature string `json:"forward_signature,omitempty"` + // ForwardSenderName is the sender's name for messages forwarded from users + // who disallow adding a link to their account in forwarded messages + // + // optional + ForwardSenderName string `json:"forward_sender_name,omitempty"` + // ForwardDate for forwarded messages, date the original message was sent in Unix time; + // + // optional + ForwardDate int `json:"forward_date,omitempty"` + // ReplyToMessage for replies, the original message. + // Note that the Message object in this field will not contain further ReplyToMessage fields + // even if it itself is a reply; + // + // optional + ReplyToMessage *Message `json:"reply_to_message,omitempty"` + // ViaBot through which the message was sent; + // + // optional + ViaBot *User `json:"via_bot,omitempty"` + // EditDate of the message was last edited in Unix time; + // + // optional + EditDate int `json:"edit_date,omitempty"` + // MediaGroupID is the unique identifier of a media message group this message belongs to; + // + // optional + MediaGroupID string `json:"media_group_id,omitempty"` + // AuthorSignature is the signature of the post author for messages in channels; + // + // optional + AuthorSignature string `json:"author_signature,omitempty"` + // Text is for text messages, the actual UTF-8 text of the message, 0-4096 characters; + // + // optional + Text string `json:"text,omitempty"` + // Entities is for text messages, special entities like usernames, + // URLs, bot commands, etc. that appear in the text; + // + // optional + Entities []MessageEntity `json:"entities,omitempty"` + // Animation message is an animation, information about the animation. + // For backward compatibility, when this field is set, the document field will also be set; + // + // optional + Animation *Animation `json:"animation,omitempty"` + // Audio message is an audio file, information about the file; + // + // optional + Audio *Audio `json:"audio,omitempty"` + // Document message is a general file, information about the file; + // + // optional + Document *Document `json:"document,omitempty"` + // Photo message is a photo, available sizes of the photo; + // + // optional + Photo []PhotoSize `json:"photo,omitempty"` + // Sticker message is a sticker, information about the sticker; + // + // optional + Sticker *Sticker `json:"sticker,omitempty"` + // Video message is a video, information about the video; + // + // optional + Video *Video `json:"video,omitempty"` + // VideoNote message is a video note, information about the video message; + // + // optional + VideoNote *VideoNote `json:"video_note,omitempty"` + // Voice message is a voice message, information about the file; + // + // optional + Voice *Voice `json:"voice,omitempty"` + // Caption for the animation, audio, document, photo, video or voice, 0-1024 characters; + // + // optional + Caption string `json:"caption,omitempty"` + // CaptionEntities; + // + // optional + CaptionEntities []MessageEntity `json:"caption_entities,omitempty"` + // Contact message is a shared contact, information about the contact; + // + // optional + Contact *Contact `json:"contact,omitempty"` + // Dice is a dice with random value; + // + // optional + Dice *Dice `json:"dice,omitempty"` + // Game message is a game, information about the game; + // + // optional + Game *Game `json:"game,omitempty"` + // Poll is a native poll, information about the poll; + // + // optional + Poll *Poll `json:"poll,omitempty"` + // Venue message is a venue, information about the venue. + // For backward compatibility, when this field is set, the location field + // will also be set; + // + // optional + Venue *Venue `json:"venue,omitempty"` + // Location message is a shared location, information about the location; + // + // optional + Location *Location `json:"location,omitempty"` + // NewChatMembers that were added to the group or supergroup + // and information about them (the bot itself may be one of these members); + // + // optional + NewChatMembers []User `json:"new_chat_members,omitempty"` + // LeftChatMember is a member was removed from the group, + // information about them (this member may be the bot itself); + // + // optional + LeftChatMember *User `json:"left_chat_member,omitempty"` + // NewChatTitle is a chat title was changed to this value; + // + // optional + NewChatTitle string `json:"new_chat_title,omitempty"` + // NewChatPhoto is a chat photo was change to this value; + // + // optional + NewChatPhoto []PhotoSize `json:"new_chat_photo,omitempty"` + // DeleteChatPhoto is a service message: the chat photo was deleted; + // + // optional + DeleteChatPhoto bool `json:"delete_chat_photo,omitempty"` + // GroupChatCreated is a service message: the group has been created; + // + // optional + GroupChatCreated bool `json:"group_chat_created,omitempty"` + // SuperGroupChatCreated is a service message: the supergroup has been created. + // This field can't be received in a message coming through updates, + // because bot can't be a member of a supergroup when it is created. + // It can only be found in ReplyToMessage if someone replies to a very first message + // in a directly created supergroup; + // + // optional + SuperGroupChatCreated bool `json:"supergroup_chat_created,omitempty"` + // ChannelChatCreated is a service message: the channel has been created. + // This field can't be received in a message coming through updates, + // because bot can't be a member of a channel when it is created. + // It can only be found in ReplyToMessage + // if someone replies to a very first message in a channel; + // + // optional + ChannelChatCreated bool `json:"channel_chat_created,omitempty"` + // MigrateToChatID is the group has been migrated to a supergroup with the specified identifier. + // This number may be greater than 32 bits and some programming languages + // may have difficulty/silent defects in interpreting it. + // But it is smaller than 52 bits, so a signed 64 bit integer + // or double-precision float type are safe for storing this identifier; + // + // optional + MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` + // MigrateFromChatID is the supergroup has been migrated from a group with the specified identifier. + // This number may be greater than 32 bits and some programming languages + // may have difficulty/silent defects in interpreting it. + // But it is smaller than 52 bits, so a signed 64 bit integer + // or double-precision float type are safe for storing this identifier; + // + // optional + MigrateFromChatID int64 `json:"migrate_from_chat_id,omitempty"` + // PinnedMessage is a specified message was pinned. + // Note that the Message object in this field will not contain further ReplyToMessage + // fields even if it is itself a reply; + // + // optional + PinnedMessage *Message `json:"pinned_message,omitempty"` + // Invoice message is an invoice for a payment; + // + // optional + Invoice *Invoice `json:"invoice,omitempty"` + // SuccessfulPayment message is a service message about a successful payment, + // information about the payment; + // + // optional + SuccessfulPayment *SuccessfulPayment `json:"successful_payment,omitempty"` + // ConnectedWebsite is Tthe domain name of the website on which the user has + // logged in; + // + // optional + ConnectedWebsite string `json:"connected_website,omitempty"` + // PassportData is a Telegram Passport data; + // + // optional + PassportData *PassportData `json:"passport_data,omitempty"` + // ReplyMarkup is the Inline keyboard attached to the message. + // login_url buttons are represented as ordinary url buttons. + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` } // Time converts the message timestamp into a Time. @@ -278,14 +556,42 @@ func (m *Message) CommandArguments() string { return m.Text[entity.Length+1:] } -// MessageEntity contains information about data in a Message. +// MessageEntity represents one special entity in a text message. type MessageEntity struct { - Type string `json:"type"` - Offset int `json:"offset"` - Length int `json:"length"` - URL string `json:"url,omitempty"` // optional - User *User `json:"user,omitempty"` // optional - Language string `json:"language,omitempty"` // optional + // Type of the entity. + // Can be: + // β€œmention” (@username), + // β€œhashtag” (#hashtag), + // β€œcashtag” ($USD), + // β€œbot_command” (/start@jobs_bot), + // β€œurl” (https://telegram.org), + // β€œemail” (do-not-reply@telegram.org), + // β€œphone_number” (+1-212-555-0123), + // β€œbold” (bold text), + // β€œitalic” (italic text), + // β€œunderline” (underlined text), + // β€œstrikethrough” (strikethrough text), + // β€œcode” (monowidth string), + // β€œpre” (monowidth block), + // β€œtext_link” (for clickable text URLs), + // β€œtext_mention” (for users without usernames) + Type string `json:"type"` + // Offset in UTF-16 code units to the start of the entity + Offset int `json:"offset"` + // Length + Length int `json:"length"` + // URL for β€œtext_link” only, url that will be opened after user taps on the text + // + // optional + URL string `json:"url,omitempty"` + // User for β€œtext_mention” only, the mentioned user + // + // optional + User *User `json:"user,omitempty"` + // Language for β€œpre” only, the programming language of the entity text + // + // optional + Language string `json:"language,omitempty"` } // ParseURL attempts to parse a URL contained within a MessageEntity. @@ -347,295 +653,709 @@ func (e MessageEntity) IsTextLink() bool { return e.Type == "text_link" } -// PhotoSize contains information about photos. +// PhotoSize represents one size of a photo or a file / sticker thumbnail. type PhotoSize struct { - FileID string `json:"file_id"` + // FileID identifier for this file, which can be used to download or reuse + // the file + FileID string `json:"file_id"` + // FileUniqueID is the unique identifier for this file, which is supposed to + // be the same over time and for different bots. Can't be used to download + // or reuse the file. FileUniqueID string `json:"file_unique_id"` - Width int `json:"width"` - Height int `json:"height"` - FileSize int `json:"file_size,omitempty"` // optional + // Width photo width + Width int `json:"width"` + // Height photo height + Height int `json:"height"` + // FileSize file size + // + // optional + FileSize int `json:"file_size,omitempty"` } -// Audio contains information about audio. +// Animation represents an animation file. +type Animation struct { + // FileID odentifier for this file, which can be used to download or reuse + // the file + FileID string `json:"file_id"` + // FileUniqueID is the unique identifier for this file, which is supposed to + // be the same over time and for different bots. Can't be used to download + // or reuse the file. + FileUniqueID string `json:"file_unique_id"` + // Width video width as defined by sender + Width int `json:"width"` + // Height video height as defined by sender + Height int `json:"height"` + // Duration of the video in seconds as defined by sender + Duration int `json:"duration"` + // Thumbnail animation thumbnail as defined by sender + // + // optional + Thumbnail *PhotoSize `json:"thumb,omitempty"` + // FileName original animation filename as defined by sender + // + // optional + FileName string `json:"file_name,omitempty"` + // MimeType of the file as defined by sender + // + // optional + MimeType string `json:"mime_type,omitempty"` + // FileSize file size + // + // optional + FileSize int `json:"file_size,omitempty"` +} + +// Audio represents an audio file to be treated as music by the Telegram clients. type Audio struct { - FileID string `json:"file_id"` + // FileID is an identifier for this file, which can be used to download or + // reuse the file + FileID string `json:"file_id"` + // FileUniqueID is the unique identifier for this file, which is supposed to + // be the same over time and for different bots. Can't be used to download + // or reuse the file. FileUniqueID string `json:"file_unique_id"` - Duration int `json:"duration"` - Performer string `json:"performer,omitempty"` // optional - Title string `json:"title,omitempty"` // optional - MimeType string `json:"mime_type,omitempty"` // optional - FileSize int `json:"file_size,omitempty"` // optional + // Duration of the audio in seconds as defined by sender + Duration int `json:"duration"` + // Performer of the audio as defined by sender or by audio tags + // + // optional + Performer string `json:"performer,omitempty"` + // Title of the audio as defined by sender or by audio tags + // + // optional + Title string `json:"title,omitempty"` + // MimeType of the file as defined by sender + // + // optional + MimeType string `json:"mime_type,omitempty"` + // FileSize file size + // + // optional + FileSize int `json:"file_size,omitempty"` + // Thumbnail is the album cover to which the music file belongs + // + // optional + Thumbnail *PhotoSize `json:"thumb,omitempty"` } -// Document contains information about a document. +// Document represents a general file. type Document struct { - FileID string `json:"file_id"` - FileUniqueID string `json:"file_unique_id"` - Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional - FileName string `json:"file_name,omitempty"` // optional - MimeType string `json:"mime_type,omitempty"` // optional - FileSize int `json:"file_size,omitempty"` // optional -} - -// Sticker contains information about a sticker. -type Sticker struct { - FileID string `json:"file_id"` - FileUniqueID string `json:"file_unique_id"` - Width int `json:"width"` - Height int `json:"height"` - IsAnimated bool `json:"is_animated"` - Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional - Emoji string `json:"emoji,omitempty"` // optional - SetName string `json:"set_name,omitempty"` // optional - MaskPosition MaskPosition `json:"mask_position,omitempty"` //optional - FileSize int `json:"file_size,omitempty"` // optional -} - -// MaskPosition is the position of a mask. -type MaskPosition struct { - Point string `json:"point"` - XShift float32 `json:"x_shift"` - YShift float32 `json:"y_shift"` - Scale float32 `json:"scale"` - FileID string `json:"file_id"` - Width int `json:"width"` - Height int `json:"height"` - Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional - Emoji string `json:"emoji,omitempty"` // optional - FileSize int `json:"file_size,omitempty"` // optional - SetName string `json:"set_name,omitempty"` // optional -} - -// ChatAnimation contains information about an animation. -type ChatAnimation struct { - FileID string `json:"file_id"` - FileUniqueID string `json:"file_unique_id"` - Width int `json:"width"` - Height int `json:"height"` - Duration int `json:"duration"` - Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional - FileName string `json:"file_name,omitempty"` // optional - MimeType string `json:"mime_type,omitempty"` // optional - FileSize int `json:"file_size,omitempty"` // optional -} - -// Video contains information about a video. -type Video struct { - FileID string `json:"file_id"` - FileUniqueID string `json:"file_unique_id"` - Width int `json:"width"` - Height int `json:"height"` - Duration int `json:"duration"` - Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional - MimeType string `json:"mime_type,omitempty"` // optional - FileSize int `json:"file_size,omitempty"` // optional -} - -// VideoNote contains information about a video. -type VideoNote struct { - FileID string `json:"file_id"` - FileUniqueID string `json:"file_unique_id"` - Length int `json:"length"` - Duration int `json:"duration"` - Thumbnail *PhotoSize `json:"thumb,omitempty"` // optional - FileSize int `json:"file_size,omitempty"` // optional -} - -// Voice contains information about a voice. -type Voice struct { - FileID string `json:"file_id"` + // FileID is a identifier for this file, which can be used to download or + // reuse the file + FileID string `json:"file_id"` + // FileUniqueID is the unique identifier for this file, which is supposed to + // be the same over time and for different bots. Can't be used to download + // or reuse the file. FileUniqueID string `json:"file_unique_id"` - Duration int `json:"duration"` - MimeType string `json:"mime_type,omitempty"` // optional - FileSize int `json:"file_size,omitempty"` // optional + // Thumbnail document thumbnail as defined by sender + // + // optional + Thumbnail *PhotoSize `json:"thumb,omitempty"` + // FileName original filename as defined by sender + // + // optional + FileName string `json:"file_name,omitempty"` + // MimeType of the file as defined by sender + // + // optional + MimeType string `json:"mime_type,omitempty"` + // FileSize file size + // + // optional + FileSize int `json:"file_size,omitempty"` } -// Contact contains information about a contact. +// Video represents a video file. +type Video struct { + // FileID identifier for this file, which can be used to download or reuse + // the file + FileID string `json:"file_id"` + // FileUniqueID is the unique identifier for this file, which is supposed to + // be the same over time and for different bots. Can't be used to download + // or reuse the file. + FileUniqueID string `json:"file_unique_id"` + // Width video width as defined by sender + Width int `json:"width"` + // Height video height as defined by sender + Height int `json:"height"` + // Duration of the video in seconds as defined by sender + Duration int `json:"duration"` + // Thumbnail video thumbnail + // + // optional + Thumbnail *PhotoSize `json:"thumb,omitempty"` + // MimeType of a file as defined by sender + // + // optional + MimeType string `json:"mime_type,omitempty"` + // FileSize file size + // + // optional + FileSize int `json:"file_size,omitempty"` +} + +// VideoNote object represents a video message. +type VideoNote struct { + // FileID identifier for this file, which can be used to download or reuse the file + FileID string `json:"file_id"` + // FileUniqueID is the unique identifier for this file, which is supposed to + // be the same over time and for different bots. Can't be used to download + // or reuse the file. + FileUniqueID string `json:"file_unique_id"` + // Length video width and height (diameter of the video message) as defined by sender + Length int `json:"length"` + // Duration of the video in seconds as defined by sender + Duration int `json:"duration"` + // Thumbnail video thumbnail + // + // optional + Thumbnail *PhotoSize `json:"thumb,omitempty"` + // FileSize file size + // + // optional + FileSize int `json:"file_size,omitempty"` +} + +// Voice represents a voice note. +type Voice struct { + // FileID identifier for this file, which can be used to download or reuse the file + FileID string `json:"file_id"` + // FileUniqueID is the unique identifier for this file, which is supposed to + // be the same over time and for different bots. Can't be used to download + // or reuse the file. + FileUniqueID string `json:"file_unique_id"` + // Duration of the audio in seconds as defined by sender + Duration int `json:"duration"` + // MimeType of the file as defined by sender + // + // optional + MimeType string `json:"mime_type,omitempty"` + // FileSize file size + // + // optional + FileSize int `json:"file_size,omitempty"` +} + +// Contact represents a phone contact. // // Note that LastName and UserID may be empty. type Contact struct { + // PhoneNumber contact's phone number PhoneNumber string `json:"phone_number"` - FirstName string `json:"first_name"` - LastName string `json:"last_name,omitempty"` // optional - UserID int `json:"user_id,omitempty"` // optional - VCard string `json:"vcard,omitempty"` // optional + // FirstName contact's first name + FirstName string `json:"first_name"` + // LastName contact's last name + // + // optional + LastName string `json:"last_name,omitempty"` + // UserID contact's user identifier in Telegram + // + // optional + UserID int `json:"user_id,omitempty"` + // VCard is additional data about the contact in the form of a vCard. + // + // optional + VCard string `json:"vcard,omitempty"` } -// Location contains information about a place. -type Location struct { - Longitude float64 `json:"longitude"` - Latitude float64 `json:"latitude"` -} - -// Venue contains information about a venue, including its Location. -type Venue struct { - Location Location `json:"location"` - Title string `json:"title"` - Address string `json:"address"` - FoursquareID string `json:"foursquare_id,omitempty"` // optional +// Dice represents an animated emoji that displays a random value. +type Dice struct { + // Emoji on which the dice throw animation is based + Emoji string `json:"emoji"` + // Value of the dice + Value int `json:"value"` } // PollOption contains information about one answer option in a poll. type PollOption struct { - Text string `json:"text"` - VoterCount int `json:"voter_count"` + // Text is the option text, 1-100 characters + Text string `json:"text"` + // VoterCount is the number of users that voted for this option + VoterCount int `json:"voter_count"` } // PollAnswer represents an answer of a user in a non-anonymous poll. type PollAnswer struct { - PollID string `json:"poll_id"` - User User `json:"user"` - OptionIDs []int `json:"option_ids"` + // PollID is the unique poll identifier + PollID string `json:"poll_id"` + // User who changed the answer to the poll + User User `json:"user"` + // OptionIDs is the 0-based identifiers of poll options chosen by the user. + // May be empty if user retracted vote. + OptionIDs []int `json:"option_ids"` } // Poll contains information about a poll. type Poll struct { - ID string `json:"id"` - Question string `json:"question"` - Options []PollOption `json:"options"` - IsClosed bool `json:"is_closed"` - IsAnonymous bool `json:"is_anonymous"` - Type string `json:"type"` - AllowsMultipleAnswers bool `json:"allows_multiple_answers"` - CorrectOptionID int `json:"correct_option_id,omitempty"` // optional - Explanation string `json:"explanation,omitempty"` // optional - ExplanationEntities []MessageEntity `json:"explanation_entities,omitempty"` // optional - OpenPeriod int `json:"open_period,omitempty"` // optional - CloseDate int `json:"close_date,omitempty"` // optional + // ID is the unique poll identifier + ID string `json:"id"` + // Question is the poll question, 1-255 characters + Question string `json:"question"` + // Options is the list of poll options + Options []PollOption `json:"options"` + // TotalVoterCount is the total numbers of users who voted in the poll + TotalVoterCount int `json:"total_voter_count"` + // IsClosed is if the poll is closed + IsClosed bool `json:"is_closed"` + // IsAnonymous is if the poll is anonymous + IsAnonymous bool `json:"is_anonymous"` + // Type is the poll type, currently can be "regular" or "quiz" + Type string `json:"type"` + // AllowsMultipleAnswers is true, if the poll allows multiple answers + AllowsMultipleAnswers bool `json:"allows_multiple_answers"` + // CorrectOptionID is the 0-based identifier of the correct answer option. + // Available only for polls in quiz mode, which are closed, or was sent (not + // forwarded) by the bot or to the private chat with the bot. + // + // optional + CorrectOptionID int `json:"correct_option_id,omitempty"` + // Explanation is text that is shown when a user chooses an incorrect answer + // or taps on the lamp icon in a quiz-style poll, 0-200 characters + // + // optional + Explanation string `json:"explanation,omitempty"` + // ExplainationEntities are special entities like usernames, URLs, bot + // commands, etc. that appear in the explanation + // + // optional + ExplanationEntities []MessageEntity `json:"explanation_entities,omitempty"` + // OpenPeriod is the amount of time in seconds the poll will be active + // after creation + // + // optional + OpenPeriod int `json:"open_period,omitempty"` + // Closedate is the point in time (unix timestamp) when the poll will be + // automatically closed + // + // optional + CloseDate int `json:"close_date,omitempty"` } -// Dice represents a single dice value. -type Dice struct { - Emoji string `json:"emoji"` - Value int `json:"value"` +// Location represents a point on the map. +type Location struct { + // Longitude as defined by sender + Longitude float64 `json:"longitude"` + // Latitude as defined by sender + Latitude float64 `json:"latitude"` +} + +// Venue represents a venue. +type Venue struct { + // Location is the venue location + Location Location `json:"location"` + // Title is the name of the venue + Title string `json:"title"` + // Address of the venue + Address string `json:"address"` + // FoursquareID is the foursquare identifier of the venue + // + // optional + FoursquareID string `json:"foursquare_id,omitempty"` + // FoursquareType is the foursquare type of the venue + // + // optional + FoursquareType string `json:"foursquare_type,omitempty"` } // UserProfilePhotos contains a set of user profile photos. type UserProfilePhotos struct { - TotalCount int `json:"total_count"` - Photos [][]PhotoSize `json:"photos"` + // TotalCount total number of profile pictures the target user has + TotalCount int `json:"total_count"` + // Photos requested profile pictures (in up to 4 sizes each) + Photos [][]PhotoSize `json:"photos"` } // File contains information about a file to download from Telegram. type File struct { - FileID string `json:"file_id"` + // FileID identifier for this file, which can be used to download or reuse + // the file + FileID string `json:"file_id"` + // FileUniqueID is the unique identifier for this file, which is supposed to + // be the same over time and for different bots. Can't be used to download + // or reuse the file. FileUniqueID string `json:"file_unique_id"` - FileSize int `json:"file_size,omitempty"` // optional - FilePath string `json:"file_path,omitempty"` // optional + // FileSize file size, if known + // + // optional + FileSize int `json:"file_size,omitempty"` + // FilePath file path + // + // optional + FilePath string `json:"file_path,omitempty"` } // Link returns a full path to the download URL for a File. // -// It requires the Bot Token to create the link. +// It requires the Bot token to create the link. func (f *File) Link(token string) string { return fmt.Sprintf(FileEndpoint, token, f.FilePath) } -// ReplyKeyboardMarkup allows the Bot to set a custom keyboard. +// ReplyKeyboardMarkup represents a custom keyboard with reply options. type ReplyKeyboardMarkup struct { - Keyboard [][]KeyboardButton `json:"keyboard"` - ResizeKeyboard bool `json:"resize_keyboard,omitempty"` // optional - OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"` // optional - Selective bool `json:"selective,omitempty"` // optional + // Keyboard is an array of button rows, each represented by an Array of KeyboardButton objects + Keyboard [][]KeyboardButton `json:"keyboard"` + // ResizeKeyboard requests clients to resize the keyboard vertically for optimal fit + // (e.g., make the keyboard smaller if there are just two rows of buttons). + // Defaults to false, in which case the custom keyboard + // is always of the same height as the app's standard keyboard. + // + // optional + ResizeKeyboard bool `json:"resize_keyboard,omitempty"` + // OneTimeKeyboard requests clients to hide the keyboard as soon as it's been used. + // The keyboard will still be available, but clients will automatically display + // the usual letter-keyboard in the chat – the user can press a special button + // in the input field to see the custom keyboard again. + // Defaults to false. + // + // optional + OneTimeKeyboard bool `json:"one_time_keyboard,omitempty"` + // Selective use this parameter if you want to show the keyboard to specific users only. + // Targets: + // 1) users that are @mentioned in the text of the Message object; + // 2) if the bot's message is a reply (has Message.ReplyToMessage not nil), sender of the original message. + // + // Example: A user requests to change the bot's language, + // bot replies to the request with a keyboard to select the new language. + // Other users in the group don't see the keyboard. + // + // optional + Selective bool `json:"selective,omitempty"` } -// KeyboardButton is a button within a custom keyboard. +// KeyboardButton represents one button of the reply keyboard. For simple text +// buttons String can be used instead of this object to specify text of the +// button. Optional fields request_contact, request_location, and request_poll +// are mutually exclusive. type KeyboardButton struct { - Text string `json:"text"` - RequestContact bool `json:"request_contact"` - RequestLocation bool `json:"request_location"` - RequestPoll *KeyboardButtonPollType `json:"request_poll,omitempty"` + // Text of the button. If none of the optional fields are used, + // it will be sent as a message when the button is pressed. + Text string `json:"text"` + // RequestContact if True, the user's phone number will be sent + // as a contact when the button is pressed. + // Available in private chats only. + // + // optional + RequestContact bool `json:"request_contact,omitempty"` + // RequestLocation if True, the user's current location will be sent when + // the button is pressed. + // Available in private chats only. + // + // optional + RequestLocation bool `json:"request_location,omitempty"` + // RequestPoll if True, the user will be asked to create a poll and send it + // to the bot when the button is pressed. Available in private chats only + // + // optional + RequestPoll *KeyboardButtonPollType `json:"request_poll,omitempty"` } // KeyboardButtonPollType represents type of a poll, which is allowed to // be created and sent when the corresponding button is pressed. type KeyboardButtonPollType struct { + // Type is if quiz is passed, the user will be allowed to create only polls + // in the quiz mode. If regular is passed, only regular polls will be + // allowed. Otherwise, the user will be allowed to create a poll of any type. Type string `json:"type"` } -// ReplyKeyboardHide allows the Bot to hide a custom keyboard. -type ReplyKeyboardHide struct { - HideKeyboard bool `json:"hide_keyboard"` - Selective bool `json:"selective,omitempty"` // optional -} - -// ReplyKeyboardRemove allows the Bot to hide a custom keyboard. +// ReplyKeyboardRemove Upon receiving a message with this object, Telegram +// clients will remove the current custom keyboard and display the default +// letter-keyboard. By default, custom keyboards are displayed until a new +// keyboard is sent by a bot. An exception is made for one-time keyboards +// that are hidden immediately after the user presses a button. type ReplyKeyboardRemove struct { + // RemoveKeyboard requests clients to remove the custom keyboard + // (user will not be able to summon this keyboard; + // if you want to hide the keyboard from sight but keep it accessible, + // use one_time_keyboard in ReplyKeyboardMarkup). RemoveKeyboard bool `json:"remove_keyboard"` - Selective bool `json:"selective"` + // Selective use this parameter if you want to remove the keyboard for specific users only. + // Targets: + // 1) users that are @mentioned in the text of the Message object; + // 2) if the bot's message is a reply (has Message.ReplyToMessage not nil), sender of the original message. + // + // Example: A user votes in a poll, bot returns confirmation message + // in reply to the vote and removes the keyboard for that user, + // while still showing the keyboard with poll options to users who haven't voted yet. + // + // optional + Selective bool `json:"selective,omitempty"` } -// InlineKeyboardMarkup is a custom keyboard presented for an inline bot. +// InlineKeyboardMarkup represents an inline keyboard that appears right next to +// the message it belongs to. type InlineKeyboardMarkup struct { + // InlineKeyboard array of button rows, each represented by an Array of + // InlineKeyboardButton objects InlineKeyboard [][]InlineKeyboardButton `json:"inline_keyboard"` } -// InlineKeyboardButton is a button within a custom keyboard for -// inline query responses. +// InlineKeyboardButton represents one button of an inline keyboard. You must +// use exactly one of the optional fields. // // Note that some values are references as even an empty string // will change behavior. // // CallbackGame, if set, MUST be first button in first row. type InlineKeyboardButton struct { - Text string `json:"text"` - URL *string `json:"url,omitempty"` // optional - LoginURL *LoginURL `json:"login_url,omitempty"` // optional - CallbackData *string `json:"callback_data,omitempty"` // optional - SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` // optional - SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` // optional - CallbackGame *CallbackGame `json:"callback_game,omitempty"` // optional - Pay bool `json:"pay,omitempty"` // optional + // Text label text on the button + Text string `json:"text"` + // URL HTTP or tg:// url to be opened when button is pressed. + // + // optional + URL *string `json:"url,omitempty"` + // LoginURL is an HTTP URL used to automatically authorize the user. Can be + // used as a replacement for the Telegram Login Widget + // + // optional + LoginURL *LoginURL `json:"login_url,omitempty"` + // CallbackData data to be sent in a callback query to the bot when button is pressed, 1-64 bytes. + // + // optional + CallbackData *string `json:"callback_data,omitempty"` + // SwitchInlineQuery if set, pressing the button will prompt the user to select one of their chats, + // open that chat and insert the bot's username and the specified inline query in the input field. + // Can be empty, in which case just the bot's username will be inserted. + // + // This offers an easy way for users to start using your bot + // in inline mode when they are currently in a private chat with it. + // Especially useful when combined with switch_pm… actions – in this case + // the user will be automatically returned to the chat they switched from, + // skipping the chat selection screen. + // + // optional + SwitchInlineQuery *string `json:"switch_inline_query,omitempty"` + // SwitchInlineQueryCurrentChat if set, pressing the button will insert the bot's username + // and the specified inline query in the current chat's input field. + // Can be empty, in which case only the bot's username will be inserted. + // + // This offers a quick way for the user to open your bot in inline mode + // in the same chat – good for selecting something from multiple options. + // + // optional + SwitchInlineQueryCurrentChat *string `json:"switch_inline_query_current_chat,omitempty"` + // CallbackGame description of the game that will be launched when the user presses the button. + // + // optional + CallbackGame *CallbackGame `json:"callback_game,omitempty"` + // Pay specify True, to send a Pay button. + // + // NOTE: This type of button must always be the first button in the first row. + // + // optional + Pay bool `json:"pay,omitempty"` } -// LoginURL is the parameters for the login inline keyboard button type. +// LoginURL represents a parameter of the inline keyboard button used to +// automatically authorize a user. Serves as a great replacement for the +// Telegram Login Widget when the user is coming from Telegram. All the user +// needs to do is tap/click a button and confirm that they want to log in. type LoginURL struct { - URL string `json:"url"` - ForwardText string `json:"forward_text"` - BotUsername string `json:"bot_username"` - RequestWriteAccess bool `json:"request_write_access"` + // URL is an HTTP URL to be opened with user authorization data added to the + // query string when the button is pressed. If the user refuses to provide + // authorization data, the original URL without information about the user + // will be opened. The data added is the same as described in Receiving + // authorization data. + // + // NOTE: You must always check the hash of the received data to verify the + // authentication and the integrity of the data as described in Checking + // authorization. + URL string `json:"url"` + // ForwardText is the new text of the button in forwarded messages + // + // optional + ForwardText string `json:"forward_text,omitempty"` + // BotUsername is the username of a bot, which will be used for user + // authorization. See Setting up a bot for more details. If not specified, + // the current bot's username will be assumed. The url's domain must be the + // same as the domain linked with the bot. See Linking your domain to the + // bot for more details. + // + // optional + BotUsername string `json:"bot_username,omitempty"` + // RequestWriteAccess if true requests permission for your bot to send + // messages to the user + // + // optional + RequestWriteAccess bool `json:"request_write_access,omitempty"` } -// CallbackQuery is data sent when a keyboard button with callback data -// is clicked. +// CallbackQuery represents an incoming callback query from a callback button in +// an inline keyboard. If the button that originated the query was attached to a +// message sent by the bot, the field message will be present. If the button was +// attached to a message sent via the bot (in inline mode), the field +// inline_message_id will be present. Exactly one of the fields data or +// game_short_name will be present. type CallbackQuery struct { - ID string `json:"id"` - From *User `json:"from"` - Message *Message `json:"message,omitempty"` // optional - InlineMessageID string `json:"inline_message_id,omitempty"` // optional - ChatInstance string `json:"chat_instance"` - Data string `json:"data,omitempty"` // optional - GameShortName string `json:"game_short_name,omitempty"` // optional + // ID unique identifier for this query + ID string `json:"id"` + // From sender + From *User `json:"from"` + // Message with the callback button that originated the query. + // Note that message content and message date will not be available if the + // message is too old. + // + // optional + Message *Message `json:"message,omitempty"` + // InlineMessageID identifier of the message sent via the bot in inline + // mode, that originated the query. + // + // optional + InlineMessageID string `json:"inline_message_id,omitempty"` + // ChatInstance global identifier, uniquely corresponding to the chat to + // which the message with the callback button was sent. Useful for high + // scores in games. + ChatInstance string `json:"chat_instance"` + // Data associated with the callback button. Be aware that + // a bad client can send arbitrary data in this field. + // + // optional + Data string `json:"data,omitempty"` + // GameShortName short name of a Game to be returned, serves as the unique identifier for the game. + // + // optional + GameShortName string `json:"game_short_name,omitempty"` } -// ForceReply allows the Bot to have users directly reply to it without -// additional interaction. +// ForceReply when receiving a message with this object, Telegram clients will +// display a reply interface to the user (act as if the user has selected the +// bot's message and tapped 'Reply'). This can be extremely useful if you want +// to create user-friendly step-by-step interfaces without having to sacrifice +// privacy mode. type ForceReply struct { + // ForceReply shows reply interface to the user, + // as if they manually selected the bot's message and tapped 'Reply'. ForceReply bool `json:"force_reply"` - Selective bool `json:"selective"` // optional + // Selective use this parameter if you want to force reply from specific users only. + // Targets: + // 1) users that are @mentioned in the text of the Message object; + // 2) if the bot's message is a reply (has Message.ReplyToMessage not nil), sender of the original message. + // + // optional + Selective bool `json:"selective,omitempty"` } -// ChatMember is information about a member in a chat. +// ChatPhoto represents a chat photo. +type ChatPhoto struct { + // SmallFileID is a file identifier of small (160x160) chat photo. + // This file_id can be used only for photo download and + // only for as long as the photo is not changed. + SmallFileID string `json:"small_file_id"` + // SmallFileUniqueID is a unique file identifier of small (160x160) chat + // photo, which is supposed to be the same over time and for different bots. + // Can't be used to download or reuse the file. + SmallFileUniqueID string `json:"small_file_unique_id"` + // BigFileID is a file identifier of big (640x640) chat photo. + // This file_id can be used only for photo download and + // only for as long as the photo is not changed. + BigFileID string `json:"big_file_id"` + // BigFileUniqueID is a file identifier of big (640x640) chat photo, which + // is supposed to be the same over time and for different bots. Can't be + // used to download or reuse the file. + BigFileUniqueID string `json:"big_file_unique_id"` +} + +// ChatMember contains information about one member of a chat. type ChatMember struct { - User *User `json:"user"` - Status string `json:"status"` - CustomTitle string `json:"custom_title,omitempty"` // optional - UntilDate int64 `json:"until_date,omitempty"` // optional - CanBeEdited bool `json:"can_be_edited,omitempty"` // optional - CanPostMessages bool `json:"can_post_messages,omitempty"` // optional - CanEditMessages bool `json:"can_edit_messages,omitempty"` // optional - CanDeleteMessages bool `json:"can_delete_messages,omitempty"` // optional - CanRestrictMembers bool `json:"can_restrict_members,omitempty"` // optional - CanPromoteMembers bool `json:"can_promote_members,omitempty"` // optional - CanChangeInfo bool `json:"can_change_info,omitempty"` // optional - CanInviteUsers bool `json:"can_invite_users,omitempty"` // optional - CanPinMessages bool `json:"can_pin_messages,omitempty"` // optional - IsChatMember bool `json:"is_member,omitempty"` // optional - CanSendMessages bool `json:"can_send_messages,omitempty"` // optional - CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"` // optional - CanSendPolls bool `json:"can_send_polls,omitempty"` // optional - CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` // optional - CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` // optional + // User information about the user + User *User `json:"user"` + // Status the member's status in the chat. + // Can be + // β€œcreator”, + // β€œadministrator”, + // β€œmember”, + // β€œrestricted”, + // β€œleft” or + // β€œkicked” + Status string `json:"status"` + // CustomTitle owner and administrators only. Custom title for this user + // + // optional + CustomTitle string `json:"custom_title,omitempty"` + // UntilDate restricted and kicked only. + // Date when restrictions will be lifted for this user; + // unix time. + // + // optional + UntilDate int64 `json:"until_date,omitempty"` + // CanBeEdited administrators only. + // True, if the bot is allowed to edit administrator privileges of that user. + // + // optional + CanBeEdited bool `json:"can_be_edited,omitempty"` + // CanPostMessages administrators only. + // True, if the administrator can post in the channel; + // channels only. + // + // optional + CanPostMessages bool `json:"can_post_messages,omitempty"` + // CanEditMessages administrators only. + // True, if the administrator can edit messages of other users and can pin messages; + // channels only. + // + // optional + CanEditMessages bool `json:"can_edit_messages,omitempty"` + // CanDeleteMessages administrators only. + // True, if the administrator can delete messages of other users. + // + // optional + CanDeleteMessages bool `json:"can_delete_messages,omitempty"` + // CanRestrictMembers administrators only. + // True, if the administrator can restrict, ban or unban chat members. + // + // optional + CanRestrictMembers bool `json:"can_restrict_members,omitempty"` + // CanPromoteMembers administrators only. + // True, if the administrator can add new administrators + // with a subset of their own privileges or demote administrators that he has promoted, + // directly or indirectly (promoted by administrators that were appointed by the user). + // + // optional + CanPromoteMembers bool `json:"can_promote_members,omitempty"` + // CanChangeInfo administrators and restricted only. + // True, if the user is allowed to change the chat title, photo and other settings. + // + // optional + CanChangeInfo bool `json:"can_change_info,omitempty"` + // CanInviteUsers administrators and restricted only. + // True, if the user is allowed to invite new users to the chat. + // + // optional + CanInviteUsers bool `json:"can_invite_users,omitempty"` + // CanPinMessages administrators and restricted only. + // True, if the user is allowed to pin messages; groups and supergroups only + // + // optional + CanPinMessages bool `json:"can_pin_messages,omitempty"` + // IsMember is true, if the user is a member of the chat at the moment of + // the request + IsMember bool `json:"is_member"` + // CanSendMessages + // + // optional + CanSendMessages bool `json:"can_send_messages,omitempty"` + // CanSendMediaMessages restricted only. + // True, if the user is allowed to send text messages, contacts, locations and venues + // + // optional + CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"` + // CanSendPolls restricted only. + // True, if the user is allowed to send polls + // + // optional + CanSendPolls bool `json:"can_send_polls,omitempty"` + // CanSendOtherMessages restricted only. + // True, if the user is allowed to send audios, documents, + // photos, videos, video notes and voice notes. + // + // optional + CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` + // CanAddWebPagePreviews restricted only. + // True, if the user is allowed to add web page previews to their messages. + // + // optional + CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` } // IsCreator returns if the ChatMember was the creator of the chat. @@ -644,40 +1364,277 @@ func (chat ChatMember) IsCreator() bool { return chat.Status == "creator" } // IsAdministrator returns if the ChatMember is a chat administrator. func (chat ChatMember) IsAdministrator() bool { return chat.Status == "administrator" } -// IsMember returns if the ChatMember is a current member of the chat. -func (chat ChatMember) IsMember() bool { return chat.Status == "member" } - // HasLeft returns if the ChatMember left the chat. func (chat ChatMember) HasLeft() bool { return chat.Status == "left" } // WasKicked returns if the ChatMember was kicked from the chat. func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" } -// Game is a game within Telegram. -type Game struct { - Title string `json:"title"` - Description string `json:"description"` - Photo []PhotoSize `json:"photo"` - Text string `json:"text"` - TextEntities []MessageEntity `json:"text_entities"` - Animation Animation `json:"animation"` +// ChatPermissions describes actions that a non-administrator user is +// allowed to take in a chat. All fields are optional. +type ChatPermissions struct { + // CanSendMessages is true, if the user is allowed to send text messages, + // contacts, locations and venues + // + // optional + CanSendMessages bool `json:"can_send_messages,omitempty"` + // CanSendMediaMessages is true, if the user is allowed to send audios, + // documents, photos, videos, video notes and voice notes, implies + // can_send_messages + // + // optional + CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"` + // CanSendPolls is true, if the user is allowed to send polls, implies + // can_send_messages + // + // optional + CanSendPolls bool `json:"can_send_polls,omitempty"` + // CanSendOtherMessages is true, if the user is allowed to send animations, + // games, stickers and use inline bots, implies can_send_media_messages + // + // optional + CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` + // CanAddWebPagePreviews is true, if the user is allowed to add web page + // previews to their messages, implies can_send_media_messages + // + // optional + CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` + // CanChangeInfo is true, if the user is allowed to change the chat title, + // photo and other settings. Ignored in public supergroups + // + // optional + CanChangeInfo bool `json:"can_change_info,omitempty"` + // CanInviteUsers is true, if the user is allowed to invite new users to the + // chat + // + // optional + CanInviteUsers bool `json:"can_invite_users,omitempty"` + // CanPinMessages is true, if the user is allowed to pin messages. Ignored + // in public supergroups + // + // optional + CanPinMessages bool `json:"can_pin_messages,omitempty"` } -// Animation is a GIF animation demonstrating the game. -type Animation struct { - FileID string `json:"file_id"` - FileUniqueID string `json:"file_unique_id"` - Thumb PhotoSize `json:"thumb"` - FileName string `json:"file_name"` - MimeType string `json:"mime_type"` - FileSize int `json:"file_size"` +// BotCommand represents a bot command. +type BotCommand struct { + // Command text of the command, 1-32 characters. + // Can contain only lowercase English letters, digits and underscores. + Command string `json:"command"` + // Description of the command, 3-256 characters. + Description string `json:"description"` +} + +// ResponseParameters are various errors that can be returned in APIResponse. +type ResponseParameters struct { + // The group has been migrated to a supergroup with the specified identifier. + // + // optional + MigrateToChatID int64 `json:"migrate_to_chat_id,omitempty"` + // In case of exceeding flood control, the number of seconds left to wait + // before the request can be repeated. + // + // optional + RetryAfter int `json:"retry_after,omitempty"` +} + +// BaseInputMedia is a base type for the InputMedia types. +type BaseInputMedia struct { + // Type of the result. + Type string `json:"type"` + // Media file to send. Pass a file_id to send a file + // that exists on the Telegram servers (recommended), + // pass an HTTP URL for Telegram to get a file from the Internet, + // or pass β€œattach://” to upload a new one + // using multipart/form-data under name. + Media string `json:"media"` + // thumb intentionally missing as it is not currently compatible + + // Caption of the video to be sent, 0-1024 characters after entities parsing. + // + // optional + Caption string `json:"caption,omitempty"` + // ParseMode mode for parsing entities in the video caption. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` +} + +// InputMediaPhoto is a photo to send as part of a media group. +type InputMediaPhoto struct { + BaseInputMedia +} + +// InputMediaVideo is a video to send as part of a media group. +type InputMediaVideo struct { + BaseInputMedia + // Width video width + // + // optional + Width int `json:"width,omitempty"` + // Height video height + // + // optional + Height int `json:"height,omitempty"` + // Duration video duration + // + // optional + Duration int `json:"duration,omitempty"` + // SupportsStreaming pass True, if the uploaded video is suitable for streaming. + // + // optional + SupportsStreaming bool `json:"supports_streaming,omitempty"` +} + +// InputMediaAnimation is an animation to send as part of a media group. +type InputMediaAnimation struct { + BaseInputMedia + // Width video width + // + // optional + Width int `json:"width,omitempty"` + // Height video height + // + // optional + Height int `json:"height,omitempty"` + // Duration video duration + // + // optional + Duration int `json:"duration,omitempty"` +} + +// InputMediaAudio is a audio to send as part of a media group. +type InputMediaAudio struct { + BaseInputMedia + // Duration of the audio in seconds + // + // optional + Duration int `json:"duration,omitempty"` + // Performer of the audio + // + // optional + Performer string `json:"performer,omitempty"` + // Title of the audio + // + // optional + Title string `json:"title,omitempty"` +} + +// InputMediaDocument is a general file to send as part of a media group. +type InputMediaDocument struct { + BaseInputMedia +} + +// Sticker represents a sticker. +type Sticker struct { + // FileID is an identifier for this file, which can be used to download or + // reuse the file + FileID string `json:"file_id"` + // FileUniqueID is an unique identifier for this file, + // which is supposed to be the same over time and for different bots. + // Can't be used to download or reuse the file. + FileUniqueID string `json:"file_unique_id"` + // Width sticker width + Width int `json:"width"` + // Height sticker height + Height int `json:"height"` + // IsAnimated true, if the sticker is animated + // + // optional + IsAnimated bool `json:"is_animated,omitempty"` + // Thumbnail sticker thumbnail in the .WEBP or .JPG format + // + // optional + Thumbnail *PhotoSize `json:"thumb,omitempty"` + // Emoji associated with the sticker + // + // optional + Emoji string `json:"emoji,omitempty"` + // SetName of the sticker set to which the sticker belongs + // + // optional + SetName string `json:"set_name,omitempty"` + // MaskPosition is for mask stickers, the position where the mask should be + // placed + // + // optional + MaskPosition *MaskPosition `json:"mask_position,omitempty"` + // FileSize + // + // optional + FileSize int `json:"file_size,omitempty"` +} + +// StickerSet represents a sticker set. +type StickerSet struct { + // Name sticker set name + Name string `json:"name"` + // Title sticker set title + Title string `json:"title"` + // IsAnimated true, if the sticker set contains animated stickers + IsAnimated bool `json:"is_animated"` + // ContainsMasks true, if the sticker set contains masks + ContainsMasks bool `json:"contains_masks"` + // Stickers list of all set stickers + Stickers []Sticker `json:"stickers"` + // Thumb is the sticker set thumbnail in the .WEBP or .TGS format + Thumbnail *PhotoSize `json:"thumb"` +} + +// MaskPosition describes the position on faces where a mask should be placed +// by default. +type MaskPosition struct { + // The part of the face relative to which the mask should be placed. + // One of β€œforehead”, β€œeyes”, β€œmouth”, or β€œchin”. + Point string `json:"point"` + // Shift by X-axis measured in widths of the mask scaled to the face size, + // from left to right. For example, choosing -1.0 will place mask just to + // the left of the default mask position. + XShift float64 `json:"x_shift"` + // Shift by Y-axis measured in heights of the mask scaled to the face size, + // from top to bottom. For example, 1.0 will place the mask just below the + // default mask position. + YShift float64 `json:"y_shift"` + // Mask scaling coefficient. For example, 2.0 means double size. + Scale float64 `json:"scale"` +} + +// Game represents a game. Use BotFather to create and edit games, their short +// names will act as unique identifiers. +type Game struct { + // Title of the game + Title string `json:"title"` + // Description of the game + Description string `json:"description"` + // Photo that will be displayed in the game message in chats. + Photo []PhotoSize `json:"photo"` + // Text a brief description of the game or high scores included in the game message. + // Can be automatically edited to include current high scores for the game + // when the bot calls setGameScore, or manually edited using editMessageText. 0-4096 characters. + // + // optional + Text string `json:"text,omitempty"` + // TextEntities special entities that appear in text, such as usernames, URLs, bot commands, etc. + // + // optional + TextEntities []MessageEntity `json:"text_entities,omitempty"` + // Animation animation that will be displayed in the game message in chats. + // Upload via BotFather (https://t.me/botfather). + // + // optional + Animation Animation `json:"animation,omitempty"` } // GameHighScore is a user's score and position on the leaderboard. type GameHighScore struct { - Position int `json:"position"` - User User `json:"user"` - Score int `json:"score"` + // Position in high score table for the game + Position int `json:"position"` + // User user + User User `json:"user"` + // Score score + Score int `json:"score"` } // CallbackGame is for starting a game in an inline keyboard button. @@ -685,12 +1642,32 @@ type CallbackGame struct{} // WebhookInfo is information about a currently set webhook. type WebhookInfo struct { - URL string `json:"url"` - HasCustomCertificate bool `json:"has_custom_certificate"` - PendingUpdateCount int `json:"pending_update_count"` - LastErrorDate int `json:"last_error_date"` // optional - LastErrorMessage string `json:"last_error_message"` // optional - MaxConnections int `json:"max_connections"` // optional + // URL webhook URL, may be empty if webhook is not set up. + URL string `json:"url"` + // HasCustomCertificate true, if a custom certificate was provided for webhook certificate checks. + HasCustomCertificate bool `json:"has_custom_certificate"` + // PendingUpdateCount number of updates awaiting delivery. + PendingUpdateCount int `json:"pending_update_count"` + // LastErrorDate unix time for the most recent error + // that happened when trying to deliver an update via webhook. + // + // optional + LastErrorDate int `json:"last_error_date,omitempty"` + // LastErrorMessage error message in human-readable format for the most recent error + // that happened when trying to deliver an update via webhook. + // + // optional + LastErrorMessage string `json:"last_error_message,omitempty"` + // MaxConnections maximum allowed number of simultaneous + // HTTPS connections to the webhook for update delivery. + // + // optional + MaxConnections int `json:"max_connections,omitempty"` + // AllowedUpdates is a list of update types the bot is subscribed to. + // Defaults to all update types + // + // optional + AllowedUpdates []string `json:"allowed_updates,omitempty"` } // IsSet returns true if a webhook is currently set. @@ -700,245 +1677,405 @@ func (info WebhookInfo) IsSet() bool { // InlineQuery is a Query from Telegram for an inline request. type InlineQuery struct { - ID string `json:"id"` - From *User `json:"from"` - Location *Location `json:"location,omitempty"` // optional - Query string `json:"query"` - Offset string `json:"offset"` -} - -// InlineQueryResultArticle is an inline query response article. -type InlineQueryResultArticle struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - Title string `json:"title"` // required - InputMessageContent interface{} `json:"input_message_content,omitempty"` // required - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - URL string `json:"url"` - HideURL bool `json:"hide_url"` - Description string `json:"description"` - ThumbURL string `json:"thumb_url"` - ThumbWidth int `json:"thumb_width"` - ThumbHeight int `json:"thumb_height"` -} - -// InlineQueryResultPhoto is an inline query response photo. -type InlineQueryResultPhoto struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - URL string `json:"photo_url"` // required - MimeType string `json:"mime_type"` - Width int `json:"photo_width"` - Height int `json:"photo_height"` - ThumbURL string `json:"thumb_url"` - Title string `json:"title"` - Description string `json:"description"` - Caption string `json:"caption"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultCachedPhoto is an inline query response with cached photo. -type InlineQueryResultCachedPhoto struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - PhotoID string `json:"photo_file_id"` // required - Title string `json:"title"` - Description string `json:"description"` - Caption string `json:"caption"` - ParseMode string `json:"parse_mode"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultGIF is an inline query response GIF. -type InlineQueryResultGIF struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - URL string `json:"gif_url"` // required - ThumbURL string `json:"thumb_url"` // required - ThumbMimeType string `json:"thumb_mime_type"` - Width int `json:"gif_width,omitempty"` - Height int `json:"gif_height,omitempty"` - Duration int `json:"gif_duration,omitempty"` - Title string `json:"title,omitempty"` - Caption string `json:"caption,omitempty"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultCachedGIF is an inline query response with cached gif. -type InlineQueryResultCachedGIF struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - GifID string `json:"gif_file_id"` // required - Title string `json:"title"` - Caption string `json:"caption"` - ParseMode string `json:"parse_mode"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF. -type InlineQueryResultMPEG4GIF struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - URL string `json:"mpeg4_url"` // required - Width int `json:"mpeg4_width"` - Height int `json:"mpeg4_height"` - Duration int `json:"mpeg4_duration"` - ThumbURL string `json:"thumb_url"` - ThumbMimeType string `json:"thumb_mime_type"` - Title string `json:"title"` - Caption string `json:"caption"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultCachedMpeg4Gif is an inline query response with cached -// H.264/MPEG-4 AVC video without sound gif. -type InlineQueryResultCachedMpeg4Gif struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - MGifID string `json:"mpeg4_file_id"` // required - Title string `json:"title"` - Caption string `json:"caption"` - ParseMode string `json:"parse_mode"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultVideo is an inline query response video. -type InlineQueryResultVideo struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - URL string `json:"video_url"` // required - MimeType string `json:"mime_type"` // required - ThumbURL string `json:"thumb_url"` - Title string `json:"title"` - Caption string `json:"caption"` - Width int `json:"video_width"` - Height int `json:"video_height"` - Duration int `json:"video_duration"` - Description string `json:"description"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultCachedVideo is an inline query response with cached video. -type InlineQueryResultCachedVideo struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - VideoID string `json:"video_file_id"` // required - Title string `json:"title"` // required - Description string `json:"description"` - Caption string `json:"caption"` - ParseMode string `json:"parse_mode"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultCachedSticker is an inline query response with cached sticker. -type InlineQueryResultCachedSticker struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - StickerID string `json:"sticker_file_id"` // required - Title string `json:"title"` // required - ParseMode string `json:"parse_mode"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultAudio is an inline query response audio. -type InlineQueryResultAudio struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - URL string `json:"audio_url"` // required - Title string `json:"title"` // required - Caption string `json:"caption"` - Performer string `json:"performer"` - Duration int `json:"audio_duration"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` + // ID unique identifier for this query + ID string `json:"id"` + // From sender + From *User `json:"from"` + // Location sender location, only for bots that request user location. + // + // optional + Location *Location `json:"location,omitempty"` + // Query text of the query (up to 256 characters). + Query string `json:"query"` + // Offset of the results to be returned, can be controlled by the bot. + Offset string `json:"offset"` } // InlineQueryResultCachedAudio is an inline query response with cached audio. type InlineQueryResultCachedAudio struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - AudioID string `json:"audio_file_id"` // required - Caption string `json:"caption"` - ParseMode string `json:"parse_mode"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultVoice is an inline query response voice. -type InlineQueryResultVoice struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - URL string `json:"voice_url"` // required - Title string `json:"title"` // required - Caption string `json:"caption"` - Duration int `json:"voice_duration"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultCachedVoice is an inline query response with cached voice. -type InlineQueryResultCachedVoice struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - VoiceID string `json:"voice_file_id"` // required - Title string `json:"title"` // required - Caption string `json:"caption"` - ParseMode string `json:"parse_mode"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` -} - -// InlineQueryResultDocument is an inline query response document. -type InlineQueryResultDocument struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - Title string `json:"title"` // required - Caption string `json:"caption"` - URL string `json:"document_url"` // required - MimeType string `json:"mime_type"` // required - Description string `json:"description"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` - ThumbURL string `json:"thumb_url"` - ThumbWidth int `json:"thumb_width"` - ThumbHeight int `json:"thumb_height"` + // Type of the result, must be audio + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // AudioID a valid file identifier for the audio file + // + // required + AudioID string `json:"audio_file_id"` + // Caption 0-1024 characters after entities parsing + // + // optional + Caption string `json:"caption,omitempty"` + // ParseMode mode for parsing entities in the video caption. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the audio + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` } // InlineQueryResultCachedDocument is an inline query response with cached document. type InlineQueryResultCachedDocument struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - DocumentID string `json:"document_file_id"` // required - Title string `json:"title"` // required - Caption string `json:"caption"` - Description string `json:"description"` - ParseMode string `json:"parse_mode"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` + // Type of the result, must be document + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // DocumentID a valid file identifier for the file + // + // required + DocumentID string `json:"document_file_id"` + // Title for the result + // + // optional + Title string `json:"title,omitempty"` // required + // Caption of the document to be sent, 0-1024 characters after entities parsing + // + // optional + Caption string `json:"caption,omitempty"` + // Description short description of the result + // + // optional + Description string `json:"description,omitempty"` + // ParseMode mode for parsing entities in the video caption. + // // See formatting options for more details + // // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the file + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` } -// InlineQueryResultLocation is an inline query response location. -type InlineQueryResultLocation struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - Latitude float64 `json:"latitude"` // required - Longitude float64 `json:"longitude"` // required - LivePeriod int `json:"live_period"` // optional - Title string `json:"title"` // required - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` - ThumbURL string `json:"thumb_url"` - ThumbWidth int `json:"thumb_width"` - ThumbHeight int `json:"thumb_height"` +// InlineQueryResultCachedGIF is an inline query response with cached gif. +type InlineQueryResultCachedGIF struct { + // Type of the result, must be gif. + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes. + // + // required + ID string `json:"id"` + // GifID a valid file identifier for the GIF file. + // + // required + GifID string `json:"gif_file_id"` + // Title for the result + // + // optional + Title string `json:"title,omitempty"` + // Caption of the GIF file to be sent, 0-1024 characters after entities parsing. + // + // optional + Caption string `json:"caption,omitempty"` + // ParseMode mode for parsing entities in the caption. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // ReplyMarkup inline keyboard attached to the message. + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the GIF animation. + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultCachedMPEG4GIF is an inline query response with cached +// H.264/MPEG-4 AVC video without sound gif. +type InlineQueryResultCachedMPEG4GIF struct { + // Type of the result, must be mpeg4_gif + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // MGifID a valid file identifier for the MP4 file + // + // required + MPEG4FileID string `json:"mpeg4_file_id"` + // Title for the result + // + // optional + Title string `json:"title,omitempty"` + // Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing. + // + // optional + Caption string `json:"caption,omitempty"` + // ParseMode mode for parsing entities in the caption. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // ReplyMarkup inline keyboard attached to the message. + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the video animation. + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultCachedPhoto is an inline query response with cached photo. +type InlineQueryResultCachedPhoto struct { + // Type of the result, must be photo. + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes. + // + // required + ID string `json:"id"` + // PhotoID a valid file identifier of the photo. + // + // required + PhotoID string `json:"photo_file_id"` + // Title for the result. + // + // optional + Title string `json:"title,omitempty"` + // Description short description of the result. + // + // optional + Description string `json:"description,omitempty"` + // Caption of the photo to be sent, 0-1024 characters after entities parsing. + // + // optional + Caption string `json:"caption,omitempty"` + // ParseMode mode for parsing entities in the photo caption. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // ReplyMarkup inline keyboard attached to the message. + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the photo. + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultCachedSticker is an inline query response with cached sticker. +type InlineQueryResultCachedSticker struct { + // Type of the result, must be sticker + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // StickerID a valid file identifier of the sticker + // + // required + StickerID string `json:"sticker_file_id"` + // Title is a title + Title string `json:"title"` + // ParseMode mode for parsing entities in the video caption. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the sticker + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultCachedVideo is an inline query response with cached video. +type InlineQueryResultCachedVideo struct { + // Type of the result, must be video + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // VideoID a valid file identifier for the video file + // + // required + VideoID string `json:"video_file_id"` + // Title for the result + // + // required + Title string `json:"title"` + // Description short description of the result + // + // optional + Description string `json:"description,omitempty"` + // Caption of the video to be sent, 0-1024 characters after entities parsing + // + // optional + Caption string `json:"caption,omitempty"` + // ParseMode mode for parsing entities in the video caption. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the video + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultCachedVoice is an inline query response with cached voice. +type InlineQueryResultCachedVoice struct { + // Type of the result, must be voice + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // VoiceID a valid file identifier for the voice message + // + // required + VoiceID string `json:"voice_file_id"` + // Title voice message title + // + // required + Title string `json:"title"` + // Caption 0-1024 characters after entities parsing + // + // optional + Caption string `json:"caption,omitempty"` + // ParseMode mode for parsing entities in the video caption. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the voice message + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultArticle represents a link to an article or web page. +type InlineQueryResultArticle struct { + // Type of the result, must be article. + Type string `json:"type"` + // ID unique identifier for this result, 1-64 Bytes. + ID string `json:"id"` + // Title of the result + Title string `json:"title"` + // InputMessageContent content of the message to be sent. + InputMessageContent interface{} `json:"input_message_content,omitempty"` + // ReplyMarkup Inline keyboard attached to the message. + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // URL of the result. + // + // optional + URL string `json:"url,omitempty"` + // HideURL pass True, if you don't want the URL to be shown in the message. + // + // optional + HideURL bool `json:"hide_url,omitempty"` + // Description short description of the result. + // + // optional + Description string `json:"description,omitempty"` + // ThumbURL url of the thumbnail for the result + // + // optional + ThumbURL string `json:"thumb_url,omitempty"` + // ThumbWidth thumbnail width + // + // optional + ThumbWidth int `json:"thumb_width,omitempty"` + // ThumbHeight thumbnail height + // + // optional + ThumbHeight int `json:"thumb_height,omitempty"` +} + +// InlineQueryResultAudio is an inline query response audio. +type InlineQueryResultAudio struct { + // Type of the result, must be audio + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // URL a valid url for the audio file + // + // required + URL string `json:"audio_url"` + // Title is a title + // + // required + Title string `json:"title"` + // Caption 0-1024 characters after entities parsing + // + // optional + Caption string `json:"caption,omitempty"` + // Performer is a performer + // + // optional + Performer string `json:"performer,omitempty"` + // Duration audio duration in seconds + // + // optional + Duration int `json:"audio_duration,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the audio + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` } // InlineQueryResultContact is an inline query response contact. @@ -956,211 +2093,654 @@ type InlineQueryResultContact struct { ThumbHeight int `json:"thumb_height"` } -// InlineQueryResultVenue is an inline query response venue. -type InlineQueryResultVenue struct { - Type string `json:"type"` // required - ID string `json:"id"` // required - Latitude float64 `json:"latitude"` // required - Longitude float64 `json:"longitude"` // required - Title string `json:"title"` // required - Address string `json:"address"` // required - FoursquareID string `json:"foursquare_id"` - FoursquareType string `json:"foursquare_type"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` - InputMessageContent interface{} `json:"input_message_content,omitempty"` - ThumbURL string `json:"thumb_url"` - ThumbWidth int `json:"thumb_width"` - ThumbHeight int `json:"thumb_height"` -} - // InlineQueryResultGame is an inline query response game. type InlineQueryResultGame struct { - Type string `json:"type"` - ID string `json:"id"` - GameShortName string `json:"game_short_name"` - ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // Type of the result, must be game + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // GameShortName short name of the game + // + // required + GameShortName string `json:"game_short_name"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` +} + +// InlineQueryResultDocument is an inline query response document. +type InlineQueryResultDocument struct { + // Type of the result, must be document + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // Title for the result + // + // required + Title string `json:"title"` + // Caption of the document to be sent, 0-1024 characters after entities parsing + // + // optional + Caption string `json:"caption,omitempty"` + // URL a valid url for the file + // + // required + URL string `json:"document_url"` + // MimeType of the content of the file, either β€œapplication/pdf” or β€œapplication/zip” + // + // required + MimeType string `json:"mime_type"` + // Description short description of the result + // + // optional + Description string `json:"description,omitempty"` + // ReplyMarkup nline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the file + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` + // ThumbURL url of the thumbnail (jpeg only) for the file + // + // optional + ThumbURL string `json:"thumb_url,omitempty"` + // ThumbWidth thumbnail width + // + // optional + ThumbWidth int `json:"thumb_width,omitempty"` + // ThumbHeight thumbnail height + // + // optional + ThumbHeight int `json:"thumb_height,omitempty"` +} + +// InlineQueryResultGIF is an inline query response GIF. +type InlineQueryResultGIF struct { + // Type of the result, must be gif. + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes. + // + // required + ID string `json:"id"` + // URL a valid URL for the GIF file. File size must not exceed 1MB. + // + // required + URL string `json:"gif_url"` + // ThumbURL url of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result. + // + // required + ThumbURL string `json:"thumb_url"` + // Width of the GIF + // + // optional + Width int `json:"gif_width,omitempty"` + // Height of the GIF + // + // optional + Height int `json:"gif_height,omitempty"` + // Duration of the GIF + // + // optional + Duration int `json:"gif_duration,omitempty"` + // Title for the result + // + // optional + Title string `json:"title,omitempty"` + // Caption of the GIF file to be sent, 0-1024 characters after entities parsing. + // + // optional + Caption string `json:"caption,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the GIF animation. + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultLocation is an inline query response location. +type InlineQueryResultLocation struct { + // Type of the result, must be location + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 Bytes + // + // required + ID string `json:"id"` + // Latitude of the location in degrees + // + // required + Latitude float64 `json:"latitude"` + // Longitude of the location in degrees + // + // required + Longitude float64 `json:"longitude"` + // Title of the location + // + // required + Title string `json:"title"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the location + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` + // ThumbURL url of the thumbnail for the result + // + // optional + ThumbURL string `json:"thumb_url,omitempty"` + // ThumbWidth thumbnail width + // + // optional + ThumbWidth int `json:"thumb_width,omitempty"` + // ThumbHeight thumbnail height + // + // optional + ThumbHeight int `json:"thumb_height,omitempty"` +} + +// InlineQueryResultMPEG4GIF is an inline query response MPEG4 GIF. +type InlineQueryResultMPEG4GIF struct { + // Type of the result, must be mpeg4_gif + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // URL a valid URL for the MP4 file. File size must not exceed 1MB + // + // required + URL string `json:"mpeg4_url"` + // Width video width + // + // optional + Width int `json:"mpeg4_width"` + // Height vVideo height + // + // optional + Height int `json:"mpeg4_height"` + // Duration video duration + // + // optional + Duration int `json:"mpeg4_duration"` + // ThumbURL url of the static (JPEG or GIF) or animated (MPEG4) thumbnail for the result. + ThumbURL string `json:"thumb_url"` + // Title for the result + // + // optional + Title string `json:"title,omitempty"` + // Caption of the MPEG-4 file to be sent, 0-1024 characters after entities parsing. + // + // optional + Caption string `json:"caption,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the video animation + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultPhoto is an inline query response photo. +type InlineQueryResultPhoto struct { + // Type of the result, must be article. + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 Bytes. + // + // required + ID string `json:"id"` + // URL a valid URL of the photo. Photo must be in jpeg format. + // Photo size must not exceed 5MB. + URL string `json:"photo_url"` + // MimeType + MimeType string `json:"mime_type"` + // Width of the photo + // + // optional + Width int `json:"photo_width,omitempty"` + // Height of the photo + // + // optional + Height int `json:"photo_height,omitempty"` + // ThumbURL url of the thumbnail for the photo. + // + // optional + ThumbURL string `json:"thumb_url,omitempty"` + // Title for the result + // + // optional + Title string `json:"title,omitempty"` + // Description short description of the result + // + // optional + Description string `json:"description,omitempty"` + // Caption of the photo to be sent, 0-1024 characters after entities parsing. + // + // optional + Caption string `json:"caption,omitempty"` + // ParseMode mode for parsing entities in the photo caption. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // ReplyMarkup inline keyboard attached to the message. + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the photo. + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultVenue is an inline query response venue. +type InlineQueryResultVenue struct { + // Type of the result, must be venue + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 Bytes + // + // required + ID string `json:"id"` + // Latitude of the venue location in degrees + // + // required + Latitude float64 `json:"latitude"` + // Longitude of the venue location in degrees + // + // required + Longitude float64 `json:"longitude"` + // Title of the venue + // + // required + Title string `json:"title"` + // Address of the venue + // + // required + Address string `json:"address"` + // FoursquareID foursquare identifier of the venue if known + // + // optional + FoursquareID string `json:"foursquare_id,omitempty"` + // FoursquareType foursquare type of the venue, if known. + // (For example, β€œarts_entertainment/default”, β€œarts_entertainment/aquarium” or β€œfood/icecream”.) + // + // optional + FoursquareType string `json:"foursquare_type,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the venue + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` + // ThumbURL url of the thumbnail for the result + // + // optional + ThumbURL string `json:"thumb_url,omitempty"` + // ThumbWidth thumbnail width + // + // optional + ThumbWidth int `json:"thumb_width,omitempty"` + // ThumbHeight thumbnail height + // + // optional + ThumbHeight int `json:"thumb_height,omitempty"` +} + +// InlineQueryResultVideo is an inline query response video. +type InlineQueryResultVideo struct { + // Type of the result, must be video + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // URL a valid url for the embedded video player or video file + // + // required + URL string `json:"video_url"` + // MimeType of the content of video url, β€œtext/html” or β€œvideo/mp4” + // + // required + MimeType string `json:"mime_type"` + // + // ThumbURL url of the thumbnail (jpeg only) for the video + // optional + ThumbURL string `json:"thumb_url,omitempty"` + // Title for the result + // + // required + Title string `json:"title"` + // Caption of the video to be sent, 0-1024 characters after entities parsing + // + // optional + Caption string `json:"caption,omitempty"` + // Width video width + // + // optional + Width int `json:"video_width,omitempty"` + // Height video height + // + // optional + Height int `json:"video_height,omitempty"` + // Duration video duration in seconds + // + // optional + Duration int `json:"video_duration,omitempty"` + // Description short description of the result + // + // optional + Description string `json:"description,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the video. + // This field is required if InlineQueryResultVideo is used to send + // an HTML-page as a result (e.g., a YouTube video). + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` +} + +// InlineQueryResultVoice is an inline query response voice. +type InlineQueryResultVoice struct { + // Type of the result, must be voice + // + // required + Type string `json:"type"` + // ID unique identifier for this result, 1-64 bytes + // + // required + ID string `json:"id"` + // URL a valid URL for the voice recording + // + // required + URL string `json:"voice_url"` + // Title recording title + // + // required + Title string `json:"title"` + // Caption 0-1024 characters after entities parsing + // + // optional + Caption string `json:"caption,omitempty"` + // Duration recording duration in seconds + // + // optional + Duration int `json:"voice_duration,omitempty"` + // ReplyMarkup inline keyboard attached to the message + // + // optional + ReplyMarkup *InlineKeyboardMarkup `json:"reply_markup,omitempty"` + // InputMessageContent content of the message to be sent instead of the voice recording + // + // optional + InputMessageContent interface{} `json:"input_message_content,omitempty"` } // ChosenInlineResult is an inline query result chosen by a User type ChosenInlineResult struct { - ResultID string `json:"result_id"` - From *User `json:"from"` - Location *Location `json:"location"` - InlineMessageID string `json:"inline_message_id"` - Query string `json:"query"` + // ResultID the unique identifier for the result that was chosen + ResultID string `json:"result_id"` + // From the user that chose the result + From *User `json:"from"` + // Location sender location, only for bots that require user location + // + // optional + Location *Location `json:"location,omitempty"` + // InlineMessageID identifier of the sent inline message. + // Available only if there is an inline keyboard attached to the message. + // Will be also received in callback queries and can be used to edit the message. + // + // optional + InlineMessageID string `json:"inline_message_id,omitempty"` + // Query the query that was used to obtain the result + Query string `json:"query"` } // InputTextMessageContent contains text for displaying // as an inline query result. type InputTextMessageContent struct { - Text string `json:"message_text"` - ParseMode string `json:"parse_mode"` - DisableWebPagePreview bool `json:"disable_web_page_preview"` + // Text of the message to be sent, 1-4096 characters + Text string `json:"message_text"` + // ParseMode mode for parsing entities in the message text. + // See formatting options for more details + // (https://core.telegram.org/bots/api#formatting-options). + // + // optional + ParseMode string `json:"parse_mode,omitempty"` + // DisableWebPagePreview disables link previews for links in the sent message + // + // optional + DisableWebPagePreview bool `json:"disable_web_page_preview,omitempty"` } // InputLocationMessageContent contains a location for displaying // as an inline query result. type InputLocationMessageContent struct { - Latitude float64 `json:"latitude"` + // Latitude of the location in degrees + Latitude float64 `json:"latitude"` + // Longitude of the location in degrees Longitude float64 `json:"longitude"` + // LivePeriod is the period in seconds for which the location can be + // updated, should be between 60 and 86400 + // + // optional + LivePeriod int `json:"live_period,omitempty"` } // InputVenueMessageContent contains a venue for displaying // as an inline query result. type InputVenueMessageContent struct { - Latitude float64 `json:"latitude"` - Longitude float64 `json:"longitude"` - Title string `json:"title"` - Address string `json:"address"` - FoursquareID string `json:"foursquare_id"` + // Latitude of the venue in degrees + Latitude float64 `json:"latitude"` + // Longitude of the venue in degrees + Longitude float64 `json:"longitude"` + // Title name of the venue + Title string `json:"title"` + // Address of the venue + Address string `json:"address"` + // FoursquareID foursquare identifier of the venue, if known + // + // optional + FoursquareID string `json:"foursquare_id,omitempty"` + // FoursquareType Foursquare type of the venue, if known + // + // optional + FoursquareType string `json:"foursquare_type,omitempty"` } // InputContactMessageContent contains a contact for displaying // as an inline query result. type InputContactMessageContent struct { + // PhoneNumber contact's phone number PhoneNumber string `json:"phone_number"` - FirstName string `json:"first_name"` - LastName string `json:"last_name"` - VCard string `json:"vcard"` -} - -// Invoice contains basic information about an invoice. -type Invoice struct { - Title string `json:"title"` - Description string `json:"description"` - StartParameter string `json:"start_parameter"` - Currency string `json:"currency"` - TotalAmount int `json:"total_amount"` + // FirstName contact's first name + FirstName string `json:"first_name"` + // LastName contact's last name + // + // optional + LastName string `json:"last_name,omitempty"` + // Additional data about the contact in the form of a vCard + // + // optional + VCard string `json:"vcard,omitempty"` } // LabeledPrice represents a portion of the price for goods or services. type LabeledPrice struct { - Label string `json:"label"` - Amount int `json:"amount"` + // Label portion label + Label string `json:"label"` + // Amount price of the product in the smallest units of the currency (integer, not float/double). + // For example, for a price of US$ 1.45 pass amount = 145. + // See the exp parameter in currencies.json + // (https://core.telegram.org/bots/payments/currencies.json), + // it shows the number of digits past the decimal point + // for each currency (2 for the majority of currencies). + Amount int `json:"amount"` +} + +// Invoice contains basic information about an invoice. +type Invoice struct { + // Title product name + Title string `json:"title"` + // Description product description + Description string `json:"description"` + // StartParameter unique bot deep-linking parameter that can be used to generate this invoice + StartParameter string `json:"start_parameter"` + // Currency three-letter ISO 4217 currency code + // (see https://core.telegram.org/bots/payments#supported-currencies) + Currency string `json:"currency"` + // TotalAmount total price in the smallest units of the currency (integer, not float/double). + // For example, for a price of US$ 1.45 pass amount = 145. + // See the exp parameter in currencies.json + // (https://core.telegram.org/bots/payments/currencies.json), + // it shows the number of digits past the decimal point + // for each currency (2 for the majority of currencies). + TotalAmount int `json:"total_amount"` } // ShippingAddress represents a shipping address. type ShippingAddress struct { + // CountryCode ISO 3166-1 alpha-2 country code CountryCode string `json:"country_code"` - State string `json:"state"` - City string `json:"city"` + // State if applicable + State string `json:"state"` + // City city + City string `json:"city"` + // StreetLine1 first line for the address StreetLine1 string `json:"street_line1"` + // StreetLine2 second line for the address StreetLine2 string `json:"street_line2"` - PostCode string `json:"post_code"` + // PostCode address post code + PostCode string `json:"post_code"` } // OrderInfo represents information about an order. type OrderInfo struct { - Name string `json:"name,omitempty"` - PhoneNumber string `json:"phone_number,omitempty"` - Email string `json:"email,omitempty"` + // Name user name + // + // optional + Name string `json:"name,omitempty"` + // PhoneNumber user's phone number + // + // optional + PhoneNumber string `json:"phone_number,omitempty"` + // Email user email + // + // optional + Email string `json:"email,omitempty"` + // ShippingAddress user shipping address + // + // optional ShippingAddress *ShippingAddress `json:"shipping_address,omitempty"` } // ShippingOption represents one shipping option. type ShippingOption struct { - ID string `json:"id"` - Title string `json:"title"` + // ID shipping option identifier + ID string `json:"id"` + // Title option title + Title string `json:"title"` + // Prices list of price portions Prices []LabeledPrice `json:"prices"` } // SuccessfulPayment contains basic information about a successful payment. type SuccessfulPayment struct { - Currency string `json:"currency"` - TotalAmount int `json:"total_amount"` - InvoicePayload string `json:"invoice_payload"` - ShippingOptionID string `json:"shipping_option_id,omitempty"` - OrderInfo *OrderInfo `json:"order_info,omitempty"` - TelegramPaymentChargeID string `json:"telegram_payment_charge_id"` - ProviderPaymentChargeID string `json:"provider_payment_charge_id"` + // Currency three-letter ISO 4217 currency code + // (see https://core.telegram.org/bots/payments#supported-currencies) + Currency string `json:"currency"` + // TotalAmount total price in the smallest units of the currency (integer, not float/double). + // For example, for a price of US$ 1.45 pass amount = 145. + // See the exp parameter in currencies.json, + // (https://core.telegram.org/bots/payments/currencies.json) + // it shows the number of digits past the decimal point + // for each currency (2 for the majority of currencies). + TotalAmount int `json:"total_amount"` + // InvoicePayload bot specified invoice payload + InvoicePayload string `json:"invoice_payload"` + // ShippingOptionID identifier of the shipping option chosen by the user + // + // optional + ShippingOptionID string `json:"shipping_option_id,omitempty"` + // OrderInfo order info provided by the user + // + // optional + OrderInfo *OrderInfo `json:"order_info,omitempty"` + // TelegramPaymentChargeID telegram payment identifier + TelegramPaymentChargeID string `json:"telegram_payment_charge_id"` + // ProviderPaymentChargeID provider payment identifier + ProviderPaymentChargeID string `json:"provider_payment_charge_id"` } // ShippingQuery contains information about an incoming shipping query. type ShippingQuery struct { - ID string `json:"id"` - From *User `json:"from"` - InvoicePayload string `json:"invoice_payload"` + // ID unique query identifier + ID string `json:"id"` + // From user who sent the query + From *User `json:"from"` + // InvoicePayload bot specified invoice payload + InvoicePayload string `json:"invoice_payload"` + // ShippingAddress user specified shipping address ShippingAddress *ShippingAddress `json:"shipping_address"` } // PreCheckoutQuery contains information about an incoming pre-checkout query. type PreCheckoutQuery struct { - ID string `json:"id"` - From *User `json:"from"` - Currency string `json:"currency"` - TotalAmount int `json:"total_amount"` - InvoicePayload string `json:"invoice_payload"` - ShippingOptionID string `json:"shipping_option_id,omitempty"` - OrderInfo *OrderInfo `json:"order_info,omitempty"` -} - -// StickerSet is a collection of stickers. -type StickerSet struct { - Name string `json:"name"` - Title string `json:"title"` - IsAnimated bool `json:"is_animated"` - ContainsMasks bool `json:"contains_masks"` - Stickers []Sticker `json:"stickers"` - Thumb *PhotoSize `json:"thumb"` -} - -// BotCommand represents Telegram's understanding of a command. -type BotCommand struct { - Command string `json:"command"` - Description string `json:"description"` -} - -// BaseInputMedia is a base type for the InputMedia types. -type BaseInputMedia struct { - Type string `json:"type"` - Media string `json:"media"` - Caption string `json:"caption"` - ParseMode string `json:"parse_mode"` -} - -// InputMediaPhoto is a photo to send as part of a media group. -type InputMediaPhoto struct { - BaseInputMedia -} - -// InputMediaVideo is a video to send as part of a media group. -type InputMediaVideo struct { - BaseInputMedia - Width int `json:"width"` - Height int `json:"height"` - Duration int `json:"duration"` - SupportsStreaming bool `json:"supports_streaming"` -} - -// InputMediaAnimation is an animation to send as part of a media group. -type InputMediaAnimation struct { - BaseInputMedia - Width int `json:"width"` - Height int `json:"height"` - Duration int `json:"duration"` -} - -// InputMediaAudio is a audio to send as part of a media group. -type InputMediaAudio struct { - BaseInputMedia - Duration int `json:"duration"` - Performer string `json:"performer"` - Title string `json:"title"` -} - -// InputMediaDocument is a audio to send as part of a media group. -type InputMediaDocument struct { - BaseInputMedia -} - -// Error is an error containing extra information returned by the Telegram API. -type Error struct { - Code int - Message string - ResponseParameters -} - -// Error message string. -func (e Error) Error() string { - return e.Message + // ID unique query identifier + ID string `json:"id"` + // From user who sent the query + From *User `json:"from"` + // Currency three-letter ISO 4217 currency code + // // (see https://core.telegram.org/bots/payments#supported-currencies) + Currency string `json:"currency"` + // TotalAmount total price in the smallest units of the currency (integer, not float/double). + // // For example, for a price of US$ 1.45 pass amount = 145. + // // See the exp parameter in currencies.json, + // // (https://core.telegram.org/bots/payments/currencies.json) + // // it shows the number of digits past the decimal point + // // for each currency (2 for the majority of currencies). + TotalAmount int `json:"total_amount"` + // InvoicePayload bot specified invoice payload + InvoicePayload string `json:"invoice_payload"` + // ShippingOptionID identifier of the shipping option chosen by the user + // + // optional + ShippingOptionID string `json:"shipping_option_id,omitempty"` + // OrderInfo order info provided by the user + // + // optional + OrderInfo *OrderInfo `json:"order_info,omitempty"` } diff --git a/types_test.go b/types_test.go index 401cb6a..f0bd45f 100644 --- a/types_test.go +++ b/types_test.go @@ -310,6 +310,7 @@ var ( _ Chattable = MessageConfig{} _ Chattable = PhotoConfig{} _ Chattable = PinChatMessageConfig{} + _ Chattable = PreCheckoutConfig{} _ Chattable = PromoteChatMemberConfig{} _ Chattable = RemoveWebhookConfig{} _ Chattable = RestrictChatMemberConfig{} @@ -318,6 +319,7 @@ var ( _ Chattable = SetChatPhotoConfig{} _ Chattable = SetChatTitleConfig{} _ Chattable = SetGameScoreConfig{} + _ Chattable = ShippingConfig{} _ Chattable = StickerConfig{} _ Chattable = StopPollConfig{} _ Chattable = StopMessageLiveLocationConfig{} From 4064ced03f921894c1c8ee0b40476903f7d10b40 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Fri, 6 Nov 2020 12:36:00 -0500 Subject: [PATCH 6/8] Add some tests, fix copyMessage. --- bot.go | 20 ++++++++++++++++++ bot_test.go | 57 ++++++++++++++++++++++++++++++++++++++++++++++----- configs.go | 4 ++++ helpers.go | 12 +++++++++++ types.go | 5 +++++ types_test.go | 3 +++ 6 files changed, 96 insertions(+), 5 deletions(-) diff --git a/bot.go b/bot.go index a78e635..d7b5b88 100644 --- a/bot.go +++ b/bot.go @@ -668,3 +668,23 @@ func (bot *BotAPI) GetMyCommands() ([]BotCommand, error) { return commands, err } + +// CopyMessage copy messages of any kind. The method is analogous to the method +// forwardMessage, but the copied message doesn't have a link to the original +// message. Returns the MessageID of the sent message on success. +func (bot *BotAPI) CopyMessage(config CopyMessageConfig) (MessageID, error) { + params, err := config.params() + if err != nil { + return MessageID{}, err + } + + resp, err := bot.MakeRequest(config.method(), params) + if err != nil { + return MessageID{}, err + } + + var messageID MessageID + err = json.Unmarshal(resp.Result, &messageID) + + return messageID, err +} diff --git a/bot_test.go b/bot_test.go index ddb8fb2..c465909 100644 --- a/bot_test.go +++ b/bot_test.go @@ -73,7 +73,7 @@ func TestSendWithMessage(t *testing.T) { bot, _ := getBot(t) msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api") - msg.ParseMode = "markdown" + msg.ParseMode = ModeMarkdown _, err := bot.Send(msg) if err != nil { @@ -104,6 +104,26 @@ func TestSendWithMessageForward(t *testing.T) { } } +func TestCopyMessage(t *testing.T) { + bot, _ := getBot(t) + + msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api") + message, err := bot.Send(msg) + if err != nil { + t.Error(err) + } + + copyMessageConfig := NewCopyMessage(SupergroupChatID, message.Chat.ID, message.MessageID) + messageID, err := bot.CopyMessage(copyMessageConfig) + if err != nil { + t.Error(err) + } + + if messageID.MessageID == message.MessageID { + t.Error("copied message ID was the same as original message") + } +} + func TestSendWithNewPhoto(t *testing.T) { bot, _ := getBot(t) @@ -724,7 +744,7 @@ func TestDeleteMessage(t *testing.T) { bot, _ := getBot(t) msg := NewMessage(ChatID, "A test message from the test library in telegram-bot-api") - msg.ParseMode = "markdown" + msg.ParseMode = ModeMarkdown message, _ := bot.Send(msg) deleteMessageConfig := DeleteMessageConfig{ @@ -742,7 +762,7 @@ func TestPinChatMessage(t *testing.T) { bot, _ := getBot(t) msg := NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api") - msg.ParseMode = "markdown" + msg.ParseMode = ModeMarkdown message, _ := bot.Send(msg) pinChatMessageConfig := PinChatMessageConfig{ @@ -761,7 +781,7 @@ func TestUnpinChatMessage(t *testing.T) { bot, _ := getBot(t) msg := NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api") - msg.ParseMode = "markdown" + msg.ParseMode = ModeMarkdown message, _ := bot.Send(msg) // We need pin message to unpin something @@ -776,7 +796,8 @@ func TestUnpinChatMessage(t *testing.T) { } unpinChatMessageConfig := UnpinChatMessageConfig{ - ChatID: message.Chat.ID, + ChatID: message.Chat.ID, + MessageID: message.MessageID, } if _, err := bot.Request(unpinChatMessageConfig); err != nil { @@ -784,6 +805,32 @@ func TestUnpinChatMessage(t *testing.T) { } } +func TestUnpinAllChatMessages(t *testing.T) { + bot, _ := getBot(t) + + msg := NewMessage(SupergroupChatID, "A test message from the test library in telegram-bot-api") + msg.ParseMode = ModeMarkdown + message, _ := bot.Send(msg) + + pinChatMessageConfig := PinChatMessageConfig{ + ChatID: message.Chat.ID, + MessageID: message.MessageID, + DisableNotification: true, + } + + if _, err := bot.Request(pinChatMessageConfig); err != nil { + t.Error(err) + } + + unpinAllChatMessagesConfig := UnpinAllChatMessagesConfig{ + ChatID: message.Chat.ID, + } + + if _, err := bot.Request(unpinAllChatMessagesConfig); err != nil { + t.Error(err) + } +} + func TestPolls(t *testing.T) { bot, _ := getBot(t) diff --git a/configs.go b/configs.go index c1321cd..cf192a4 100644 --- a/configs.go +++ b/configs.go @@ -241,6 +241,10 @@ func (config CopyMessageConfig) params() (Params, error) { return params, err } +func (config CopyMessageConfig) method() string { + return "copyMessage" +} + // PhotoConfig contains information about a SendPhoto request. type PhotoConfig struct { BaseFile diff --git a/helpers.go b/helpers.go index 4338c0a..e98ae06 100644 --- a/helpers.go +++ b/helpers.go @@ -52,6 +52,18 @@ func NewForward(chatID int64, fromChatID int64, messageID int) ForwardConfig { } } +// NewCopyMessage creates a new copy message. +// +// chatID is where to send it, fromChatID is the source chat, +// and messageID is the ID of the original message. +func NewCopyMessage(chatID int64, fromChatID int64, messageID int) CopyMessageConfig { + return CopyMessageConfig{ + BaseChat: BaseChat{ChatID: chatID}, + FromChatID: fromChatID, + MessageID: messageID, + } +} + // NewPhotoUpload creates a new photo uploader. // // chatID is where to send it, file is a string path to the file, diff --git a/types.go b/types.go index 63bcb13..22ae9f1 100644 --- a/types.go +++ b/types.go @@ -584,6 +584,11 @@ func (m *Message) CommandArguments() string { return m.Text[entity.Length+1:] } +// MessageID represents a unique message identifier. +type MessageID struct { + MessageID int `json:"message_id"` +} + // MessageEntity represents one special entity in a text message. type MessageEntity struct { // Type of the entity. diff --git a/types_test.go b/types_test.go index 0b1be9d..e9e2026 100644 --- a/types_test.go +++ b/types_test.go @@ -286,6 +286,8 @@ var ( _ Chattable = ChatActionConfig{} _ Chattable = ChatInfoConfig{} _ Chattable = ChatInviteLinkConfig{} + _ Chattable = CloseConfig{} + _ Chattable = CopyMessageConfig{} _ Chattable = ContactConfig{} _ Chattable = DeleteChatPhotoConfig{} _ Chattable = DeleteChatStickerSetConfig{} @@ -306,6 +308,7 @@ var ( _ Chattable = KickChatMemberConfig{} _ Chattable = LeaveChatConfig{} _ Chattable = LocationConfig{} + _ Chattable = LogOutConfig{} _ Chattable = MediaGroupConfig{} _ Chattable = MessageConfig{} _ Chattable = PhotoConfig{} From 24d4f79474ff891d3ee1b2e3756a094556c78464 Mon Sep 17 00:00:00 2001 From: Syfaro Date: Tue, 9 Mar 2021 12:27:17 -0500 Subject: [PATCH 7/8] Updates for Bot API 5.1. --- configs.go | 102 +++++++++++++++++++++++++++++++++++++++------ types.go | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++ types_test.go | 11 +++-- 3 files changed, 209 insertions(+), 16 deletions(-) diff --git a/configs.go b/configs.go index cf192a4..4b53b87 100644 --- a/configs.go +++ b/configs.go @@ -1067,7 +1067,8 @@ func (config UnbanChatMemberConfig) params() (Params, error) { // KickChatMemberConfig contains extra fields to kick user type KickChatMemberConfig struct { ChatMemberConfig - UntilDate int64 + UntilDate int64 + RevokeMessages bool } func (config KickChatMemberConfig) method() string { @@ -1080,6 +1081,7 @@ func (config KickChatMemberConfig) params() (Params, error) { params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) params.AddNonZero("user_id", config.UserID) params.AddNonZero64("until_date", config.UntilDate) + params.AddBool("revoke_messages", config.RevokeMessages) return params, nil } @@ -1110,15 +1112,17 @@ func (config RestrictChatMemberConfig) params() (Params, error) { // PromoteChatMemberConfig contains fields to promote members of chat type PromoteChatMemberConfig struct { ChatMemberConfig - IsAnonymous bool - CanChangeInfo bool - CanPostMessages bool - CanEditMessages bool - CanDeleteMessages bool - CanInviteUsers bool - CanRestrictMembers bool - CanPinMessages bool - CanPromoteMembers bool + IsAnonymous bool + CanManageChat bool + CanChangeInfo bool + CanPostMessages bool + CanEditMessages bool + CanDeleteMessages bool + CanManageVoiceChats bool + CanInviteUsers bool + CanRestrictMembers bool + CanPinMessages bool + CanPromoteMembers bool } func (config PromoteChatMemberConfig) method() string { @@ -1132,10 +1136,12 @@ func (config PromoteChatMemberConfig) params() (Params, error) { params.AddNonZero("user_id", config.UserID) params.AddBool("is_anonymous", config.IsAnonymous) + params.AddBool("can_manage_chat", config.CanManageChat) params.AddBool("can_change_info", config.CanChangeInfo) params.AddBool("can_post_messages", config.CanPostMessages) params.AddBool("can_edit_messages", config.CanEditMessages) params.AddBool("can_delete_messages", config.CanDeleteMessages) + params.AddBool("can_manage_voice_chats", config.CanManageVoiceChats) params.AddBool("can_invite_users", config.CanInviteUsers) params.AddBool("can_restrict_members", config.CanRestrictMembers) params.AddBool("can_pin_messages", config.CanPinMessages) @@ -1246,6 +1252,77 @@ func (config ChatInviteLinkConfig) params() (Params, error) { return params, nil } +// CreateChatInviteLinkConfig allows you to create an additional invite link for +// a chat. The bot must be an administrator in the chat for this to work and +// must have the appropriate admin rights. The link can be revoked using the +// RevokeChatInviteLinkConfig. +type CreateChatInviteLinkConfig struct { + ChatConfig + ExpireDate int + MemberLimit int +} + +func (CreateChatInviteLinkConfig) method() string { + return "createChatInviteLink" +} + +func (config CreateChatInviteLinkConfig) params() (Params, error) { + params := make(Params) + + params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + params.AddNonZero("expire_date", config.ExpireDate) + params.AddNonZero("member_limit", config.MemberLimit) + + return params, nil +} + +// EditChatInviteLinkConfig allows you to edit a non-primary invite link created +// by the bot. The bot must be an administrator in the chat for this to work and +// must have the appropriate admin rights. +type EditChatInviteLinkConfig struct { + ChatConfig + InviteLink string + ExpireDate int + MemberLimit int +} + +func (EditChatInviteLinkConfig) method() string { + return "editChatInviteLink" +} + +func (config EditChatInviteLinkConfig) params() (Params, error) { + params := make(Params) + + params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + params["invite_link"] = config.InviteLink + params.AddNonZero("expire_date", config.ExpireDate) + params.AddNonZero("member_limit", config.MemberLimit) + + return params, nil +} + +// RevokeChatInviteLinkConfig allows you to revoke an invite link created by the +// bot. If the primary link is revoked, a new link is automatically generated. +// The bot must be an administrator in the chat for this to work and must have +// the appropriate admin rights. +type RevokeChatInviteLinkConfig struct { + ChatConfig + InviteLink string +} + +func (RevokeChatInviteLinkConfig) method() string { + return "revokeChatInviteLink" +} + +func (config RevokeChatInviteLinkConfig) params() (Params, error) { + params := make(Params) + + params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + params["invite_link"] = config.InviteLink + + return params, nil +} + // LeaveChatConfig allows you to leave a chat. type LeaveChatConfig struct { ChatID int64 @@ -1885,8 +1962,9 @@ func (config SetMyCommandsConfig) params() (Params, error) { type DiceConfig struct { BaseChat // Emoji on which the dice throw animation is based. - // Currently, must be one of β€œπŸŽ²β€, β€œπŸŽ―β€, or β€œπŸ€β€. - // Dice can have values 1-6 for β€œπŸŽ²β€ and β€œπŸŽ―β€, and values 1-5 for β€œπŸ€β€. + // Currently, must be one of 🎲, 🎯, πŸ€, ⚽, 🎳, or 🎰. + // Dice can have values 1-6 for 🎲, 🎯, and 🎳, values 1-5 for πŸ€ and ⚽, + // and values 1-64 for 🎰. // Defaults to β€œπŸŽ²β€ Emoji string } diff --git a/types.go b/types.go index 22ae9f1..e6810ae 100644 --- a/types.go +++ b/types.go @@ -96,6 +96,18 @@ type Update struct { // // optional PollAnswer *PollAnswer `json:"poll_answer,omitempty"` + // MyChatMember is the bot's chat member status was updated in a chat. For + // private chats, this update is received only when the bot is blocked or + // unblocked by the user. + // + // optional + MyChatMember *ChatMemberUpdated `json:"my_chat_member"` + // ChatMember is a chat member's status was updated in a chat. The bot must + // be an administrator in the chat and must explicitly specify "chat_member" + // in the list of allowed_updates to receive these updates. + // + // optional + ChatMember *ChatMemberUpdated `json:"chat_member"` } // UpdatesChannel is the channel for getting updates. @@ -463,6 +475,11 @@ type Message struct { // // optional ChannelChatCreated bool `json:"channel_chat_created,omitempty"` + // MessageAutoDeleteTimerChanged is a service message: auto-delete timer + // settings changed in the chat. + // + // optional + MessageAutoDeleteTimerChanged *MessageAutoDeleteTimerChanged `json:"message_auto_delete_timer_changed"` // MigrateToChatID is the group has been migrated to a supergroup with the specified identifier. // This number may be greater than 32 bits and some programming languages // may have difficulty/silent defects in interpreting it. @@ -508,6 +525,19 @@ type Message struct { // // optional ProximityAlertTriggered *ProximityAlertTriggered `json:"proximity_alert_triggered"` + // VoiceChatStarted is a service message: voice chat started. + // + // optional + VoiceChatStarted *VoiceChatStarted `json:"voice_chat_started"` + // VoiceChatEnded is a service message: voice chat ended. + // + // optional + VoiceChatEnded *VoiceChatEnded `json:"voice_chat_ended"` + // VoiceChatParticipantsInvited is a service message: new participants + // invited to a voice chat. + // + // optional + VoiceChatParticipantsInvited *VoiceChatParticipantsInvited `json:"voice_chat_participants_invited"` // ReplyMarkup is the Inline keyboard attached to the message. // login_url buttons are represented as ordinary url buttons. // @@ -1037,6 +1067,33 @@ type ProximityAlertTriggered struct { Distance int `json:"distance"` } +// MessageAutoDeleteTimerChanged represents a service message about a change in +// auto-delete timer settings. +type MessageAutoDeleteTimerChanged struct { + // New auto-delete time for messages in the chat. + MessageAutoDeleteTime int `json:"message_auto_delete_time"` +} + +// VoiceChatStarted represents a service message about a voice chat started in +// the chat. +type VoiceChatStarted struct{} + +// VoiceChatEnded represents a service message about a voice chat ended in the +// chat. +type VoiceChatEnded struct { + // Voice chat duration; in seconds. + Duration int `json:"duration"` +} + +// VoiceChatParticipantsInvited represents a service message about new members +// invited to a voice chat. +type VoiceChatParticipantsInvited struct { + // New members that were invited to the voice chat. + // + // optional + Users []User `json:"users"` +} + // UserProfilePhotos contains a set of user profile photos. type UserProfilePhotos struct { // TotalCount total number of profile pictures the target user has @@ -1336,6 +1393,29 @@ type ChatPhoto struct { BigFileUniqueID string `json:"big_file_unique_id"` } +// ChatInviteLink represents an invite link for a chat. +type ChatInviteLink struct { + // InviteLink is the invite link. If the link was created by another chat + // administrator, then the second part of the link will be replaced with β€œβ€¦β€. + InviteLink string `json:"invite_link"` + // Creator of the link. + Creator User `json:"creator"` + // IsPrimary is true, if the link is primary. + IsPrimary bool `json:"is_primary"` + // IsRevoked is true, if the link is revoked. + IsRevoked bool `json:"is_revoked"` + // ExpireDate is the point in time (Unix timestamp) when the link will + // expire or has been expired. + // + // optional + ExpireDate int `json:"expire_date"` + // MemberLimit is the maximum number of users that can be members of the + // chat simultaneously after joining the chat via this invite link; 1-99999. + // + // optional + MemberLimit int `json:"member_limit"` +} + // ChatMember contains information about one member of a chat. type ChatMember struct { // User information about the user @@ -1369,6 +1449,14 @@ type ChatMember struct { // // optional CanBeEdited bool `json:"can_be_edited,omitempty"` + // CanManageChat administrators only. + // True, if the administrator can access the chat event log, chat + // statistics, message statistics in channels, see channel members, see + // anonymous administrators in supergoups and ignore slow mode. Implied by + // any other administrator privilege. + // + // optional + CanManageChat bool `json:"can_manage_chat"` // CanPostMessages administrators only. // True, if the administrator can post in the channel; // channels only. @@ -1386,6 +1474,11 @@ type ChatMember struct { // // optional CanDeleteMessages bool `json:"can_delete_messages,omitempty"` + // CanManageVoiceChats administrators only. + // True, if the administrator can manage voice chats. + // + // optional + CanManageVoiceChats bool `json:"can_manage_voice_chats"` // CanRestrictMembers administrators only. // True, if the administrator can restrict, ban or unban chat members. // @@ -1455,6 +1548,25 @@ func (chat ChatMember) HasLeft() bool { return chat.Status == "left" } // WasKicked returns if the ChatMember was kicked from the chat. func (chat ChatMember) WasKicked() bool { return chat.Status == "kicked" } +// ChatMemberUpdated represents changes in the status of a chat member. +type ChatMemberUpdated struct { + // Chat the user belongs to. + Chat Chat `json:"chat"` + // From is the performer of the action, which resulted in the change. + From User `json:"from"` + // Date the change was done in Unix time. + Date int `json:"date"` + // Previous information about the chat member. + OldChatMember ChatMember `json:"old_chat_member"` + // New information about the chat member. + NewChatMember ChatMember `json:"new_chat_member"` + // InviteLink is the link which was used by the user to join the chat; + // for joining by invite link events only. + // + // optional + InviteLink *ChatInviteLink `json:"invite_link"` +} + // ChatPermissions describes actions that a non-administrator user is // allowed to take in a chat. All fields are optional. type ChatPermissions struct { diff --git a/types_test.go b/types_test.go index e9e2026..ba5f457 100644 --- a/types_test.go +++ b/types_test.go @@ -282,17 +282,20 @@ var ( _ Chattable = AnimationConfig{} _ Chattable = AudioConfig{} _ Chattable = CallbackConfig{} - _ Chattable = ChatAdministratorsConfig{} _ Chattable = ChatActionConfig{} + _ Chattable = ChatAdministratorsConfig{} _ Chattable = ChatInfoConfig{} _ Chattable = ChatInviteLinkConfig{} _ Chattable = CloseConfig{} - _ Chattable = CopyMessageConfig{} _ Chattable = ContactConfig{} + _ Chattable = CopyMessageConfig{} + _ Chattable = CreateChatInviteLinkConfig{} _ Chattable = DeleteChatPhotoConfig{} _ Chattable = DeleteChatStickerSetConfig{} _ Chattable = DeleteMessageConfig{} + _ Chattable = DeleteWebhookConfig{} _ Chattable = DocumentConfig{} + _ Chattable = EditChatInviteLinkConfig{} _ Chattable = EditMessageCaptionConfig{} _ Chattable = EditMessageLiveLocationConfig{} _ Chattable = EditMessageMediaConfig{} @@ -315,8 +318,8 @@ var ( _ Chattable = PinChatMessageConfig{} _ Chattable = PreCheckoutConfig{} _ Chattable = PromoteChatMemberConfig{} - _ Chattable = DeleteWebhookConfig{} _ Chattable = RestrictChatMemberConfig{} + _ Chattable = RevokeChatInviteLinkConfig{} _ Chattable = SendPollConfig{} _ Chattable = SetChatDescriptionConfig{} _ Chattable = SetChatPhotoConfig{} @@ -324,8 +327,8 @@ var ( _ Chattable = SetGameScoreConfig{} _ Chattable = ShippingConfig{} _ Chattable = StickerConfig{} - _ Chattable = StopPollConfig{} _ Chattable = StopMessageLiveLocationConfig{} + _ Chattable = StopPollConfig{} _ Chattable = UnbanChatMemberConfig{} _ Chattable = UnpinChatMessageConfig{} _ Chattable = UpdateConfig{} From 3b5c8a96d7bd1c2b89d8eb1f22db94034e05b820 Mon Sep 17 00:00:00 2001 From: TJ Horner Date: Tue, 9 Mar 2021 15:52:22 -0500 Subject: [PATCH 8/8] Add allowed_updates to GetUpdates --- bot.go | 2 +- configs.go | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/bot.go b/bot.go index d7b5b88..4590eab 100644 --- a/bot.go +++ b/bot.go @@ -387,7 +387,7 @@ func (bot *BotAPI) GetFile(config FileConfig) (File, error) { // GetUpdates fetches updates. // If a WebHook is set, this will not return any data! // -// Offset, Limit, and Timeout are optional. +// Offset, Limit, Timeout, and AllowedUpdates are optional. // To avoid stale items, set Offset to one higher than the previous item. // Set Timeout to a large number to reduce requests so you can get updates // instantly instead of having to wait between requests. diff --git a/configs.go b/configs.go index 4b53b87..b08c3eb 100644 --- a/configs.go +++ b/configs.go @@ -42,6 +42,54 @@ const ( ModeHTML = "HTML" ) +// Constant values for update types +const ( + // New incoming message of any kind β€” text, photo, sticker, etc. + UpdateTypeMessage = "message" + + // New version of a message that is known to the bot and was edited + UpdateTypeEditedMessage = "edited_message" + + // New incoming channel post of any kind β€” text, photo, sticker, etc. + UpdateTypeChannelPost = "channel_post" + + // New version of a channel post that is known to the bot and was edited + UpdateTypeEditedChannelPost = "edited_channel_post" + + // New incoming inline query + UpdateTypeInlineQuery = "inline_query" + + // The result of an inline query that was chosen by a user and sent to their + // chat partner. Please see the documentation on the feedback collecting for + // details on how to enable these updates for your bot. + UpdateTypeChosenInlineResult = "chosen_inline_result" + + // New incoming callback query + UpdateTypeCallbackQuery = "callback_query" + + // New incoming shipping query. Only for invoices with flexible price + UpdateTypeShippingQuery = "shipping_query" + + // New incoming pre-checkout query. Contains full information about checkout + UpdateTypePreCheckoutQuery = "pre_checkout_query" + + // New poll state. Bots receive only updates about stopped polls and polls + // which are sent by the bot + UpdateTypePoll = "poll" + + // A user changed their answer in a non-anonymous poll. Bots receive new votes + // only in polls that were sent by the bot itself. + UpdateTypePollAnswer = "poll_answer" + + // The bot's chat member status was updated in a chat. For private chats, this + // update is received only when the bot is blocked or unblocked by the user. + UpdateTypeMyChatMember = "my_chat_member" + + // The bot must be an administrator in the chat and must explicitly specify + // this update in the list of allowed_updates to receive these updates. + UpdateTypeChatMember = "chat_member" +) + // Library errors const ( // ErrBadFileType happens when you pass an unknown type @@ -888,9 +936,10 @@ func (config FileConfig) params() (Params, error) { // UpdateConfig contains information about a GetUpdates request. type UpdateConfig struct { - Offset int - Limit int - Timeout int + Offset int + Limit int + Timeout int + AllowedUpdates []string } func (UpdateConfig) method() string { @@ -903,6 +952,7 @@ func (config UpdateConfig) params() (Params, error) { params.AddNonZero("offset", config.Offset) params.AddNonZero("limit", config.Limit) params.AddNonZero("timeout", config.Timeout) + params.AddInterface("allowed_updates", config.AllowedUpdates) return params, nil }