无法使用 slack-go Actions 显示按钮

问题描述 投票:0回答:1

我正在尝试显示两个按钮:“不,谢谢!”和“是的,请!”按照这个教程。但是,我只获得临时消息中的文本字段,而不是标题和两个按钮:

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

}

我可以看到响应中的操作,但看不到按钮:

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> }] [] {[]}   }}

我的 linter 还收到以下警告(也在上面的屏幕截图中):

"redundant type from array, slice or map composite literal"

FWIW,我尝试将

Type
值设置为“button”作为字符串,并将其设置为
slack.ActionType
,因为这似乎是基于文档的预期值。

go slack-api slack-block-kit
1个回答
0
投票

因此,由于某种原因,使用上述实现似乎是不可能的。相反,我使用了 slack-go 存储库中的example。 该函数似乎可以处理显示正确的按钮(尽管我似乎没有返回值)--

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
}

© www.soinside.com 2019 - 2024. All rights reserved.