fix: telegram callback query handler dereferencing nil pointer if memo not found (#3003)

* fix: telegram callback query handler dereferencing nil pointer if memo not found

* chore: add an answer to callback query if memo not found
This commit is contained in:
ercd 2024-02-27 00:03:08 +08:00 committed by GitHub
parent 51a7934616
commit 1ae9bf23a0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -130,6 +130,20 @@ func (t *TelegramHandler) CallbackQueryHandle(ctx context.Context, bot *telegram
return bot.AnswerCallbackQuery(ctx, callbackQuery.ID, fmt.Sprintf("Failed to parse callbackQuery.Data %s", callbackQuery.Data))
}
memo, err := t.store.GetMemo(ctx, &store.FindMemo{
ID: &memoID,
})
if err != nil {
return bot.AnswerCallbackQuery(ctx, callbackQuery.ID, fmt.Sprintf("Failed to call FindMemo %s", err))
}
if memo == nil {
_, err = bot.EditMessage(ctx, callbackQuery.Message.Chat.ID, callbackQuery.Message.MessageID, fmt.Sprintf("Memo %d not found", memoID), nil)
if err != nil {
return bot.AnswerCallbackQuery(ctx, callbackQuery.ID, fmt.Sprintf("Failed to EditMessage %s", err))
}
return bot.AnswerCallbackQuery(ctx, callbackQuery.ID, fmt.Sprintf("Memo %d not found, possibly deleted elsewhere", memoID))
}
update := store.UpdateMemo{
ID: memoID,
Visibility: &visibility,