Skip to content

Commit 609c37c

Browse files
committed
Fix username of bot
1 parent 9d5e850 commit 609c37c

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

service/slack.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -403,19 +403,25 @@ func (s *SlackService) CreateMessage(message slack.Message, channelID string) co
403403

404404
// Get username from cache
405405
name, ok := s.UserCache[message.User]
406-
name, ok = s.UserCache[message.BotID]
407406

408407
// Name not in cache
409408
if !ok {
410409
if message.BotID != "" {
411-
// Bot, not in cache get bot info
412-
bot, err := s.Client.GetBotInfo(message.BotID)
413-
if err != nil {
414-
name = "unkown"
415-
s.UserCache[message.BotID] = name
416-
} else {
417-
name = bot.Name
418-
s.UserCache[message.BotID] = bot.Name
410+
name, ok = s.UserCache[message.BotID]
411+
if !ok {
412+
if message.Username != "" {
413+
name = message.Username
414+
s.UserCache[message.BotID] = message.Username
415+
} else {
416+
bot, err := s.Client.GetBotInfo(message.BotID)
417+
if err != nil {
418+
name = "unkown"
419+
s.UserCache[message.BotID] = name
420+
} else {
421+
name = bot.Name
422+
s.UserCache[message.BotID] = bot.Name
423+
}
424+
}
419425
}
420426
} else {
421427
// Not a bot, not in cache, get user info

0 commit comments

Comments
 (0)