Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

eure/bobo

Repository files navigation

bobo

GoDoc License: MIT 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,