-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (42 loc) · 1.02 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
package main
import (
"fmt" // formatting package
"os" // Accessing stdinput
"github.com/joho/godotenv" // for accessing .env variables
"github.com/slack-go/slack" //github.com slack library
"net/http"
)
func wuffwuff(writer http.ResponseWriter, req *http.Request) {
s, err := slack.SlashCommandParse(req)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
return
}
if !s.ValidateToken(os.Getenv("SLACK_BOT_TOKEN")) {
writer.WriteHeader(http.StatusUnauthorized)
return
}
switch s.Command {
case "/wuffwuff":
response := fmt.Sprintf("Wuff Wuff!")
writer.Write([]byte(response))
default:
writer.WriteHeader(http.StatusInternalServerError)
}
}
func hello(writer http.ResponseWriter, req *http.Request) {
fmt.Fprintf(writer, "hello\n")
}
func main() {
err := godotenv.Load()
if err != nil {
fmt.Println(err)
}
port := os.Getenv("PORT")
if port == "" {
port = "9000"
}
http.HandleFunc("/wuffwuff", wuffwuff)
http.HandleFunc("/hello", hello)
http.ListenAndServe(":"+port, nil)
}