-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (62 loc) · 1.24 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"os"
"github.com/joho/godotenv"
"github.com/nlopes/slack"
)
func init() {
err := godotenv.Load()
if err != nil {
panic(err)
}
}
func main() {
api := slack.New(os.Getenv("TOKEN"))
// Delete previous snippet
{
params := slack.GetFilesParameters{
Types: "snippets",
}
files, _, _ := api.GetFiles(params)
for _, file := range files {
if file.Title == "slackの使い方" {
err := api.DeleteFile(file.ID)
if err != nil {
panic(err)
}
}
}
}
// Send a snippet with DM to a newly joined team
{
groups, err := api.GetChannels(false)
if err != nil {
panic(err)
}
var content string
for _, group := range groups {
content = content + fmt.Sprintf("#%s:\t%s\n", group.Name, group.Topic.Value)
}
params := slack.FileUploadParameters{
Channels: []string{"CAPV96FJS"},
Title: "slackの使い方",
Content: content,
}
_, err = api.UploadFile(params)
if err != nil {
panic(err)
}
}
}
func StartSlackRTM(api *slack.Client) {
rtm := api.NewRTM()
go rtm.ManageConnection()
for msg := range rtm.IncomingEvents {
switch ev := msg.Data.(type) {
case *slack.TeamJoinEvent:
// fmt.Println("join a new member!")
fmt.Println(ev.User.Name)
}
}
}