SlackProgressBar is a Go library for creating a real-time progress bar in a Slack channel. It provides a way to visualize the progress of long-running tasks directly in Slack, so your team can stay updated on the task's progress.
- Real-time progress updates in Slack
- Customizable progress bar with ETA
- Pause, resume, and log additional information while processing
- Memory usage display
go get github.com/r-scheele/SlackProgressBar@v0.1.0
- First, import the library in your Go file:
import (
"github.com/r-scheele/SlackProgressBar/bar"
)
- Create a new
SlackProgress
instance with your Slack token and channel:
sp := &bar.SlackProgress{
Token: "your-slack-token",
Channel: "#your-channel",
}
- Define your list of items and the function to process each item:
items := make([]string, 100)
for i := 1; i <= 100; i++ {
items[i-1] = fmt.Sprintf("item%d", i)
}
func processItem(item string) {
// Your item processing code here
}
- Call
Iter
on yourSlackProgress
instance to process the items and update the progress bar in Slack:
sp.Iter(items, processItem)
You can customize the appearance and behavior of the progress bar by setting additional fields on the SlackProgress
struct:
sp := &SlackProgress{
Token: "your-slack-token",
Channel: "#your-channel",
Suffix: "%",
ProgressBarChar: "▓",
Precision: 1,
RateLimit: time.Millisecond * 500,
CompletionCallback: func() {
fmt.Println("Task completed!")
},
}
-
Navigate to Slack API Page:
- Go to the Slack API page and click on
Create New App
.
- Go to the Slack API page and click on
-
Name Your App:
- Enter a name for your app (e.g.,
SlackProgressBar
) and select the Slack workspace where you want the app to reside, then clickCreate App
.
- Enter a name for your app (e.g.,
-
Configure Basic Information:
- Under the
Basic Information
section, you can set up various information about your app such as its name, description, and icons.
- Under the
-
Navigate to OAuth & Permissions:
- On the left sidebar, click on
OAuth & Permissions
.
- On the left sidebar, click on
-
Add OAuth Scopes:
- Under the
Bot Token Scopes
section, clickAdd an OAuth Scope
and add the following scopes:chat:write
(to send messages)chat:write.public
(if you want to post to channels without joining)
- Under the
-
Install App to Workspace:
- Click on
Install to Workspace
button at the top of the page. - You'll be redirected to a permission request screen in your Slack workspace. Click
Allow
to install the app and grant it the requested permissions.
- Click on
-
Copy the Bot User OAuth Token:
- Once the app is installed, you'll be redirected back to the
OAuth & Permissions
page. - Under the
OAuth Tokens for Your Workspace
section, you'll find aBot User OAuth Token
. This token will start withxoxb-
. Copy this token as you'll need it for your Go code.
- Once the app is installed, you'll be redirected back to the
Now that you have the OAuth token, you can use it in your Go code as follows:
sp := &SlackProgress{
Token: "xoxb-your-token-here",
Channel: "#your-channel",
// ... other configuration ...
}
Replace "xoxb-your-token-here"
with the actual Bot User OAuth Token you copied earlier.
Now you can run your Go code, and it should be able to post and update messages in the specified Slack channel using the credentials of the Slack app you created.
This setup allows your Go code to interact with the Slack API and post progress updates to your Slack workspace.
- Make sure that the channel you specify in your Go code exists in your Slack workspace.
- If you need to post messages to multiple channels or private channels, you may need to invite the Slack app bot user to those channels within Slack.
We welcome contributions! Please feel free to submit a pull request with any improvements.
This project is licensed under the MIT License.
You can copy and paste this template into a `README.md` file in the root of your GitHub repository, and then customize it to match the exact features and usage of your library.