all repos — telegram-bot-api @ d23f8e850e134a13dbbc77d5378ff28981853646

Golang bindings for the Telegram Bot API

Merge pull request #100 from mamal72/implement-delete-message

Implement deleteMessage method
Syfaro syfaro@foxpaw.in
Thu, 08 Jun 2017 14:07:35 -0500
commit

d23f8e850e134a13dbbc77d5378ff28981853646

parent

79b26b07c5c454d625961b1691a80e7e9b7e945a

3 files changed, 50 insertions(+), 0 deletions(-)

jump to
M bot.gobot.go

@@ -740,3 +740,15 @@ bot.debugLog("answerPreCheckoutQuery", v, nil)

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) +}
M bot_test.gobot_test.go

@@ -590,3 +590,22 @@ log.Println(err)

} } } + +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() + } +}
M configs.goconfigs.go

@@ -986,3 +986,22 @@ PreCheckoutQueryID string // required

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 +}