bot

package
v0.0.0-...-bb79c78 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2016 License: Apache-2.0 Imports: 14 Imported by: 0

README

Micro Bot

The micro bot is a bot that sits inside your microservices platform which you can interact with via Slack, HipChat, XMPP, etc. It mimics the functions of the CLI via messaging.

Supported Inputs

  • Slack
  • HipChat

Getting Started

Install Micro
go get github.com/micro/micro
Run with Slack
$ micro bot --inputs=slack --slack_token=SLACK_TOKEN
-
Run with HipChat
$ micro bot --inputs=hipchat --hipchat_username=XMPP_USER --hipchat_password=XMPP_PASSWORD
-

Use multiple inputs by specifying a comma separated list

$ micro bot --inputs=hipchat,slack --slack_token=SLACK_TOKEN --hipchat_username=XMPP_USER --hipchat_password=XMPP_PASSWORD
Help

In slack

$ micro help
deregister service [definition] - Deregisters a service
echo [text] - Returns the [text]
get service [name] - Returns a registered service
health [service] - Returns health of a service
hello - Returns a greeting
list services - Returns a list of registered services
ping - Returns pong
query [service] [method] [request] - Returns the response for a service query
register service [definition] - Registers a service
the three laws - Returns the three laws of robotics
time - Returns the server time

Adding new Commands

Commands are functions executed by the bot based on text based pattern matching.

Write a Command
import "github.com/micro/micro/bot/command"

func Ping() command.Command {
	usage := "ping"
	description := "Returns pong"

	return command.NewCommand("ping", usage, desc, func(args ...string) ([]byte, error) {
		return []byte("pong"), nil
	})
}
Register the command

Add the command to the Commands map with a pattern key that can be matched by golang/regexp.Match

import "github.com/micro/micro/bot/command"

func init() {
	command.Commands["^ping$"] = Ping()
}

Drop a link to your command into the top level dir

link_command.go:

import _ "path/to/import"

Adding new Inputs

Inputs are plugins for communication e.g Slack, HipChat, XMPP, IRC, SMTP, etc, etc.

New inputs can be added in the following way.

Write an Input

Write an input that satisfies the Input interface.

type Input interface {
	// Provide cli flags
	Flags() []cli.Flag
	// Initialise input using cli context
	Init(*cli.Context) error
	// Stream events from the input
	Stream() (Conn, error)
	// Start the input
	Start() error
	// Stop the input
	Stop() error
	// name of the input
	String() string
}
Register the input

Add the input to the Inputs map.

import "github.com/micro/micro/bot/input"

func init() {
	input.Inputs["name"] = MyInput
}

Drop a link to your input into the top level dir

link_input.go:

import _ "path/to/import"

Documentation

Overview

Package bot is a Hubot style bot that sits inside your microservices platform.

It can be interacted with via Slack, HipChat, XMPP, etc. It provides the features of the CLI via messaging. Additional commands can be added to automate common ops tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commands

func Commands() []cli.Command

func Plugins

func Plugins() []plugin.Plugin

Plugins lists the bot plugins

func Register

func Register(pl plugin.Plugin) error

Register registers an bot plugin

Types

This section is empty.

Directories

Path Synopsis
Package command is an interface for defining bot commands.
Package command is an interface for defining bot commands.
Package input is an interface for bot inputs.
Package input is an interface for bot inputs.

Jump to

Keyboard shortcuts

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