bobo

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 16 Imported by: 4

README

bobo

GoDoc Release Build Status Co decov Coverage Go Report Card Code Climate BCH compliance Downloads

bobo is Slack Bot Kit with flexibility for Golang.

Install

$ go get -u github.com/eure/bobo

Build

$ make build

for Raspberry Pi

$ make build-arm6

Run

SLACK_RTM_TOKEN=xoxb-0000... ./bin/bobo

Environment variables

Name Description
SLACK_RTM_TOKEN Slack Bot Token
SLACK_BOT_TOKEN Slack Bot Token
SLACK_TOKEN Slack Bot Token
BOBO_DEBUG Flag for debug logging. Set boolean like value.

How to build your original bot

At first, create your own command.

import (
	"github.com/eure/bobo/command"
)

// EchoCommand is an example command.
// This command says same text.
var EchoCommand = command.BasicCommandTemplate{
	Help:           "reply same text",
	MentionCommand: "echo",
	GenerateFn: func(d command.CommandData) command.Command {
		c := command.Command{}
		if d.TextOther == "" {
			return c
		}

		text := fmt.Sprintf("<@%s> %s", d.SenderID, d.TextOther)
		task := command.NewReplyEngineTask(d.Engine, d.Channel, text)
		c.Add(task)
		return c
	},
}

Then create main.go and add the command,

package main

import (
	"github.com/eure/bobo"
	"github.com/eure/bobo/command"
	"github.com/eure/bobo/engine/slack"
	"github.com/eure/bobo/log"
)

// Entry Point
func main() {
	bobo.Run(bobo.RunOption{
		Engine: &slack.SlackEngine{},
		Logger: &log.StdLogger{
			IsDebug: bobo.IsDebug(),
		},
		CommandSet: command.NewCommandSet(
			// defalt example commands
			command.PingCommand,
			command.HelpCommand,
			// add your original commands
			EchoCommand,
		),
	})
}

And run it with Slack Token,

SLACK_RTM_TOKEN=xoxb-0000... go run ./main.go

Running with self-upgrading

bobo supports self-upgrading binary using jpillora/overseer.

Quick example

Set these option on RunOption ,

  • UseUpgrade = true
  • UpgradeFetcher = fetcher.Interface (see document)
package main

import (
	"time"

	"github.com/jpillora/overseer/fetcher"

	"github.com/eure/bobo"
	"github.com/eure/bobo/command"
	"github.com/eure/bobo/engine/slack"
	"github.com/eure/bobo/log"
)

// Entry Point
func main() {
	bobo.Run(bobo.RunOption{
		Engine: &slack.SlackEngine{},
		Logger: &log.StdLogger{
			IsDebug: bobo.IsDebug(),
		},
		CommandSet: command.NewCommandSet(),
		// Set upgrade options
		UseUpgrade: true,
		UpgradeFetcher: &fetcher.File{
			Path:     "/usr/local/bin/my-bobo-binary", // watch the path for updating
			Interval: 60 * time.Second,
		},
	})
}

Supported tasks

  • Slack
    • Reply message
    • Reply message as a thread
    • Add reaction
    • Upload file
  • GoogleHome

Experimental Commands

Credit

This project depends on these awesome libraries,

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDebug

func IsDebug() bool

IsDebug checks debug flag is true or not. debug flag is set via envvar "BOBO_DEBUG".

func Run

func Run(opt RunOption)

Run is entry-point of bot daemon.

Types

type Bot

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

Bot is core struct for a bot.

func NewBot

func NewBot() (*Bot, error)

NewBot returns initialized Bot.

func NewBotWithConfig

func NewBotWithConfig(conf Config) (*Bot, error)

NewBot returns initialized Bot from Config.

func (Bot) LogInfo

func (b Bot) LogInfo(typ, msg string, v ...interface{})

LogInfo logs info level log.

func (*Bot) Run

func (b *Bot) Run() (errCode int)

Run starts to run engine.

func (*Bot) SetStatus

func (b *Bot) SetStatus(f bool)

SetStatus sets active status. if it's false, bot does not react to any message from a user.

type Config

type Config struct {
	engine.Engine
	*command.CommandSet
	Logger     log.Logger
	HTTPClient *http.Client

	SlackToken         string
	MaxRunningCommands int
}

Config is a config struct for bot.

func (Config) GetCommandSet

func (c Config) GetCommandSet() *command.CommandSet

func (Config) GetLogger

func (c Config) GetLogger() log.Logger

func (Config) GetMaxRunningCommands

func (c Config) GetMaxRunningCommands() int

func (Config) GetSlackToken

func (c Config) GetSlackToken() string

type Fetcher added in v0.0.3

type Fetcher interface {
	fetcher.Interface
}

type MultiFetcher added in v0.0.3

type MultiFetcher struct {
	List           []fetcher.Interface
	GlobalInterval time.Duration
	// contains filtered or unexported fields
}

func (*MultiFetcher) Fetch added in v0.0.3

func (f *MultiFetcher) Fetch() (io.Reader, error)

func (*MultiFetcher) Init added in v0.0.3

func (f *MultiFetcher) Init() error

type RunOption

type RunOption struct {
	Engine             engine.Engine
	CommandSet         *command.CommandSet
	Logger             log.Logger
	HTTPClient         *http.Client
	MaxRunningCommands int
	NoPanic            bool

	// for self-upgrading
	UseUpgrade     bool
	UpgradeDebug   bool
	UpgradeFetcher Fetcher
}

RunOption contains options.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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