Skip to content

Commit

Permalink
Add is_enterprise_install flag to command, interactions, and oauth2 r…
Browse files Browse the repository at this point in the history
…esponse
  • Loading branch information
hussachai committed Sep 10, 2023
1 parent 4c00dbd commit b13e91d
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 48 deletions.
47 changes: 24 additions & 23 deletions interactions.go
Expand Up @@ -33,29 +33,30 @@ const (

// InteractionCallback is sent from slack when a user interactions with a button or dialog.
type InteractionCallback struct {
Type InteractionType `json:"type"`
Token string `json:"token"`
CallbackID string `json:"callback_id"`
ResponseURL string `json:"response_url"`
TriggerID string `json:"trigger_id"`
ActionTs string `json:"action_ts"`
Team Team `json:"team"`
Channel Channel `json:"channel"`
User User `json:"user"`
OriginalMessage Message `json:"original_message"`
Message Message `json:"message"`
Name string `json:"name"`
Value string `json:"value"`
MessageTs string `json:"message_ts"`
AttachmentID string `json:"attachment_id"`
ActionCallback ActionCallbacks `json:"actions"`
View View `json:"view"`
ActionID string `json:"action_id"`
APIAppID string `json:"api_app_id"`
BlockID string `json:"block_id"`
Container Container `json:"container"`
Enterprise Enterprise `json:"enterprise"`
WorkflowStep InteractionWorkflowStep `json:"workflow_step"`
Type InteractionType `json:"type"`
Token string `json:"token"`
CallbackID string `json:"callback_id"`
ResponseURL string `json:"response_url"`
TriggerID string `json:"trigger_id"`
ActionTs string `json:"action_ts"`
Team Team `json:"team"`
Channel Channel `json:"channel"`
User User `json:"user"`
OriginalMessage Message `json:"original_message"`
Message Message `json:"message"`
Name string `json:"name"`
Value string `json:"value"`
MessageTs string `json:"message_ts"`
AttachmentID string `json:"attachment_id"`
ActionCallback ActionCallbacks `json:"actions"`
View View `json:"view"`
ActionID string `json:"action_id"`
APIAppID string `json:"api_app_id"`
BlockID string `json:"block_id"`
Container Container `json:"container"`
Enterprise Enterprise `json:"enterprise"`
IsEnterpriseInstall bool `json:"is_enterprise_install"`
WorkflowStep InteractionWorkflowStep `json:"workflow_step"`
DialogSubmissionCallback
ViewSubmissionCallback
ViewClosedCallback
Expand Down
23 changes: 12 additions & 11 deletions oauth.go
Expand Up @@ -33,17 +33,18 @@ type OAuthResponse struct {

// OAuthV2Response ...
type OAuthV2Response struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
Scope string `json:"scope"`
BotUserID string `json:"bot_user_id"`
AppID string `json:"app_id"`
Team OAuthV2ResponseTeam `json:"team"`
IncomingWebhook OAuthResponseIncomingWebhook `json:"incoming_webhook"`
Enterprise OAuthV2ResponseEnterprise `json:"enterprise"`
AuthedUser OAuthV2ResponseAuthedUser `json:"authed_user"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
AccessToken string `json:"access_token"`
TokenType string `json:"token_type"`
Scope string `json:"scope"`
BotUserID string `json:"bot_user_id"`
AppID string `json:"app_id"`
Team OAuthV2ResponseTeam `json:"team"`
IncomingWebhook OAuthResponseIncomingWebhook `json:"incoming_webhook"`
Enterprise OAuthV2ResponseEnterprise `json:"enterprise"`
IsEnterpriseInstall bool `json:"is_enterprise_install"`
AuthedUser OAuthV2ResponseAuthedUser `json:"authed_user"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
SlackResponse
}

Expand Down
30 changes: 16 additions & 14 deletions slash.go
Expand Up @@ -6,20 +6,21 @@ 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"`
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"`
APIAppID string `json:"api_app_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"`
IsEnterpriseInstall bool `json:"is_enterprise_install"`
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"`
APIAppID string `json:"api_app_id"`
}

// SlashCommandParse will parse the request of the slash command
Expand All @@ -32,6 +33,7 @@ func SlashCommandParse(r *http.Request) (s SlashCommand, err error) {
s.TeamDomain = r.PostForm.Get("team_domain")
s.EnterpriseID = r.PostForm.Get("enterprise_id")
s.EnterpriseName = r.PostForm.Get("enterprise_name")
s.IsEnterpriseInstall = r.PostForm.Get("is_enterprise_install") == "true"
s.ChannelID = r.PostForm.Get("channel_id")
s.ChannelName = r.PostForm.Get("channel_name")
s.UserID = r.PostForm.Get("user_id")
Expand Down

4 comments on commit b13e91d

@parsley42
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's an issue with this - my guess is it needs to be a string? See: #1267

@hussachai
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my bad. I haven't tested it with websockets. I think it's sometimes a string and sometimes a boolean. One of the unit tests for socket mode indicates that it's a boolean, so I thought it would be fine there, but apparently not.
You can find the unit test here: https://github.com/slack-go/slack/blob/master/socketmode/socketmode_test.go#L82

@hussachai
Copy link
Contributor Author

@hussachai hussachai commented on b13e91d Feb 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the parameter from Slack doc.

{
  "ok": true,
  "access_token": "xoxb-XXXX",
  "token_type": "bot",
  "scope": "identify,users:read",
  "bot_user_id": "W0XXXX",
  "app_id": "A0UXXXX",
  "team": null,
  "enterprise": {
    "id": "E1XXX",
    "name": "Starship"
  },
  "is_enterprise_install": true,
  "authed_user": {
    "id": "WXXXX",
    "access_token": "xoxp-XXXX",
    ...
  }
}

Also, I checked the interactive payload, and it is also a boolean. I think we may need a special treatment for websockets if that is actually the problem.

{
  "type": "block_actions",
....
  "enterprise": null,
  "is_enterprise_install": false,
...

@hussachai
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to work on this, but it seems like it's already been addressed #1266

Please sign in to comment.