Introduction
In this tutorial, we will see how easy it is to send messages to a Slack channel in our Java application with jslack framework.
jSlack
jSlack is a Java library to easily integrate your operations with Slack. This library supports all the APIs listed in Slack platform features and APIs.
Incoming Webhook with Slack
Webhook is a simple way to post messages from external sources into Slack via ordinary HTTP requests. See the Slack Incoming Webhooks guide for more details.
Getting started
Getting the Webhook URL
The first thing we need to do is find out from Slack the correct URL it will use to post the messages.
Go to https://YOUR_ALIAS_TEAM.slack.com/apps/manage/custom-integrations
Choose the Incoming WebHooks option.
Access Add configuration and choose the channel to which you want to send messages and then Add Incoming WebHooks Integration.
Slack gives you the URL to which you will be posting your messages.
Similar to this: https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX
Create Demo App
Go to https://start.spring.io/ and create a demo app with the Web dependency.
Import application in your IDE and follow steps below:
1 - Edit application.properties
file.
server.servlet.context-path=/
slack.webhook=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXX
2 - Edit pom.xml
file and add jslack:
<dependency>
<groupId>com.github.seratch</groupId>
<artifactId>jslack</artifactId>
<version>1.5.6</version>
</dependency>
3 - Add controller and service classes:
Run Demo App
Start demo app just running a main class.
Using any rest client, make the POST request:
http://localhost:8080/apps/my simple message here
And Wow! Your message exposed in slack.
Conclusion
In this post, we can see how its works slack webhook integration implemented in Spring Boot 2 with jslack. This framework also provides support to real-time Messaging API, events API, among other resources.
Sources
silviobuss / demo-jslack
Send slack messages with jslack
demo-jslack
Send slack messages with jslack
What is this and how it works?
https://dev.to/silviobuss/send-slack-messages-with-java-in-5-minutes-2lio
Top comments (0)