diff --git a/.gitignore b/.gitignore index aa7ac80..c875660 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea/ coverage.out +debug.test \ No newline at end of file diff --git a/bot_test.go b/bot_test.go index d7cec08..bf36ec8 100644 --- a/bot_test.go +++ b/bot_test.go @@ -422,12 +422,17 @@ func TestSendChatConfig(t *testing.T) { func TestSendEditMessage(t *testing.T) { bot, _ := getBot(t) - msg, err := bot.Send(tgbotapi.NewMessage(ChatID, "Testing editing.")) + testMsg := tgbotapi.NewMessage(ChatID, "Testing editing.") + testBtn := tgbotapi.NewInlineKeyboardButtonData("Test", "testdata") + testMsg.ReplyMarkup = tgbotapi.NewInlineKeyboardMarkup(tgbotapi.NewInlineKeyboardRow(testBtn)) + + msg, err := bot.Send(testMsg) if err != nil { t.Error(err) t.Fail() } + //Keyboard should be removed here! edit := tgbotapi.EditMessageTextConfig{ BaseEdit: tgbotapi.BaseEdit{ ChatID: ChatID, @@ -443,6 +448,27 @@ func TestSendEditMessage(t *testing.T) { } } +func TestSendDeleteMessage(t *testing.T) { + bot, _ := getBot(t) + + msg, err := bot.Send(tgbotapi.NewMessage(ChatID, "Testing deleting.")) + if err != nil { + t.Error(err) + t.Fail() + } + + delete := tgbotapi.DeleteMessageConfig{ + ChatID: ChatID, + MessageID: msg.MessageID, + } + + _, err = bot.Send(delete) + if err != nil { + t.Error(err) + t.Fail() + } +} + func TestGetUserProfilePhotos(t *testing.T) { bot, _ := getBot(t) diff --git a/configs.go b/configs.go index 836d1da..04487a0 100644 --- a/configs.go +++ b/configs.go @@ -815,6 +815,25 @@ func (config EditMessageReplyMarkupConfig) method() string { return "editMessageReplyMarkup" } +// DeleteMessageConfig allows you to delete an existing message (sent by the bot). +type DeleteMessageConfig struct { + ChatID int64 + MessageID int +} + +func (config DeleteMessageConfig) values() (url.Values, error) { + v := url.Values{} + + v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) + v.Add("message_id", strconv.Itoa(config.MessageID)) + + return v, nil +} + +func (config DeleteMessageConfig) method() string { + return "deleteMessage" +} + // UserProfilePhotosConfig contains information about a // GetUserProfilePhotos request. type UserProfilePhotosConfig struct { @@ -988,21 +1007,3 @@ type PreCheckoutConfig struct { ErrorMessage string } -// DeleteMessageConfig contains information of a message in a chat to delete. -type DeleteMessageConfig struct { - ChatID int64 - MessageID int -} - -func (config DeleteMessageConfig) method() string { - return "deleteMessage" -} - -func (config DeleteMessageConfig) values() (url.Values, error) { - v := url.Values{} - - v.Add("chat_id", strconv.FormatInt(config.ChatID, 10)) - v.Add("message_id", strconv.Itoa(config.MessageID)) - - return v, nil -} diff --git a/helpers.go b/helpers.go index 132d957..c2e5fb7 100644 --- a/helpers.go +++ b/helpers.go @@ -509,6 +509,14 @@ func NewEditMessageReplyMarkup(chatID int64, messageID int, replyMarkup InlineKe } } +// NewDeleteMessage allows you to delete an existing message (sent previously by the bot) +func NewDeleteMessage(chatID int64, messageID int) DeleteMessageConfig { + return DeleteMessageConfig{ + ChatID: chatID, + MessageID: messageID, + } +} + // NewHideKeyboard hides the keyboard, with the option for being selective // or hiding for everyone. func NewHideKeyboard(selective bool) ReplyKeyboardHide {