Edit message when delete fails
This commit is contained in:
parent
201f9df3d3
commit
bb9a12ef13
19
main.go
19
main.go
@ -222,9 +222,28 @@ func deleteMessage(chatID int, messageID int) {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
body := logBody(resp.Body)
|
||||
ok := struct {
|
||||
Ok bool `json:"ok"`
|
||||
}{}
|
||||
|
||||
if err := json.Unmarshal(body, &ok); err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
//Old messages can't be deleted, so edit text instead
|
||||
if !ok.Ok {
|
||||
updateURL := fmt.Sprintf("https://api.telegram.org/bot%s/editMessageText?chat_id=%d&message_id=%d&text=%s", apiToken, chatID, messageID, "<list updated>")
|
||||
resp, err := http.Get(updateURL)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
logBody(resp.Body)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func logBody(respBody io.ReadCloser) []byte {
|
||||
defer func() {
|
||||
err := respBody.Close()
|
||||
|
Loading…
Reference in New Issue
Block a user