2
0
mirror of https://github.com/42wim/matterbridge synced 2024-11-05 12:00:27 +00:00

Fix slack file/image downloads after api changes (slack)

This commit is contained in:
Wim 2018-08-10 00:39:07 +02:00
parent 68aeb93afa
commit 7690be1647

View File

@ -313,18 +313,14 @@ func (b *Bslack) handleSlackClient(messages chan *config.Message) {
b.Users, _ = b.sc.GetUsers() b.Users, _ = b.sc.GetUsers()
b.Usergroups, _ = b.sc.GetUserGroups() b.Usergroups, _ = b.sc.GetUserGroups()
case *slack.ConnectedEvent: case *slack.ConnectedEvent:
b.channels = ev.Info.Channels var err error
b.channels, _, err = b.sc.GetConversations(&slack.GetConversationsParameters{})
if err != nil {
b.Log.Errorf("Channel list failed: %#v", err)
}
b.si = ev.Info b.si = ev.Info
b.Users, _ = b.sc.GetUsers() b.Users, _ = b.sc.GetUsers()
b.Usergroups, _ = b.sc.GetUserGroups() b.Usergroups, _ = b.sc.GetUserGroups()
// add private channels
groups, _ := b.sc.GetGroups(true)
for _, g := range groups {
channel := new(slack.Channel)
channel.ID = g.ID
channel.Name = g.Name
b.channels = append(b.channels, *channel)
}
case *slack.InvalidAuthEvent: case *slack.InvalidAuthEvent:
b.Log.Fatalf("Invalid Token %#v", ev) b.Log.Fatalf("Invalid Token %#v", ev)
case *slack.ConnectionErrorEvent: case *slack.ConnectionErrorEvent:
@ -444,7 +440,6 @@ func (b *Bslack) handleDownloadFile(rmsg *config.Message, file *slack.File) erro
if len(results) > 0 { if len(results) > 0 {
comment = results[0][1] comment = results[0][1]
} }
err := helper.HandleDownloadSize(b.Log, rmsg, file.Name, int64(file.Size), b.General) err := helper.HandleDownloadSize(b.Log, rmsg, file.Name, int64(file.Size), b.General)
if err != nil { if err != nil {
return err return err
@ -592,7 +587,7 @@ func (b *Bslack) handleMessageEvent(ev *slack.MessageEvent) (*config.Message, er
} }
// Only deleted messages can have a empty username and text // Only deleted messages can have a empty username and text
if (rmsg.Text == "" || rmsg.Username == "") && ev.SubType != messageDeleted { if (rmsg.Text == "" || rmsg.Username == "") && ev.SubType != messageDeleted && len(ev.Files) == 0 {
// this is probably a webhook we couldn't resolve // this is probably a webhook we couldn't resolve
if ev.BotID != "" { if ev.BotID != "" {
return nil, fmt.Errorf("probably an incoming webhook we couldn't resolve (maybe ourselves)") return nil, fmt.Errorf("probably an incoming webhook we couldn't resolve (maybe ourselves)")
@ -606,10 +601,12 @@ func (b *Bslack) handleMessageEvent(ev *slack.MessageEvent) (*config.Message, er
} }
// if we have a file attached, download it (in memory) and put a pointer to it in msg.Extra // if we have a file attached, download it (in memory) and put a pointer to it in msg.Extra
if ev.File != nil { if len(ev.Files) > 0 {
err := b.handleDownloadFile(&rmsg, ev.File) for _, f := range ev.Files {
if err != nil { err := b.handleDownloadFile(&rmsg, &f)
b.Log.Errorf("download failed: %s", err) if err != nil {
b.Log.Errorf("download failed: %s", err)
}
} }
} }