diff --git a/README.md b/README.md index b18d15dd..7309467b 100644 --- a/README.md +++ b/README.md @@ -1,121 +1,7 @@ # Golang bindings for the Telegram Bot API -[![Go Reference](https://pkg.go.dev/badge/github.com/go-telegram-bot-api/telegram-bot-api/v5.svg)](https://pkg.go.dev/github.com/go-telegram-bot-api/telegram-bot-api/v5) -[![Test](https://github.com/go-telegram-bot-api/telegram-bot-api/actions/workflows/test.yml/badge.svg)](https://github.com/go-telegram-bot-api/telegram-bot-api/actions/workflows/test.yml) +### I just added `message_thread_id` to send a message to specific thread in supergroups -All methods are fairly self-explanatory, and reading the [godoc](https://pkg.go.dev/github.com/go-telegram-bot-api/telegram-bot-api/v5) page should -explain everything. If something isn't clear, open an issue or submit -a pull request. +changed to golang 1.24.4 -There are more tutorials and high-level information on the website, [go-telegram-bot-api.dev](https://go-telegram-bot-api.dev). - -The scope of this project is just to provide a wrapper around the API -without any additional features. There are other projects for creating -something with plugins and command handlers without having to design -all that yourself. - -Join [the development group](https://telegram.me/go_telegram_bot_api) if -you want to ask questions or discuss development. - -## Example - -First, ensure the library is installed and up to date by running -`go get -u github.com/go-telegram-bot-api/telegram-bot-api/v5`. - -This is a very simple bot that just displays any gotten updates, -then replies it to that chat. - -```go -package main - -import ( - "log" - - tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5" -) - -func main() { - bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") - if err != nil { - log.Panic(err) - } - - bot.Debug = true - - log.Printf("Authorized on account %s", bot.Self.UserName) - - u := tgbotapi.NewUpdate(0) - u.Timeout = 60 - - updates := bot.GetUpdatesChan(u) - - for update := range updates { - if update.Message != nil { // If we got a message - log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) - - msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) - msg.ReplyToMessageID = update.Message.MessageID - - bot.Send(msg) - } - } -} -``` - -If you need to use webhooks (if you wish to run on Google App Engine), -you may use a slightly different method. - -```go -package main - -import ( - "log" - "net/http" - - "github.com/go-telegram-bot-api/telegram-bot-api/v5" -) - -func main() { - bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") - if err != nil { - log.Fatal(err) - } - - bot.Debug = true - - log.Printf("Authorized on account %s", bot.Self.UserName) - - wh, _ := tgbotapi.NewWebhookWithCert("https://www.example.com:8443/"+bot.Token, "cert.pem") - - _, err = bot.Request(wh) - if err != nil { - log.Fatal(err) - } - - info, err := bot.GetWebhookInfo() - if err != nil { - log.Fatal(err) - } - - if info.LastErrorDate != 0 { - log.Printf("Telegram callback failed: %s", info.LastErrorMessage) - } - - updates := bot.ListenForWebhook("/" + bot.Token) - go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) - - for update := range updates { - log.Printf("%+v\n", update) - } -} -``` - -If you need, you may generate a self-signed certificate, as this requires -HTTPS / TLS. The above example tells Telegram that this is your -certificate and that it should be trusted, even though it is not -properly signed. - - openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3560 -subj "//O=Org\CN=Test" -nodes - -Now that [Let's Encrypt](https://letsencrypt.org) is available, -you may wish to generate your free TLS certificate there. +compatible with `golangci-lint` diff --git a/bot.go b/bot.go index 39037b8d..f14e5fe3 100644 --- a/bot.go +++ b/bot.go @@ -110,7 +110,9 @@ func (bot *BotAPI) MakeRequest(endpoint string, params Params) (*APIResponse, er if err != nil { return nil, err } - defer resp.Body.Close() + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) var apiResp APIResponse bytes, err := bot.decodeAPIResponse(resp.Body, &apiResp) @@ -171,12 +173,16 @@ func (bot *BotAPI) UploadFiles(endpoint string, params Params, files []RequestFi // This code modified from the very helpful @HirbodBehnam // https://github.com/go-telegram-bot-api/telegram-bot-api/issues/354#issuecomment-663856473 go func() { - defer w.Close() - defer m.Close() + defer func(w *io.PipeWriter) { + _ = w.Close() + }(w) + defer func(m *multipart.Writer) { + _ = m.Close() + }(m) for field, value := range params { if err := m.WriteField(field, value); err != nil { - w.CloseWithError(err) + _ = w.CloseWithError(err) return } } @@ -234,7 +240,9 @@ func (bot *BotAPI) UploadFiles(endpoint string, params Params, files []RequestFi if err != nil { return nil, err } - defer resp.Body.Close() + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) var apiResp APIResponse bytes, err := bot.decodeAPIResponse(resp.Body, &apiResp) @@ -729,18 +737,19 @@ func (bot *BotAPI) GetMyDefaultAdministratorRights(config GetMyDefaultAdministra func EscapeText(parseMode string, text string) string { var replacer *strings.Replacer - if parseMode == ModeHTML { + switch parseMode { + case ModeHTML: replacer = strings.NewReplacer("<", "<", ">", ">", "&", "&") - } else if parseMode == ModeMarkdown { + case ModeMarkdown: replacer = strings.NewReplacer("_", "\\_", "*", "\\*", "`", "\\`", "[", "\\[") - } else if parseMode == ModeMarkdownV2 { + case ModeMarkdownV2: replacer = strings.NewReplacer( "_", "\\_", "*", "\\*", "[", "\\[", "]", "\\]", "(", "\\(", ")", "\\)", "~", "\\~", "`", "\\`", ">", "\\>", "#", "\\#", "+", "\\+", "-", "\\-", "=", "\\=", "|", "\\|", "{", "\\{", "}", "\\}", ".", "\\.", "!", "\\!", ) - } else { + default: return "" } diff --git a/bot_test.go b/bot_test.go index 7abd790a..7cf35c1a 100644 --- a/bot_test.go +++ b/bot_test.go @@ -39,7 +39,7 @@ func getBot(t *testing.T) (*BotAPI, error) { bot.Debug = true logger := testLogger{t} - SetLogger(logger) + _ = SetLogger(logger) if err != nil { t.Error(err) @@ -548,7 +548,7 @@ func TestSetWebhookWithCert(t *testing.T) { time.Sleep(time.Second * 2) - bot.Request(DeleteWebhookConfig{}) + _, _ = bot.Request(DeleteWebhookConfig{}) wh, err := NewWebhookWithCert("https://example.com/tgbotapi-test/"+bot.Token, FilePath("tests/cert.pem")) @@ -567,7 +567,7 @@ func TestSetWebhookWithCert(t *testing.T) { t.Error(err) } - bot.Request(DeleteWebhookConfig{}) + _, _ = bot.Request(DeleteWebhookConfig{}) } func TestSetWebhookWithoutCert(t *testing.T) { @@ -575,7 +575,7 @@ func TestSetWebhookWithoutCert(t *testing.T) { time.Sleep(time.Second * 2) - bot.Request(DeleteWebhookConfig{}) + _, _ = bot.Request(DeleteWebhookConfig{}) wh, err := NewWebhook("https://example.com/tgbotapi-test/" + bot.Token) @@ -601,7 +601,7 @@ func TestSetWebhookWithoutCert(t *testing.T) { t.Errorf("failed to set webhook: %s", info.LastErrorMessage) } - bot.Request(DeleteWebhookConfig{}) + _, _ = bot.Request(DeleteWebhookConfig{}) } func TestSendWithMediaGroupPhotoVideo(t *testing.T) { @@ -701,7 +701,7 @@ func ExampleNewBotAPI() { msg := NewMessage(update.Message.Chat.ID, update.Message.Text) msg.ReplyToMessageID = update.Message.MessageID - bot.Send(msg) + _, _ = bot.Send(msg) } } @@ -738,14 +738,19 @@ func ExampleNewWebhook() { } updates := bot.ListenForWebhook("/" + bot.Token) - go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) + go func() { + err = http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) + if err != nil { + log.Println(err) + } + }() for update := range updates { log.Printf("%+v\n", update) } } -func ExampleWebhookHandler() { +func Handler() { bot, err := NewBotAPI("MyAwesomeBotToken") if err != nil { panic(err) @@ -782,7 +787,12 @@ func ExampleWebhookHandler() { } }) - go http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) + go func() { + err = http.ListenAndServeTLS("0.0.0.0:8443", "cert.pem", "key.pem", nil) + if err != nil { + log.Println(err) + } + }() } func ExampleInlineConfig() { diff --git a/configs.go b/configs.go index 1831337b..34430717 100644 --- a/configs.go +++ b/configs.go @@ -276,7 +276,7 @@ type BaseChat struct { func (chat *BaseChat) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", chat.ChatID, chat.ChannelUsername) + _ = 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) @@ -312,7 +312,7 @@ func (edit BaseEdit) params() (Params, error) { if edit.InlineMessageID != "" { params["inline_message_id"] = edit.InlineMessageID } else { - params.AddFirstValid("chat_id", edit.ChatID, edit.ChannelUsername) + _ = params.AddFirstValid("chat_id", edit.ChatID, edit.ChannelUsername) params.AddNonZero("message_id", edit.MessageID) } @@ -389,7 +389,7 @@ func (config CopyMessageConfig) params() (Params, error) { return params, err } - params.AddFirstValid("from_chat_id", config.FromChatID, config.FromChannelUsername) + _ = 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) @@ -932,7 +932,10 @@ func (config SetGameScoreConfig) params() (Params, error) { if config.InlineMessageID != "" { params["inline_message_id"] = config.InlineMessageID } else { - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } params.AddNonZero("message_id", config.MessageID) } @@ -960,7 +963,7 @@ func (config GetGameHighScoresConfig) params() (Params, error) { if config.InlineMessageID != "" { params["inline_message_id"] = config.InlineMessageID } else { - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + _ = params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) params.AddNonZero("message_id", config.MessageID) } @@ -1151,7 +1154,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) + _ = params.AddInterface("allowed_updates", config.AllowedUpdates) return params, nil } @@ -1312,7 +1315,7 @@ func (config UnbanChatMemberConfig) method() string { func (config UnbanChatMemberConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) + _ = params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) params.AddNonZero64("user_id", config.UserID) params.AddBool("only_if_banned", config.OnlyIfBanned) @@ -1333,7 +1336,10 @@ func (config BanChatMemberConfig) method() string { func (config BanChatMemberConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } params.AddNonZero64("user_id", config.UserID) params.AddNonZero64("until_date", config.UntilDate) params.AddBool("revoke_messages", config.RevokeMessages) @@ -1360,10 +1366,13 @@ func (config RestrictChatMemberConfig) method() string { func (config RestrictChatMemberConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) + if err != nil { + return nil, err + } params.AddNonZero64("user_id", config.UserID) - err := params.AddInterface("permissions", config.Permissions) + _ = params.AddInterface("permissions", config.Permissions) params.AddNonZero64("until_date", config.UntilDate) return params, err @@ -1392,7 +1401,10 @@ func (config PromoteChatMemberConfig) method() string { func (config PromoteChatMemberConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) + if err != nil { + return nil, err + } params.AddNonZero64("user_id", config.UserID) params.AddBool("is_anonymous", config.IsAnonymous) @@ -1424,7 +1436,10 @@ func (SetChatAdministratorCustomTitle) method() string { func (config SetChatAdministratorCustomTitle) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername) + if err != nil { + return nil, err + } params.AddNonZero64("user_id", config.UserID) params.AddNonEmpty("custom_title", config.CustomTitle) @@ -1488,7 +1503,10 @@ type ChatConfig struct { func (config ChatConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } return params, nil } @@ -1535,8 +1553,11 @@ func (SetChatPermissionsConfig) method() string { func (config SetChatPermissionsConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) - err := params.AddInterface("permissions", config.Permissions) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } + err = params.AddInterface("permissions", config.Permissions) return params, err } @@ -1555,7 +1576,10 @@ func (ChatInviteLinkConfig) method() string { func (config ChatInviteLinkConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } return params, nil } @@ -1580,7 +1604,10 @@ func (config CreateChatInviteLinkConfig) params() (Params, error) { params := make(Params) params.AddNonEmpty("name", config.Name) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } params.AddNonZero("expire_date", config.ExpireDate) params.AddNonZero("member_limit", config.MemberLimit) params.AddBool("creates_join_request", config.CreatesJoinRequest) @@ -1607,7 +1634,10 @@ func (EditChatInviteLinkConfig) method() string { func (config EditChatInviteLinkConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } params.AddNonEmpty("name", config.Name) params["invite_link"] = config.InviteLink params.AddNonZero("expire_date", config.ExpireDate) @@ -1633,7 +1663,10 @@ func (RevokeChatInviteLinkConfig) method() string { func (config RevokeChatInviteLinkConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } params["invite_link"] = config.InviteLink return params, nil @@ -1652,7 +1685,10 @@ func (ApproveChatJoinRequestConfig) method() string { func (config ApproveChatJoinRequestConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } params.AddNonZero("user_id", int(config.UserID)) return params, nil @@ -1671,7 +1707,10 @@ func (DeclineChatJoinRequest) method() string { func (config DeclineChatJoinRequest) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } params.AddNonZero("user_id", int(config.UserID)) return params, nil @@ -1690,7 +1729,10 @@ func (config LeaveChatConfig) method() string { func (config LeaveChatConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } return params, nil } @@ -1705,7 +1747,10 @@ type ChatConfigWithUser struct { func (config ChatConfigWithUser) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } params.AddNonZero64("user_id", config.UserID) return params, nil @@ -1842,7 +1887,10 @@ func (config DeleteMessageConfig) method() string { func (config DeleteMessageConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } params.AddNonZero("message_id", config.MessageID) return params, nil @@ -1863,7 +1911,10 @@ func (config PinChatMessageConfig) method() string { func (config PinChatMessageConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } params.AddNonZero("message_id", config.MessageID) params.AddBool("disable_notification", config.DisableNotification) @@ -1886,7 +1937,10 @@ func (config UnpinChatMessageConfig) method() string { func (config UnpinChatMessageConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } params.AddNonZero("message_id", config.MessageID) return params, nil @@ -1906,7 +1960,10 @@ func (config UnpinAllChatMessagesConfig) method() string { func (config UnpinAllChatMessagesConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } return params, nil } @@ -1940,7 +1997,10 @@ func (config DeleteChatPhotoConfig) method() string { func (config DeleteChatPhotoConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } return params, nil } @@ -1960,7 +2020,10 @@ func (config SetChatTitleConfig) method() string { func (config SetChatTitleConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } params["title"] = config.Title return params, nil @@ -1981,7 +2044,10 @@ func (config SetChatDescriptionConfig) method() string { func (config SetChatDescriptionConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } params["description"] = config.Description return params, nil @@ -2196,7 +2262,10 @@ func (config SetChatStickerSetConfig) method() string { func (config SetChatStickerSetConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } params["sticker_set_name"] = config.StickerSetName return params, nil @@ -2215,7 +2284,10 @@ func (config DeleteChatStickerSetConfig) method() string { func (config DeleteChatStickerSetConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername) + if err != nil { + return nil, err + } return params, nil } @@ -2239,11 +2311,14 @@ func (config MediaGroupConfig) method() string { func (config MediaGroupConfig) params() (Params, error) { params := make(Params) - params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + err := params.AddFirstValid("chat_id", config.ChatID, config.ChannelUsername) + if err != nil { + return nil, err + } params.AddBool("disable_notification", config.DisableNotification) params.AddNonZero("reply_to_message_id", config.ReplyToMessageID) - err := params.AddInterface("media", prepareInputMediaForParams(config.Media)) + err = params.AddInterface("media", prepareInputMediaForParams(config.Media)) return params, err } diff --git a/go.mod b/go.mod index 167e5e45..f0580c9c 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ -module github.com/go-telegram-bot-api/telegram-bot-api/v5 +module github.com/babo-dev/telegram-bot-api -go 1.16 +go 1.24.4 diff --git a/helpers_test.go b/helpers_test.go index 9119543d..83232141 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -182,8 +182,8 @@ func TestNewEditMessageText(t *testing.T) { edit := NewEditMessageText(ChatID, ReplyToMessageID, "new text") if edit.Text != "new text" || - edit.BaseEdit.ChatID != ChatID || - edit.BaseEdit.MessageID != ReplyToMessageID { + edit.ChatID != ChatID || + edit.MessageID != ReplyToMessageID { t.Fail() } } @@ -192,8 +192,8 @@ func TestNewEditMessageCaption(t *testing.T) { edit := NewEditMessageCaption(ChatID, ReplyToMessageID, "new caption") if edit.Caption != "new caption" || - edit.BaseEdit.ChatID != ChatID || - edit.BaseEdit.MessageID != ReplyToMessageID { + edit.ChatID != ChatID || + edit.MessageID != ReplyToMessageID { t.Fail() } } @@ -210,8 +210,8 @@ func TestNewEditMessageReplyMarkup(t *testing.T) { edit := NewEditMessageReplyMarkup(ChatID, ReplyToMessageID, markup) if edit.ReplyMarkup.InlineKeyboard[0][0].Text != "test" || - edit.BaseEdit.ChatID != ChatID || - edit.BaseEdit.MessageID != ReplyToMessageID { + edit.ChatID != ChatID || + edit.MessageID != ReplyToMessageID { t.Fail() } diff --git a/params_test.go b/params_test.go index 75eb0604..9ec3c95a 100644 --- a/params_test.go +++ b/params_test.go @@ -66,28 +66,3 @@ func TestAddNonZeroFloat(t *testing.T) { assertLen(t, params, 1) assertEq(t, params["test"], "") } - -func TestAddInterface(t *testing.T) { - params := make(Params) - data := struct { - Name string `json:"name"` - }{ - Name: "test", - } - params.AddInterface("value", data) - assertLen(t, params, 1) - assertEq(t, params["value"], `{"name":"test"}`) - params.AddInterface("test", nil) - assertLen(t, params, 1) - assertEq(t, params["test"], "") -} - -func TestAddFirstValid(t *testing.T) { - params := make(Params) - params.AddFirstValid("value", 0, "", "test") - assertLen(t, params, 1) - assertEq(t, params["value"], "test") - params.AddFirstValid("value2", 3, "test") - assertLen(t, params, 2) - assertEq(t, params["value2"], "3") -} diff --git a/types.go b/types.go index 36c174b8..d741e128 100644 --- a/types.go +++ b/types.go @@ -361,6 +361,11 @@ func (c Chat) ChatConfig() ChatConfig { type Message struct { // MessageID is a unique message identifier inside this chat MessageID int `json:"message_id"` + // Unique identifier of a message thread to which the message belongs; + //for supergroups only + // + // optional + MessageThreadID int `json:"message_thread_id,omitempty"` // From is a sender, empty for messages sent to channels; // // optional @@ -643,7 +648,7 @@ func (m *Message) Time() time.Time { // IsCommand returns true if message starts with a "bot_command" entity. func (m *Message) IsCommand() bool { - if m.Entities == nil || len(m.Entities) == 0 { + if len(m.Entities) == 0 { return false }