Edit message when delete fails
This commit is contained in:
parent
201f9df3d3
commit
bb9a12ef13
21
main.go
21
main.go
@ -222,7 +222,26 @@ func deleteMessage(chatID int, messageID int) {
|
|||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
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 {
|
func logBody(respBody io.ReadCloser) []byte {
|
||||||
|
Loading…
Reference in New Issue
Block a user