fix(slack): prevent app_mention from blocking message handler dedup key

Move the requireMention early-return check before the dedup LoadOrStore
in handleAppMention. Previously, when requireMention=false, an
app_mention event arriving before its corresponding message event would
store the dedup key and return early without processing — causing the
message handler to see the key as already loaded and silently drop the
message (~50% of @mentions lost).
This commit is contained in:
viettranx committed 2026-03-24 21:43:25 +07:00
1 parent 6bfbfe06c1
commit 68406f4a44
1 file changed
+8 -5
+8 -5
View File
@@ -21,14 +21,17 @@ func (c *Channel) handleAppMention(ev *slackevents.AppMentionEvent) {
return
}
// Dedup: app_mention may arrive alongside a message event
dedupKey := ev.Channel + ":" + ev.TimeStamp
if _, loaded := c.dedup.LoadOrStore(dedupKey, time.Now()); loaded {
// If requireMention is false, message handler already processes all channel messages.
// Return BEFORE storing dedup key so we don't block the message handler.
if !c.requireMention {
return
}
// If requireMention is false, message handler already processes all channel messages
if !c.requireMention {
// Dedup: app_mention may arrive alongside a message event.
// Shares the same key format as handleMessage so whichever arrives first
// processes the mention; the other is safely dropped.
dedupKey := ev.Channel + ":" + ev.TimeStamp
if _, loaded := c.dedup.LoadOrStore(dedupKey, time.Now()); loaded {
return
}