Set up nix shell
Fix typo in README
Update format of version printer
Tool to manage Slack channels in bulk.
Over many years of using Slack, there are many channels that have built up which I don't interact with on a daily, or even weekly basis. Perhaps it's a channel for a project that is no longer active, or for a team that I no longer engage with regularly.
Whatever the reason, I would like to bulk manage my involvement across all the Slack channels I am a member of. And by "manage my involvement" I'm referring to actions like leaving, archiving, muting, and unmuting.
Now performing these updates in singular is easy enough in the Slack Web UI. But
across hundreds of channels going through the multiple clicks it takes to leave
a channel is just too much for me. So I wrote this tool to perform these actions
in the command line, inspired by Git's interactive flows of committing and
rebasing which pops open instance of your desired
This isn't a serious tool. It is a tool that has been built for a specific use case of my own. And while it is intended for repeated use it is not in anyway productionised.
Potential future expansions to the functionality.
Before editing your involvement of Slack channels, you must first fetch some state about what channels you are currently involved with. If you are familiar with the Slack API you may wonder if this is totally necessary, and so the reasoning for splitting out fetching and editing are discussed in Design.
$ SLACK_TOKEN="token" slackchan fetch -o scstate
Fetch state from Slack, for the user associated with the token "foo", and output that state to the file "scstate".
Once you have fetched the required state from Slack, you can operate on it. Any edits made using this tool will also update the state file. For example, using this tool to leave a channel will update the state file to reflect that you are no longer a member of that channel.
$ SLACK_TOKEN="token" slackchan edit -i scstate
Operate on state from the state file "scstate".
Slack's API is centered around the notion of apps which need to be installed into workspaces. For a Slack bot, or an app that is intended to be used by multiple users this seems reasonable.
Yet this tool is intended to be run quickly and infrequently by a single user. To me, it doesn't make sense to create a new Slack app for slackchan if there is another way - that is if you even have permissions/approval to create and add a new Slack app.
Thankfully there is another way, though it isn't ideal for serious use.
Navigating to your account settings page, and inspecting some of the requests
that are made, you can extract a token specific to your user account. This token
has a prefix
xoxs. Now it's important to be very careful with this token as
AFAIK, unlike authentication with apps, this token may not be revokable.
The Slack API has a very convenient endpoint for what we want to do called
lists the channels the calling user may access. Unfortunately though, with our
xoxs token we do not have permissions to call this endpoint.
However, an endpoint we do have the ability to call is
will allow us to list all the channels in the workspace and included in each
channel is whether or not the requesting user is a member of that channel.
Unfortunately though calling this endpoint is slow. It is rate limited at tier 2 (20 requests per minute) and each request has to be done serially as the list of channels is paginated by a cursor token.
So that we don't sit waiting for multiple minutes to fetch the list of channels
evertime the we want to make an edit, I was inspired by Terraform's approach of
.tfstate file to encode the state of infrastructure components and
then operate on that.
Although this is a pretty heavy tradeoff, for me it is worth it to not have to get approval to add a Slack app for such a short lived use case.