@@ -10,23 +10,21 @@ import (
1010
1111func main () {
1212 debug := flag .Bool ("debug" , false , "Show JSON output" )
13+ channelID := flag .String ("channel" , "" , "Channel ID (required)" )
1314 flag .Parse ()
1415
1516 // Get token from environment variable
16- apiToken := os .Getenv ("SLACK_BOT_TOKEN " )
17+ apiToken := os .Getenv ("SLACK_USER_TOKEN " )
1718 if apiToken == "" {
18- fmt .Println ("SLACK_BOT_TOKEN environment variable is required" )
19+ fmt .Println ("SLACK_USER_TOKEN environment variable is required" )
1920 os .Exit (1 )
2021 }
2122
2223 api := slack .New (apiToken , slack .OptionDebug (* debug ))
2324
2425 var (
25- postAsUserName string
26- postAsUserID string
27- postToUserName string
28- postToUserID string
29- postToChannelID string
26+ postAsUserName string
27+ postAsUserID string
3028 )
3129
3230 // Find the user to post as.
@@ -40,29 +38,19 @@ func main() {
4038 postAsUserName = authTest .User
4139 postAsUserID = authTest .UserID
4240
43- // Posting to DM with self causes a conversation with slackbot.
44- postToUserName = authTest .User
45- postToUserID = authTest .UserID
46-
47- // Find the channel.
48- channel , _ , _ , err := api .OpenConversation (& slack.OpenConversationParameters {ChannelID : postToUserID })
49- if err != nil {
50- fmt .Printf ("Error opening IM: %s\n " , err )
51- return
52- }
53- postToChannelID = channel .ID
54-
55- fmt .Printf ("Posting as %s (%s) in DM with %s (%s), channel %s\n " , postAsUserName , postAsUserID , postToUserName , postToUserID , postToChannelID )
41+ fmt .Printf ("Posting as %s (%s) in channel %s\n " , postAsUserName , postAsUserID , * channelID )
5642
5743 // Post a message.
58- channelID , timestamp , err := api .PostMessage (postToChannelID , slack .MsgOptionText ("Is this any good?" , false ))
44+ _ , timestamp , err := api .PostMessage (* channelID , slack .MsgOptionText ("Is this any good?" , false ))
5945 if err != nil {
6046 fmt .Printf ("Error posting message: %s\n " , err )
6147 return
6248 }
6349
64- // Grab a reference to the message.
65- msgRef := slack .NewRefToMessage (channelID , timestamp )
50+ // // Grab a reference to the message.
51+ msgRef := slack .NewRefToMessage (* channelID , timestamp )
52+
53+ fmt .Printf ("Adding reaction to message with reference %v\n " , msgRef )
6654
6755 // React with :+1:
6856 if err = api .AddReaction ("+1" , msgRef ); err != nil {
@@ -85,13 +73,19 @@ func main() {
8573 fmt .Printf ("\n " )
8674 fmt .Printf ("%d reactions to message...\n " , len (msgReactionsResp .Reactions ))
8775 for _ , r := range msgReactionsResp .Reactions {
88- fmt .Printf (" %d users say %s\n " , r .Count , r .Name )
76+ fmt .Printf (" %d users say %s in channel %s \n " , r .Count , r .Name , msgReactionsResp . Item . Channel )
8977 }
9078
9179 // List all of the users reactions.
92- listReactions , _ , err := api .ListReactions (slack .NewListReactionsParameters ())
80+ listParams := slack .NewListReactionsParameters ()
81+ fmt .Printf ("Listing reactions with params: User=%q, TeamID=%q, Count=%d, Page=%d, Full=%v\n " ,
82+ listParams .User , listParams .TeamID , listParams .Count , listParams .Page , listParams .Full )
83+ listReactions , _ , err := api .ListReactions (listParams )
9384 if err != nil {
94- fmt .Printf ("Error listing reactions: %s\n " , err )
85+ fmt .Printf ("Error listing reactions: %v\n " , err )
86+ if slackErr , ok := err .(slack.SlackErrorResponse ); ok {
87+ fmt .Printf (" ResponseMetadata.Messages: %v\n " , slackErr .ResponseMetadata .Messages )
88+ }
9589 return
9690 }
9791 fmt .Printf ("\n " )
0 commit comments