bot

package
v2.3.19 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger(cfg config.Logger)

InitLogger provides logger instance for the given config

func RegisterPlugin added in v2.3.9

func RegisterPlugin(plugin Plugin)

RegisterPlugin registers a new plugin, usually called in the init() function of the plugin package

Types

type BaseCommand

type BaseCommand struct {
	client.SlackClient
}

BaseCommand is base struct which is handy for all commands, as a direct Slack communication is possible

type Bot

type Bot struct {
	// contains filtered or unexported fields
}

Bot is the main object which is holding the connection to Slack and all possible commands it also registers the listener and handles topics like authentication and logging

func NewBot

func NewBot(cfg config.Config, slackClient *client.Slack, commands *Commands) *Bot

NewBot created main Bot struct which holds the slack connection and dispatch messages to commands

func (*Bot) HandleMessage

func (b *Bot) HandleMessage(message *slack.MessageEvent)

HandleMessage is the entry point for incoming slack messages: - checks if the message is relevant (direct message to bot or mentioned via @bot) - is the user allowed to interact with the bot? - find the matching command and execute it

func (*Bot) Init

func (b *Bot) Init() (err error)

Init establishes the slack connection and load allowed users

func (*Bot) ProcessMessage added in v2.2.4

func (b *Bot) ProcessMessage(message msg.Message, fromUserContext bool)

ProcessMessage process the incoming message and respond appropriately

func (*Bot) Run added in v2.2.3

func (b *Bot) Run(ctx *util.ServerContext)

Run is blocking method to handle new incoming events...from different sources

type Category

type Category struct {
	Name        string
	Description string
	HelpURL     string
}

Category of Help entries. -> Groups command in help command by "Jenkins", "Pull request" etc

type Command

type Command interface {
	GetMatcher() matcher.Matcher
}

Command is the main command struct which needs to provide the matcher and the actual executed action

type Commands

type Commands struct {
	// contains filtered or unexported fields
}

Commands is a wrapper of a list of commands. Only the first matched command will be executed

func (*Commands) AddCommand

func (c *Commands) AddCommand(commands ...Command)

AddCommand registers a command to the command list

func (*Commands) Count

func (c *Commands) Count() int

Count the registered/valid commands

func (*Commands) GetCommandNames added in v2.2.10

func (c *Commands) GetCommandNames() []string

func (*Commands) GetHelp

func (c *Commands) GetHelp() []Help

GetHelp returns the help for ALL included commands

func (*Commands) Merge

func (c *Commands) Merge(commands Commands)

Merge two list of commands

func (*Commands) Run

func (c *Commands) Run(message msg.Message) bool

Run executes the first matched command and return true in case one command matched

func (*Commands) RunWithName added in v2.2.10

func (c *Commands) RunWithName(message msg.Message) (bool, string)

RunWithName executes the first matched command and return the command name if there was a match

type Conditional

type Conditional interface {
	IsEnabled() bool
}

Conditional checks if the command should be activated. E.g. is dependencies are not present or it's disabled in the config

type Help

type Help struct {
	Command     string
	Description string
	HelpURL     string
	Category    Category
	Examples    []string
}

Help command can provide help objects which are searchable by keywords

func (*Help) GetKeywords

func (h *Help) GetKeywords() []string

GetKeywords crates a string slice of help keywords -> used by fuzzy search

type HelpProvider

type HelpProvider interface {
	// GetHelp each command should provide information, like a description or examples
	GetHelp() []Help
}

HelpProvider can be provided by a command to add information within "help" command

type Plugin added in v2.3.9

type Plugin struct {
	// Name is the unique identifier of the plugin, it's also the key within the "plugins" config section
	Name string

	// Setup creates the commands of the plugin. It's only called when the plugin is enabled in the config.
	Setup func(ctx *PluginContext) (Commands, error)

	// Init creates the commands of the plugin.
	//
	// Deprecated: use Setup, which also provides the plugin specific config via PluginContext.LoadConfig
	Init func(slackClient client.SlackClient, cfg config.Config) Commands
}

Plugin is an extension of the bot which is compiled into the bot binary, usually via the slack-bot-builder. Plugin authors create a Go package with an init() function which calls RegisterPlugin(). A compiled-in plugin is only loaded when it's listed in the "plugins" section of the config, see docs/plugins.md

type PluginContext added in v2.3.19

type PluginContext struct {
	// Name of the plugin
	Name string

	// SlackClient is the common interface to interact with Slack, it's also embedded in BaseCommand
	SlackClient client.SlackClient

	// Slack is the full Slack client, providing the whole Slack API via the embedded *slack.Client and the socket mode client.
	// It's nil when the SlackClient is mocked, e.g. in unit tests.
	Slack *client.Slack

	// Config is the whole bot config
	Config config.Config

	// Logger which adds the plugin name to all log entries
	Logger *log.Entry
	// contains filtered or unexported fields
}

PluginContext provides access to the bot framework for a plugin. Other parts of the framework, like the storage ("bot/storage"), the queue ("command/queue") or stats ("bot/stats"), are packages which can be used directly.

func NewPluginContext added in v2.3.19

func NewPluginContext(name string, slackClient client.SlackClient, cfg config.Config) *PluginContext

NewPluginContext creates the context for the given plugin. It's used to load the plugins and can be used to test them.

func (*PluginContext) BaseCommand added in v2.3.19

func (c *PluginContext) BaseCommand() BaseCommand

BaseCommand returns a BaseCommand which can be embedded into the commands of the plugin

func (*PluginContext) LoadConfig added in v2.3.19

func (c *PluginContext) LoadConfig(target any) error

LoadConfig decodes the plugin specific options ("config" of the plugin in the "plugins" config section) into the target. "${ENV_VAR}" placeholders get replaced by the value of the environment variable.

type Runnable added in v2.2.10

type Runnable interface {
	RunAsync(ctx *util.ServerContext)
}

Runnable indicates that the command executes a go function

Directories

Path Synopsis
Package builder compiles a custom slack-bot binary which includes all plugins listed in the "plugins" config section.
Package builder compiles a custom slack-bot binary which includes all plugins listed in the "plugins" config section.
Package cli provides an interactive shell to communicate with the bot in the terminal, using a mocked Slack server
Package cli provides an interactive shell to communicate with the bot in the terminal, using a mocked Slack server
Package tester provides functionality to test the bot against a fake slack server
Package tester provides functionality to test the bot against a fake slack server

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL