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 is a Java library to easily integrate your operations with Slack. This library supports all the APIs listed in Slack platform features and APIs.
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.
The first thing we need to do is find out from Slack the correct URL it will use to post the messages.
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
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
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:
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.
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.
Send slack messages with jslack