Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/genkami/go-slack-event-router
Slack Event Router
https://github.com/genkami/go-slack-event-router
go golang slack slack-api slack-bot slackbot
Last synced: about 3 hours ago
JSON representation
Slack Event Router
- Host: GitHub
- URL: https://github.com/genkami/go-slack-event-router
- Owner: genkami
- License: apache-2.0
- Created: 2021-03-10T15:22:49.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-11-12T03:52:33.000Z (6 days ago)
- Last Synced: 2024-11-12T04:28:40.971Z (6 days ago)
- Topics: go, golang, slack, slack-api, slack-bot, slackbot
- Language: Go
- Homepage:
- Size: 209 KB
- Stars: 9
- Watchers: 3
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-slack-event-router
![ci status](https://github.com/genkami/go-slack-event-router/workflows/Test/badge.svg)
[![Go Reference](https://pkg.go.dev/badge/github.com/genkami/go-slack-event-router.svg)](https://pkg.go.dev/github.com/genkami/go-slack-event-router)This is not a chatbot framework, but rather a simple event dispatcher that enhances the functionality of [slack-go/slack](https://github.com/slack-go/slack).
## Example
To handle Events API:
```go
import (
"context"
"net/http"
"os"
"regexp"eventrouter "github.com/genkami/go-slack-event-router"
"github.com/genkami/go-slack-event-router/message"
"github.com/genkami/go-slack-event-router/reaction"
"github.com/slack-go/slack/slackevents"
)func ExampleRouter() {
signingSecret := os.Getenv("SLACK_SIGNING_SECRET")
r, _ := eventrouter.New(eventrouter.WithSigningSecret(signingSecret)) // omitted error handling// Call handleDeploy whenever the router receives `message` events and the text of the message matches to /deploy/.
r.OnMessage(message.HandlerFunc(handleDeploy), message.TextRegexp(regexp.MustCompile(`deploy`)))// Call handleIssue whenever the router receives `reaction_added` events with reaction `:issue:` and the event happens in the channel ABCXYZ.
r.OnReactionAdded(reaction.AddedHandlerFunc(handleIssue), reaction.Name("issue"), reaction.Channel("ABCXYZ"))http.Handle("/slack/events", r)
// ...
}func handleDeploy(ctx context.Context, e *slackevents.MessageEvent) error {
// Do whatever you want...
return nil
}func handleIssue(ctx context.Context, e *slackevents.ReactionAddedEvent) error {
// Do whatever you want...
return nil
}
```To handle user interaction:
```go
import (
"context"
"net/http"
"os""github.com/genkami/go-slack-event-router/interactionrouter"
"github.com/slack-go/slack"
)func ExampleRouter() {
signingSecret := os.Getenv("SLACK_SIGNING_SECRET")
r, _ := interactionrouter.New(interactionrouter.WithSigningSecret(signingSecret)) // omitted error handling// Call handlePostNiceGif whenever the router receives `block_actions` event with a block `post_nice_gif` with an action `gif_keyword`.
r.On(slack.InteractionTypeBlockActions, interactionrouter.HandlerFunc(handlePostNiceGif),
interactionrouter.BlockAction("post_nice_gif", "gif_keyword"))http.Handle("/slack/actions", r)
// ...
}func handlePostNiceGif(ctx context.Context, callback *slack.InteractionCallback) error {
// Do whatever you want...
return nil
}
```## License
Distributed under the Apache License Version 2.0. See LICENSE for more information.