mattermost

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Joe Bot - Mattermost Adapter

Connecting joe with the Mattermost 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/go-joe-mattermost

Example usage

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

package main

import (
	"os"

	"github.com/dwmunster/go-joe-mattermost"
	"github.com/go-joe/joe"
)

func main() {
	b := joe.New("example-bot",
		mattermost.Adapter(
			os.Getenv("MM_EMAIL"),
			os.Getenv("MM_PASSWORD"),
			os.Getenv("MM_URL"),
		),
	)
	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 mattermost 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.

Authors

  • Friedrich Große - Initial work on Slack adapter - fgrosse
  • Drayton Munster - Conversion to Mattermost 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 mattermost implements a mattermost adapter for the joe bot library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapter

func Adapter(token, serverURL, teamName string, opts ...Option) joe.Module

Adapter returns a new mattermost Adapter as joe.Module.

Types

type BotAdapter

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

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

func NewAdapter

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

NewAdapter creates a new *BotAdapter that connects to mattermost. Note that you will usually configure the mattermost 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 mattermost API.

func (*BotAdapter) React added in v0.2.0

func (a *BotAdapter) React(r reactions.Reaction, msg joe.Message) error

// newMessage creates basic message with an ID, a RoomID, and a Msg // Takes channel and text

func (a *BotAdapter) newMessage(channel *models.Channel, text string) *models.Message {
	return &models.Message{
		ID:     a.idgen.ID(),
		RoomID: channel.ID,
		Msg:    text,
		User:   a.user,
	}
}

func (*BotAdapter) RegisterAt

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

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

func (*BotAdapter) Send

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

Send implements joe.Adapter by sending all received text messages to the given mattermost channel name.

type Config

type Config struct {
	Token     string
	Team      string
	ServerURL *url.URL
	Name      string
	Logger    *zap.Logger
}

Config contains the configuration of a BotAdapter.

type Option

type Option func(*Config) error

An Option is used to configure the mattermost adapter.

func WithLogger

func WithLogger(logger *zap.Logger) Option

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

Jump to

Keyboard shortcuts

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