From c82b273155daf4c046e084ea6a7c710f9e2dd20e Mon Sep 17 00:00:00 2001 From: Sumner Evans Date: Mon, 13 Jan 2025 21:27:48 -0700 Subject: [PATCH] connector/reactions: return error if not logged in Previously, the getAvailableReactions function was only called with a logged in client. However, now that it is called in the GetCapabilities call, the client is no longer guaranteed to be logged in. This was causing an NPE due to the (*TelegramClient).client being nil. This commit makes the getAvailableReactions function not panic when the client is not logged in. Signed-off-by: Sumner Evans --- pkg/connector/telegram.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/connector/telegram.go b/pkg/connector/telegram.go index d805d1bd..7cfa3502 100644 --- a/pkg/connector/telegram.go +++ b/pkg/connector/telegram.go @@ -3,6 +3,7 @@ package connector import ( "bytes" "context" + "errors" "fmt" "slices" "strings" @@ -907,6 +908,10 @@ func (t *TelegramClient) getAvailableReactionsForCapability(ctx context.Context) } func (t *TelegramClient) getAvailableReactions(ctx context.Context) (map[string]struct{}, error) { + if !t.IsLoggedIn() { + return nil, errors.New("you must be logged in to get available reactions") + } + log := zerolog.Ctx(ctx).With().Str("handler", "get_available_reactions").Logger() t.availableReactionsLock.Lock() defer t.availableReactionsLock.Unlock()