diff --git a/bot.go b/bot.go index 2ff6fa2..2fd9a8e 100644 --- a/bot.go +++ b/bot.go @@ -740,3 +740,15 @@ func (bot *BotAPI) AnswerPreCheckoutQuery(config PreCheckoutConfig) (APIResponse return bot.MakeRequest("answerPreCheckoutQuery", v) } + +// DeleteMessage deletes a message in a chat +func (bot *BotAPI) DeleteMessage(config DeleteMessageConfig) (APIResponse, error) { + v, err := config.values() + if err != nil { + return APIResponse{}, err + } + + bot.debugLog(config.method(), v, nil) + + return bot.MakeRequest(config.method(), v) +} diff --git a/bot_test.go b/bot_test.go index a001dcd..d7cec08 100644 --- a/bot_test.go +++ b/bot_test.go @@ -590,3 +590,22 @@ func ExampleAnswerInlineQuery() { } } } + +func TestDeleteMessage(t *testing.T) { + bot, _ := getBot(t) + + msg := tgbotapi.NewMessage(ChatID, "A test message from the test library in telegram-bot-api") + msg.ParseMode = "markdown" + message, _ := bot.Send(msg) + + deleteMessageConfig := tgbotapi.DeleteMessageConfig{ + ChatID: message.Chat.ID, + MessageID: message.MessageID, + } + _, err := bot.DeleteMessage(deleteMessageConfig) + + if err != nil { + t.Error(err) + t.Fail() + } +} diff --git a/configs.go b/configs.go index 5f3f259..a4a0622 100644 --- a/configs.go +++ b/configs.go @@ -986,3 +986,22 @@ type PreCheckoutConfig struct { OK bool // required 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 +}