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 AnswerInExistingThread(threadTimestamp string) func(sendOpts map[string]string)
- 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)
- func UploadInThreadOption(m *IncomingMessage) func(params *slack.FileUploadParameters)
- type ActionDefinition
- type ActionDefinitionWithID
- type Answer
- type AnswerOption
- type Answerer
- type DefaultFileUploader
- type EmojiReactor
- type FileUploader
- type IncomingMessage
- type Matcher
- type Option
- type OutgoingMessage
- type Plugin
- type RealTimeMessageSender
- type SLogger
- type ScheduledAction
- type ScheduledActionDefinition
- type SlackFileUploader
- type SlackMessageID
- type Slackscot
- type UploadOption
- type UserInfoFinder
Constants ¶
const ( // ThreadedReplyOpt is the name of the option indicating a threaded-reply answer ThreadedReplyOpt = "threadedReply" // BroadcastOpt is the name of the option indicating a broadcast answer BroadcastOpt = "broadcast" // ThreadTimestamp is the name of the option indicating the explicit timestamp of the thread to reply to ThreadTimestamp = "threadTimestamp" )
const (
// VERSION represents the current slackscot version
VERSION = "1.22.0"
)
GENERATED and MANAGED by giddyup (https://github.com/alexandre-normand/giddyup)
Variables ¶
This section is empty.
Functions ¶
func AnswerInExistingThread ¶
AnswerInExistingThread sets threaded replying with the existing thread timestamp
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 sets an answer to threading (and implicitly, broadcast) disabled
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
func UploadInThreadOption ¶
func UploadInThreadOption(m *IncomingMessage) func(params *slack.FileUploadParameters)
UploadInThreadOption sets the file upload thread timestamp to an existing thread timestamp if the incoming message triggering this is on an existing thread
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. To signal the absence of an answer, an action should return nil
type DefaultFileUploader ¶
type DefaultFileUploader struct {
// contains filtered or unexported fields
}
DefaultFileUploader holds a bare-bone SlackFileUploader
func NewFileUploader ¶
func NewFileUploader(slackFileUploader SlackFileUploader) (fileUploader *DefaultFileUploader)
NewFileUploader returns a new DefaultFileUploader wrapping a FileUploader
func (*DefaultFileUploader) UploadFile ¶
func (fileUploader *DefaultFileUploader) UploadFile(params slack.FileUploadParameters, options ...UploadOption) (file *slack.File, err error)
UploadFile uploads a file given the slack.FileUploadParameters with the UploadOptions applied to it
type EmojiReactor ¶
type EmojiReactor interface { // AddReaction adds an emoji reaction to a ItemRef using the emoji associated // with the given name (i.e. name should be thumbsup rather than :thumbsup:) AddReaction(name string, item slack.ItemRef) error }
EmojiReactor is implemented by any value that has the AddReaction method. The main purpose is a slight decoupling of the slack.Client in order for plugins to be able to write cleaner tests more easily
type FileUploader ¶
type FileUploader interface { // UploadFile uploads a file to slack. For more info in this API, check // https://godoc.org/github.com/nlopes/slack#Client.UploadFile UploadFile(params slack.FileUploadParameters, options ...UploadOption) (file *slack.File, err error) }
FileUploader is implemented by any value that has the UploadFile method. slack.Client *almost* implements it but requires a thin wrapping to do so to handle UploadOption there for added extensibility. The main purpose remains is a slight decoupling of the slack.Client in order for plugins to be able to write cleaner tests more easily.
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 EmojiReactor EmojiReactor FileUploader FileUploader RealTimeMsgSender RealTimeMessageSender }
Plugin represents a plugin (its name, action definitions and slackscot injected services)
type RealTimeMessageSender ¶
type RealTimeMessageSender interface { // NewOutgoingMessage is the function that sends a new message to the specified channelID NewOutgoingMessage(text string, channelID string, options ...slack.RTMsgOption) *slack.OutgoingMessage }
RealTimeMessageSender is implemented by any value that has the NewOutgoingMessage 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
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()
ScheduledAction is what gets executed when a ScheduledActionDefinition is triggered (by its ScheduleDefinition) In order to do anything, a plugin should define its scheduled actions functions with itself as a receiver so the function has access to the injected services
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 SlackFileUploader ¶
type SlackFileUploader interface { // UploadFile uploads a file to slack. For more info in this API, check // https://godoc.org/github.com/nlopes/slack#Client.UploadFile UploadFile(params slack.FileUploadParameters) (file *slack.File, err error) }
SlackFileUploader is implemented by any value that has the UploadFile method. slack.Client implements it. The main purpose remains is a slight decoupling of the slack.Client in order for plugins to be able to write cleaner tests more easily.
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 UploadOption ¶
type UploadOption func(params *slack.FileUploadParameters)
UploadOption defines an option on a FileUploadParameters (i.e. upload on thread)
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. |
datastoredb
Package datastoredb provides an implementation of github.com/alexandre-normand/slackscot/store's StringStorer interface backed by the Google Cloud Datastore.
|
Package datastoredb provides an implementation of github.com/alexandre-normand/slackscot/store's StringStorer interface backed by the Google Cloud Datastore. |
inmemorydb
Package inmemorydb provides an implementation of github.com/alexandre-normand/slackscot/store's StringStorer interface as an in-memory data store relying on a wrapping StringStorer for actual persistence.
|
Package inmemorydb provides an implementation of github.com/alexandre-normand/slackscot/store's StringStorer interface as an in-memory data store relying on a wrapping StringStorer for actual persistence. |
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 |
assertanswer
Package assertanswer provides testing functions to validate a plugin's answer
|
Package assertanswer provides testing functions to validate a plugin's answer |
assertplugin
Package assertplugin provides testing functions to validate a plugin's overall functionality.
|
Package assertplugin provides testing functions to validate a plugin's overall functionality. |
capture
Package capture provides dummy implementations of some of the plugin services that capture data fed into them in order to allow validation in tests
|
Package capture provides dummy implementations of some of the plugin services that capture data fed into them in order to allow validation in tests |