Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: slack-app can now post to both tagged and default channel #4520

Merged
merged 1 commit into from
Aug 21, 2023
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
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