bobo

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: MIT Imports: 12 Imported by: 4

README

bobo

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

Slack Bot template 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

Supported tasks

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

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 RunOption

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

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