Building your OAuth Slack flow and storing channel data in Knock

Once you have your Slack app configured and you've figured out which OAuth scopes it will need, you're ready to build the OAuth flow your customers will use to install your Slack app in their Slack workspace.

Here's what we'll cover in this guide.

  • How to build a simple Slack OAuth in your product
  • How to use the response received in that OAuth handshake to set Knock channel data
  • How to decide when to set Knock channel data on users vs. objects

How to add a Slack OAuth flow to your product

To get the channel data required to send notifications to a public/private/DM channel in your customer's Slack workspace, you'll need an OAuth flow in your product that your customer uses to authenticate into Slack and give you an access token you'll use to send Slack notifications to your users.

The best place to start is with Slack's Installing with OAuth documentation.

Once you're receiving Slack OAuth callbacks on the endpoint you've set up, you're ready to store that response as channel data in Knock.

How to set channel data for a Slack integration in Knock

When you receive an OAuth callback from Slack, you'll need to set the returned identifier (either an incoming_webhook_url or an access_token) as channel data on a user or an object in Knock. We cover how to decide which to use in the section below.

Here's an example of setting channel data on an object in Knock.

Potential confusion alert. In the example above, the KNOCK_SLACK_CHANNEL_ID variable is the id of the Knock channel you've created to represent your Slack app within the Knock dashboard. You can find it by going to Integrations > Channels in the Knock dashboard and then copying the ID of your Slack app channel.

Channel data requirements

Here's an overview of the data requirements for setting recipient channel data for either an incoming webhook or an access token Slack connection. Both will need to live under the connections key

connectionsSlackConnection[]*One or more connections to Slack

SlackConnection with incoming webhook url

incoming_webhook.urlstring*The Slack incoming webhook URL

SlackConnection with an access token

access_tokenstring*A bot access token
channel_idstring*A Slack channel ID
user_idstring*A Slack channel ID

Setting channel data: users vs. objects

Depending on the Slack integration you build into your product, you’ll store the connection data you receive from Slack as channel_data on either a user or an object in Knock.