slack-go / slack

Slack API in Go, originally by @nlopes; Maintainers needed, contact @parsley42
https://pkg.go.dev/github.com/slack-go/slack
BSD 2-Clause "Simplified" License
4.63k stars 1.12k forks source link

Is it possible to serialize the payload into a json? #1149

Open darewreck54 opened 1 year ago

darewreck54 commented 1 year ago

Currently, the postMessage api take in a list of objects to build up the payload to send to slack.

    channelID, timestamp, err := e.slackApiClient.PostMessage(
        notification.channel,
        slack.MsgOptionUsername("Bot Name"),
        slack.MsgOptionText(titleText, false),
        slack.MsgOptionAttachments(
            slack.Attachment{
                Blocks: slack.Blocks{
                    BlockSet: blocks,
                },
                Color: notification.color,
            },
        ),
    )

I'm wondering:

In the example above, I imagine it to be something like

    e.slackApiClient.PostMessage(json)
    jsonPayload = e.slackApiClient.CreateMessagePayload(
        notification.channel,
        slack.MsgOptionUsername("Bot Name"),
        slack.MsgOptionText(titleText, false),
        slack.MsgOptionAttachments(
            slack.Attachment{
                Blocks: slack.Blocks{
                    BlockSet: blocks,
                },
                Color: notification.color,
            },
        ),
    )

Thanks, Derek