Documentation
¶
Index ¶
- type ActionCallback
- type BotCommand
- type BotContext
- type ClientDefaults
- type ClientOption
- type CommandDefinition
- type CommandEvent
- type MessageEvent
- type ReplyDefaults
- type ReplyOption
- type ReportErrorDefaults
- type ReportErrorOption
- type Request
- type ResponseWriter
- type Slacker
- func (s *Slacker) BotCommands() []BotCommand
- func (s *Slacker) Client() *slack.Client
- func (s *Slacker) Command(usage string, definition *CommandDefinition)
- func (s *Slacker) CommandEvents() <-chan *CommandEvent
- func (s *Slacker) CustomRequest(...)
- func (s *Slacker) CustomResponse(responseConstructor func(botCtx BotContext) ResponseWriter)
- func (s *Slacker) DefaultCommand(...)
- func (s *Slacker) DefaultEvent(defaultEventHandler func(interface{}))
- func (s *Slacker) Err(errorHandler func(err string))
- func (s *Slacker) GetUserInfo(user string) (*slack.User, error)
- func (s *Slacker) Help(definition *CommandDefinition)
- func (s *Slacker) Init(initHandler func())
- func (s *Slacker) Listen(ctx context.Context) error
- func (s *Slacker) SetCallback(cb ActionCallback)
- func (s *Slacker) SocketMode() *socketmode.Client
- func (s *Slacker) UnAuthorizedError(unAuthorizedError error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionCallback ¶
type ActionCallback func(ev slack.InteractionCallback)
type BotCommand ¶
type BotCommand interface {
Usage() string
Definition() *CommandDefinition
Match(text string) (*proper.Properties, bool)
Tokenize() []*commander.Token
Execute(botCtx BotContext, request Request, response ResponseWriter)
}
BotCommand interface
func NewBotCommand ¶
func NewBotCommand(usage string, definition *CommandDefinition) BotCommand
NewBotCommand creates a new bot command object
type BotContext ¶
type BotContext interface {
Context() context.Context
Event() *MessageEvent
SocketMode() *socketmode.Client
Client() *slack.Client
}
A BotContext interface is used to respond to an event
func NewBotContext ¶
func NewBotContext(ctx context.Context, client *slack.Client, socketmode *socketmode.Client, evt *MessageEvent) BotContext
NewBotContext creates a new bot context
type ClientOption ¶
type ClientOption func(*ClientDefaults)
ClientOption an option for client values
type CommandDefinition ¶
type CommandDefinition struct {
Description string
Example string
AuthorizationFunc func(botCtx BotContext, request Request) bool
Handler func(botCtx BotContext, request Request, response ResponseWriter)
}
CommandDefinition structure contains definition of the bot command
type CommandEvent ¶
type CommandEvent struct {
Timestamp time.Time
Command string
Parameters *proper.Properties
Event *MessageEvent
}
CommandEvent is an event to capture executed commands
func NewCommandEvent ¶
func NewCommandEvent(command string, parameters *proper.Properties, event *MessageEvent) *CommandEvent
NewCommandEvent creates a new command event
type MessageEvent ¶
type MessageEvent struct {
// Channel ID where the message was sent
Channel string
// User ID of the sender
User string
// Text is the unalterted text of the message, as returned by Slack
Text string
// TimeStamp is the message timestamp
TimeStamp string
// ThreadTimeStamp is the message thread timestamp.
ThreadTimeStamp string
// Data is the raw event data returned from slack. Using Type, you can assert
// this into a slackevents *Event struct.
Data interface{}
// Type is the type of the event, as returned by Slack. For instance,
// `app_mention` or `message`
Type string
// BotID holds the Slack User ID for our bot
BotID string
}
MessageEvent contains details common to message based events, including the raw event as returned from Slack along with the corresponding event type. The struct should be kept minimal and only include data that is commonly used to prevent freqeuent type assertions when evaluating the event.
func (*MessageEvent) IsBot ¶
func (e *MessageEvent) IsBot() bool
IsBot indicates if the message was sent by a bot
func (*MessageEvent) IsThread ¶
func (e *MessageEvent) IsThread() bool
IsThread indicates if a message event took place in a thread.
type ReplyDefaults ¶
type ReplyDefaults struct {
Attachments []slack.Attachment
Blocks []slack.Block
ThreadResponse bool
}
ReplyDefaults configuration
func NewReplyDefaults ¶
func NewReplyDefaults(options ...ReplyOption) *ReplyDefaults
NewReplyDefaults builds our ReplyDefaults from zero or more ReplyOption.
type ReplyOption ¶
type ReplyOption func(*ReplyDefaults)
ReplyOption an option for reply values
func WithAttachments ¶
func WithAttachments(attachments []slack.Attachment) ReplyOption
WithAttachments sets message attachments
func WithThreadReply ¶
func WithThreadReply(useThread bool) ReplyOption
WithThreadReply specifies the reply to be inside a thread of the original message
type ReportErrorDefaults ¶
type ReportErrorDefaults struct {
ThreadResponse bool
}
ReportErrorDefaults configuration
func NewReportErrorDefaults ¶
func NewReportErrorDefaults(options ...ReportErrorOption) *ReportErrorDefaults
NewReportErrorDefaults builds our ReportErrorDefaults from zero or more ReportErrorOption.
type ReportErrorOption ¶
type ReportErrorOption func(*ReportErrorDefaults)
ReportErrorOption an option for report error values
func WithThreadError ¶
func WithThreadError(useThread bool) ReportErrorOption
WithThreadError specifies the reply to be inside a thread of the original message
type Request ¶
type Request interface {
Param(key string) string
StringParam(key string, defaultValue string) string
BooleanParam(key string, defaultValue bool) bool
IntegerParam(key string, defaultValue int) int
FloatParam(key string, defaultValue float64) float64
Properties() *proper.Properties
}
Request interface that contains the Event received and parameters
func NewRequest ¶
func NewRequest(botCtx BotContext, properties *proper.Properties) Request
NewRequest creates a new Request structure
type ResponseWriter ¶
type ResponseWriter interface {
Reply(text string, options ...ReplyOption) error
ReportError(err error, options ...ReportErrorOption)
}
A ResponseWriter interface is used to respond to an event
func NewResponse ¶
func NewResponse(botCtx BotContext) ResponseWriter
NewResponse creates a new response structure
type Slacker ¶
type Slacker struct {
// contains filtered or unexported fields
}
Slacker contains the Slack API, botCommands, and handlers
func NewClient ¶
func NewClient(botToken, appToken string, options ...ClientOption) *Slacker
NewClient creates a new client using the Slack API
func (*Slacker) BotCommands ¶
func (s *Slacker) BotCommands() []BotCommand
BotCommands returns Bot Commands
func (*Slacker) Command ¶
func (s *Slacker) Command(usage string, definition *CommandDefinition)
Command define a new command and append it to the list of existing commands
func (*Slacker) CommandEvents ¶
func (s *Slacker) CommandEvents() <-chan *CommandEvent
CommandEvents returns read only command events channel
func (*Slacker) CustomRequest ¶
func (s *Slacker) CustomRequest(requestConstructor func(botCtx BotContext, properties *proper.Properties) Request)
CustomRequest creates a new request
func (*Slacker) CustomResponse ¶
func (s *Slacker) CustomResponse(responseConstructor func(botCtx BotContext) ResponseWriter)
CustomResponse creates a new response writer
func (*Slacker) DefaultCommand ¶
func (s *Slacker) DefaultCommand(defaultMessageHandler func(botCtx BotContext, request Request, response ResponseWriter))
DefaultCommand handle messages when none of the commands are matched
func (*Slacker) DefaultEvent ¶
func (s *Slacker) DefaultEvent(defaultEventHandler func(interface{}))
DefaultEvent handle events when an unknown event is seen
func (*Slacker) GetUserInfo ¶
GetUserInfo retrieve complete user information
func (*Slacker) Help ¶
func (s *Slacker) Help(definition *CommandDefinition)
Help handle the help message, it will use the default if not set
func (*Slacker) Init ¶
func (s *Slacker) Init(initHandler func())
Init handle the event when the bot is first connected
func (*Slacker) SetCallback ¶
func (s *Slacker) SetCallback(cb ActionCallback)
func (*Slacker) SocketMode ¶
func (s *Slacker) SocketMode() *socketmode.Client
SocketMode returns the internal socketmode.Client of Slacker struct
func (*Slacker) UnAuthorizedError ¶
UnAuthorizedError error message