Last time, we talked about my motivations for building a Slack autoresponder so I can better communicate with my colleagues. Today we'll walk through the components required and all the steps for wiring together the full application.

Serverless Framework

First things first, we need to build the application itself. We'll be leveraging the Serverless framework, so if you don't already have that installed go ahead and install it:

npm i -g serverless

We install this tool globally to make the sls command available everywhere. When we're ready to deploy our application, a simple sls deploy will push everything up to AWS. That said, the next thing we need to do is configure our AWS credentials for Serverless to use - rather than walk you though those steps here, I'll refer you to Serverless' excellent configuration walkthrough.

Once your system is configured, you can clone my existing project and take a look through the code. I'll step through some significant functionality below once we've configured the rest of our credentials.

RingCentral

RingCentral App Creation Interface
RingCentral's App Creation Interface

For this illustration, we're going to use the Node SDK for RingCentral. The code is straight-forward and can be taken directly from the documentation's Quick Start Guide.

Clicking the "Create SMS App" button on the Guide page will launch you into the developer console, where you can configure an Other Non-UI application for use with this tool. Accept all of the details and click through the Create buttons to get started with the app - the defaults are acceptable enough for this solution, though as you become more accustomed with RingCentral you might want to make changes.

RingCentral App Credentials
RingCentral App Credentials

Once you've created an app, you can grab all of the credentials you'll need to configure our integration. You'll need:

  • The API server URL (this should be for their dev/test platform)
  • Your client ID
  • Your client secret
  • Your account phone number (this is also be your username)
  • Your account password
  • Your phone extension (by default this is 101, so we'll just use that)

That's all we need from RingCentral for now!

Slack Application

Configuring the Slack application itself is equally straight-forward. Go to the Slack App console and create a new app. Once it's created, you'll need to grab the app's Signing Secret for use with our integration.

Next, go to the OAuth & Permissions screen (link on the left-hand side under Features). First,

Next, go to the OAuth & Permissions screen (link on the left-hand side under Features). First, scroll down the the User Token Scopes section and add the scopes we need for the integration to work:

  • chat:write
  • im:history
  • users.profile:read
  • users:read

Now scroll back up and install the app in your Slack workspace. This will set up OAuth permission for the app to work and give you the application's OAuth Access Token (which you'll need for our integration to work).

Finally, you'll need to get your user ID. I found mine by viewing my profile in the web version of Slack (not the desktop app). Create a DM with yourself and say hi. Then click on your name to view a small version of your profile with a "View full profile" link - click that link.

On your profile screen, click the kebob menu on the right and you'll see your Member ID in the resulting dropdown. This is the value you need.

Likewise, if there's anyone in your org you don't want to automatically respond to while you're away, grab their member IDs as well.

The Slack Autoresponder

The autoresponder itself is fully coded for you. It's open source, so you can use it, modify it, and do whatever you want.[ref]Note that I offer no guarantees or warranties of any kind. The system works for me and I use it daily, but it's not a fully fleshed-out system with integration tests so there might be edge cases where things break.[/ref] First, clone the repository to your local system and run npm install from the newly-created directory to set up all of the package dependencies.

Now, copy _secrets.yml to secrets.yml in the project and fill in all of the credentials we've copied down from the systems above. Ensure you set the sms_tool value to ringcentral and enter your own phone number in destination_phone. The rest of the credentials will be obvious based on the steps above.

The ignore_users field is a quoted, comma-delimited list of the user IDs you want to skip the autoresponder. At the very minimum, your ID should be in there so you don't accidentally respond to yourself. I'd also highly recommend you also include your boss' ID.

Deploying the app with Serverless.
Deploying the app with Serverless

Once everything is set up, you're ready to deploy! Use Serverless from the same directory, and it will configure your Lambda function, APIGateway endpoints, and CloudFormation monitoring all for you. Just sls deploy and wait.

Before you can use the autoresponder, though, you'll need to tell Slack about it. Go back to the app's configuration page in the Slack console and select the Event Subscriptions option under Features. You need to enable events, then add your new Lambda function's URL (Serverless will give it to you after the deployment completes). Slack will verify things, then you're good!

You also need to subscribe to message events by expanding the Subscribe to events on behalf of users section and adding the message.im event. Now the application is fully configured and ready to go!

In Summary

The application is configured to respond to anyone who sends you a DM when your Slack presence is set to "away." If you're "active," then the system remains quiet and no one gets a notice, but once you toggle yourself to being "away" they'll get a subtle reminder that you won't respond immediately to any pings.

Screenshot of RingCentral text message
RingCentral SMS

Additionally, if someone sends you a message starting with the word "urgent," you'll immediately get a text message via RingCentral alerting you that they need your attention. It's a great way to both suppress unwanted interruptions while also ensuring you're notified of actual urgent issues.

The system is also smart enough to not respond to the same person twice in a 10 minute period. It uses a DynamoDB table to keep track of who it's responded to and suppresses itself in a short window. This will (hopefully) avoid annoying your team while still reminding them you're unavailable.

Now that you have a Lambda-powered Slack integration, what are some other integrations you think would be useful?