Skip to content

Commit

Permalink
Add fields EnterpriseID and EnterpriseName to SlashCommand (slack-go#265
Browse files Browse the repository at this point in the history
)

* Add fields EnterpriseID and EnterpriseName to SlashCommand

https://api.slack.com/slash-commands#triggering_a_command

* Add omitempty option to EnterpriseID and EnterpriseName
  • Loading branch information
suzuki-shunsuke authored and james-lawrence committed Feb 21, 2018
1 parent 8ab4d0b commit 3940a5a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
26 changes: 15 additions & 11 deletions slash.go
Expand Up @@ -6,17 +6,19 @@ import (

// SlashCommand contains information about a request of the slash command
type SlashCommand struct {
Token string `json:"token"`
TeamID string `json:"team_id"`
TeamDomain string `json:"team_domain"`
ChannelID string `json:"channel_id"`
ChannelName string `json:"channel_name"`
UserID string `json:"user_id"`
UserName string `json:"user_name"`
Command string `json:"command"`
Text string `json:"text"`
ResponseURL string `json:"response_url"`
TriggerID string `json:"trigger_id"`
Token string `json:"token"`
TeamID string `json:"team_id"`
TeamDomain string `json:"team_domain"`
EnterpriseID string `json:"enterprise_id,omitempty"`
EnterpriseName string `json:"enterprise_name,omitempty"`
ChannelID string `json:"channel_id"`
ChannelName string `json:"channel_name"`
UserID string `json:"user_id"`
UserName string `json:"user_name"`
Command string `json:"command"`
Text string `json:"text"`
ResponseURL string `json:"response_url"`
TriggerID string `json:"trigger_id"`
}

// SlashCommandParse will parse the request of the slash command
Expand All @@ -27,6 +29,8 @@ func SlashCommandParse(r *http.Request) (s SlashCommand, err error) {
s.Token = r.PostForm.Get("token")
s.TeamID = r.PostForm.Get("team_id")
s.TeamDomain = r.PostForm.Get("team_domain")
s.EnterpriseID = r.PostForm.Get("enterprise_id")
s.EnterpriseName = r.PostForm.Get("enterprise_name")
s.ChannelID = r.PostForm.Get("channel_id")
s.ChannelName = r.PostForm.Get("channel_name")
s.UserID = r.PostForm.Get("user_id")
Expand Down
48 changes: 26 additions & 22 deletions slash_test.go
Expand Up @@ -20,30 +20,34 @@ func TestSlash_ServeHTTP(t *testing.T) {
}{
{
body: url.Values{
"command": []string{"/command"},
"team_domain": []string{"team"},
"channel_id": []string{"C1234ABCD"},
"text": []string{"text"},
"team_id": []string{"T1234ABCD"},
"user_id": []string{"U1234ABCD"},
"user_name": []string{"username"},
"response_url": []string{"https://hooks.slack.com/commands/XXXXXXXX/00000000000/YYYYYYYYYYYYYY"},
"token": []string{"valid"},
"channel_name": []string{"channel"},
"trigger_id": []string{"0000000000.1111111111.222222222222aaaaaaaaaaaaaa"},
"command": []string{"/command"},
"team_domain": []string{"team"},
"enterprise_id": []string{"E0001"},
"enterprise_name": []string{"Globular%20Construct%20Inc"},
"channel_id": []string{"C1234ABCD"},
"text": []string{"text"},
"team_id": []string{"T1234ABCD"},
"user_id": []string{"U1234ABCD"},
"user_name": []string{"username"},
"response_url": []string{"https://hooks.slack.com/commands/XXXXXXXX/00000000000/YYYYYYYYYYYYYY"},
"token": []string{"valid"},
"channel_name": []string{"channel"},
"trigger_id": []string{"0000000000.1111111111.222222222222aaaaaaaaaaaaaa"},
},
wantParams: SlashCommand{
Command: "/command",
TeamDomain: "team",
ChannelID: "C1234ABCD",
Text: "text",
TeamID: "T1234ABCD",
UserID: "U1234ABCD",
UserName: "username",
ResponseURL: "https://hooks.slack.com/commands/XXXXXXXX/00000000000/YYYYYYYYYYYYYY",
Token: "valid",
ChannelName: "channel",
TriggerID: "0000000000.1111111111.222222222222aaaaaaaaaaaaaa",
Command: "/command",
TeamDomain: "team",
EnterpriseID: "E0001",
EnterpriseName: "Globular%20Construct%20Inc",
ChannelID: "C1234ABCD",
Text: "text",
TeamID: "T1234ABCD",
UserID: "U1234ABCD",
UserName: "username",
ResponseURL: "https://hooks.slack.com/commands/XXXXXXXX/00000000000/YYYYYYYYYYYYYY",
Token: "valid",
ChannelName: "channel",
TriggerID: "0000000000.1111111111.222222222222aaaaaaaaaaaaaa",
},
wantStatusCode: http.StatusOK,
},
Expand Down

0 comments on commit 3940a5a

Please sign in to comment.