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

Block kit generated view JSON fails on `Client.OpenView` with `Block ID needs to be unique` error despite not being set #1184

Open peterlanoie opened 1 year ago

peterlanoie commented 1 year ago

What happened

Opening a slack.ModalViewRequest created from unmarshalled JSON produced by Slack's block kit builder fails when no block_id JSON fields are present.

Slack documentation states that block_id is NOT required.

Comment for views.go/ValidateUniqueBlockID func states it "will verify ... if set" but doesn't appear to check that.

Expected behavior

View should open

Steps to reproduce

reproducible code

package main

import (
    "encoding/json"
    "fmt"

    "github.com/slack-go/slack"
)

// modal generated with 2 standard plain text inputs, no `block_id` fields present
var slackModal string = `
{
    "type": "modal",
    "title": {
        "type": "plain_text",
        "text": "My App",
        "emoji": true
    },
    "submit": {
        "type": "plain_text",
        "text": "Submit",
        "emoji": true
    },
    "close": {
        "type": "plain_text",
        "text": "Cancel",
        "emoji": true
    },
    "blocks": [
        {
            "type": "input",
            "element": {
                "type": "plain_text_input",
                "action_id": "plain_text_input-action"
            },
            "label": {
                "type": "plain_text",
                "text": "Label",
                "emoji": true
            }
        },
        {
            "type": "input",
            "element": {
                "type": "plain_text_input",
                "action_id": "plain_text_input-action"
            },
            "label": {
                "type": "plain_text",
                "text": "Label",
                "emoji": true
            }
        }
    ]
}
`

func main() {
    var view slack.ModalViewRequest
    json.Unmarshal([]byte(slackModal), &view)
    client := slack.New("X", slack.OptionDebug(true))
    _, err := client.OpenView("X", view)
    if err != nil {
        fmt.Printf(err.Error())
    }
}

Versions