From 8fc05f9a42e2b0d7215729831ba93428e43b71f0 Mon Sep 17 00:00:00 2001 From: mamal Date: Mon, 22 May 2017 13:20:43 +0430 Subject: [PATCH] feat(bot): add DeleteMessage function --- bot.go | 14 ++++++++++++++ bot_test.go | 15 +++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/bot.go b/bot.go index e4f0452..18068ff 100644 --- a/bot.go +++ b/bot.go @@ -255,6 +255,20 @@ func (bot *BotAPI) Send(c Chattable) (Message, error) { } } +// DeleteMessage deletes a message from a Chat +// +// It requires the Message to delete +func (bot *BotAPI) DeleteMessage(message Message) (APIResponse, error) { + v := url.Values{} + + v.Add("chat_id", strconv.FormatInt(message.Chat.ID, 10)) + v.Add("message_id", strconv.Itoa(message.MessageID)) + + bot.debugLog("deleteMessage", v, nil) + + return bot.MakeRequest("deleteMessage", v) +} + // debugLog checks if the bot is currently running in debug mode, and if // so will display information about the request and response in the // debug log. diff --git a/bot_test.go b/bot_test.go index a001dcd..7918e90 100644 --- a/bot_test.go +++ b/bot_test.go @@ -58,6 +58,21 @@ func TestGetUpdates(t *testing.T) { } } +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) + + _, err := bot.DeleteMessage(message) + + if err != nil { + t.Error(err) + t.Fail() + } +} + func TestSendWithMessage(t *testing.T) { bot, _ := getBot(t)