slackbot

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package slackbot provides a wrapper around official slack library to simplify building a slack bot. bot uses the slack RTM API. Refer https://api.slack.com/bot-users#creating-bot-user

Index

Constants

This section is empty.

Variables

View Source
var ErrNotMatch = errors.New("no match")

ErrNotMatch can be returned by MessageHandler to indicate that handler cannot process the message event.

Functions

func AddressUser

func AddressUser(userID string, userName string) string

AddressUser creates the escape sequence for marking a user in a message.

Types

type Bot

type Bot struct {

	// configurations
	Handler      Handler
	GroupSupport bool
	// contains filtered or unexported fields
}

Bot represents an RTM connection based Slack Bot instance.

func New

func New(token string, opts ...Option) *Bot

New initializes a Slack Bot instance using RTM API. New does not connect to slack API until Listen() is invoked.

func (*Bot) Client

func (bot *Bot) Client() *slack.Client

Client returns the underlying Slack client instance.

func (*Bot) Listen

func (bot *Bot) Listen(ctx context.Context) error

Listen connects to slack and starts the RTM event connection. Blocks until an unrecoverable error occurs.

func (*Bot) Self

func (bot *Bot) Self() slack.UserDetails

Self returns details about the currently connected bot user.

func (*Bot) SendMessage

func (bot *Bot) SendMessage(text string, responseTo slack.Msg) error

SendMessage sends the text as message to the given channel on behalf of the bot instance.

type Handler

type Handler interface {
	Handle(bot *Bot, msg slack.MessageEvent, from slack.User) error
}

Handler implementation can be set to the bot to handle a message event.

type LuaHandler

type LuaHandler struct {
	InitFile    string
	HandlerFunc string
	// contains filtered or unexported fields
}

LuaHandler implements the Bot handler using a lua scripting layer.

func (*LuaHandler) Handle

func (h *LuaHandler) Handle(bot *Bot, msg slack.MessageEvent, from slack.User) error

type Option

type Option func(bot *Bot)

Option can be provided with New() to customise the bot instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL