4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-26 21:19:22 +00:00

Compare commits

...

12 Commits

10 changed files with 82 additions and 68 deletions

View File

@ -36,7 +36,7 @@ Has a REST API.
# Requirements # Requirements
Accounts to one of the supported bridges Accounts to one of the supported bridges
* [Mattermost](https://github.com/mattermost/platform/) 3.8.x - 3.10.x, 4.0.x - 4.1.x * [Mattermost](https://github.com/mattermost/platform/) 3.8.x - 3.10.x, 4.0.x - 4.2.x
* [IRC](http://www.mirc.com/servers.html) * [IRC](http://www.mirc.com/servers.html)
* [XMPP](https://jabber.org) * [XMPP](https://jabber.org)
* [Gitter](https://gitter.im) * [Gitter](https://gitter.im)
@ -53,7 +53,7 @@ See https://github.com/42wim/matterbridge/wiki
# Installing # Installing
## Binaries ## Binaries
* Latest stable release [v1.1.0](https://github.com/42wim/matterbridge/releases/latest) * Latest stable release [v1.1.2](https://github.com/42wim/matterbridge/releases/latest)
* Development releases (follows master) can be downloaded [here](https://dl.bintray.com/42wim/nightly/) * Development releases (follows master) can be downloaded [here](https://dl.bintray.com/42wim/nightly/)
## Building ## Building

View File

@ -88,6 +88,7 @@ func (b *Bgitter) JoinChannel(channel config.ChannelInfo) error {
rmsg.Event = config.EVENT_USER_ACTION rmsg.Event = config.EVENT_USER_ACTION
rmsg.Text = strings.Replace(rmsg.Text, "@"+ev.Message.From.Username+" ", "", -1) rmsg.Text = strings.Replace(rmsg.Text, "@"+ev.Message.From.Username+" ", "", -1)
} }
flog.Debugf("Message is %#v", rmsg)
b.Remote <- rmsg b.Remote <- rmsg
} }
case *gitter.GitterConnectionClosed: case *gitter.GitterConnectionClosed:

View File

@ -195,6 +195,7 @@ func (b *Bmattermost) handleMatter() {
} }
rmsg.Text = text rmsg.Text = text
flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account) flog.Debugf("Sending message from %s on %s to gateway", message.Username, b.Account)
flog.Debugf("Message is %#v", rmsg)
b.Remote <- rmsg b.Remote <- rmsg
} }
} }

View File

