1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

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

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)
This commit is contained in:
Christopher Kolstad 2023-08-21 09:00:06 +02:00 committed by GitHub
parent dbae2d1153
commit f114aa401a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View File

@ -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,

View File

@ -23,6 +23,7 @@ import { IEvent } from '../types/events';
interface ISlackAppAddonParameters {
accessToken: string;
defaultChannels: string;
alwaysPostToDefault: string;
}
export default class SlackAppAddon extends Addon {
@ -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(