Created by Kashyap Todi (www.kashyaptodi.com)
This script can be used to automatically create a batch of Slack channels, and to invite particular users to each of them. It uses methods from the Slack API to complete tasks. Input data can be provided either as a JSON or a CSV file.
- Python 3.6 or above
- Go to https://api.slack.com/apps =>
Create New App
- Give the app a name, and select the appropriate workspace
- In the "Basic Information" page for the app, navigate to
Add features and functionality
=>Permissions
- Under "Scopes", add the following "Bot Token Scopes":
channels:manage
channels:read
groups:read
groups:write
im:read
mpim:read
users:read
- Scroll to the top =>
Install App to Workspace
=>Allow
- Copy your Bot User OAuth Access Token
- Create a JSON or CSV input data file. See the section on
Input File Formats
below for details and example. - Run the python script:
python3 slack_channel_creator.py # Input filepath will be entered at runtime
python3 slack_channel_creator.py <INPUT_FILE_PATH> # Input filepath as an argument
- Specify path to input CSV/JSON file (no quotes)
- The script will display the detected field names. Upon prompt, enter the field names you want to use for
channel names
andmember lists
- Paste token upon prompt
- The script will display the number of existing channels, and number of members.
- Finally, it will iterate over all entries in the input data:
- Create a new private channel if it does not exist
- Get the channel ID
- Check the input member list, and get member IDs for all valid members
- Serially invite (add) each member to the channel
The script allows you to provide input data either using JSON or CSV formats.
The input file should contain a list of entries, where each entry has a field for channel name
and a field for members list
Your JSON file should contain an array of objects.
Each object should have two keys – one for the channel name
, and another for the members list
for the corresponding channel. You can use whatever key names you like, as the script will ask you to specify them at run time.
channel name
: This should be a string value
members list
: This should either be an array object containing strings (one string per member name), or a string value with member names separated using commas or semi-colons. Each member name within the members list should correspond to a valid real_name
in the Slack team's user list. Invalid member names will be ignored.
(You can use the web-based tester at https://api.slack.com/methods/users.list to retrieve the user list)
[
{"channel_name":"test-channel1","members":["Member1 Name1", "Member2 Name2"]},
{"channel_name":"test-channel2","members":["Member1 Name1", "Member2 Name3"]},
{"channel_name":"test-channel3","members":["Member2 Name2", "Member3 Name3"]}
]
Your CSV file should have two columns – one for the channel name
, and another for the members list
for the corresponding channel. The header row should contain the column names. You can use whatever names you like, as the script will ask you to specify them at run time.
channel name
: This should be a string value
members list
: This should be a string value containing member names. Each member name should be separated either by a comma or semi-colon. Each member name within the membesr list should correspond to a valid real_name
in the Slack team's user list. Invalid member names will be ignored.
(You can use the web-based tester at https://api.slack.com/methods/users.list to retrieve the user list)
Channel Name, Members
test-channel1, "Member1 Name1, Member2 Name2"
test-channel2, "Member1 Name1, Member3 Name3"
test-channel3, "Member2 Name2, Member3 Name3"