/slack-calendar-topic

Set the topic of a Slack channel to the currently ongoing event in a Google calendar

Primary LanguageJavaScriptMIT LicenseMIT

Slack Calendar Topic

Build Status Maintainability License

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.

Image

Getting started

Create a service account

Create a Google Service Account, download the credentials in JSON format and export it to GOOGLE_CREDENTIALS.

Create a Slack bot

Create a Slack bot with scopes channels:manage and channels:read, and export its access token to SLACK_ACCESS_TOKEN.

Share calendar(s) with your service account

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.

Mentions in calendar events

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.

Connect calendars and channels

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"
  },
  ...
]

Run it

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

Deploying

Anywhere you want

You can deploy this script anywhere that runs Node and has some mechanism for running it on a schedule (like cron).

AWS Lambda

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.