rocketbot

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2018 License: MIT Imports: 9 Imported by: 0

README

rocketbot

rocketbot is a chat bot framework for Rocket.Chat.

  • Support message handler.
  • Support cron style job.
  • Including feeds (RSS, Atom, etc) job.
  • Including example bot implementation in _example/mybot.

Using Docker (for example bot)

# copy and edit configuration files
cp ./_example/mybot/config/mybot.toml.example ./_example/mybot/config/mybot.toml
cp ./_example/mybot/config/feeds.toml.example ./_example/mybot/config/feeds.toml
$EDITOR ./_example/mybot/config/mybot.toml
$EDITOR ./_example/mybot/config/feeds.toml

# build and run example bot
docker-compose build
docker-compose run mybot

Build your own bot

  1. git init /path/to/your_bot
  2. Copy _example/mybot/* into your repository.
  3. Edit handlers/*.go and jobs/*.go
    Or customize all of codes.

License

MIT

Author

yukithm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Debug bool
	// contains filtered or unexported fields
}

func NewClient

func NewClient(serverURL string, connectionLog bool, debug bool) (*Client, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) GetChannelId

func (c *Client) GetChannelId(name string) (string, error)

func (*Client) GetChannelInfo

func (c *Client) GetChannelInfo(roomID string) (*models.Channel, error)

func (*Client) JoinChannel

func (c *Client) JoinChannel(roomID string) error

func (*Client) Login

func (c *Client) Login(credentials *models.UserCredentials) (*models.User, error)

func (*Client) Logout

func (c *Client) Logout() error

func (*Client) PostMessage

func (c *Client) PostMessage(msg *models.PostMessage) (*rest.MessageResponse, error)

func (*Client) RealtimeClient

func (c *Client) RealtimeClient() *realtime.Client

func (*Client) RestClient

func (c *Client) RestClient() *rest.Client

func (*Client) SendMessage

func (c *Client) SendMessage(channel *models.Channel, text string) (*models.Message, error)

func (*Client) SubscribeToMessageStream

func (c *Client) SubscribeToMessageStream(channel *models.Channel, msgCh chan models.Message) error

type CronJob

type CronJob interface {
	// JobSchedule returns schedule pattern.
	// See https://godoc.org/github.com/robfig/cron
	// NOTE: It is different from cron, there is also seconds field.
	JobSchedule() string

	// Run job action.
	Run(*Robot) error
}

CronJob is a scheduled task.

type CronJobFunc

type CronJobFunc func(*Robot) error

JobFunc is job action function.

type Handler

type Handler interface {
	Acceptable(*models.Message, *models.Channel) bool
	Run(*Robot, *models.Message) error
}

Handler is a message handler.

type HandlerFilter

type HandlerFilter struct {
	Channel  *regexp.Regexp
	UserName *regexp.Regexp
	Message  *regexp.Regexp
}

func (*HandlerFilter) Match

func (f *HandlerFilter) Match(msg *models.Message, channel *models.Channel) bool

func (*HandlerFilter) MatchChannel

func (f *HandlerFilter) MatchChannel(channel *models.Channel) bool

func (*HandlerFilter) MatchMessage

func (f *HandlerFilter) MatchMessage(msg *models.Message) bool

func (*HandlerFilter) MatchUser

func (f *HandlerFilter) MatchUser(user *models.User) bool

type HandlerFunc

type HandlerFunc func(*Robot, *models.Message) error

type Robot

type Robot struct {
	ServerURL      string
	Credentials    *models.UserCredentials
	DefaultChannel string
	ErrorChannel   string
	CronJobs       []CronJob
	Handlers       []Handler
	OnStart        func(*Robot) error
	OnStop         func(*Robot) error
	Logger         *log.Logger
	ConnectionLog  bool
	Debug          bool
	// contains filtered or unexported fields
}

func (*Robot) Client

func (bot *Robot) Client() *Client

func (*Robot) GetChannelByName

func (bot *Robot) GetChannelByName(name string) (*models.Channel, error)

func (*Robot) GetRoomIDByName

func (bot *Robot) GetRoomIDByName(name string) (*models.Channel, error)

func (*Robot) PostMessage

func (bot *Robot) PostMessage(msg *models.PostMessage) (*rest.MessageResponse, error)

func (*Robot) Reply

func (bot *Robot) Reply(src *models.Message, text string) (*models.Message, error)

func (*Robot) SendMessage

func (bot *Robot) SendMessage(channel *models.Channel, text string) (*models.Message, error)

func (*Robot) SendText

func (bot *Robot) SendText(channelName string, text string) (*rest.MessageResponse, error)

func (*Robot) Start

func (bot *Robot) Start() error

func (*Robot) Stop

func (bot *Robot) Stop()

type SimpleCronJob

type SimpleCronJob struct {
	// Schedule pattern.
	// See https://godoc.org/github.com/robfig/cron
	// NOTE: It is different from cron, there is also seconds field.
	Schedule string

	// Job function.
	Action CronJobFunc
}

SimpleCronJob is a scheduled task.

func (*SimpleCronJob) JobSchedule

func (j *SimpleCronJob) JobSchedule() string

func (*SimpleCronJob) Run

func (j *SimpleCronJob) Run(bot *Robot) error

type SimpleHandler

type SimpleHandler struct {
	Filter *HandlerFilter
	Action HandlerFunc
}

func (*SimpleHandler) Acceptable

func (h *SimpleHandler) Acceptable(msg *models.Message, channel *models.Channel) bool

func (*SimpleHandler) Run

func (h *SimpleHandler) Run(bot *Robot, msg *models.Message) error

Directories

Path Synopsis
_example
mybot command

Jump to

Keyboard shortcuts

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