slackapi/python-slack-sdk

`initial_value` for `RichTextInputElement` should also accept type `RichTextBlock`

Closed this issue · 0 comments

While using the RichTextInputElement, I realized through the type information that the type of initial_value expects to be an optional dictionary. There is seemingly no mention of RichTextBlock, so I had thought that at that point I would need to go and look at the API and manually create dictionaries to handle this.

This is not true. initial_value can be set to a RichTextBlock directly, without even needing to convert it to a dictionary. For example, this code works, without me even needing to transform any of these blocks to a dict:

blocks.InputBlock(
    label="Description / Context",
    block_id="description",
    element=blocks.RichTextInputElement(
        action_id="contents",
        initial_value=blocks.RichTextBlock(
            elements=[
                blocks.RichTextSectionElement(
                    elements=[
                        blocks.RichTextElementParts.Text(text="Hey, "),
                        blocks.RichTextElementParts.Text(
                            text="this", style={"italic": True}
                        ),
                        blocks.RichTextElementParts.Text(
                            text="is what you should be looking at. "
                        ),
                        blocks.RichTextElementParts.Text(
                            text="Please", style={"bold": True}
                        ),
                    ]
                )
            ],
        ),
    ),
)

...but it gives me an error in my IDE from mypy (rightly, because initial_value doesn't have RichTextBlock in its type definition):

CleanShot 2024-10-09 at 17 08 26@2x

Can the initial_value for RichTextInputElement include RichTextBlock? Thanks!

Category (place an x in each of the [ ])

  • slack_sdk.web.WebClient (sync/async) (Web API client)
  • slack_sdk.webhook.WebhookClient (sync/async) (Incoming Webhook, response_url sender)
  • slack_sdk.models (UI component builders)
  • slack_sdk.oauth (OAuth Flow Utilities)
  • slack_sdk.socket_mode (Socket Mode client)
  • slack_sdk.audit_logs (Audit Logs API client)
  • slack_sdk.scim (SCIM API client)
  • slack_sdk.rtm (RTM client)
  • slack_sdk.signature (Request Signature Verifier)

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.