Open JinoArch opened 1 year ago
@JinoArch I am not sure what you code looks like, or what AMI is supposed to be but you make a []slack.Blocks and store the actionBlocks using append and then append them to the MsgOptionBlocks using the spread operator.
getAmiList := []ami{
{
text: "1",
},
{
text: "2",
},
}
var blocks []slack.Block
for _, ami := range getAmiList {
newBlock := slack.NewSectionBlock(&slack.TextBlockObject{
Text: ami.text,
Type: "mrkdwn",
}, nil, slack.NewAccessory(
slack.NewButtonBlockElement("button", ami.text, &slack.TextBlockObject{
Text: ami.text,
Type: "plain_text",
})),
)
blocks = append(blocks, *newBlock)
}
header := slack.NewSectionBlock(&slack.TextBlockObject{
Type: "mrkdwn",
Text: "header",
}, nil, nil)
msgBlocks := []slack.Block{
header,
}
msgBlocks = append(msgBlocks, blocks...)
message := slack.MsgOptionBlocks(msgBlocks...)
channelID, timestamp, err := api.PostMessage(channel, message)
Is that what you are looking for?
Hello I was trying to create a block message where I want to dynamically set a MsgBlock to sent over to the channel. Like below
I am not able to iterate and create blocks with each ami details in MsgOptionBlocks section . Tried append but it only works with slices, not sure how to iterate and get all ami section blocks. any help is appreciated
The output I am getting is something like this in slack:
expecting something like this in slack: