Skip to content

Commit

Permalink
feat: slack-app can now post to both tagged and default channel (#4520)
Browse files Browse the repository at this point in the history
Currently the slack-app addon only posts to either the tagged channel
for the feature or the default channels. This PR adds a new field that
will allow you to configure the addon to post to both the default
channels and the tagged channel (s)
  • Loading branch information
Christopher Kolstad authored Aug 21, 2023
1 parent dbae2d1 commit f114aa4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/lib/addons/slack-app-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ const slackAppDefinition: IAddonDefinition = {
required: false,
sensitive: false,
},
{
name: 'alwaysPostToDefault',
displayName: 'Always post to default channels',
description: `If set to 'true' or 'yes', the app will always post events to the default channels, even if the feature toggle has slack tags`,
type: 'text',
required: false,
sensitive: false,
},
],
events: [
FEATURE_CREATED,
Expand Down
21 changes: 16 additions & 5 deletions src/lib/addons/slack-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { IEvent } from '../types/events';
interface ISlackAppAddonParameters {
accessToken: string;
defaultChannels: string;
alwaysPostToDefault: string;
}

export default class SlackAppAddon extends Addon {
Expand All @@ -45,16 +46,26 @@ export default class SlackAppAddon extends Addon {
parameters: ISlackAppAddonParameters,
): Promise<void> {
try {
const { accessToken, defaultChannels } = parameters;
const { accessToken, defaultChannels, alwaysPostToDefault } =
parameters;
if (!accessToken) {
this.logger.warn('No access token provided.');
return;
}

let postToDefault =
alwaysPostToDefault === 'true' || alwaysPostToDefault === 'yes';
this.logger.debug(`Post to default was set to ${postToDefault}`);
const taggedChannels = this.findTaggedChannels(event);
const eventChannels = taggedChannels.length
? taggedChannels
: this.getDefaultChannels(defaultChannels);
let eventChannels: string[];
if (postToDefault) {
eventChannels = taggedChannels.concat(
this.getDefaultChannels(defaultChannels),
);
} else {
eventChannels = taggedChannels.length
? taggedChannels
: this.getDefaultChannels(defaultChannels);
}

if (!eventChannels.length) {
this.logger.debug(
Expand Down

0 comments on commit f114aa4

Please sign in to comment.