summaryrefslogtreecommitdiffstats
path: root/bridge
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-09-07 23:47:23 +0200
committerWim <wim@42.be>2017-09-07 23:47:23 +0200
commita3470f8aec6f38efbb80f9bf2ec0776421e687de (patch)
treebbc242cadc9275d607af6426f666259f14e85493 /bridge
parent01badde21ddbf4d6c04572d679af7211ed6ec7fa (diff)
downloadmatterbridge-msglm-a3470f8aec6f38efbb80f9bf2ec0776421e687de.tar.gz
matterbridge-msglm-a3470f8aec6f38efbb80f9bf2ec0776421e687de.tar.bz2
matterbridge-msglm-a3470f8aec6f38efbb80f9bf2ec0776421e687de.zip
Send first message after connect (slack). Closes #252
Diffstat (limited to 'bridge')
-rw-r--r--bridge/slack/slack.go89
1 files changed, 42 insertions, 47 deletions
diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go
index e681c784..68ff8f8b 100644
--- a/bridge/slack/slack.go
+++ b/bridge/slack/slack.go
@@ -257,65 +257,60 @@ func (b *Bslack) handleSlack() {
}
func (b *Bslack) handleSlackClient(mchan chan *MMMessage) {
- count := 0
for msg := range b.rtm.IncomingEvents {
switch ev := msg.Data.(type) {
case *slack.MessageEvent:
- // ignore first message
- if count > 0 {
- flog.Debugf("Receiving from slackclient %#v", ev)
- if len(ev.Attachments) > 0 {
- // skip messages we made ourselves
- 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)
- ev.User = ev.SubMessage.User
- ev.Text = ev.SubMessage.Text + b.Config.EditSuffix
+ flog.Debugf("Receiving from slackclient %#v", ev)
+ if len(ev.Attachments) > 0 {
+ // skip messages we made ourselves
+ if ev.Attachments[0].CallbackID == "matterbridge" {
+ continue
}
- // use our own func because rtm.GetChannelInfo doesn't work for private channels
- channel, err := b.getChannelByID(ev.Channel)
+ }
+ if !b.Config.EditDisable && ev.SubMessage != nil && ev.SubMessage.ThreadTimestamp != ev.SubMessage.Timestamp {
+ flog.Debugf("SubMessage %#v", ev.SubMessage)
+ 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)
+ if err != nil {
+ continue
+ }
+ m := &MMMessage{}
+ if ev.BotID == "" {
+ user, err := b.rtm.GetUserInfo(ev.User)
if err != nil {
continue
}
- m := &MMMessage{}
- if ev.BotID == "" {
- 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.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
}
- 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
- }
+ if bot.Name != "" {
+ m.Username = bot.Name
+ m.UserID = bot.ID
}
- mchan <- m
}
- count++
+ mchan <- m
case *slack.OutgoingErrorEvent:
flog.Debugf("%#v", ev.Error())
case *slack.ChannelJoinedEvent: