[![Build Status])
The Slack connector allows you to send slack message through the Slack REST API.
Ballerina Language Version | Slack API Version |
---|---|
1.0.0 | v1 |
|
- Refer the Getting Started guide to download and install Ballerina.
- To use Slack endpoint, you need to provide the following:
- Webhook URL
- Create a new Ballerina project by executing the following command.
<PROJECT_ROOT_DIRECTORY>$ ballerina new <project_name>
4. Import the Slack module to your Ballerina program as follows. ```
import ballerina/config;
import ballerina/io;
import hackbros/slack;
slack:SlackConfiguration slackConfig = {
webhookUrl: config:getAsString("WEBHOOK_Url")
};
slack:Client slackClient = new(slackConfig);
public function main() {
slack:SlackConfiguration slackConfig = {
webhookUrl: "https://hooks.slack.com/services/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"
};
slack:Client slackClient = new(slackConfig);
string | error response = slackClient->sendWebhookMessage("text","*hello balleria from hackbros*",false);
if (response is error) {
// If unsuccessful, print error details
io:println("Error in call to Slack: ", response);
} else {
if (response == "ok") {
io:println("Slack Send Message is successful: ");
}
else {
// If unsuccessful, print the error returned.
io:println("Slack Error Code: ", response);
}
}
}
```