Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

adds support for <@userId|username> syntax for mentions and direct_mentions #189

Merged
merged 2 commits into from
May 23, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/SlackBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,9 @@ function Slackbot(configuration) {

slack_botkit.log('** Setting up custom handlers for processing Slack messages');
slack_botkit.on('message_received', function(bot, message) {
var mentionSyntax = '<@' + bot.identity.id + '(\\|' + bot.identity.name.replace('.', '\\.') + ')?>';
var mention = new RegExp(mentionSyntax, 'i');
var direct_mention = new RegExp('^' + mentionSyntax, 'i');


if (message.ok != undefined) {
Expand Down Expand Up @@ -463,7 +466,6 @@ function Slackbot(configuration) {
}

// remove direct mention so the handler doesn't have to deal with it
var direct_mention = new RegExp('^\<\@' + bot.identity.id + '\>', 'i');
message.text = message.text.replace(direct_mention, '')
.replace(/^\s+/, '').replace(/^\:\s+/, '').replace(/^\s+/, '');

Expand All @@ -481,9 +483,6 @@ function Slackbot(configuration) {
return false;
}

var direct_mention = new RegExp('^\<\@' + bot.identity.id + '\>', 'i');
var mention = new RegExp('\<\@' + bot.identity.id + '\>', 'i');

if (message.text.match(direct_mention)) {
// this is a direct mention
message.text = message.text.replace(direct_mention, '')
Expand Down