slackbot

package
v0.0.0-...-49cf9ae Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2015 License: MIT, MIT Imports: 6 Imported by: 0

README

slackbot

Circle CI Coverage 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 struct {
	Plugins plugins.PluginManager
	Client  *slack.Client
	RTM     *slack.RTM
}

func NewBotContext

func NewBotContext(token string) (*BotContext, error)

func NewBotContextNotSysstd

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

func (*BotContext) AddPlugin

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

func (*BotContext) SendMessage

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

func (*BotContext) WebSocketRTM

func (ctx *BotContext) WebSocketRTM()

type OnMemoryRepository

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

func (*OnMemoryRepository) Close

func (r *OnMemoryRepository) Close() error

func (*OnMemoryRepository) Load

func (r *OnMemoryRepository) Load(key string) (string, error)

func (*OnMemoryRepository) Save

func (r *OnMemoryRepository) Save(key string, value string) error

type Repository

type Repository interface {
	Load(key string) (string, error)
	Save(key string, value string) error
	Close() error
}

func NewOnMemoryRepository

func NewOnMemoryRepository() Repository

Jump to

Keyboard shortcuts

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