all repos — telegram-bot-api @ bdb0f1f4c5dac4388bb0de5610be737ca2ca378d

Golang bindings for the Telegram Bot API

feat(bot): implement deleteMessage method
Mohamad Jahani m4m4lj@gmail.com
Thu, 08 Jun 2017 14:02:05 +0430
commit

bdb0f1f4c5dac4388bb0de5610be737ca2ca378d

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