Documentation
¶
Index ¶
- type BotCommand
- type BotContext
- type BotInteractionMode
- 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) BotCommand(usage string, definition *CommandDefinition)
- 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) Interactive(...)
- func (s *Slacker) Listen(ctx context.Context) error
- func (s *Slacker) SocketMode() *socketmode.Client
- func (s *Slacker) UnAuthorizedError(errUnauthorized error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BotCommand ¶
type BotCommand interface { Usage() string Definition() *CommandDefinition Match(req string) (allot.MatchInterface, error) Matches(text string) bool Tokenize() []*allot.Token Parameters() []allot.Parameter 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 BotInteractionMode ¶
type BotInteractionMode int
BotInteractionMode instruct the bot on how to handle incoming events that originated from a bot.
const ( // BotInteractionModeIgnoreAll instructs our bot to ignore any activity coming // from other bots, including our self. BotInteractionModeIgnoreAll BotInteractionMode = iota // BotInteractionModeIgnoreApp will ignore any events that originate from a // bot that is associated with the same App (ie. share the same App ID) as // this bot. OAuth scope `user:read` is required for this mode. BotInteractionModeIgnoreApp // BotInteractionModeIgnoreNone will not ignore any bots, including our self. // This can lead to bots "talking" to each other so care must be taken when // selecting this option. BotInteractionModeIgnoreNone )
type ClientDefaults ¶
type ClientDefaults struct { Debug bool BotMode BotInteractionMode }
ClientDefaults configuration
type ClientOption ¶
type ClientOption func(*ClientDefaults)
ClientOption an option for client values
func WithBotInteractionMode ¶
func WithBotInteractionMode(mode BotInteractionMode) ClientOption
WithBotInteractionMode instructs Slacker on how to handle message events coming from a bot.
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 []allot.Parameter Event *MessageEvent }
CommandEvent is an event to capture executed commands
func NewCommandEvent ¶
func NewCommandEvent(command string, parameters []allot.Parameter, 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 of the bot that sent this message. If a bot did not send this // message, this will be an empty string. 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 IntegerParam(key string, defaultValue int) int Parameters() []allot.Parameter }
Request interface that contains the Event received and parameters
func NewRequest ¶
func NewRequest(botCtx BotContext, parameters []allot.Parameter, match allot.MatchInterface) 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) BotCommand ¶ added in v1.0.2
func (s *Slacker) BotCommand(usage string, definition *CommandDefinition)
BotCommand define a new bot command and append it to the list of existing commands
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, parameters []allot.Parameter, match allot.MatchInterface) 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) Interactive ¶
func (s *Slacker) Interactive(interactiveEventHandler func(*Slacker, *socketmode.Event, *slack.InteractionCallback))
Interactive assigns an interactive event handler
func (*Slacker) SocketMode ¶
func (s *Slacker) SocketMode() *socketmode.Client
SocketMode returns the internal socketmode.Client of Slacker struct
func (*Slacker) UnAuthorizedError ¶
UnAuthorizedError error message