mirror of
https://github.com/cwinfo/matterbridge.git
synced 2025-06-27 22:39:25 +00:00
Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
a64deb1238 | |||
f914695801 | |||
304dc2e25f | |||
fd74dca175 | |||
c7ace91bf6 | |||
9f07a2cfd5 | |||
0dc5e042d2 | |||
f0a5d2396f | |||
bdac03f725 | |||
c1f80383f7 |
29
README.md
29
README.md
@ -3,12 +3,12 @@
|
|||||||
Simple bridge between mattermost and IRC. Uses the in/outgoing webhooks.
|
Simple bridge between mattermost and IRC. Uses the in/outgoing webhooks.
|
||||||
Relays public channel messages between mattermost and IRC.
|
Relays public channel messages between mattermost and IRC.
|
||||||
|
|
||||||
Work in progress.
|
Requires mattermost 1.2.0+
|
||||||
|
|
||||||
Requires mattermost build from master (or 1.2.0 when released).
|
There is also [matterbridge-plus] (https://github.com/42wim/matterbridge-plus) which uses the mattermost API and needs a dedicated user (bot). But requires no incoming/outgoing webhook setup.
|
||||||
|
|
||||||
## binaries
|
## binaries
|
||||||
Binaries can be found [here] (https://github.com/42wim/matterbridge/releases/tag/v0.1)
|
Binaries can be found [here] (https://github.com/42wim/matterbridge/releases/tag/v0.3)
|
||||||
|
|
||||||
## building
|
## building
|
||||||
Make sure you have [Go](https://golang.org/doc/install) properly installed, including setting up your [GOPATH] (https://golang.org/doc/code.html#GOPATH)
|
Make sure you have [Go](https://golang.org/doc/install) properly installed, including setting up your [GOPATH] (https://golang.org/doc/code.html#GOPATH)
|
||||||
@ -28,7 +28,12 @@ matterbridge
|
|||||||
## running
|
## running
|
||||||
1) Copy the matterbridge.conf.sample to matterbridge.conf in the same directory as the matterbridge binary.
|
1) Copy the matterbridge.conf.sample to matterbridge.conf in the same directory as the matterbridge binary.
|
||||||
2) Edit matterbridge.conf with the settings for your environment. See below for more config information.
|
2) Edit matterbridge.conf with the settings for your environment. See below for more config information.
|
||||||
3) Now you can run matterbridge.
|
3) Now you can run matterbridge.
|
||||||
|
|
||||||
|
```
|
||||||
|
Usage of matterbridge:
|
||||||
|
-conf="matterbridge.conf": config file
|
||||||
|
```
|
||||||
|
|
||||||
Matterbridge will:
|
Matterbridge will:
|
||||||
* start a webserver listening on the port specified in the configuration.
|
* start a webserver listening on the port specified in the configuration.
|
||||||
@ -37,7 +42,7 @@ Matterbridge will:
|
|||||||
|
|
||||||
## config
|
## config
|
||||||
### matterbridge
|
### matterbridge
|
||||||
matterbridge looks for matterbridge.conf in current directory.
|
matterbridge looks for matterbridge.conf in current directory. (use -conf to specify another file)
|
||||||
|
|
||||||
Look at matterbridge.conf.sample for an example
|
Look at matterbridge.conf.sample for an example
|
||||||
|
|
||||||
@ -50,18 +55,32 @@ UseTLS=false
|
|||||||
SkipTLSVerify=true
|
SkipTLSVerify=true
|
||||||
nick="matterbot"
|
nick="matterbot"
|
||||||
channel="#matterbridge"
|
channel="#matterbridge"
|
||||||
|
UseSlackCircumfix=false
|
||||||
|
|
||||||
[mattermost]
|
[mattermost]
|
||||||
#url is your incoming webhook url (account settings - integrations - incoming webhooks)
|
#url is your incoming webhook url (account settings - integrations - incoming webhooks)
|
||||||
url="http://mattermost.yourdomain.com/hooks/incomingwebhookkey"
|
url="http://mattermost.yourdomain.com/hooks/incomingwebhookkey"
|
||||||
#port the bridge webserver will listen on
|
#port the bridge webserver will listen on
|
||||||
port=9999
|
port=9999
|
||||||
|
#address the webserver will bind to
|
||||||
|
BindAddress="0.0.0.0"
|
||||||
showjoinpart=true #show irc users joining and parting
|
showjoinpart=true #show irc users joining and parting
|
||||||
#the token you get from the outgoing webhook in mattermost. If empty no token check will be done.
|
#the token you get from the outgoing webhook in mattermost. If empty no token check will be done.
|
||||||
|
#if you use multiple IRC channel (see below, this must be empty!)
|
||||||
token=yourtokenfrommattermost
|
token=yourtokenfrommattermost
|
||||||
#disable certificate checking (selfsigned certificates)
|
#disable certificate checking (selfsigned certificates)
|
||||||
#SkipTLSVerify=true
|
#SkipTLSVerify=true
|
||||||
|
|
||||||
|
#multiple channel config
|
||||||
|
#token you can find in your outgoing webhook
|
||||||
|
[Token "outgoingwebhooktoken1"]
|
||||||
|
IRCChannel="#off-topic"
|
||||||
|
MMChannel="off-topic"
|
||||||
|
|
||||||
|
[Token "outgoingwebhooktoken2"]
|
||||||
|
IRCChannel="#testing"
|
||||||
|
MMChannel="testing"
|
||||||
|
|
||||||
[general]
|
[general]
|
||||||
#request your API key on https://github.com/giphy/GiphyAPI. This is a public beta key
|
#request your API key on https://github.com/giphy/GiphyAPI. This is a public beta key
|
||||||
GiphyApiKey="dc6zaTOxFJmzC"
|
GiphyApiKey="dc6zaTOxFJmzC"
|
||||||
|
20
config.go
20
config.go
@ -8,12 +8,14 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
IRC struct {
|
IRC struct {
|
||||||
UseTLS bool
|
UseTLS bool
|
||||||
SkipTLSVerify bool
|
SkipTLSVerify bool
|
||||||
Server string
|
Server string
|
||||||
Port int
|
Port int
|
||||||
Nick string
|
Nick string
|
||||||
Channel string
|
Password string
|
||||||
|
Channel string
|
||||||
|
UseSlackCircumfix bool
|
||||||
}
|
}
|
||||||
Mattermost struct {
|
Mattermost struct {
|
||||||
URL string
|
URL string
|
||||||
@ -22,6 +24,12 @@ type Config struct {
|
|||||||
Token string
|
Token string
|
||||||
IconURL string
|
IconURL string
|
||||||
SkipTLSVerify bool
|
SkipTLSVerify bool
|
||||||
|
BindAddress string
|
||||||
|
Channel string
|
||||||
|
}
|
||||||
|
Token map[string]*struct {
|
||||||
|
IRCChannel string
|
||||||
|
MMChannel string
|
||||||
}
|
}
|
||||||
General struct {
|
General struct {
|
||||||
GiphyAPIKey string
|
GiphyAPIKey string
|
||||||
|
@ -5,14 +5,28 @@ UseTLS=false
|
|||||||
SkipTLSVerify=true
|
SkipTLSVerify=true
|
||||||
nick="matterbot"
|
nick="matterbot"
|
||||||
channel="#matterbridge"
|
channel="#matterbridge"
|
||||||
|
UseSlackCircumfix=false
|
||||||
|
|
||||||
[mattermost]
|
[mattermost]
|
||||||
url="http://yourdomain/hooks/yourhookkey"
|
url="http://yourdomain/hooks/yourhookkey"
|
||||||
port=9999
|
port=9999
|
||||||
showjoinpart=true
|
showjoinpart=true
|
||||||
#token=yourtokenfrommattermost
|
#remove token when using multiple channels!
|
||||||
|
token=yourtokenfrommattermost
|
||||||
IconURL="http://youricon.png"
|
IconURL="http://youricon.png"
|
||||||
#SkipTLSVerify=true
|
#SkipTLSVerify=true
|
||||||
|
#BindAddress="0.0.0.0"
|
||||||
|
|
||||||
[general]
|
[general]
|
||||||
GiphyAPIKey=dc6zaTOxFJmzC
|
GiphyAPIKey=dc6zaTOxFJmzC
|
||||||
|
|
||||||
|
#multiple channel config
|
||||||
|
#token you can find in your outgoing webhook
|
||||||
|
[Token "outgoingwebhooktoken1"]
|
||||||
|
IRCChannel="#off-topic"
|
||||||
|
MMChannel="off-topic"
|
||||||
|
|
||||||
|
[Token "outgoingwebhooktoken2"]
|
||||||
|
IRCChannel="#testing"
|
||||||
|
MMChannel="testing"
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"flag"
|
||||||
"github.com/42wim/matterbridge/matterhook"
|
"github.com/42wim/matterbridge/matterhook"
|
||||||
"github.com/peterhellberg/giphy"
|
"github.com/peterhellberg/giphy"
|
||||||
"github.com/thoj/go-ircevent"
|
"github.com/thoj/go-ircevent"
|
||||||
@ -12,17 +13,25 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Bridge struct {
|
type Bridge struct {
|
||||||
i *irc.Connection
|
i *irc.Connection
|
||||||
m *matterhook.Client
|
m *matterhook.Client
|
||||||
|
cmap map[string]string
|
||||||
*Config
|
*Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBridge(name string, config *Config) *Bridge {
|
func NewBridge(name string, config *Config) *Bridge {
|
||||||
b := &Bridge{}
|
b := &Bridge{}
|
||||||
b.Config = config
|
b.Config = config
|
||||||
|
b.cmap = make(map[string]string)
|
||||||
|
if len(b.Config.Token) > 0 {
|
||||||
|
for _, val := range b.Config.Token {
|
||||||
|
b.cmap[val.IRCChannel] = val.MMChannel
|
||||||
|
}
|
||||||
|
}
|
||||||
b.m = matterhook.New(b.Config.Mattermost.URL,
|
b.m = matterhook.New(b.Config.Mattermost.URL,
|
||||||
matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token,
|
matterhook.Config{Port: b.Config.Mattermost.Port, Token: b.Config.Mattermost.Token,
|
||||||
InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify})
|
InsecureSkipVerify: b.Config.Mattermost.SkipTLSVerify,
|
||||||
|
BindAddress: b.Config.Mattermost.BindAddress})
|
||||||
b.i = b.createIRC(name)
|
b.i = b.createIRC(name)
|
||||||
go b.handleMatter()
|
go b.handleMatter()
|
||||||
return b
|
return b
|
||||||
@ -32,17 +41,24 @@ func (b *Bridge) createIRC(name string) *irc.Connection {
|
|||||||
i := irc.IRC(b.Config.IRC.Nick, b.Config.IRC.Nick)
|
i := irc.IRC(b.Config.IRC.Nick, b.Config.IRC.Nick)
|
||||||
i.UseTLS = b.Config.IRC.UseTLS
|
i.UseTLS = b.Config.IRC.UseTLS
|
||||||
i.TLSConfig = &tls.Config{InsecureSkipVerify: b.Config.IRC.SkipTLSVerify}
|
i.TLSConfig = &tls.Config{InsecureSkipVerify: b.Config.IRC.SkipTLSVerify}
|
||||||
|
if b.Config.IRC.Password != "" {
|
||||||
|
i.Password = b.Config.IRC.Password
|
||||||
|
}
|
||||||
i.Connect(b.Config.IRC.Server + ":" + strconv.Itoa(b.Config.IRC.Port))
|
i.Connect(b.Config.IRC.Server + ":" + strconv.Itoa(b.Config.IRC.Port))
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
log.Println("Joining", b.Config.IRC.Channel, "as", b.Config.IRC.Nick)
|
log.Println("Joining", b.Config.IRC.Channel, "as", b.Config.IRC.Nick)
|
||||||
i.Join(b.Config.IRC.Channel)
|
i.Join(b.Config.IRC.Channel)
|
||||||
|
for _, val := range b.Config.Token {
|
||||||
|
log.Println("Joining", val.IRCChannel, "as", b.Config.IRC.Nick)
|
||||||
|
i.Join(val.IRCChannel)
|
||||||
|
}
|
||||||
i.AddCallback("PRIVMSG", b.handlePrivMsg)
|
i.AddCallback("PRIVMSG", b.handlePrivMsg)
|
||||||
i.AddCallback("CTCP_ACTION", b.handlePrivMsg)
|
i.AddCallback("CTCP_ACTION", b.handlePrivMsg)
|
||||||
if b.Config.Mattermost.ShowJoinPart {
|
if b.Config.Mattermost.ShowJoinPart {
|
||||||
i.AddCallback("JOIN", b.handleJoinPart)
|
i.AddCallback("JOIN", b.handleJoinPart)
|
||||||
i.AddCallback("PART", b.handleJoinPart)
|
i.AddCallback("PART", b.handleJoinPart)
|
||||||
}
|
}
|
||||||
i.AddCallback("353", b.handleOther)
|
//i.AddCallback("353", b.handleOther)
|
||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,26 +68,29 @@ func (b *Bridge) handlePrivMsg(event *irc.Event) {
|
|||||||
msg = event.Nick + " "
|
msg = event.Nick + " "
|
||||||
}
|
}
|
||||||
msg += event.Message()
|
msg += event.Message()
|
||||||
b.Send("irc-"+event.Nick, msg)
|
b.Send("irc-"+event.Nick, msg, b.getMMChannel(event.Arguments[0]))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) handleJoinPart(event *irc.Event) {
|
func (b *Bridge) handleJoinPart(event *irc.Event) {
|
||||||
b.SendType(b.Config.IRC.Nick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), "join_leave")
|
b.Send(b.Config.IRC.Nick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0]))
|
||||||
|
//b.SendType(b.Config.IRC.Nick, "irc-"+event.Nick+" "+strings.ToLower(event.Code)+"s "+event.Message(), b.getMMChannel(event.Arguments[0]), "join_leave")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) handleOther(event *irc.Event) {
|
func (b *Bridge) handleOther(event *irc.Event) {
|
||||||
switch event.Code {
|
switch event.Code {
|
||||||
case "353":
|
case "353":
|
||||||
b.Send(b.Config.IRC.Nick, event.Message()+" currently on IRC")
|
log.Println("handleOther", b.getMMChannel(event.Arguments[0]))
|
||||||
|
b.Send(b.Config.IRC.Nick, event.Message()+" currently on IRC", b.getMMChannel(event.Arguments[0]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) Send(nick string, message string) error {
|
func (b *Bridge) Send(nick string, message string, channel string) error {
|
||||||
return b.SendType(nick, message, "")
|
return b.SendType(nick, message, channel, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) SendType(nick string, message string, mtype string) error {
|
func (b *Bridge) SendType(nick string, message string, channel string, mtype string) error {
|
||||||
matterMessage := matterhook.OMessage{IconURL: b.Config.Mattermost.IconURL}
|
matterMessage := matterhook.OMessage{IconURL: b.Config.Mattermost.IconURL}
|
||||||
|
matterMessage.Channel = channel
|
||||||
matterMessage.UserName = nick
|
matterMessage.UserName = nick
|
||||||
matterMessage.Text = message
|
matterMessage.Text = message
|
||||||
matterMessage.Type = mtype
|
matterMessage.Type = mtype
|
||||||
@ -84,20 +103,25 @@ func (b *Bridge) SendType(nick string, message string, mtype string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Bridge) handleMatter() {
|
func (b *Bridge) handleMatter() {
|
||||||
|
var username string
|
||||||
for {
|
for {
|
||||||
message := b.m.Receive()
|
message := b.m.Receive()
|
||||||
|
username = message.UserName + ": "
|
||||||
|
if b.Config.IRC.UseSlackCircumfix {
|
||||||
|
username = "<" + message.UserName + "> "
|
||||||
|
}
|
||||||
cmd := strings.Fields(message.Text)[0]
|
cmd := strings.Fields(message.Text)[0]
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case "!users":
|
case "!users":
|
||||||
log.Println("received !users from", message.UserName)
|
log.Println("received !users from", message.UserName)
|
||||||
b.i.SendRaw("NAMES " + b.Config.IRC.Channel)
|
b.i.SendRaw("NAMES " + b.getIRCChannel(message.Token))
|
||||||
case "!gif":
|
case "!gif":
|
||||||
message.Text = b.giphyRandom(strings.Fields(strings.Replace(message.Text, "!gif ", "", 1)))
|
message.Text = b.giphyRandom(strings.Fields(strings.Replace(message.Text, "!gif ", "", 1)))
|
||||||
b.Send(b.Config.IRC.Nick, message.Text)
|
b.Send(b.Config.IRC.Nick, message.Text, b.getIRCChannel(message.Token))
|
||||||
}
|
}
|
||||||
texts := strings.Split(message.Text, "\n")
|
texts := strings.Split(message.Text, "\n")
|
||||||
for _, text := range texts {
|
for _, text := range texts {
|
||||||
b.i.Privmsg(b.Config.IRC.Channel, message.UserName+": "+text)
|
b.i.Privmsg(b.getIRCChannel(message.Token), username+text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +138,26 @@ func (b *Bridge) giphyRandom(query []string) string {
|
|||||||
return res.Data.FixedHeightDownsampledURL
|
return res.Data.FixedHeightDownsampledURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Bridge) getMMChannel(ircChannel string) string {
|
||||||
|
mmchannel, ok := b.cmap[ircChannel]
|
||||||
|
if !ok {
|
||||||
|
mmchannel = b.Config.Mattermost.Channel
|
||||||
|
}
|
||||||
|
return mmchannel
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *Bridge) getIRCChannel(token string) string {
|
||||||
|
ircchannel := b.Config.IRC.Channel
|
||||||
|
_, ok := b.Config.Token[token]
|
||||||
|
if ok {
|
||||||
|
ircchannel = b.Config.Token[token].IRCChannel
|
||||||
|
}
|
||||||
|
return ircchannel
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
NewBridge("matterbot", NewConfig("matterbridge.conf"))
|
flagConfig := flag.String("conf", "matterbridge.conf", "config file")
|
||||||
|
flag.Parse()
|
||||||
|
NewBridge("matterbot", NewConfig(*flagConfig))
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,7 @@ type Client struct {
|
|||||||
// Config for client.
|
// Config for client.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Port int // Port to listen on.
|
Port int // Port to listen on.
|
||||||
|
BindAddress string // Address to listen on
|
||||||
Token string // Only allow this token from Mattermost. (Allow everything when empty)
|
Token string // Only allow this token from Mattermost. (Allow everything when empty)
|
||||||
InsecureSkipVerify bool // disable certificate checking
|
InsecureSkipVerify bool // disable certificate checking
|
||||||
DisableServer bool // Do not start server for outgoing webhooks from Mattermost.
|
DisableServer bool // Do not start server for outgoing webhooks from Mattermost.
|
||||||
@ -63,6 +64,7 @@ func New(url string, config Config) *Client {
|
|||||||
if c.Port == 0 {
|
if c.Port == 0 {
|
||||||
c.Port = 9999
|
c.Port = 9999
|
||||||
}
|
}
|
||||||
|
c.BindAddress += ":"
|
||||||
tr := &http.Transport{
|
tr := &http.Transport{
|
||||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify},
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.InsecureSkipVerify},
|
||||||
}
|
}
|
||||||
@ -77,8 +79,8 @@ func New(url string, config Config) *Client {
|
|||||||
func (c *Client) StartServer() {
|
func (c *Client) StartServer() {
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/", c)
|
mux.Handle("/", c)
|
||||||
log.Printf("Listening on http://0.0.0.0:%v...\n", c.Port)
|
log.Printf("Listening on http://%v:%v...\n", c.BindAddress, c.Port)
|
||||||
if err := http.ListenAndServe((":" + strconv.Itoa(c.Port)), mux); err != nil {
|
if err := http.ListenAndServe((c.BindAddress + strconv.Itoa(c.Port)), mux); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user