# README
go-slack-event-router
This is not a chatbot framework, but rather a simple event dispatcher that enhances the functionality of slack-go/slack.
Example
To handle Events API:
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:
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.
# Packages
Package appmention provides handlers to process `app_mention` events.
package appratelimited provides handler to process `app_rate_limited` events.
Package errors provides error values and types that are intended to be used to implement handlers.
Package interactionrouter provides a way to dispatch interactive callbacks sent from Slack.
Package message provides handlers to process `message` events.
Package reaction provides handlers to process `reaction_*` events.
Package signature provides helpers to validate request signature.
Package urlverification provides handlers to process `url_verification` events.
# Functions
InsecureSkipVerification skips verifying request signatures.
New creates a new Router.
If VerboseResponse is set, the Router shows error details when it fails to process requests.
WithSigningSecret sets a signing token to verify requests from Slack.
# Type aliases
No description provided by the author