Skip to content

Commit

Permalink
Fix a bug where the bot-in-channel check would fail for private groups
Browse files Browse the repository at this point in the history
  • Loading branch information
ekmartin committed Jan 21, 2016
1 parent 28dfb2a commit 117fbb1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.7.4] - 2016-01-21
### Fixed
- Fix a bug where the bot-in-channel check would fail for private groups.

## [3.7.3] - 2016-01-12
### Fixed
- Don't crash when trying to send a message to a Slack channel the bot
Expand Down
4 changes: 3 additions & 1 deletion lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ class Bot {
if (slackChannelName) {
const slackChannel = this.slack.getChannelGroupOrDMByName(slackChannelName);

if (!slackChannel || !slackChannel.is_member) {
// If it's a private group and the bot isn't in it, we won't find anything here.
// If it's a channel however, we need to check is_member.
if (!slackChannel || (!slackChannel.is_member && !slackChannel.is_group)) {
logger.info('Tried to send a message to a channel the bot isn\'t in: ',
slackChannelName);
return;
Expand Down
19 changes: 19 additions & 0 deletions test/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,25 @@ describe('Bot', function() {
ChannelStub.prototype.postMessage.should.have.been.calledWith(message);
});

it('should send messages to slack groups if the bot is in the channel', function() {
this.bot.slack.getChannelGroupOrDMByName = () => {
const channel = new ChannelStub();
delete channel.is_member;
channel.is_group = true;
return channel;
};

const message = {
text: 'testmessage',
username: 'testuser',
parse: 'full',
icon_url: 'http://api.adorable.io/avatars/48/testuser.png'
};

this.bot.sendToSlack(message.username, '#irc', message.text);
ChannelStub.prototype.postMessage.should.have.been.calledWith(message);
});

it('should not include an avatar for the bot\'s own messages',
function() {
const message = {
Expand Down

0 comments on commit 117fbb1

Please sign in to comment.