Documentation ¶
Overview ¶
Package slackbot provides a basic slackbot implementation. Using this package typically involves creating a bot as follows:
bot := slackbot.New("some-token", slackbot.WithCommands(...) go bot.Run(context.Background())
Once running, the bot will listen for any commands specified and execute them. Slackbot itself implements two commands: "version" (which responds with the bot's name; see WithName option) and "help" (which shows all supported commands).
Applications can send messages as follows:
bot.Send(channel, []slack.Attachment{{Text: "Hello world"}})
Example ¶
package main import ( "context" "github.com/clambin/go-common/slackbot" "github.com/slack-go/slack" ) func main() { b := slackbot.New("my-slack-token", slackbot.WithCommands(map[string]slackbot.CommandFunc{ "hello": func(_ context.Context, _ ...string) []slack.Attachment { return []slack.Attachment{{ Color: "good", Text: "General Kenobi!", }} }, })) b.Run(context.Background()) }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandFunc ¶
type CommandFunc func(ctx context.Context, args ...string) []slack.Attachment
CommandFunc signature for command callback functions
type Option ¶ added in v0.4.0
type Option func(*SlackBot)
func WithCommands ¶ added in v0.4.0
func WithCommands(commands map[string]CommandFunc) Option
func WithLogger ¶ added in v0.4.0
Click to show internal directories.
Click to hide internal directories.