Build a Slack Integration

Learn how to create a simple slack integration in just a few minutes using Kolla Konnect

Prerequisites

You must have a Slack account. You can setup a free workspace on Slack here:https://slack.com/get-started

1. Create Your Slack App in the Slack Developer Portal

Go to https://api.slack.com/apps and click "Create New App". A modal appears with two options, select "From and app manifest".

Copy and paste this simple Slack manifest into the window:

{
    "display_information": {
        "name": "Kolla Example App",
        "description": "An simple Kolla example app",
        "background_color": "#da3a79",
        "long_description": "This is an example app manifest from the Kolla tutorial for creating a Slack integration quickly. Kolla manages all your OAuth2 connections to third parties so you can focus on the important parts of your integrations. See https://getkolla.com for more information."
    },
    "features": {
        "bot_user": {
            "display_name": "Kolla",
            "always_online": true
        }
    },
    "oauth_config": {
        "redirect_urls": [
            "https://connect.getkolla.com/oauth"
        ],
        "scopes": {
            "bot": [
                "channels:read",
                "chat:write",
                "chat:write.public"
            ]
        }
    },
    "settings": {
        "org_deploy_enabled": false,
        "socket_mode_enabled": false,
        "token_rotation_enabled": true
    }
}

Click "Next" then click "Create"

You will be taken to the App Details page. Under the section Basic Information, scroll down to App Credentials and note the Client ID and Client Secret for later configuration of the Kolla Slack Connector.

Now go to the section Manage Distribution and scroll down Public Distribution. Click on Remove Hard Coded Information and mark the check box.

Click on Activate Public Distribution.

Last thing to note is the Shareable URL in this section.

Now your Slack app is ready to be added to Kolla!

2. Configure a new Slack connector in your Kolla account

Login to your Kolla admin portal and click on Connectors.

Click on the Add Connector button and select Slack from the list of available connectors.

Enter the Client ID, Client Secret, and Shareable URL from the previous steps and click save.

You are now in the connector details for the new Slack connector you added. Click on the Publish toggle switch at the top right and it is live!

Now that you are all configured, you can use Kolla to manage the entire OAuth2 authentication process and connect to your customers' Slack accounts. For building and testing your integration however, you can also just link to your own.

To link to a Slack instance go to your connector details for the Slack connector you just created and click Actions and then Create Invite Link.

Enter a customer ID for reference, typically the ID from your own customer data, or you can just enter "test" for testing.

You can also add a Customer Name and Customer Email for reference in the Kolla Admin so you can easily identify which linked account belongs to which customer.

Click on Generate Link

The window then shows a URL that you can send to your customer or that you can go to yourself for testing. The URL loads a standalone version of our Embedded Integration Marketplace and guides your customers through the authentication process for your connectors, creating a linked account. See more details on this feature here.

Go to the URL that was given to you and see the Marketplace load the Slack connector details. Click connect, and then follow the authentication process by logging into slack and choosing a workspace to install this app into.

When you are done, go back to the Kolla Admin and click on Linked Accounts. You will see your new linked account there are ready to use!

4. Write your backend business logic

Now that we got that pesky configuration out of the way, we do the fun stuff! Writing our business logic for our new Slack integration!

For this tutorial, we are simply going to show you how to send a message to a slack channel. In your software you may want to send a message to your customers slack whenever an action is taken, or do more interactive Slack messages. This will be a good starting point for you but is a trivial example to get you going.

Here is an example that loads the Slack token for our test customer's linked account, and sends a message to the general channel.

package main

import (
	"context"
	"os"

	"github.com/kollalabs/sdk-go/kc"
	"github.com/slack-go/slack"
)

func main() {
	// Get api key from environment variable
	apiKey := os.Getenv("KOLLA_API_KEY")
	// Create a new client
	kolla, err := kc.New(apiKey)
	if err != nil {
		log.Fatalf("unable to create kolla connect client: %s\n", err)
	}

	ctx := context.Background()
	creds, err := kolla.Credentials(ctx, "slack-10223", "test")
	if err != nil {
		panic(err)
	}
	//creds.LinkedAccount.AuthData
	slackapi := slack.New(creds.Token)
	_, _, err = slackapi.PostMessage("general", slack.MsgOptionText("Hello world! (Sent with Kolla managed token)", false))
	if err != nil {
		panic(err)
	}
}

Stepping through this code:

  • On line 13, we load the Kolla API key from an environment variable. You can create a Kolla API key in your Kolla Admin portal under Settings. This should be stored as a Secret and not publicly available.

  • On line 15 we instantiate a new Kolla client

  • On line 21 we load the Slack token for the custer ID "test" like we used previously. Note that slack-10223 is the ID of the connector. Your connector ID will be different and can be obtained from the connector details page in your Kolla Admin.

  • Lastly, onlinkes 26 through 30 we create a new Slack client from the Slack SDK and use the token we just got from Kolla. We then send a "Hello World" message to the general channel

Next Steps

Now you created your first slack integration, and Kolla helped you Authenticate in a very simple way! Behind the scenes Kolla manages all the token refreshes for you as well, so you don't ever have to worry about the headache that OAuth2 can be!

Your next step will be to add the Embedded Integration Marketplace right into your software allowing your customer to link their third party software to you easily.

Head to Installing Konnect to see how you can integration management right into your user interface with only a few linkes of code.

Last updated