slackbot

package module
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2017 License: MIT Imports: 8 Imported by: 0

README

slackbot Coverage Status

wercker status

Plugin extension a simple slack bot for golang.

Description

plugins.BotMessagePluginを実装して、slackbot.BotContextAddPluginするだけでプラグイン追加できます。

Bot側の実装は、こちらを参考にしてください。

Usage

package main

import (
	"flag"
	"net/http"
	"os"

	"github.com/kyokomi/slackbot"
	"github.com/kyokomi/slackbot/plugins/echo"
)

func main() {
	var token string
	flag.StringVar(&token, "token", os.Getenv("SLACK_BOT_TOKEN"), "SlackのBotToken")
	flag.Parse()

	bot, err := slackbot.NewBotContext(token)
	if err != nil {
		panic(err)
	}
	bot.AddPlugin("echo", echo.NewPlugin())

	bot.WebSocketRTM()

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("OK"))
	})
	http.ListenAndServe(":8000", nil)
}

Plugin Example

package echo

import (
	"github.com/kyokomi/slackbot/plugins"
)

type plugin struct {
}

func NewPlugin() plugins.BotMessagePlugin {
	return &plugin{}
}

func (p *plugin) CheckMessage(_ plugins.BotEvent, message string) (bool, string) {
	return true, message
}

func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
	event.Reply(message)
	return true // next ok
}

func (p *plugin) Help() string {
	return `echo:
	all message echo
	`
}

var _ plugins.BotMessagePlugin = (*plugin)(nil)

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotContext

type BotContext interface {
	PluginManager() plugins.PluginManager
	AddPlugin(key interface{}, val plugins.BotMessagePlugin)
	WebSocketRTM()
	Run(connectedFunc func(event plugins.BotEvent))

	// plugins.MessageSender
	SendMessage(message, channel string)
}

func NewBotContext

func NewBotContext(token string) (BotContext, error)

type Context

type Context struct {
	Plugins plugins.PluginManager
	Client  *slack.Client
	RTM     *slack.RTM
}

func NewBotContextNotSysstd

func NewBotContextNotSysstd(token string) (*Context, error)

func NewContext

func NewContext(token string) (*Context, error)

func (*Context) AddPlugin

func (ctx *Context) AddPlugin(key interface{}, val plugins.BotMessagePlugin)

func (*Context) PluginManager

func (b *Context) PluginManager() plugins.PluginManager

func (*Context) Run

func (ctx *Context) Run(connectedFunc func(event plugins.BotEvent))

func (*Context) SendMessage

func (ctx *Context) SendMessage(message, channel string)

func (*Context) WebSocketRTM

func (ctx *Context) WebSocketRTM()

WebSocketRTM is Deprecated

type Repository

type Repository interface {
	Load(key string) (string, error)
	LoadList(key string) ([]string, error)
	Save(key string, value string) error
	SaveList(key string, values []string) error
	Close() error
}

Repository is slackbot common repository interface

func NewOnMemoryRepository

func NewOnMemoryRepository() Repository

NewOnMemoryRepository create on memory repository

func NewRedisRepository

func NewRedisRepository(addr, password string, db int64) Repository

NewRedisRepository create on redis repository

Jump to

Keyboard shortcuts

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