Documentation
¶
Overview ¶
Package botbooter is a small framework for building chat bots that behave the same way across Slack, Discord and a local CLI. A single Bot abstracts over the platforms; you register Command handlers and optional Middleware, then run the bot.
This package is a thin facade over the implementation in the internal packages, so that consumers keep a single import path.
Example ¶
Example shows the CLI adapter, which needs no external credentials: it reads messages from an io.Reader and writes replies to an io.Writer.
package main
import (
"context"
"os"
"strings"
"github.com/lao/botbooter"
)
func main() {
bot := botbooter.InitAsCLIBot(strings.NewReader("echo hello\n"), os.Stdout)
_ = bot.HandleFunc("^echo ", func(ctx context.Context, b *botbooter.Bot, m *botbooter.Message) {
_ = b.SendMessageContext(ctx, m.ChannelID, strings.TrimPrefix(m.Content, "echo "))
})
// Run returns when the input reaches EOF.
_ = bot.Run(context.Background())
}
Output: hello
Index ¶
Examples ¶
Constants ¶
const ( SlackBotType = core.SlackBotType DiscordBotType = core.DiscordBotType CLIBotType = core.CLIBotType )
Supported bot types.
Variables ¶
var ( ErrUnknownBotType = core.ErrUnknownBotType ErrAlreadyConnected = core.ErrAlreadyConnected )
Errors returned by Bot methods.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
type Attachment = core.Attachment
Attachment is a platform-agnostic file attachment. See core.Attachment.
type Bot ¶
Bot is the platform-agnostic chat bot. See core.Bot.
func InitAsCLIBot ¶
InitAsCLIBot creates a bot that reads newline-delimited messages from in and writes replies to out. When in or out is nil, os.Stdin and os.Stdout are used respectively. It is intended for trusted, local input only.
func InitAsDiscordBot ¶
InitAsDiscordBot creates a Discord bot from a bot token. It returns an error if the token cannot be used to construct a session.
func InitAsSlackBot ¶
InitAsSlackBot creates a Slack bot that connects via Socket Mode. appToken is the app-level token (xapp-...) and botToken is the bot token (xoxb-...).
type CLIMessage ¶
type CLIMessage = core.CLIMessage
CLIMessage is the raw payload of a CLI message. See core.CLIMessage.
type Command ¶
Command pairs a regexp pattern with a handler. See core.Command.
type CommandHandler ¶
type CommandHandler = core.CommandHandler
CommandHandler handles a matched message. See core.CommandHandler.
type Message ¶
Message is an incoming message handed to handlers. See core.Message.
type Middleware ¶
type Middleware = core.Middleware
Middleware wraps message dispatch. See core.Middleware.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
v1
command
Command v1 is a small demo of botbooter.
|
Command v1 is a small demo of botbooter. |
|
internal
|
|
|
asserts
Package asserts holds tiny test assertion helpers shared across botbooter's test packages.
|
Package asserts holds tiny test assertion helpers shared across botbooter's test packages. |
|
cli
Package cli is the local CLI adapter for botbooter.
|
Package cli is the local CLI adapter for botbooter. |
|
core
Package core holds botbooter's platform-agnostic engine: the Bot type, its command/middleware dispatch, and the connection lifecycle.
|
Package core holds botbooter's platform-agnostic engine: the Bot type, its command/middleware dispatch, and the connection lifecycle. |
|
discord
Package discord is the Discord adapter for botbooter.
|
Package discord is the Discord adapter for botbooter. |
|
slack
Package slack is the Slack adapter for botbooter.
|
Package slack is the Slack adapter for botbooter. |