-- import "astuart.co/slot"
package slot gives some helpful abstractions over the nlopes/slack RTM integrations. Most use cases are intended to be made easier. The common bot response abstraction is the Responder. Many implementations will be created to assist in most of the common bot use cases.
func GetAction(ev *slack.MessageEvent) string
GetAction takes an event and returns either the empty string, or the first !action string in the message text.
func MaybeRespond(r *slack.RTM, ev *slack.MessageEvent, res Responder) error
MaybeRespond checks if a Responder is a MatchResponder and conditionally exits if there is no match.
type ActionMap map[string]Responder
ActionMap holds action words and responders, calling the appropriate responder when an !action message is received.
func (m ActionMap) Match(r *slack.RTM, ev *slack.MessageEvent) bool
Match implements MatchResponder for efficiency
func (m ActionMap) Respond(r *slack.RTM, ev *slack.MessageEvent) error
Respond implements Responder
type Bot struct {
Responders []Responder
}
A Bot handles a client
func (b *Bot) Handle(cli *slack.Client) error
Handle manages an RTM based on the configured Handlers
type BotMentionAction struct {
FollowingText string
Responder Responder
}
BotMentionAction executes a responder if the bot's name is @mentioned
func (b *BotMentionAction) Match(rtm *slack.RTM, ev *slack.MessageEvent) bool
Match implements MatchResponder
func (b *BotMentionAction) Respond(rtm *slack.RTM, ev *slack.MessageEvent) error
Respond implements Responder
type MatchResponder interface {
Responder
Match(*slack.RTM, *slack.MessageEvent) bool
}
A MatchResponder conditionally acts on a message
type RegexResponder struct {
Regexp *regexp.Regexp
Responder Responder
}
RegexResponder matches a regex against an incoming string and executes a response if a match occurred
func (r *RegexResponder) Match(rtm *slack.RTM, ev *slack.MessageEvent) bool
Match implements MatchResponder
func (r *RegexResponder) Respond(rtm *slack.RTM, ev *slack.MessageEvent) error
Respond implements Responder
type Responder interface {
Respond(*slack.RTM, *slack.MessageEvent) error
}
A Responder handles an event
type ResponderFunc func(*slack.RTM, *slack.MessageEvent) error
An ResponderFunc is a function that can respond to a slack event
func (f ResponderFunc) Respond(r *slack.RTM, ev *slack.MessageEvent) error
Respond implements Responder.
type StringFuncResponder func() string
StringFuncResponder always responds with the result of calling the function
func (s StringFuncResponder) Respond(r *slack.RTM, ev *slack.MessageEvent) error
Respond implements Responder
type TextResponder string
TextResponder always responds with a string
func (p TextResponder) Respond(r *slack.RTM, ev *slack.MessageEvent) error
Respond implements Responder