An app that watches for new public channels and checks whether their name matches an existing channel category.
If it does match an existing category, the app posts a notification to the parent channel for the category. For example, if you have a category of channels that starts with
#support- for different types of support, a notification would get sent into the overarching #support channel when a new
#support- channel is created.
To find out when a channel has been created you'll need to subscribe to the
channel_created team event being sent out through the Events API. The Events API sends a POST request to a URL you've provided whenever certain events occur on your Slack team. In the case of
channel_creaed event, Slack will send an event when a public channel is created. The event will include the channel name and ID.
The app assumes that everything before the first hyphen in the channel name is the prefix used as part of the channel naming convention. Using the channel prefix the checks its datastore to see if a matching channel category already exists. If it does, the app will send a notification to the category's parent channel that includes the new channel's name and purpose. To get the channel's purpose, the app has to call the
conversations.info method, passing in the channel ID from the
channel_created event. The notification to the parent channel is sent via the
In instances where the channel's prefix doesn't match any existing channel categories, the app will prompt the user to create one. Using
chat.postMessage, the app will send a message into the newly created channel asking the user if they'd like to create a channel category for the prefix. The message will include "Yes" and "No" buttons. To include message actions (such as buttons and menus), you'll need to enable Interactive Messages in the app settings and supply a URL where Slack can send the button click event.
If the user clicks 'Yes', the app will receive a POST request on its Interactive Message endpoint. The payload will include information about the channel where this action originated along with a
response_url that can be used to update the original message. Using the response URL, replace the 'Yes' and "No" buttons with a message menu and ask the user to select the parent channel for the new channel category. The message menu can be pre-populated with a list of channels by setting the menu's
Once the user selects a channel, the app will receive a POST request on its Interactive Message endpoint. The request will include information about the channel the user selected and the channel they took the action in. Using this information, the app will save a new channel category in its datastore. It will also use
conversations.info to send a notification to the new category's parent channel.