Documentation ¶
Overview ¶
Package slackscot provides the building blocks to create a slack bot. It is easily extendable via plugins that can combine commands, hear actions (listeners) as well as scheduled actions. It also supports updating of triggered responses on message updates as well as deleting triggered responses when the triggering messages are deleted by users.
Index ¶
- Constants
- func AnswerInThread() func(sendOpts map[string]string)
- func AnswerInThreadWithBroadcast() func(sendOpts map[string]string)
- func AnswerInThreadWithoutBroadcast() func(sendOpts map[string]string)
- func AnswerWithoutThreading() func(sendOpts map[string]string)
- func ApplyAnswerOpts(opts ...AnswerOption) (sendOptions map[string]string)
- func NewSLogger(log *log.Logger, debug bool) (l *sLogger)
- func OptionLog(logger *log.Logger) func(*Slackscot)
- func OptionLogfile(logfile *os.File) func(*Slackscot)
- type ActionDefinition
- type ActionDefinitionWithID
- type Answer
- type AnswerOption
- type Answerer
- type IncomingMessage
- type Matcher
- type Option
- type OutgoingMessage
- type Plugin
- type RealTimeMessageSender
- type SLogger
- type ScheduledAction
- type ScheduledActionDefinition
- type SlackMessageID
- type Slackscot
- type UserInfoFinder
Constants ¶
const ( ThreadedReplyOpt = "threadedReply" BroadcastOpt = "broadcast" )
const (
// VERSION represents the current slackscot version
VERSION = "1.8.0"
)
GENERATED and MANAGED by giddyup (https://github.com/alexandre-normand/giddyup)
Variables ¶
This section is empty.
Functions ¶
func AnswerInThread ¶
AnswerInThread sets threaded replying
func AnswerInThreadWithBroadcast ¶
AnswerInThreadWithBroadcast sets threaded replying with broadcast enabled
func AnswerInThreadWithoutBroadcast ¶
AnswerInThreadWithoutBroadcast sets threaded replying with broadcast disabled
func AnswerWithoutThreading ¶
AnswerWithoutThreading
func ApplyAnswerOpts ¶
func ApplyAnswerOpts(opts ...AnswerOption) (sendOptions map[string]string)
ApplyAnswerOpts applies answering options to build the send configuration
func NewSLogger ¶
NewSLogger creates a new Slackscot logger provided with an interface logger and a debug flag
func OptionLogfile ¶
OptionLogfile sets a logfile for Slackscot while using the other default logging prefix and options
Types ¶
type ActionDefinition ¶
type ActionDefinition struct { // Indicates whether the action should be omitted from the help message Hidden bool // Matcher that will determine whether or not the action should be triggered Match Matcher // Usage example Usage string // Help description for the action Description string // Function to execute if the Matcher matches Answer Answerer }
ActionDefinition represents how an action is triggered, published, used and described along with defining the function defining its behavior
type ActionDefinitionWithID ¶
type ActionDefinitionWithID struct { ActionDefinition // contains filtered or unexported fields }
ActionDefinitionWithID holds an action definition along with its identifier string
type Answer ¶
type Answer struct { Text string // Options to apply when sending a message Options []AnswerOption }
Answer holds data of an Action's Answer: namely, its text and options to use when delivering it
type AnswerOption ¶
AnswerOption defines a function applied to Answers
type Answerer ¶
type Answerer func(m *IncomingMessage) *Answer
Answerer is what gets executed when an ActionDefinition is triggered
type IncomingMessage ¶
type IncomingMessage struct { // The original slack.Msg text stripped from the "<@Mention>" prefix, if applicable NormalizedText string slack.Msg }
IncomingMessage holds data for an incoming slack message. In addition to a slack.Msg, it also has a normalized text that is the original text stripped from the "<@Mention>" prefix when a message is addressed to a slackscot instance. Since commands are usually received either via direct message (without @Mention) or on channels with @Mention, the normalized text is useful there to allow plugins to have a single version to do Match and Answer against
type Matcher ¶
type Matcher func(m *IncomingMessage) bool
Matcher is the function that determines whether or not an action should be triggered based on a IncomingMessage (which includes a slack.Msg and a normalized text content. Note that a match doesn't guarantee that the action should actually respond with anything once invoked
type OutgoingMessage ¶
type OutgoingMessage struct { *slack.OutgoingMessage // contains filtered or unexported fields }
OutgoingMessage holds a plugin generated slack outgoing message along with the plugin identifier
type Plugin ¶
type Plugin struct { Name string Commands []ActionDefinition HearActions []ActionDefinition ScheduledActions []ScheduledActionDefinition // Those slackscot services are injected post-creation when slackscot is called. // A plugin shouldn't rely on those being available during creation UserInfoFinder UserInfoFinder Logger SLogger }
Plugin represents a plugin (its name, action definitions and slackscot injected services)
type RealTimeMessageSender ¶
type RealTimeMessageSender interface { // SendNewMessage is the function that sends a new message to the specified channelID SendNewMessage(message string, channelID string) (err error) // GetAPI is a function that returns the internal slack RTM GetAPI() *slack.RTM }
RealTimeMessageSender is implemented by any value that has the SendNewMessage and GetAPI method. The main purpose is a slight decoupling of the slack.RTM in order for plugins to be able to write tests more easily if all they do is send new messages on a channel. GetAPI leaks the slack.RTM for more advanced uses.
type SLogger ¶
type SLogger interface { Printf(format string, v ...interface{}) Debugf(format string, v ...interface{}) }
SLogger is the slackscot internal logging interface. The standard library logger implements this interface
type ScheduledAction ¶
type ScheduledAction func(sender RealTimeMessageSender)
ScheduledAction is what gets executed when a ScheduledActionDefinition is triggered (by its ScheduleDefinition)
type ScheduledActionDefinition ¶
type ScheduledActionDefinition struct { // Indicates whether the action should be omitted from the help message Hidden bool // Schedule definition determining when the action runs Schedule schedule.Definition // Help description for the scheduled action Description string // ScheduledAction is the function that is invoked when the schedule activates Action ScheduledAction }
ScheduledActionDefinition represents when a scheduled action is triggered as well as what it does and how
type SlackMessageID ¶
type SlackMessageID struct {
// contains filtered or unexported fields
}
SlackMessageID holds the elements that form a unique message identifier for slack. Technically, slack also uses the workspace id as the first part of that unique identifier but since an instance of slackscot only lives within a single workspace, that part is left out
type Slackscot ¶
type Slackscot struct {
// contains filtered or unexported fields
}
Slackscot represents what defines a Slack Mascot (mostly, a name and its plugins)
func NewSlackscot ¶
NewSlackscot creates a new slackscot from an array of plugins and a name
func (*Slackscot) RegisterPlugin ¶
RegisterPlugin registers a plugin with the Slackscot engine. This should be invoked prior to calling Run
type UserInfoFinder ¶
UserInfoFinder defines the interface for finding a slack user's info
func NewCachingUserInfoFinder ¶
func NewCachingUserInfoFinder(v *viper.Viper, loader UserInfoFinder, logger SLogger) (uf UserInfoFinder, err error)
NewCachingUserInfoFinder creates a new user info service with caching if enabled via userProfileCacheSizeKey. It requires an implementation of the interface that will do the actual loading when not in cache
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package config provides some utilities and structs to access configuration loaded via Viper
|
Package config provides some utilities and structs to access configuration loaded via Viper |
Package plugins provides a collection of example (and usable) plugins for instances of slackscot Package plugins provides a collection of example (and usable) plugins for instances of slackscot
|
Package plugins provides a collection of example (and usable) plugins for instances of slackscot Package plugins provides a collection of example (and usable) plugins for instances of slackscot |
Package schedule defines the interface for scheduling of slackscot actions
|
Package schedule defines the interface for scheduling of slackscot actions |
Package store provides a simple and convenient data store interface for plugins to persist data along with a default filed-based leveldb implementation.
|
Package store provides a simple and convenient data store interface for plugins to persist data along with a default filed-based leveldb implementation. |
Package test provides testing utilities for users of slackscot to help writing tests for their plugins and extensions
|
Package test provides testing utilities for users of slackscot to help writing tests for their plugins and extensions |
assertaction
Package assertaction provides testing functions for validation a plugin action's behavior
|
Package assertaction provides testing functions for validation a plugin action's behavior |
assertanswer
Package assertanswer provides testing functions to validate a plugin's answer
|
Package assertanswer provides testing functions to validate a plugin's answer |