Slack is a channel-based messaging platform. With Slack, people can work together more effectively, connect all their software tools and services, and find the information they need to do their best work — all within a secure, enterprise-grade environment.
This connector allows you to access the Slack Web API and Slack Events API through Ballerina. It provides the capability to query information from and perform some actions in a Slack workspace.
For more information, go to the modules.
Slack is a collaboration platform for teams, offering real-time messaging, file sharing, and integrations with various tools. It helps streamline communication and enhance productivity through organized channels and direct messaging.
-
To use the Slack Connector you need to be signed in to Slack. If you haven't created an account already, you can create it here.
-
Navigate to your apps in Slack API and create a new Slack app.
-
Provide an app name and choose a workspace of your choice.
-
Click on the "Create App" button.
-
Once the application is created, go to the "Add Features and Functionality" section and click on "Permissions" to set the token scopes.
-
In the User Token Scopes section set the following token scopes.
-
Install the application to workspace.
-
Copy the OAuth token that is generated upon installation.
To use the slack
connector in your Ballerina application, modify the .bal
file as follows:
Import the slack
module.
import ballerinax/slack;
Assign the OAuth token obtained to the variable token, and then initialize a new instance of the slack client by passing the token.
configurable string token = ?;
slack:Client slack = check new({
auth: {
token
}
});
Now, utilize the available connector operations.
slack:ChatPostMessageResponse postMessageResponse = check slack->/chat\.postMessage.post({channel: "general", text: "hello"});
bal run
The Slack
connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:
-
Automated Summary Report - This use case demonstrates how the Slack API can be utilized to generate a summarized report of daily stand up chats in the general channel.
-
Survey Feedback Analysis - This use case demonstrates how the Slack API can be utilized to perform a company-wide survey by creating a dedicated channel to receive and track feedback replies.
-
Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:
Note: After installation, remember to set the
JAVA_HOME
environment variable to the directory where JDK was installed. -
Download and install Ballerina Swan Lake.
-
Download and install Docker.
Note: Ensure that the Docker daemon is running before executing any tests.
-
Export Github Personal access token with read package permissions as follows,
export packageUser=<Username> export packagePAT=<Personal access token>
Execute the commands below to build from the source.
-
To build the package:
./gradlew clean build
-
To run the tests:
./gradlew clean test
-
To build the without the tests:
./gradlew clean build -x test
-
To run tests against different environment:
./gradlew clean test -Pgroups=<Comma separated groups/test cases>
-
To debug package with a remote debugger:
./gradlew clean build -Pdebug=<port>
-
To debug with the Ballerina language:
./gradlew clean build -PbalJavaDebug=<port>
-
Publish the generated artifacts to the local Ballerina Central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina Central repository:
./gradlew clean build -PpublishToCentral=true
As an open source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All contributors are encouraged to read the Ballerina Code of Conduct.
- Discuss the code changes of the Ballerina project in [email protected].
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.