rocket

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2019 License: BSD-3-Clause Imports: 13 Imported by: 0

README

Joe Bot - Rocket.Chat Adapter

Connecting joe with the Rocket.Chat chat application. https://github.com/go-joe/joe


This repository contains a module for the Joe Bot library.

THIS SOFTWARE IS STILL IN ALPHA AND THERE ARE NO GUARANTEES REGARDING API STABILITY YET.

Getting Started

This library is packaged using the new Go modules. You can get it via:

go get github.com/dwmunster/rocket-adapter

Example usage

In order to connect your bot to rocket.chat you can simply pass it as module when creating a new bot:

package main

import (
	"os"

	"github.com/dwmunster/rocket-adapter"
	"github.com/go-joe/joe"
)

func main() {
	b := joe.New("example-bot",
		rocket.Adapter(
			os.Getenv("ROCKET_EMAIL"),
			os.Getenv("ROCKET_PASSWORD"),
			os.Getenv("ROCKET_URL"),
			os.Getenv("ROCKET_USER"),
		),
	)
	b.Respond("ping", Pong)

	err := b.Run()
	if err != nil {
		b.Logger.Fatal(err.Error())
	}
}

func Pong(msg joe.Message) error {
	return msg.RespondE("PONG")
}

So far the adapter will emit the following events to the robot brain:

  • joe.ReceiveMessageEvent

Built With

Contributing

The current implementation is rather minimal and there are many more features that could be implemented on the rocket.chat adapter so you are highly encouraged to contribute. If you want to hack on this repository, please read the short CONTRIBUTING.md guide first.

Versioning

We use SemVer for versioning. For the versions available, see the [tags on this repository][tags.

Authors

  • Friedrich Große - Initial work on Slack adapter - fgrosse
  • Drayton Munster - Conversion to Rocket.Chat API - dwmunster

See also the list of contributors who participated in this project.

License

This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.

Documentation

Overview

Package rocket implements a rocket.chat adapter for the joe bot library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapter

func Adapter(email, password, serverURL, botUser string, opts ...Option) joe.Module

Adapter returns a new rocket.chat Adapter as joe.Module.

func NewRandID

func NewRandID() *randID

NewRandID generates a new randID and initializes it with the current time.

Types

type BotAdapter

type BotAdapter struct {
	// contains filtered or unexported fields
}

BotAdapter implements a joe.Adapter that reads and writes messages to and from Rocket.Chat.

func NewAdapter

func NewAdapter(ctx context.Context, conf Config) (*BotAdapter, error)

NewAdapter creates a new *BotAdapter that connects to Rocket.Chat. Note that you will usually configure the slack adapter as joe.Module (i.e. using the Adapter function of this package).

func (*BotAdapter) Close

func (a *BotAdapter) Close() error

Close disconnects the adapter from the rocket.chat API.

func (*BotAdapter) RegisterAt

func (a *BotAdapter) RegisterAt(brain *joe.Brain)

RegisterAt implements the joe.Adapter interface by emitting the slack API events to the given brain.

func (*BotAdapter) Send

func (a *BotAdapter) Send(text, channelID string) error

Send implements joe.Adapter by sending all received text messages to the given rocket.chat channel ID.

type Config

type Config struct {
	Email     string
	Password  string
	ServerURL *url.URL

	Name   string
	Debug  bool
	Logger *zap.Logger
	// contains filtered or unexported fields
}

Config contains the configuration of a BotAdapter.

type IDGen

type IDGen interface {
	Seed(int64)
	ID() string
}

IDGen represents the capacity to generate unique ID for each message, as rocket.chat requires. ksuids would be great, but that would be an external dependency.

type Option

type Option func(*Config) error

An Option is used to configure the slack adapter.

func WithDebug

func WithDebug(debug bool) Option

WithDebug enables debug messages of the slack client.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger can be used to inject a different logger for the slack adapater.

Jump to

Keyboard shortcuts

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