paint-brush
Writing Your Own Slack App in 5 Steps by@sergeidzeboev
1,051 reads
1,051 reads

Writing Your Own Slack App in 5 Steps

by Sergei DzeboevDecember 19th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Slack is a powerful tool for communications in a company. Slack allows the creation of apps and enriches already a convenient default functionality. If you already have a handy tool that you like to add to your daily environment, creating a slack app would be a great way to do it.
featured image - Writing Your Own Slack App in 5 Steps
Sergei Dzeboev HackerNoon profile picture
Slack is a powerful tool for communications in a company. Slack allows the creation of apps and enriches already a convenient default functionality. If you already have a handy tool that you like to add to your daily environment, creating a slack app would be a great way to do it.

STEP 1. CREATING A SERVICE

Let’s create a service that we will integrate into Slack. In order to do it let’s use the website //www.shouldideploy.today/. This website provides a message if you should deploy now. We will use it to take the provided message and return it as a text to integrate it into Slack later.

So, let's create a spring boot application, and add a controller class. This class will contain a method mapped to GET request that will do a request to the website and will return the message from it as text:
@RestController
public class ShouldIDeployController {
 
   @GetMapping("/should")
   public Mono<String> shouldIDeploy() {
       return WebClient.builder()
               .baseUrl("//shouldideploy.today/api?tz=UTC")
               .build()
               .get()
               .exchangeToMono(response -> response.bodyToMono(String.class));
   }
}
Let’s now start our Spring Boot application and check how it works. You can open the link in a browser and see how the service works:
As you can see it works as planned. The backend service is done, now we need to register our service in Slack. The full code can be found in this GitHub repository

STEP 2. REGISTERING A SLACK APP

Go to and click "Create an app":
Then click "From scratch":
Then name your app and pick a workspace. You can pick your current workspace or you can create a new one - it is free. I named the app "should-i-deploy" and picked my workspace:
That's it. The app has been created. Now let’s do a couple of configurations and the whole work is done.

STEP 3. CREATING A COMMAND

Open the application you have just created, go to "Basic information" and click "Slash Commands":
Then click "Create New Command". Now put any text into the "Command",  it later will be used to trigger our service. I put a question mark to keep it simple, but you can put any preferable to your name.In the "Request URL" field you have to put the URL of the service we created. It must be accessible via the internet to work properly. If you can launch only the local version, later we will use a ready-to-use service to make the app work:
After configuring the command and the URL go to "Basic Information" → "Bots" and toggle "Message Tab" and "Allow user to send Slash commands". Also, you can toggle "Always Show my Bot as Online", but this is not necessary:

STEP 4. INSTALLING TO WORKSPACE

The last step that you have to do is to install the app into a workspace. Go to "Basic Information" → "Install your app" → "Install to Workspace":
Then pick your workspace and click "Allow":

STEP 5. USING YOUR APP

Now, the app is ready to use. To use it go to "Browse apps" and find your app by name:
After that, you will see your app in the list and you can use it via your specified command, in my case it was /?:
That was the final step, now you can use your app in daily routines. In the next section, you will see how to use the same app without creating a backend service.

THE FREE SLACK API

As was mentioned previously this would work if your backend service is accessible from the web. If your service is not accessible don’t worry, since //shouldideploy.today/ provides slack API that can be used instead of your own service, all you have to do is to put the API link into the "Request URL" using the preferable timezone. For instance, the UTC timezone link would look like this: //shouldideploy.today/api/slack?tz=UTC. So you just need to reconfigure the app and put the link in the "Request URL", then redeploy your app into your workspace and it’s all done:
Now you can use your app without your own backend service and receive preformatted answers:

SUMMARY

In order to create your own Slack app you need to do these 5 steps:
  • Create your service or use a free API
  • Register your Slack app
  • Create a command
  • Deploy to your Workspace
  • Use the app


바카라사이트 바카라사이트 온라인바카라