Skip to content

Commit e308584

Browse files
authored
fix(slack/reactions): add handling for reactions to events api based bot (#547)
1 parent 1c929d6 commit e308584

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

remote/slack/helper.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,36 @@ func handleCallBack(api *slack.Client, event slackevents.EventsAPIInnerEvent, bo
9090
if !mentioned {
9191
handleMessageEvent(api, bot, ev.Channel, text, ev.User, ev.BotID, ev.TimeStamp, ev.ThreadTimeStamp, mentioned, inputMsgs)
9292
}
93+
case *slackevents.ReactionAddedEvent:
94+
senderID := ev.User
95+
96+
if senderID != "" && bot.ID != senderID {
97+
channel := ev.Item.Channel
98+
99+
// determine the message type
100+
msgType, err := getMessageType(channel)
101+
if err != nil {
102+
log.Error().Msg(err.Error())
103+
}
104+
105+
// get information on the user
106+
user, err := api.GetUserInfo(senderID)
107+
if err != nil {
108+
log.Error().Msgf("did not get slack user info: %s", err.Error())
109+
}
110+
111+
timestamp := ev.Item.Timestamp
112+
113+
reaction := ev.Reaction
114+
115+
// get the link to the message, will be empty string if there's an error
116+
link, err := api.GetPermalink(&slack.PermalinkParameters{Channel: channel, Ts: timestamp})
117+
if err != nil {
118+
log.Error().Msgf("unable to retrieve link to message: %s", err.Error())
119+
}
120+
121+
inputMsgs <- populateReaction(models.NewMessage(), msgType, channel, "added", reaction, timestamp, link, user, bot)
122+
}
93123
case *slackevents.MemberJoinedChannelEvent:
94124
// limit to our bot
95125
if ev.User == bot.ID {

0 commit comments

Comments
 (0)