Skip to content

Commit

Permalink
fix: use botinfo api to get user (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3r authored Mar 31, 2021
1 parent 248d088 commit cef183b
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions remote/slack/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,20 @@ func handleCallBack(api *slack.Client, event slackevents.EventsAPIInnerEvent, bo
case *slackevents.MessageEvent:
senderID := ev.User

// check if we should respond to other bot messages
// check if message originated from a bot
// and whether we should respond to other bot messages
if ev.BotID != "" && bot.RespondToBots {
senderID = ev.BotID
// get bot information to get
// the associated user id
user, err := api.GetBotInfo(ev.BotID)
if err != nil {
bot.Log.Infof("unable to retrieve bot info for %s", ev.BotID)

return
}

// use the bot's user id as the senderID
senderID = user.UserID
}

// only process messages that aren't from our bot
Expand All @@ -144,9 +155,7 @@ func handleCallBack(api *slack.Client, event slackevents.EventsAPIInnerEvent, bo

text, mentioned := removeBotMention(ev.Text, bot.ID)

// if senderID is a BotID, we could use .GetBotInfo()
// but this should also give us information on the sender
// including whether it is a bot
// get the full user object for the given ID
user, err := api.GetUserInfo(senderID)
if err != nil {
bot.Log.Errorf("getEventsAPIEventHandler: Did not get Slack user info: %s", err.Error())
Expand Down Expand Up @@ -570,9 +579,20 @@ func readFromRTM(rtm *slack.RTM, inputMsgs chan<- models.Message, bot *models.Bo
case *slack.MessageEvent:
senderID := ev.User

// check if we should respond to other bot messages
// check if message originated from a bot
// and whether we should respond to other bot messages
if ev.BotID != "" && bot.RespondToBots {
senderID = ev.BotID
// get bot information to get
// the associated user id
user, err := rtm.GetBotInfo(ev.BotID)
if err != nil {
bot.Log.Infof("unable to retrieve bot info for %s", ev.BotID)

return
}

// use the bot's user id as the senderID
senderID = user.UserID
}

// only process messages that aren't from our bot
Expand All @@ -585,9 +605,7 @@ func readFromRTM(rtm *slack.RTM, inputMsgs chan<- models.Message, bot *models.Bo

text, mentioned := removeBotMention(ev.Text, bot.ID)

// if senderID is a BotID, we could use .GetBotInfo()
// but this should also give us information on the sender
// including whether it is a bot
// get the full user object for the given ID
user, err := rtm.GetUserInfo(senderID)
if err != nil {
bot.Log.Errorf("Did not get Slack user info: %s", err.Error())
Expand Down

0 comments on commit cef183b

Please sign in to comment.