1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-19 01:17:18 +02:00
unleash.unleash/src/lib/addons/slack-app-definition.ts
weekwith.me d75c63b6e8
feat: Add PROJECT_ARCHIVED event to send message to Slack (#8848)
<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

### Summary

- Add `PROJECT_ARCHIVED` event on `EVENT_MAP` to use
- Add a test case for `PROJECT_ARCHIVED` event formatting 
- Add `PROJECT_ARCHIVED` event when users choose which events they send
to Slack
- Fix Slack integration document by adding `PROJECT_ARCHIVED`

### Example

The example message looks like the image below. I covered my email with
a black rectangle to protect my privacy 😄
The link refers `/projects-archive` to see archived projects.

<img width="529" alt="Slack message example"
src="https://github.com/user-attachments/assets/938c639f-f04a-49af-9b4a-4632cdea9ca7">

## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

I considered the reason why Unleash didn't implement to send
`PROJECT_ARCHIVED` message to Slack integration.

One thing I assumed that it is impossible to create a new project with
open source codes, which means it is only enabled in the enterprise
plan. However,
[document](https://docs.getunleash.io/reference/integrations/slack-app#events)
explains that users can send `PROJECT_CREATED` and `PROJECT_DELETED`
events to Slack, which are also available only in the enterprise plan,
hence it means we need to embrace all worthwhile events.

I think it is reasonable to add `PROJECT_ARCHIVED` event to Slack
integration because users, especially operators, need to track them
through Slack by separating steps, `_CREATED`, `_ARCHIVED`, and
`_DELETED`.
2024-11-25 14:33:50 +00:00

166 lines
5.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import {
FEATURE_CREATED,
FEATURE_ARCHIVED,
FEATURE_REVIVED,
FEATURE_STALE_ON,
FEATURE_STALE_OFF,
FEATURE_ENVIRONMENT_ENABLED,
FEATURE_ENVIRONMENT_DISABLED,
FEATURE_STRATEGY_REMOVE,
FEATURE_STRATEGY_UPDATE,
FEATURE_STRATEGY_ADD,
FEATURE_METADATA_UPDATED,
FEATURE_PROJECT_CHANGE,
FEATURE_POTENTIALLY_STALE_ON,
FEATURE_ENVIRONMENT_VARIANTS_UPDATED,
FEATURE_DELETED,
FEATURE_TAGGED,
FEATURE_UNTAGGED,
CONTEXT_FIELD_CREATED,
CONTEXT_FIELD_UPDATED,
CONTEXT_FIELD_DELETED,
PROJECT_CREATED,
PROJECT_DELETED,
ADDON_CONFIG_CREATED,
ADDON_CONFIG_UPDATED,
ADDON_CONFIG_DELETED,
USER_CREATED,
USER_UPDATED,
USER_DELETED,
SEGMENT_CREATED,
SEGMENT_UPDATED,
SEGMENT_DELETED,
GROUP_CREATED,
GROUP_UPDATED,
CHANGE_REQUEST_CREATED,
CHANGE_REQUEST_DISCARDED,
CHANGE_ADDED,
CHANGE_DISCARDED,
CHANGE_EDITED,
CHANGE_REQUEST_REJECTED,
CHANGE_REQUEST_APPROVED,
CHANGE_REQUEST_APPROVAL_ADDED,
CHANGE_REQUEST_CANCELLED,
CHANGE_REQUEST_SENT_TO_REVIEW,
CHANGE_REQUEST_APPLIED,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
API_TOKEN_CREATED,
API_TOKEN_DELETED,
SERVICE_ACCOUNT_CREATED,
SERVICE_ACCOUNT_DELETED,
SERVICE_ACCOUNT_UPDATED,
GROUP_DELETED,
BANNER_CREATED,
BANNER_UPDATED,
BANNER_DELETED,
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
PROJECT_ARCHIVED,
} from '../types/events';
import type { IAddonDefinition } from '../types/model';
const slackAppDefinition: IAddonDefinition = {
name: 'slack-app',
displayName: 'Slack App',
description:
'The Unleash Slack App posts messages to the selected channels in your Slack workspace.',
howTo: 'Below you can specify which Slack channels receive event notifications. The configuration settings allow you to choose the events and whether you want to filter them by projects and environments.\n\nYou can also select which channels to post to by configuring your feature flags with “slack” tags. For example, if youd like the bot to post messages to the #general channel, you can configure your feature flag with the “slack:general” tag.\n\nThe Unleash Slack App bot has access to public channels by default. If you want the bot to post messages to private channels, youll need to invite it to those channels.',
documentationUrl: 'https://docs.getunleash.io/docs/addons/slack-app',
installation: {
url: 'https://unleash-slack-app.vercel.app/install',
title: 'Slack App installation',
helpText:
'After installing the Unleash Slack app in your Slack workspace, paste the access token into the appropriate field below in order to configure this integration.',
},
parameters: [
{
name: 'accessToken',
displayName: 'Access token',
description: '(Required)',
type: 'text',
required: true,
sensitive: true,
},
{
name: 'defaultChannels',
displayName: 'Channels',
description:
'A comma-separated list of channels to post the configured events to. These channels are always notified, regardless of the event type or the presence of a slack tag.',
type: 'text',
required: false,
sensitive: false,
},
],
events: [
ADDON_CONFIG_CREATED,
ADDON_CONFIG_DELETED,
ADDON_CONFIG_UPDATED,
API_TOKEN_CREATED,
API_TOKEN_DELETED,
CHANGE_ADDED,
CHANGE_DISCARDED,
CHANGE_EDITED,
CHANGE_REQUEST_APPLIED,
CHANGE_REQUEST_APPROVAL_ADDED,
CHANGE_REQUEST_APPROVED,
CHANGE_REQUEST_CANCELLED,
CHANGE_REQUEST_CREATED,
CHANGE_REQUEST_DISCARDED,
CHANGE_REQUEST_REJECTED,
CHANGE_REQUEST_SENT_TO_REVIEW,
CHANGE_REQUEST_SCHEDULED,
CHANGE_REQUEST_SCHEDULED_APPLICATION_SUCCESS,
CHANGE_REQUEST_SCHEDULED_APPLICATION_FAILURE,
CHANGE_REQUEST_SCHEDULE_SUSPENDED,
CONTEXT_FIELD_CREATED,
CONTEXT_FIELD_DELETED,
CONTEXT_FIELD_UPDATED,
FEATURE_ARCHIVED,
FEATURE_CREATED,
FEATURE_DELETED,
FEATURE_ENVIRONMENT_DISABLED,
FEATURE_ENVIRONMENT_ENABLED,
FEATURE_ENVIRONMENT_VARIANTS_UPDATED,
FEATURE_METADATA_UPDATED,
FEATURE_POTENTIALLY_STALE_ON,
FEATURE_PROJECT_CHANGE,
FEATURE_REVIVED,
FEATURE_STALE_OFF,
FEATURE_STALE_ON,
FEATURE_STRATEGY_ADD,
FEATURE_STRATEGY_REMOVE,
FEATURE_STRATEGY_UPDATE,
FEATURE_TAGGED,
FEATURE_UNTAGGED,
GROUP_CREATED,
GROUP_DELETED,
GROUP_UPDATED,
BANNER_CREATED,
BANNER_UPDATED,
BANNER_DELETED,
PROJECT_CREATED,
PROJECT_ARCHIVED,
PROJECT_DELETED,
SEGMENT_CREATED,
SEGMENT_DELETED,
SEGMENT_UPDATED,
SERVICE_ACCOUNT_CREATED,
SERVICE_ACCOUNT_DELETED,
SERVICE_ACCOUNT_UPDATED,
USER_CREATED,
USER_DELETED,
USER_UPDATED,
],
tagTypes: [
{
name: 'slack',
description:
'Slack tag used by the slack-addon to specify the slack channel.',
icon: 'S',
},
],
};
export default slackAppDefinition;