slackapi / deno-slack-sdk

SDK for building Run on Slack apps using Deno

Home Page:https://api.slack.com/automation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[FEATURE] Support more than just buttons in SendDM's `interactive_blocks`

tgray2os opened this issue · comments

The deno-slack versions

    "deno-slack-sdk/": "https://deno.land/x/deno_slack_sdk@2.5.0/",
    "deno-slack-api/": "https://deno.land/x/deno_slack_api@2.1.2/",

Deno runtime version

deno 1.38.2 (release, aarch64-apple-darwin)
v8 12.0.267.1
typescript 5.2.2

OS info

ProductName:		macOS
ProductVersion:		14.1.1
BuildVersion:		23B81
Darwin Kernel Version 23.1.0: Mon Oct  9 21:28:45 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6020

Describe the bug

I'm using the Schema.slack.functions.SendDM function to try to send a message. I'm using the interactive_blocks option to try to send a static select menu in the message. If I use the example block code here my code works. However once I change it to something created in Block Kit Builder, it no longer works. The message fails with the following error Function 'Send a message to a person' (Slack function) failed invalid_interactive_element. In trying different blocks I've also seen invalid_interactive_block_type.

Steps to reproduce

Scenario 1:
This code works using the example from here

const sendMessageStep = InOfficeWorkflow.addStep(Schema.slack.functions.SendDm, {
  user_id: "U0636RHFE8P",
  message: "Please pick an option",
  interactive_blocks: [
    {
      "type": "actions",
      "block_id": "approve-deny-buttons",
      "elements": [
        {
          type: "button",
          action_id: "approve",
          text: { type: "plain_text", text: "Approve" },
          style: "primary",
        },
        {
          type: "button",
          action_id: "deny",
          text: { type: "plain_text", text: "Deny" },
          style: "danger",
        },
      ],
    },
  ],
});

Scenario 2:
The following code works if I remove the interactive_blocks piece - a DM gets sent to the user. With the interactive_blocks option it fails. The blocks code was pulled directly from Block Kit Builder.

const sendMessageStep = UpdateWorkflow.addStep(Schema.slack.functions.SendDm, {
  user_id: "<user_id>",
  message: "Please pick an option",
  interactive_blocks: [
		{
			"type": "actions",
			"elements": [
				{
					"type": "static_select",
					"placeholder": {
						"type": "plain_text",
						"text": "Select an item",
						"emoji": true
					},
					"options": [
						{
							"text": {
								"type": "plain_text",
								"text": "*this is plain_text text*",
								"emoji": true
							},
							"value": "value-0"
						},
						{
							"text": {
								"type": "plain_text",
								"text": "*this is plain_text text*",
								"emoji": true
							},
							"value": "value-1"
						},
						{
							"text": {
								"type": "plain_text",
								"text": "*this is plain_text text*",
								"emoji": true
							},
							"value": "value-2"
						}
					],
					"action_id": "actionId-3"
				}
			]
		}
	]
});

Expected result

Expected result is to have a DM containing a drop-down selection menu sent to the specified user.

Actual result

Scenario 1: A DM with approve/deny buttons is sent to the user.

Scenario 2:
When run with the interactive_blocks option the following error is produced:

2023-11-28 10:51:47 [info] [Fn010M] (Trace=Tr067QCB8R5J) Function 'Send a message to a person' (Slack function) started
2023-11-28 10:51:47 [error] [Fn010M] (Trace=Tr067QCB8R5J) Function 'Send a message to a person' (Slack function) failed
	invalid_interactive_element
2023-11-28 10:51:47 [error] [Wf0685D6M6EL] (Trace=Tr067QCB8R5J) Workflow step 'Send a message to a person' failed
2023-11-28 10:51:47 [error] [Wf0685D6M6EL] (Trace=Tr067QCB8R5J) Workflow 'Update workflow' failed
	invalid_interactive_element
2023-11-28 10:51:48 [error] [Fn0679Q6T8MU] (Trace=Tr067QCB8R5J) Function 'Update workflow' (workflow function) failed
	invalid_interactive_element

Requirements

Please read the Contributing guidelines and Code of Conduct before creating this issue or pull request. By submitting, you are agreeing to those rules.

I believe this is because the interactive_blocks parameter of SendMessage says it only accepts button and workflow_button interactive elements only. See the description of the parameter on our documentation here: https://api.slack.com/reference/functions/send_message#arg_interactive_blocks

As a workaround, you should have complete freedom to post valid blocks using a custom function and the client.chat.postMessage API.

I see, thanks! I missed that piece of the docs, but that does explain it. I'll figure out a different way to go about what I was trying to do.