Skip to content
Merged
Show file tree
Hide file tree
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: 6 additions & 1 deletion lib/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import emojis from '../assets/emoji.json';
import { validateChannelMapping } from './validators';
import { highlightUsername } from './helpers';

const ALLOWED_SUBTYPES = ['me_message'];
const ALLOWED_SUBTYPES = ['me_message', 'file_share'];
const REQUIRED_FIELDS = ['server', 'nickname', 'channelMapping', 'token'];

/**
Expand Down Expand Up @@ -208,6 +208,11 @@ class Bot {
this.ircClient.say(ircChannel, prelude);
} else if (!message.subtype) {
text = `<${user.name}> ${text}`;
} else if (message.subtype === 'file_share') {
text = `<${user.name}> File uploaded ${message.file.permalink} / ${message.file.permalink_public}`;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't showing one of these enough? I.e. message.file.permalink_public || message.file.permalink.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permalink_public is always generated even if file is not shared. So it's rather hard to guess which would be better to show.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

permalink_public doesn't seem to work for logged in users before it is "created". On external link creation Slack seems to send file_change event but not file_public event. Additionally file_change has just file id without any other details and slack.rtm.dataStore doesn't seem to have method for looking up file by ID. So this would need some own temporary storage for storing file id + url, then on file_change event poll URL whether it works and finally generate another line to IRC if it succeeds.

So I'd guess showing both links is somewhat reasonable.

I also added tests.

if (message.file.initial_comment) {
text += ` - ${message.file.initial_comment.comment}`;
}
} else if (message.subtype === 'me_message') {
text = `Action: ${user.name} ${text}`;
}
Expand Down
13 changes: 13 additions & 0 deletions test/bot-events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,19 @@ describe('Bot Events', function () {
this.bot.sendToIRC.should.have.been.calledWithExactly(message);
});

it('should send files to irc if correct', function () {
const message = {
type: 'message',
subtype: 'file_share',
file: {
permalink: 'test',
permalink_public: 'test'
}
};
this.bot.slack.rtm.emit('message', message);
this.bot.sendToIRC.should.have.been.calledWithExactly(message);
});

it('should not send messages to irc if the type isn\'t message', function () {
const message = {
type: 'notmessage'
Expand Down
22 changes: 22 additions & 0 deletions test/bot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,28 @@ describe('Bot', function () {
ClientStub.prototype.say.should.have.been.calledWith('#irc', ircText);
});

it('should send files to irc', function () {
const link1 = 'test1';
const link2 = 'test2';
const text = 'testcomment';
const message = {
text: '',
channel: 'slack',
subtype: 'file_share',
file: {
permalink: link1,
permalink_public: link2,
initial_comment: {
comment: text
}
}
};

this.bot.sendToIRC(message);
const ircText = `<testuser> File uploaded ${link1} / ${link2} - ${text}`;
ClientStub.prototype.say.should.have.been.calledWith('#irc', ircText);
});

it('should not send messages to irc if the channel isn\'t in the channel mapping',
function () {
this.bot.slack.rtm.dataStore.getChannelGroupOrDMById = () => null;
Expand Down