A script that sets the topic of a Slack channel to the currently ongoing event in a Google calendar. Great for keeping track of who's on call, for example.
Create a Google Service Account, download the credentials in JSON format and
export it to GOOGLE_CREDENTIALS
.
Create a Slack bot with scopes channels:manage
and channels:read
, and export
its access token to SLACK_ACCESS_TOKEN
.
Go to Settings and sharing for the Google Calendar(s) you'd like to use, and share them with the service account by entering the e-mail address of the service account in Share with specific people.
If you want to use mentions in the topic, you need to use Slack's special syntax for
that. Open Slack and go to the profile of the user you want to mention, click the More
button and then Copy member ID
. You can now mention that user with <@{MEMBER-ID}>
For example, if the desired member ID is F4K3ID123
:
Person on-call: <@F4K3ID123>
Unfortunately, this can make it hard to read your calendar at a glance. To get around that, put your topic in the event description instead of the title, and we'll use that when it's set.
Create a mapping between calendars and channels like so, and export it to
CHANNEL_CALENDAR_MAP
:
[
{
"calendarId": "c_413612vkasdr1126ckja82sa0v@group.calendar.google.com",
"channelId": "C018DQTCFNX"
},
...
]
That's it! Run it with npm run update
(or ./bin/update
) and watch your channels
be updated to the currently ongoing events in the corresponding calendars:
$ ./bin/update
#backend-bugs: Set topic to 'Person on call: Tuesday talent 🤩'
#infrastructure-issues: Topic already set
#petty-problems: No ongoing event
You can deploy this script anywhere that runs Node and has some mechanism for running it on a schedule (like cron).
It's a particularly good fit for a Lambda scheduled with CloudWatch. Create your lambda,
set the environment variables, and configure the handler as lambda.handler
. Then, run
AWS_LAMBDA_NAME=slack-calendar-topic ./deploy.sh
to deploy it.
If you haven't already, remember to install and configure your aws
command line interface first:
- Log into your AWS Console and retrieve your IAM credentials.
- Run
aws configure
and follow the steps.