Skip to content

Commit bc256fb

Browse files
committed
chore: avoid panics from Slack connector
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 8014d22 commit bc256fb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

services/connectors/slack.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,13 +760,16 @@ func (t *Slack) handleMention(
760760

761761
// get user id
762762
user, err := api.GetUserInfo(ev.User)
763+
displayName := ev.User
763764
if err != nil {
764765
xlog.Error(fmt.Sprintf("Error getting user info: %v", err))
766+
} else if user != nil {
767+
displayName = user.Name
765768
}
766769

767770
// Format the final response (convert GitHub markdown to Slack mrkdwn)
768771
convertedResponse := githubmarkdownconvertergo.Slack(res.Response)
769-
finalResponse := fmt.Sprintf("@%s %s", user.Name, convertedResponse)
772+
finalResponse := fmt.Sprintf("@%s %s", displayName, convertedResponse)
770773
xlog.Debug("Send final response to slack", "response", finalResponse)
771774

772775
replyToUpdateMessage(finalResponse, api, ev, msgTs, ts, postMessageParams, res)

0 commit comments

Comments
 (0)