Bug Description
When using multi-workspace OAuth (no defaultBotToken), detectMention() always returns false because adapter.botUserId is undefined. This is harmless when only app_mention events are subscribed (the Slack adapter sets isMention = true directly for app_mention events). However, when message.channels is also subscribed, the message event arrives before app_mention, wins the dedupe check, and routes to onNewMessage instead of onNewMention. The subsequent app_mention event is then silently dropped by deduplication.
The root cause is in detectMention() — it relies on adapter.botUserId which is only populated when defaultBotToken is configured (via auth.test in initialize()). In multi-workspace OAuth mode where tokens are per-workspace, _botUserId is never set from auth.test, and the per-context botUserId is not available during handleIncomingMessage.
Steps to Reproduce
- Create a
Chat instance with multi-workspace OAuth (no defaultBotToken)
- Subscribe to both
message.channels and app_mention in Slack Event Subscriptions
- Register both
onNewMention and onNewMessage(/.*/) handlers
- @mention the bot in a public channel
- Observe that
onNewMention handler is never called; onNewMessage handler fires instead
Expected Behavior
When a user @mentions the bot in a public channel, onNewMention should fire. The message event should be routed to onNewMention because the bot's user ID is present in the message text (<@BOT_USER_ID>).
The app_mention event being deduped is acceptable as long as the message event is correctly routed.
Actual Behavior
detectMention() returns false because adapter.botUserId is undefined in multi-workspace OAuth mode. The message event falls through to onNewMessage pattern matching (step 4 in the routing chain). The
app_mention event is then dropped by deduplication (same ts). The onNewMention handler never fires.
Code Sample
import {Chat} from 'chat';
import {createSlackAdapter} from '@chat-adapter/slack';
import {createRedisState} from '@chat-adapter/state-redis';
// Multi-workspace OAuth — no defaultBotToken
const bot = new Chat({
userName: 'mybot',
adapters: {
slack: createSlackAdapter({
signingSecret: process.env.SLACK_SIGNING_SECRET!,
clientId: process.env.SLACK_CLIENT_ID!,
clientSecret: process.env.SLACK_CLIENT_SECRET!,
encryptionKey: process.env.SLACK_ENCRYPTION_KEY!,
}),
},
state: createRedisState({url: process.env.REDIS_URL!}),
});
// This handler NEVER fires when message.channels is subscribed
bot.onNewMention(async (thread, message) => {
console.log('Mention received!'); // Never logged
await thread.post('Hello!');
});
// This handler catches everything, including mentions
bot.onNewMessage(/.*/, async (thread, message) => {
console.log('New message:', message.text); // Fires for mentions too
});
Chat SDK Version
4.23.0
Node.js Version
No response
Platform Adapter
Slack
Operating System
None
Additional Context
No response
Bug Description
When using multi-workspace OAuth (no
defaultBotToken),detectMention()always returnsfalsebecauseadapter.botUserIdisundefined. This is harmless when onlyapp_mentionevents are subscribed (the Slack adapter setsisMention = truedirectly forapp_mentionevents). However, whenmessage.channelsis also subscribed, themessageevent arrives beforeapp_mention, wins the dedupe check, and routes toonNewMessageinstead ofonNewMention. The subsequentapp_mentionevent is then silently dropped by deduplication.The root cause is in
detectMention()— it relies onadapter.botUserIdwhich is only populated whendefaultBotTokenis configured (viaauth.testininitialize()). In multi-workspace OAuth mode where tokens are per-workspace,_botUserIdis never set fromauth.test, and the per-contextbotUserIdis not available duringhandleIncomingMessage.Steps to Reproduce
Chatinstance with multi-workspace OAuth (nodefaultBotToken)message.channelsandapp_mentionin Slack Event SubscriptionsonNewMentionandonNewMessage(/.*/)handlersonNewMentionhandler is never called;onNewMessagehandler fires insteadExpected Behavior
When a user @mentions the bot in a public channel,
onNewMentionshould fire. Themessageevent should be routed toonNewMentionbecause the bot's user ID is present in the message text (<@BOT_USER_ID>).The
app_mentionevent being deduped is acceptable as long as themessageevent is correctly routed.Actual Behavior
detectMention()returnsfalsebecauseadapter.botUserIdisundefinedin multi-workspace OAuth mode. Themessageevent falls through toonNewMessagepattern matching (step 4 in the routing chain). Theapp_mentionevent is then dropped by deduplication (samets). TheonNewMentionhandler never fires.Code Sample
Chat SDK Version
4.23.0
Node.js Version
No response
Platform Adapter
Slack
Operating System
None
Additional Context
No response