Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Mar 24, 2023 · 0 comments

Comments

@peterlanoie
Copy link

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

  • Create a new modal view using Slack's block kit builder tool with 2 input blocks. (note: as generated, there are no block_ids set on the input blocks.)
  • Save view JSON to file or in code literal
  • Unmarshal view JSON to slack.ModalViewRequest
  • Attempt to slack.Client.Open() the slack.ModalViewRequest
  • Fails with error: Block ID needs to be unique

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

  • Go: 1.20
  • slack-go/slack: 0.12.1
@peterlanoie peterlanoie changed the title Block kit generated view JSON fails on view.open with Block ID needs to be unique error despite not being set Block kit generated view JSON fails on views.open with Block ID needs to be unique error despite not being set Mar 24, 2023
@peterlanoie peterlanoie changed the title Block kit generated view JSON fails on views.open with Block ID needs to be unique error despite not being set Block kit generated view JSON fails on client.OpenView with Block ID needs to be unique error despite not being set Mar 24, 2023
@peterlanoie peterlanoie changed the title Block kit generated view JSON fails on client.OpenView with Block ID needs to be unique error despite not being set Block kit generated view JSON fails on Client.OpenView with Block ID needs to be unique error despite not being set Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants