I am trying to display two buttons: "No thanks!" and "Yes, please!" following this tutorial. However, I only get the Text field in an ephemeral message instead of the title and two buttons:
func handleIsArticleGood() (interface{}, error) {
attachment := slack.Attachment{
Text: "Would you like to see the most recent scores?",
CallbackID: "ask_us",
Color: "#666666",
Actions: []slack.AttachmentAction{
slack.AttachmentAction{
Name: "action",
Text: "No thanks!",
Type: slack.ActionType("button"),
Value: "no",
},
slack.AttachmentAction{
Name: "action",
Text: "Yes, please!",
Type: slack.ActionType("button"),
Value: "yes",
},
},
}
return attachment, nil
}
I can see the actions in the response, but not the buttons:
socketmode: 2024/02/29 12:00:27 socket_mode_managed_conn.go:348: Sending Socket Mode response with envelope ID "$envID": &{d02eddad-fe96-4a46-8aa0-ccd6a7e4bd09 {#666666 ask_us 0 Would you like to see the most recent scores? [] [{action No thanks! button no 0 [] [] [] <nil> } {action Yes, please! button yes 0 [] [] [] <nil> }] [] {[]} }}
My linter also picks up the following warning (in the screenshot above as well):
"redundant type from array, slice or map composite literal"
FWIW, I tried setting the Type
value to "button" as a string and setting it as a slack.ActionType
as that seemed to be the expected value based on the documentation.
So, it seems that this is, for some reason, not possible using the above implementation. Instead, I used an example from the slack-go repository. This function seems to handle displaying the correct buttons (though I don't appear to be getting a value back)--
func handleIsArticleGood(command slack.SlashCommand, client *slack.Client) error {
attachment := slack.Attachment{
Pretext: "pretext",
Fallback: "We don't currently support your client",
CallbackID: "accept_or_reject",
Color: "#3AA3E3",
Actions: []slack.AttachmentAction{
slack.AttachmentAction{
Name: "accept",
Text: "Accept",
Type: "button",
Value: "accept",
},
slack.AttachmentAction{
Name: "reject",
Text: "Reject",
Type: "button",
Value: "reject",
Style: "danger",
},
},
}
_, _, err := client.PostMessage(command.ChannelID, slack.MsgOptionAttachments(attachment))
if err != nil {
return fmt.Errorf("failed to post message: %w", err)
}
return nil
}