@ -257,65 +257,60 @@ func (b *Bslack) handleSlack() {
} }
func (b *Bslack) handleSlackClient(mchan chan *MMMessage) { func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {
count := 0
for msg := range b.rtm.IncomingEvents { for msg := range b.rtm.IncomingEvents {
switch ev := msg.Data.(type) { switch ev := msg.Data.(type) {
case *slack.MessageEvent: case *slack.MessageEvent:
// ignore first message flog.Debugf("Receiving from slackclient %#v", ev)
if count > 0 { if len(ev.Attachments) > 0 {
flog.Debugf("Receiving from slackclient %#v", ev) // skip messages we made ourselves
if len(ev.Attachments) > 0 { if ev.Attachments[0].CallbackID == "matterbridge" {
// skip messages we made ourselves continue
if ev.Attachments[0].CallbackID == "matterbridge" {
continue
}
} }
if !b.Config.EditDisable && ev.SubMessage != nil && ev.SubMessage.ThreadTimestamp != ev.SubMessage.Timestamp { }
flog.Debugf("SubMessage %#v", ev.SubMessage) if !b.Config.EditDisable && ev.SubMessage != nil && ev.SubMessage.ThreadTimestamp != ev.SubMessage.Timestamp {
ev.User = ev.SubMessage.User flog.Debugf("SubMessage %#v", ev.SubMessage)
ev.Text = ev.SubMessage.Text + b.Config.EditSuffix ev.User = ev.SubMessage.User
} ev.Text = ev.SubMessage.Text + b.Config.EditSuffix
// use our own func because rtm.GetChannelInfo doesn't work for private channels }
channel, err := b.getChannelByID(ev.Channel) // use our own func because rtm.GetChannelInfo doesn't work for private channels
channel, err := b.getChannelByID(ev.Channel)
if err != nil {
continue
}
m := &MMMessage{}
if ev.BotID == "" {
user, err := b.rtm.GetUserInfo(ev.User)
if err != nil { if err != nil {
continue continue
} }
m := &MMMessage{} m.UserID = user.ID
if ev.BotID == "" { m.Username = user.Name
user, err := b.rtm.GetUserInfo(ev.User)
if err != nil {
continue
}
m.UserID = user.ID
m.Username = user.Name
}
m.Channel = channel.Name
m.Text = ev.Text
if m.Text == "" {
for _, attach := range ev.Attachments {
if attach.Text != "" {
m.Text = attach.Text
} else {
m.Text = attach.Fallback
}
}
}
m.Raw = ev
m.Text = b.replaceMention(m.Text)
// when using webhookURL we can't check if it's our webhook or not for now
if ev.BotID != "" && b.Config.WebhookURL == "" {
bot, err := b.rtm.GetBotInfo(ev.BotID)
if err != nil {
continue
}
if bot.Name != "" {
m.Username = bot.Name
m.UserID = bot.ID
}
}
mchan <- m
} }
count++ m.Channel = channel.Name
m.Text = ev.Text
if m.Text == "" {
for _, attach := range ev.Attachments {
if attach.Text != "" {
m.Text = attach.Text
} else {
m.Text = attach.Fallback
}
}
}
m.Raw = ev
m.Text = b.replaceMention(m.Text)
// when using webhookURL we can't check if it's our webhook or not for now
if ev.BotID != "" && b.Config.WebhookURL == "" {
bot, err := b.rtm.GetBotInfo(ev.BotID)
if err != nil {
continue
}
if bot.Name != "" {
m.Username = bot.Name
m.UserID = bot.ID
}
}
mchan <- m
case *slack.OutgoingErrorEvent: case *slack.OutgoingErrorEvent:
flog.Debugf("%#v", ev.Error()) flog.Debugf("%#v", ev.Error())
case *slack.ChannelJoinedEvent: case *slack.ChannelJoinedEvent:

View File

@ -1,3 +1,13 @@
# v1.1.2
* general: also build darwin binaries
* mattermost: add support for mattermost 4.2.x
* mattermost: Send images when text is empty regression. (mattermost). Closes #254
* slack: also send the first messsage after connect. #252
# v1.1.1
## Bugfix
* mattermost: fix public links
# v1.1.0 # v1.1.0
## New features ## New features
* general: Add better editing support. (actually edit the messages on bridges that support it) * general: Add better editing support. (actually edit the messages on bridges that support it)

View File

@ -2,9 +2,10 @@
go version |grep go1.9 || exit go version |grep go1.9 || exit
VERSION=$(git describe --tags) VERSION=$(git describe --tags)
mkdir ci/binaries mkdir ci/binaries
GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o ci/binaries/matterbridge-$VERSION-win64.exe GOOS=windows GOARCH=amd64 go build -ldflags "-s -w -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o ci/binaries/matterbridge-$VERSION-windows-amd64.exe
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o ci/binaries/matterbridge-$VERSION-linux64 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o ci/binaries/matterbridge-$VERSION-linux-amd64
GOOS=linux GOARCH=arm go build -ldflags "-s -w -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o ci/binaries/matterbridge-$VERSION-linux-arm GOOS=linux GOARCH=arm go build -ldflags "-s -w -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o ci/binaries/matterbridge-$VERSION-linux-arm
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w -X main.githash=$(git log --pretty=format:'%h' -n 1)" -o ci/binaries/matterbridge-$VERSION-darwin-amd64
cd ci cd ci
cat > deploy.json <<EOF cat > deploy.json <<EOF
{ {

View File

@ -11,7 +11,7 @@ import (
) )
var ( var (
version = "1.1.0" version = "1.1.2"
githash string githash string
) )

View File

@ -383,7 +383,6 @@ WebhookURL="https://hooks.slack.com/services/yourhook"
#AND DEDICATED BOT USER WHEN POSSIBLE! #AND DEDICATED BOT USER WHEN POSSIBLE!
#Address to listen on for outgoing webhook requests from slack #Address to listen on for outgoing webhook requests from slack
#See account settings - integrations - outgoing webhooks on slack #See account settings - integrations - outgoing webhooks on slack
#This setting will not be used when useAPI is eanbled
#webhooks #webhooks
#OPTIONAL #OPTIONAL
WebhookBindAddress="0.0.0.0:9999" WebhookBindAddress="0.0.0.0:9999"

View File

@ -6,7 +6,6 @@
[mattermost] [mattermost]
[mattermost.work] [mattermost.work]
useAPI=true
#do not prefix it wit http:// or https:// #do not prefix it wit http:// or https://
Server="yourmattermostserver.domain" Server="yourmattermostserver.domain"
Team="yourteam" Team="yourteam"

View File

@ -277,6 +277,13 @@ func (m *MMClient) WsReceiver() {
// check if we didn't empty the message // check if we didn't empty the message
if msg.Text != "" { if msg.Text != "" {
m.MessageChan <- msg m.MessageChan <- msg
continue
}
// if we have file attached but the message is empty, also send it
if msg.Post != nil {
if msg.Text != "" || len(msg.Post.FileIds) > 0 {
m.MessageChan <- msg
}
} }
continue continue
} }
@ -511,8 +518,8 @@ func (m *MMClient) GetPosts(channelId string, limit int) *model.PostList {
} }
func (m *MMClient) GetPublicLink(filename string) string { func (m *MMClient) GetPublicLink(filename string) string {
res, err := m.Client.GetFileLink(filename) res, resp := m.Client.GetFileLink(filename)
if err != nil { if resp.Error != nil {
return "" return ""
} }
return res return res
@ -521,8 +528,8 @@ func (m *MMClient) GetPublicLink(filename string) string {
func (m *MMClient) GetPublicLinks(filenames []string) []string { func (m *MMClient) GetPublicLinks(filenames []string) []string {
var output []string var output []string
for _, f := range filenames { for _, f := range filenames {
res, err := m.Client.GetFileLink(f) res, resp := m.Client.GetFileLink(f)
if err != nil { if resp.Error != nil {
continue continue
} }
output = append(output, res) output = append(output, res)
@ -538,8 +545,8 @@ func (m *MMClient) GetFileLinks(filenames []string) []string {
var output []string var output []string
for _, f := range filenames { for _, f := range filenames {
res, err := m.Client.GetFileLink(f) res, resp := m.Client.GetFileLink(f)
if err != nil { if resp.Error != nil {
// public links is probably disabled, create the link ourselves // public links is probably disabled, create the link ourselves
output = append(output, uriScheme+m.Credentials.Server+model.API_URL_SUFFIX_V3+"/files/"+f+"/get") output = append(output, uriScheme+m.Credentials.Server+model.API_URL_SUFFIX_V3+"/files/"+f+"/get")
continue continue
@ -600,9 +607,9 @@ func (m *MMClient) createCookieJar(token string) *cookiejar.Jar {
func (m *MMClient) SendDirectMessage(toUserId string, msg string) { func (m *MMClient) SendDirectMessage(toUserId string, msg string) {
m.log.Debugf("SendDirectMessage to %s, msg %s", toUserId, msg) m.log.Debugf("SendDirectMessage to %s, msg %s", toUserId, msg)
// create DM channel (only happens on first message) // create DM channel (only happens on first message)
_, err := m.Client.CreateDirectChannel(m.User.Id, toUserId) _, resp := m.Client.CreateDirectChannel(m.User.Id, toUserId)
if err != nil { if resp.Error != nil {
m.log.Debugf("SendDirectMessage to %#v failed: %s", toUserId, err) m.log.Debugf("SendDirectMessage to %#v failed: %s", toUserId, resp.Error)
return return
} }
channelName := model.GetDMNameFromIds(toUserId, m.User.Id) channelName := model.GetDMNameFromIds(toUserId, m.User.Id)
@ -854,7 +861,8 @@ func supportedVersion(version string) bool {
strings.HasPrefix(version, "3.9.0") || strings.HasPrefix(version, "3.9.0") ||
strings.HasPrefix(version, "3.10.0") || strings.HasPrefix(version, "3.10.0") ||
strings.HasPrefix(version, "4.0") || strings.HasPrefix(version, "4.0") ||
strings.HasPrefix(version, "4.1") { strings.HasPrefix(version, "4.1") ||
strings.HasPrefix(version, "4.2") {
return true return true
} }
return false return false