From f114aa401acc95b18d42063d9760a2039c6d6a52 Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Mon, 21 Aug 2023 09:00:06 +0200 Subject: [PATCH] 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) --- src/lib/addons/slack-app-definition.ts | 8 ++++++++ src/lib/addons/slack-app.ts | 21 ++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/lib/addons/slack-app-definition.ts b/src/lib/addons/slack-app-definition.ts index 5df01d5c7bf1..fb2d5eb68d19 100644 --- a/src/lib/addons/slack-app-definition.ts +++ b/src/lib/addons/slack-app-definition.ts @@ -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, diff --git a/src/lib/addons/slack-app.ts b/src/lib/addons/slack-app.ts index bdf61c91d0ee..47f901de8cc3 100644 --- a/src/lib/addons/slack-app.ts +++ b/src/lib/addons/slack-app.ts @@ -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 { 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(