Skip to content

Instantly share code, notes, and snippets.

@knqyf263
Created February 26, 2018 14:31
Show Gist options
  • Save knqyf263/f35fd1437d74aef2efbbbde89c2c3c3b to your computer and use it in GitHub Desktop.
Save knqyf263/f35fd1437d74aef2efbbbde89c2c3c3b to your computer and use it in GitHub Desktop.
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