mmbot

package module
v0.0.0-...-f5ab1f4 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2019 License: MIT Imports: 12 Imported by: 0

README

mmbot

A chatbot framework specialized in Mattermost. mmbot uses Mattermost's webhooks (Incoming/Outgoing).

Note: mmbot is currently under heavy development and the API may change at any time.

Features

  • Pattern matching handler
  • HTTP route handler
  • Cron like scheduler
  • Interactive shell mode for development
  • (Optional) Predefined application base object (based on codegangsta/cli)
    • Daemonize option

Examples

See _example directory.

License

MIT

Author

Yuki (@yukithm)

Documentation

Overview

Package mmbot provides a bot framework for Mattermost.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	UserName      string // Bot account name
	BindAddress   string // Bind address to listen on
	Port          int    // Port to listen on
	DisableServer bool   // Disable HTTP server
}

Config for the robot.

func (*Config) Address

func (c *Config) Address() string

Address returns bind address and port string.

type Handler

type Handler interface {
	CanHandle(*message.InMessage) bool
	Handle(*message.InMessage) error
}

Handler is a message handler.

type HandlerAction

type HandlerAction func(*message.InMessage) error

HandlerAction is a function that process a message.

type Job

type Job struct {

	// NOTE: It is different from cron, there is also seconds field.
	Schedule string

	// Job function.
	Action JobFunc
}

Job is a scheduled task.

type JobFunc

type JobFunc func(*Robot)

JobFunc is job action function.

type PatternHandler

type PatternHandler struct {
	MessageType message.Type
	Pattern     *regexp.Regexp
	Action      HandlerAction
}

PatternHandler is a pattern matching handler.

func (PatternHandler) CanHandle

func (h PatternHandler) CanHandle(msg *message.InMessage) bool

CanHandle returns true if the handler can process the message.

func (PatternHandler) Handle

func (h PatternHandler) Handle(msg *message.InMessage) error

Handle processes a message.

type Robot

type Robot struct {
	Config   *Config
	Client   adapter.Adapter
	Handlers []Handler
	Routes   []Route
	Jobs     []Job

	Logger *log.Logger
	// contains filtered or unexported fields
}

Robot is a main controller of the bot.

func NewRobot

func NewRobot(config *Config, client adapter.Adapter, logger *log.Logger) *Robot

NewRobot creates new bot with specified adapter.

func (*Robot) RouteVars

func (r *Robot) RouteVars(req *http.Request) map[string]string

RouteVars returns routing parameter values for the request.

func (*Robot) Send

func (r *Robot) Send(msg *message.OutMessage) error

Send sends a message to the chat service.

func (*Robot) SenderName

func (r *Robot) SenderName() string

SenderName returns the bot name.

func (*Robot) Start

func (r *Robot) Start() chan error

Start starts the bot process.

func (*Robot) Stop

func (r *Robot) Stop()

Stop stops the bot.

type Route

type Route struct {
	// HTTP method (e.g. "GET", "POST").
	// All methods are allowed if empty.
	Methods []string

	// Route pattern (e.g. "/articles/{category}/{id:[0-9]+}")
	// Pattern can have variables that are defined by "{name}" or "{name:regexp}" format.
	// Variables can be retrieved calling Robot.RouteVars().
	Pattern string

	// Route action.
	Action RouteHandlerFunc
}

Route is a HTTP route.

func NewPingRoute

func NewPingRoute(pattern string) Route

NewPingRoute returns the route "ping".

func NewStatsRoute

func NewStatsRoute(pattern string) Route

NewStatsRoute returns the route for statistics of the process.

type RouteHandlerFunc

type RouteHandlerFunc func(*Robot, http.ResponseWriter, *http.Request)

RouteHandlerFunc is route action function.

Directories

Path Synopsis
Package adapter defines Adapter interface for mmbot.
Package adapter defines Adapter interface for mmbot.
Package app provides a base of the bot application.
Package app provides a base of the bot application.
Package message defines in/out message types.
Package message defines in/out message types.
Package mmhook implements an adapter that uses Mattermost Webhooks.
Package mmhook implements an adapter that uses Mattermost Webhooks.
Package shell implements an adapter that uses readline interactive shell for development.
Package shell implements an adapter that uses readline interactive shell for development.

Jump to

Keyboard shortcuts

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