mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +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:
		
							parent
							
								
									dbae2d1153
								
							
						
					
					
						commit
						f114aa401a
					
				@ -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,
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
            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(
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user