slack-blocks-rs icon indicating copy to clipboard operation
slack-blocks-rs copied to clipboard

unknown variant `rich_text`

Open Mattsi-Jansky opened this issue 1 year ago • 4 comments

I'm hitting some issues when parsing valid blocks sent back from the Slack API because they include type of rich_text which doesn't appear to be supported. And I'm struggling to find it anywhere in the Slack blocks documentation, so it might be undocumented?

Specifically, the error:

---- should_send_acknowledgement_of_event_messages stdout ----
thread 'should_send_acknowledgement_of_event_messages' panicked at 'called `Result::unwrap()` on an `Err` value: Error("unknown variant `rich_text`, expected one of `section`, `divider`, `image`, `actions`, `context`, `input`, `header`, `file`", line: 0, column: 0)', client/tests/web_sockets.rs:97:27

And the Slack message, which is a response from the api/chat.postMessage action, some identifying details omitted:

{
  "ok": true,
  "channel": "<ommitted>",
  "ts": "1686086970.626639",
  "message": {
    "bot_id": "<ommitted>",
    "type": "message",
    "text": "foobar",
    "user": "<ommitted>",
    "ts": "1686086970.626639",
    "app_id": "<ommitted>",
    "blocks": [
      {
        "type": "rich_text",
        "block_id": "<ommitted>",
        "elements": [
          {
            "type": "rich_text_section",
            "elements": [
              {
                "type": "text",
                "text": "foobar"
              }
            ]
          }
        ]
      }
    ],
    "team": "<ommitted>",
    "bot_profile": {
      "id": "<ommitted>",
      "app_id": "<ommitted>",
      "name": "<ommitted>",
      "icons": {
        "image_36": "<ommitted>",
        "image_48": "<ommitted>",
        "image_72": "<ommitted>"
      },
      "deleted": false,
      "updated": 1686039611,
      "team_id": "<ommitted>"
    }
  },
  "warning": "missing_charset",
  "response_metadata": {
    "warnings": [
      "missing_charset"
    ]
  }
}

Mattsi-Jansky avatar Jun 21 '23 16:06 Mattsi-Jansky

Seems there might be some documentation for it in the form of this Java library: https://javadoc.io/static/com.slack.api/slack-api-model/1.0.7/com/slack/api/model/block/element/RichTextElement.html

Edit: You can also use it in Slack's "Block Kit Builder" where it is supported: https://app.slack.com/block-kit-builder/T0G5PM4NR#%7B%22blocks%22:%5B%7B%22type%22:%22rich_text%22,%22block_id%22:%22%3Committed%3E%22,%22elements%22:%5B%7B%22type%22:%22rich_text_section%22,%22elements%22:%5B%7B%22type%22:%22text%22,%22text%22:%22foobar%22%7D%5D%7D%5D%7D%5D%7D

Mattsi-Jansky avatar Jun 21 '23 16:06 Mattsi-Jansky

Hi Mattsi! Just noticed this, I'll work on adding support for this tomorrow! :smiley:

cakekindel avatar Jun 30 '23 00:06 cakekindel

Good stuff :+1: For what it's worth I've since discovered other undocumented parts of the Blocks API, like the link element and the rich_text_section element. They are returned by the API and work in the Block Kit Builder but aren't in the documentation.

I've been hacking together my own minimal implementation here that includes these non-documented types, if it helps as a reference: https://github.com/Mattsi-Jansky/termibot/tree/rewrite-in-rust/client/src/models/blocks

Mattsi-Jansky avatar Jul 05 '23 10:07 Mattsi-Jansky

Sorry I dropped this! Added a minimal change to unblock this issue. May be worth considering adding a fallthrough variant as well to be more forward-compatible with Blocks changes going forward

cakekindel avatar Aug 29 '23 17:08 cakekindel