https://github.com/pramithamj/slack-sdk-go
A lightweight and modular SDK for building Slack bots and apps in Go. With this SDK, you can easily send messages, manage users, and extend functionality to integrate with the Slack API seamlessly.
https://github.com/pramithamj/slack-sdk-go
go sdk slack
Last synced: 2 months ago
JSON representation
A lightweight and modular SDK for building Slack bots and apps in Go. With this SDK, you can easily send messages, manage users, and extend functionality to integrate with the Slack API seamlessly.
- Host: GitHub
- URL: https://github.com/pramithamj/slack-sdk-go
- Owner: PramithaMJ
- License: mit
- Created: 2024-12-28T19:38:22.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-03T21:33:50.000Z (about 1 year ago)
- Last Synced: 2025-06-19T10:46:38.934Z (about 1 year ago)
- Topics: go, sdk, slack
- Language: Go
- Homepage: https://pkg.go.dev/github.com/pramithamj/slack-sdk-go@v1.0.0#section-readme
- Size: 59.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# π Slack SDK for Go
[](https://github.com/PramithaMJ/slack-sdk-go/actions/workflows/go.yml)
[](https://github.com/PramithaMJ/slack-sdk-go/actions/workflows/main.yml)
[](https://github.com/PramithaMJ/slack-sdk-go/actions/workflows/publish.yml)
A **lightweight** and **modular** SDK for building Slack bots and apps in **Go**. With this SDK, you can easily send messages with Block Kit support, manage users, and extend functionality to integrate with the Slack API seamlessly.
*Last Updated: March 6, 2025*
---
### π Features
- π¨ **Send messages** to Slack channels with Block Kit support
- π¨ **Rich formatting** using Block Kit components
- π€ **Fetch user information**
- β‘οΈ **Extendable** for additional Slack APIs
- π§© **Lightweight** and modular design
- π― **Easy integration** into Go projects
---
### π Getting Started
#### β
Prerequisites
- **Go** 1.18 or later
- A **Slack Bot Token** with the required permissions.
> [Create a Slack App](https://api.slack.com/apps) to generate your token.
#### π¦ Installation
Add the SDK to your project using:
```sh
go get github.com/pramithamj/slack-sdk-go/pkg/slack
```
β¨ Example Usage
Hereβs a quick example to send a message using the SDK:
```go
package main
import (
"fmt"
"log"
"github.com/pramithamj/slack-sdk-go/pkg/slack"
)
func main() {
// Replace with your actual Slack Bot Token
token := "xoxb-your-slack-bot-token"
sdk := slack.NewSlackSDK(token)
channel := "C123456789" // Slack channel ID
message := "Hello, Slack from Go SDK!"
response, err := sdk.SendMessage(channel, message)
if err != nil {
log.Fatalf("Error sending message: %v", err)
}
fmt.Printf("Message sent successfully: %v\n", response)
}
```
#### π API Methods
1οΈβ£ SendMessage
Send a message to a Slack channel.
π₯ Parameters:
β’ channel (string): The channel ID where the message will be sent.
β’ text (string): The message text.
π€ Example:
```go
response, err := sdk.SendMessage("C123456789", "Hello, Slack!")
if err != nil {
log.Fatalf("Error: %v", err)
}
fmt.Println(response)
```
2οΈβ£ GetUserInfo
Fetch details about a Slack user.
π₯ Parameters:
β’ userID (string): The ID of the user.
π€ Example:
```go
response, err := sdk.GetUserInfo("U123456789")
if err != nil {
log.Fatalf("Error: %v", err)
}
fmt.Println(response)
```
#### π Testing
Run all tests using:
go test ./tests/...
#### π€ Contributing
We welcome contributions! To contribute:
1. Fork the repository
2. Create a new branch: git checkout -b feature-name
3. Commit your changes: git commit -m 'Add feature'
4. Push the branch: git push origin feature-name
5. Open a Pull Request
#### π License
This project is licensed under the MIT License. See the LICENSE file for more details.
π€ Author
PramithaMJ
β’ π» [PramithaMJ]](https://github.com/pramithamj)
β’ π§ lpramithamj@gmail.com
---
# Slack SDK for Go π
A powerful and flexible Go SDK for interacting with the Slack API, providing a simple yet comprehensive interface for sending messages and managing Slack communications.
## Features β¨
- π Simple and rich message support
- π§΅ Thread reply functionality
- π Automatic retries with configurable attempts
- β±οΈ Context support for timeouts and cancellation
- π― Custom error types and proper error handling
- π Secure configuration via environment variables
- π¦ Block kit and message attachments support
## Installation π₯
```bash
go get github.com/pramithamj/slack-go-sdk
```
## Quick Start π
```go
package main
import (
"context"
"log"
"os"
"time"
"github.com/pramithamj/slack-go-sdk/pkg/slack"
)
func main() {
// Get token from environment
token := os.Getenv("SLACK_BOT_TOKEN")
if token == "" {
log.Fatal("SLACK_BOT_TOKEN is required")
}
// Initialize SDK
sdk := slack.NewSlackSDK(token)
// Send a message
ctx := context.Background()
response, err := sdk.SendMessage(ctx, "CHANNEL_ID", "Hello from Go SDK!")
if err != nil {
log.Fatal(err)
}
log.Printf("Message sent: %v", response)
}
```
## Advanced Usage π§
### Custom Configuration
```go
sdk := slack.NewSlackSDKWithConfig(slack.Config{
Token: token,
BaseURL: "https://slack.com/api/",
Timeout: 10 * time.Second,
RetryAttempts: 2,
RetryWaitTime: time.Second,
})
```
### Rich Messages with Blocks
```go
richMessage := slack.MessagePayload{
Channel: channelID,
Blocks: []slack.Block{
{
Type: "section",
Text: &slack.TextObject{
Type: "mrkdwn",
Text: "*Hello!*\nThis is a rich message.",
},
},
},
}
response, err := sdk.SendRichMessage(ctx, richMessage)
```
### Thread Replies
```go
response, err := sdk.SendThreadReply(ctx, channelID, threadTS, "This is a reply!")
```
## Environment Variables π
- `SLACK_BOT_TOKEN`: Your Slack bot token (required)
- `SLACK_CHANNEL_ID`: Default channel ID for messages
## Error Handling π
```go
response, err := sdk.SendMessage(ctx, channelID, message)
if err != nil {
if slackErr, ok := err.(*slack.SlackError); ok {
log.Printf("Slack API error: %s", slackErr.Message)
} else {
log.Printf("Other error: %v", err)
}
}
```
## Contributing π€
Contributions are welcome! Feel free to:
- Report bugs
- Suggest new features
- Submit PRs
## Contact π«
- π» [PramithaMJ](https://github.com/pramithamj)
- π§ lpramithamj@gmail.com
## License π
This project is licensed under the MIT License - see the LICENSE file for details.
---
Last Updated: March 6, 2025