mirror of
https://github.com/42wim/matterbridge.git
synced 2024-12-19 17:42:35 +01:00
Send first message after connect (slack). Closes #252
This commit is contained in:
parent
01badde21d
commit
a3470f8aec
@ -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:
|
||||||
|
Loading…
Reference in New Issue
Block a user