slacker: github.com/shomali11/slacker Index | Files

package slacker

import "github.com/shomali11/slacker"

Index

Package Files

command.go defaults.go request.go response.go slacker.go

type BotCommand Uses

type BotCommand interface {
    Usage() string
    Definition() *CommandDefinition

    Match(text string) (*proper.Properties, bool)
    Tokenize() []*commander.Token
    Execute(request Request, response ResponseWriter)
}

BotCommand interface

func NewBotCommand Uses

func NewBotCommand(usage string, definition *CommandDefinition) BotCommand

NewBotCommand creates a new bot command object

type ClientDefaults Uses

type ClientDefaults struct {
    Debug bool
}

ClientDefaults configuration

type ClientOption Uses

type ClientOption func(*ClientDefaults)

ClientOption an option for client values

func WithDebug Uses

func WithDebug(debug bool) ClientOption

WithDebug sets debug toggle

type CommandDefinition Uses

type CommandDefinition struct {
    Description       string
    Example           string
    AuthorizationFunc func(request Request) bool
    Handler           func(request Request, response ResponseWriter)
}

CommandDefinition structure contains definition of the bot command

type ReplyDefaults Uses

type ReplyDefaults struct {
    Attachments []slack.Attachment
    Blocks      []slack.Block
}

ReplyDefaults configuration

type ReplyOption Uses

type ReplyOption func(*ReplyDefaults)

ReplyOption an option for reply values

func WithAttachments Uses

func WithAttachments(attachments []slack.Attachment) ReplyOption

WithAttachments sets message attachments

func WithBlocks Uses

func WithBlocks(blocks []slack.Block) ReplyOption

WithBlocks sets message blocks

type Request Uses

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
    Context() context.Context
    Event() *slack.MessageEvent
    Properties() *proper.Properties
}

Request interface that contains the Event received and parameters

func NewRequest Uses

func NewRequest(ctx context.Context, event *slack.MessageEvent, properties *proper.Properties) Request

NewRequest creates a new Request structure

type ResponseWriter Uses

type ResponseWriter interface {
    Reply(text string, options ...ReplyOption)
    ReportError(err error)
    Typing()
    RTM() *slack.RTM
    Client() *slack.Client
}

A ResponseWriter interface is used to respond to an event

func NewResponse Uses

func NewResponse(channel string, client *slack.Client, rtm *slack.RTM) ResponseWriter

NewResponse creates a new response structure

type Slacker Uses

type Slacker struct {
    // contains filtered or unexported fields
}

Slacker contains the Slack API, botCommands, and handlers

func NewClient Uses

func NewClient(token string, options ...ClientOption) *Slacker

NewClient creates a new client using the Slack API

func (*Slacker) BotCommands Uses

func (s *Slacker) BotCommands() []BotCommand

BotCommands returns Bot Commands

func (*Slacker) Client Uses

func (s *Slacker) Client() *slack.Client

Client returns the internal slack.Client of Slacker struct

func (*Slacker) Command Uses

func (s *Slacker) Command(usage string, definition *CommandDefinition)

Command define a new command and append it to the list of existing commands

func (*Slacker) CustomRequest Uses

func (s *Slacker) CustomRequest(requestConstructor func(ctx context.Context, event *slack.MessageEvent, properties *proper.Properties) Request)

CustomRequest creates a new request

func (*Slacker) CustomResponse Uses

func (s *Slacker) CustomResponse(responseConstructor func(channel string, client *slack.Client, rtm *slack.RTM) ResponseWriter)

CustomResponse creates a new response writer

func (*Slacker) DefaultCommand Uses

func (s *Slacker) DefaultCommand(defaultMessageHandler func(request Request, response ResponseWriter))

DefaultCommand handle messages when none of the commands are matched

func (*Slacker) DefaultEvent Uses

func (s *Slacker) DefaultEvent(defaultEventHandler func(interface{}))

DefaultEvent handle events when an unknown event is seen

func (*Slacker) Err Uses

func (s *Slacker) Err(errorHandler func(err string))

Err handle when errors are encountered

func (*Slacker) GetUserInfo Uses

func (s *Slacker) GetUserInfo(user string) (*slack.User, error)

GetUserInfo retrieve complete user information

func (*Slacker) Help Uses

func (s *Slacker) Help(definition *CommandDefinition)

Help handle the help message, it will use the default if not set

func (*Slacker) Init Uses

func (s *Slacker) Init(initHandler func())

Init handle the event when the bot is first connected

func (*Slacker) Listen Uses

func (s *Slacker) Listen(ctx context.Context) error

Listen receives events from Slack and each is handled as needed

func (*Slacker) RTM Uses

func (s *Slacker) RTM() *slack.RTM

RTM returns returns the internal slack.RTM of Slacker struct

func (*Slacker) UnAuthorizedError Uses

func (s *Slacker) UnAuthorizedError(unAuthorizedError error)

UnAuthorizedError error message

Package slacker imports 7 packages (graph) and is imported by 7 packages. Updated 2019-06-08. Refresh now. Tools for package owners.