From 1ae9bf23a055bb657f0aa395b1179ccb2e37eb3f Mon Sep 17 00:00:00 2001 From: ercd <110474835+ericd23@users.noreply.github.com> Date: Tue, 27 Feb 2024 00:03:08 +0800 Subject: [PATCH] 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 --- server/integration/telegram.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/integration/telegram.go b/server/integration/telegram.go index 2584418a..4f04175e 100644 --- a/server/integration/telegram.go +++ b/server/integration/telegram.go @@ -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,