Skip to content

Commit

Permalink
Merge pull request #1 from andersnormal/shift-from-deprecated-slack-apis
Browse files Browse the repository at this point in the history
Use Slack Conversation API
  • Loading branch information
andrewloux authored Feb 24, 2021
2 parents b4a052a + 026462d commit b90a67c
Show file tree
Hide file tree
Showing 100 changed files with 2,386 additions and 735 deletions.
35 changes: 5 additions & 30 deletions cmd/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
pb "github.com/andersnormal/autobot/proto"

"github.com/golang/protobuf/ptypes/timestamp"
"github.com/nlopes/slack"
"github.com/slack-go/slack"
)

// FromUserIDWithContext ...
Expand All @@ -31,7 +31,7 @@ func FromChannelIDWithContext(ctx context.Context, api *slack.Client, channelID
c := new(pb.Message_Channel)

// get channel
channel, err := api.GetChannelInfoContext(ctx, channelID)
channel, err := api.GetConversationInfo(channelID, false)
if err != nil {
return nil, err
}
Expand All @@ -42,11 +42,6 @@ func FromChannelIDWithContext(ctx context.Context, api *slack.Client, channelID
return c, nil
}

// FromChannelID ...
func FromChannelID(channelID string) *pb.Message_Channel {
return &pb.Message_Channel{Id: channelID}
}

// FromMsgWithContext ...
func FromMsgWithContext(ctx context.Context, api *slack.Client, msg *slack.MessageEvent) (*pb.Message, error) {
m := new(pb.Message)
Expand All @@ -62,33 +57,13 @@ func FromMsgWithContext(ctx context.Context, api *slack.Client, msg *slack.Messa

m.From = user

// get list of direct message channels
im, err := api.GetIMChannelsContext(ctx)
// get the channel information
channel, err := FromChannelIDWithContext(ctx, api, msg.Channel)
if err != nil {
return nil, err
}

var isPrivate bool
for _, dm := range im {
isPrivate = dm.ID == msg.Channel

if isPrivate {
m.Channel = FromChannelID(dm.ID)

break
}
}

if !isPrivate {
// resolve channel ...
channel, err := FromChannelIDWithContext(ctx, api, msg.Channel)
if err != nil {
return nil, err
}

m.Channel = channel
}

m.Channel = channel
m.TextFormat = pb.Message_PLAIN_TEXT
m.Text = msg.Text

Expand Down
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/andersnormal/autobot/pkg/plugins/runtime"
pb "github.com/andersnormal/autobot/proto"

"github.com/nlopes/slack"
"github.com/slack-go/slack"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ go 1.13
require (
github.com/andersnormal/autobot v1.0.0-beta.12
github.com/golang/protobuf v1.3.2
github.com/nlopes/slack v0.6.0
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2
github.com/slack-go/slack v0.6.6
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.5.0
)
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
Expand Down Expand Up @@ -94,6 +95,8 @@ github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.8.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
Expand Down Expand Up @@ -214,6 +217,8 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/slack-go/slack v0.6.6 h1:ln0fO794CudStSJEfhZ08Ok5JanMjvW6/k2xBuHqedU=
github.com/slack-go/slack v0.6.6/go.mod h1:FGqNzJBmxIsZURAxh2a8D21AnOVvvXZvGligs4npPUM=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/gorilla/websocket/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions vendor/github.com/gorilla/websocket/conn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions vendor/github.com/gorilla/websocket/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions vendor/github.com/gorilla/websocket/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions vendor/github.com/gorilla/websocket/prepared.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b90a67c

Please sign in to comment.