Is there an easy way to detect @-mentions without using a higher level kit like howdy? I hacked something together by capturing the bot's ID on the rtm.start event (as in the Readme) and shoving it into a regex... but that feels really brittle. I don't see "mention" anywhere in any of the event enumerations.
Detecting @-mentions meaning, towards the bot/user account running the client or just a message mentioning a user?
Towards the bot/user account running the client is what I had in mind.
I honestly think that's your best bet: grabbing the ID on startup, then using it against incoming messages from Slack, like you said. You probably could leave this open to see if anyone else can weigh in, but I don't believe there's any mention events just yet.
rtm.activeUserId should contain the ID you're looking for: https://github.com/slackhq/node-slack-client/blob/b4f18a482e7a34d3d03c89f221e61a669c94b643/lib/clients/rtm/client.js#L267
rtm.on(RTM_EVENTS.MESSAGE, message => {
if (message.text.includes(`<@${rtm.activeUserId}>`)) {
// handle message
}
});
Use text.indexOf/text.match if you're in an environment without .includes.
馃憤 thanks @ekmartin, that works great!
Most helpful comment
rtm.activeUserIdshould contain the ID you're looking for: https://github.com/slackhq/node-slack-client/blob/b4f18a482e7a34d3d03c89f221e61a669c94b643/lib/clients/rtm/client.js#L267Use
text.indexOf/text.matchif you're in an environment without.includes.