1package slack 2 3import ( 4 "net/http" 5) 6 7// SlashCommand contains information about a request of the slash command 8type SlashCommand struct { 9 Token string `json:"token"` 10 TeamID string `json:"team_id"` 11 TeamDomain string `json:"team_domain"` 12 EnterpriseID string `json:"enterprise_id,omitempty"` 13 EnterpriseName string `json:"enterprise_name,omitempty"` 14 ChannelID string `json:"channel_id"` 15 ChannelName string `json:"channel_name"` 16 UserID string `json:"user_id"` 17 UserName string `json:"user_name"` 18 Command string `json:"command"` 19 Text string `json:"text"` 20 ResponseURL string `json:"response_url"` 21 TriggerID string `json:"trigger_id"` 22} 23 24// SlashCommandParse will parse the request of the slash command 25func SlashCommandParse(r *http.Request) (s SlashCommand, err error) { 26 if err = r.ParseForm(); err != nil { 27 return s, err 28 } 29 s.Token = r.PostForm.Get("token") 30 s.TeamID = r.PostForm.Get("team_id") 31 s.TeamDomain = r.PostForm.Get("team_domain") 32 s.EnterpriseID = r.PostForm.Get("enterprise_id") 33 s.EnterpriseName = r.PostForm.Get("enterprise_name") 34 s.ChannelID = r.PostForm.Get("channel_id") 35 s.ChannelName = r.PostForm.Get("channel_name") 36 s.UserID = r.PostForm.Get("user_id") 37 s.UserName = r.PostForm.Get("user_name") 38 s.Command = r.PostForm.Get("command") 39 s.Text = r.PostForm.Get("text") 40 s.ResponseURL = r.PostForm.Get("response_url") 41 s.TriggerID = r.PostForm.Get("trigger_id") 42 return s, nil 43} 44 45// ValidateToken validates verificationTokens 46func (s SlashCommand) ValidateToken(verificationTokens ...string) bool { 47 for _, token := range verificationTokens { 48 if s.Token == token { 49 return true 50 } 51 } 52 return false 53} 54