From 9fc79b26ad0dbbbc93c9776a0c1308b36feda555 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Tue, 24 Sep 2019 13:52:20 -0400 Subject: [PATCH] slackApp: handle bot IDs --- connectors/slackapp/slackApp.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/connectors/slackapp/slackApp.go b/connectors/slackapp/slackApp.go index edca675..30f11e6 100644 --- a/connectors/slackapp/slackApp.go +++ b/connectors/slackapp/slackApp.go @@ -420,7 +420,11 @@ func (s *SlackApp) buildMessage(m *slackevents.MessageEvent) msg.Message { isAction := m.SubType == "me_message" // We have to try a few layers to get a valid name for the user because Slack - name := s.getUser(m.User, "unknown") + defaultName := "unknown" + if m.BotID != "" { + defaultName = m.Username + } + name := s.getUser(m.User, defaultName) if m.Username != "" && name == "unknown" { name = m.Username } @@ -517,6 +521,9 @@ func (s *SlackApp) Who(id string) []string { ret := []string{} for _, m := range members { + if m == "" { + log.Error().Msg("empty member") + } u := s.getUser(m, "unknown") if u != "unknown" { log.Error(). @@ -610,7 +617,11 @@ func (s *SlackApp) reactionReceived(event *slack.ReactionAddedEvent) error { case nil: case *slackevents.MessageEvent: if m.TimeStamp == event.Item.Timestamp { - u := s.getUser(m.User, "unknown") + defaultName := "unknown" + if m.BotID != "" { + defaultName = m.Username + } + u := s.getUser(m.User, defaultName) body = fmt.Sprintf("%s: %s", u, m.Text) } default: