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

Implement deleteMessage method
bot-api-6.1
Syfaro 2017-06-08 14:07:35 -05:00 committed by GitHub
commit d23f8e850e
3 changed files with 50 additions and 0 deletions

12
bot.go
View File

@ -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)
}

View File

@ -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()
}
}

View File

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