Edit message when delete fails

This commit is contained in:
Balakrishnan Balasubramanian 2023-03-21 13:38:20 -04:00
parent 201f9df3d3
commit bb9a12ef13

21
main.go
View File

@ -222,7 +222,26 @@ func deleteMessage(chatID int, messageID int) {
log.Println(err)
return
}
logBody(resp.Body)
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 {