Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/utils/slack/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ const getThreadTimestamp = (event) => event.thread_ts || event.ts;
* @param {object} event - The Slack event.
* @return {string | undefined} - The message without the bot mention.
*/
const getMessageFromEvent = (event) => event.text?.replace(BOT_MENTION_REGEX, '').trim();
const getMessageFromEvent = (event) => event.text?.replace(BOT_MENTION_REGEX, '').replace(/\s+/g, ' ').trim();

/**
* Wraps the Slack say function to respond in a thread. This is necessary because
Expand Down
27 changes: 27 additions & 0 deletions test/utils/slack/base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,38 @@ import {
loadProfileConfig,
parseCSV,
fetchFile,
getMessageFromEvent,
} from '../../../src/utils/slack/base.js';

use(chaiAsPromised);

describe('Base Slack Utils', () => {
describe('getMessageFromEvent ignores whitespace', () => {
it('should return the message text without leading or trailing whitespace', () => {
const event = {
text: ' Hello, World! ',
};
const result = getMessageFromEvent(event);
expect(result).to.equal('Hello, World!');
});

it('should return the message text without added whitespace', () => {
const event = {
text: 'Hello,World!',
};
const result = getMessageFromEvent(event);
expect(result).to.equal('Hello,World!');
});

it('should return the message text without multiple whitespaces between words', () => {
const event = {
text: 'Hello, World!',
};
const result = getMessageFromEvent(event);
expect(result).to.equal('Hello, World!');
});
});

describe('extractBaseURLFromInput', () => {
it('extractURLFromSlackInput when empty', async () => {
expect(extractURLFromSlackInput('')).to.be.null;
Expand Down