Package list golang-github-nlopes-slack / 19146d1
stars example Ryan Carver 6 years ago
1 changed file(s) with 46 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 package main
1
2 import (
3 "flag"
4 "fmt"
5
6 "github.com/nlopes/slack"
7 )
8
9 func main() {
10 var (
11 apiToken string
12 debug bool
13 )
14
15 flag.StringVar(&apiToken, "token", "YOUR_TOKEN_HERE", "Your Slack API Token")
16 flag.BoolVar(&debug, "debug", false, "Show JSON output")
17 flag.Parse()
18
19 api := slack.New(apiToken)
20 if debug {
21 api.SetDebug(true)
22 }
23
24 // Get all stars for the usr.
25 params := slack.NewStarsParameters()
26 starredItems, _, err := api.GetStarred(params)
27 if err != nil {
28 fmt.Printf("Error getting stars: %s\n", err)
29 return
30 }
31 for _, s := range starredItems {
32 var desc string
33 switch s.Type {
34 case slack.TYPE_MESSAGE:
35 desc = s.Message.Text
36 case slack.TYPE_FILE:
37 desc = s.File.Name
38 case slack.TYPE_FILE_COMMENT:
39 desc = s.File.Name + " - " + s.Comment.Comment
40 case slack.TYPE_CHANNEL, slack.TYPE_IM, slack.TYPE_GROUP:
41 desc = s.Channel
42 }
43 fmt.Printf("Starred %s: %s\n", s.Type, desc)
44 }
45 }