-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (50 loc) · 1.47 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
package main
import (
"context"
"log"
"os"
"github.com/nakamasato/cloud-run-slack-bot/pkg/cloudrun"
"github.com/nakamasato/cloud-run-slack-bot/pkg/cloudrunslackbot"
"github.com/nakamasato/cloud-run-slack-bot/pkg/monitoring"
slackinternal "github.com/nakamasato/cloud-run-slack-bot/pkg/slack"
"github.com/slack-go/slack"
)
func main() {
var err error
project := os.Getenv("PROJECT")
if project == "" {
log.Fatal("PROJECT env var is required")
}
region := os.Getenv("REGION")
if region == "" {
log.Fatal("REGION env var is required")
}
mClient, err := monitoring.NewMonitoringClient(project)
if err != nil {
log.Fatal(err)
}
defer mClient.Close()
ctx := context.Background()
rClient, err := cloudrun.NewClient(ctx, project, region)
if err != nil {
log.Fatalf("Failed to create run service: %v", err)
}
ops := []slack.Option{}
if appToken := os.Getenv("SLACK_APP_TOKEN"); appToken != "" {
ops = append(ops, slack.OptionAppLevelToken(appToken))
}
sClient := slack.New(os.Getenv("SLACK_BOT_TOKEN"), ops...)
handler := slackinternal.NewSlackEventHandler(sClient, rClient, mClient, os.Getenv("TMP_DIR"))
signingSecret := os.Getenv("SLACK_SIGNING_SECRET")
if signingSecret == "" && os.Getenv("SLACK_APP_MODE") != "socket" {
log.Fatal("SLACK_SIGNING_SECRET env var is required for HTTP mode")
}
svc := cloudrunslackbot.NewCloudRunSlackBotService(
sClient,
os.Getenv("SLACK_CHANNEL"),
os.Getenv("SLACK_APP_MODE"),
handler,
signingSecret,
)
svc.Run()
}