Created
February 26, 2018 14:31
-
-
Save knqyf263/f35fd1437d74aef2efbbbde89c2c3c3b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http.HandleFunc("/slash", func(w http.ResponseWriter, r *http.Request) { | |
s, err := slack.SlashCommandParse(r) | |
if err != nil { | |
w.WriteHeader(http.StatusInternalServerError) | |
return | |
} | |
if !s.ValidateToken(verificationToken) { | |
w.WriteHeader(http.StatusUnauthorized) | |
return | |
} | |
switch s.Command { | |
case "/echo": | |
params := &slack.Msg{Text: s.Text} | |
b, err := json.Marshal(params) | |
if err != nil { | |
w.WriteHeader(http.StatusInternalServerError) | |
return | |
} | |
w.Header().Set("Content-Type", "application/json") | |
w.Write(b) | |
default: | |
w.WriteHeader(http.StatusInternalServerError) | |
return | |
} | |
}) | |
fmt.Println("[INFO] Server listening") | |
http.ListenAndServe(":3000", nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment