slackapi/bolt-js

Is there a way to obtain the "text" or "mrkdwn" version of a rich_text_input?

Closed this issue ยท 3 comments

I am working with a modal that has a rich_text_input in its block elements.

After receiving the submitted rich_text data from the modal, I need to:
a) Post a message with the submitted text from the rich_text_input to a specific channel
b) Send a DM with the submitted text from the rich_text_input to the user who submitted the modal

Previously, when working with just plain text inputs(or when a message was posted to a channel with my bot tagged), I would save the message as a string - with all the markdowns - and reformatted the message to be converted to a quote by attaching a > at the frontmost part of the message.

For example, if someone posted a message like this:
@MyApp example message
then I would
a) save the <@UXXXXXXXX> example message ๐Ÿน๐Ÿน in my database
b) send the formatted version of the message (to turn it into a quote) and send it to the user / post to a channel like this
> <@UXXXXXXXX> example message :tropical_drink::tropical_drink:

However, my problem is that when the user submits the message from a modal's rich_text_input, I am getting the submitted text in the rich_text element format:

// My block_id is "campaign_whale_message".

 "campaign_whale_message": {
          "acknowledger": {
            "type": "rich_text_input",
            "rich_text_value": {
              "type": "rich_text",
              "elements": [
                {
                  "type": "rich_text_section",
                  "elements": [
                    { "type": "user", "user_id": "UXXXXXXXX" },
                    { "type": "text", "text": " " },
                    { "type": "text", "text": "example message!" }
                    { "type": "text", "text": " " },
                    { "type": "emoji", "name": "tropical_drink", "unicode": "1f379" },
                    { "type": "emoji", "name": "tropical_drink", "unicode": "1f379" },
                    
                  ]
                },
and so on..

Although it may be simple to reconvert the rich_text_section values to a rich_text_quote element when the submitted text is short, I may be getting submissions with users, emojis, plain texts, code snippets, lists.. etc., and then the conversion to the rich_text_quote element gets too complicated.

Is there a way to obtain the submitted rich_text_value 's mrkdwn version or is there an easy way to convert it into a mrkdwn version text?

Thanks in advance!

Reproducible in:

The Slack SDK version

"@slack/bolt": "^3.13.3"

Node.js runtime version

Node.js v18.16.1

OS info

ProductName:		macOS
ProductVersion:		13.2.1
BuildVersion:		22D68

Steps to reproduce:

Expected result:

Actual result:

Requirements

For general questions/issues about Slack API platform or its server-side, could you submit questions at https://my.slack.com/help/requests/new instead. ๐Ÿ™‡

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

๐Ÿ‘‹ It looks like this issue has been open for 30 days with no activity. We'll mark this as stale for now, and wait 10 days for an update or for further comment before closing this issue out. If you think this issue needs to be prioritized, please comment to get the thread going again! Maintainers also review issues marked as stale on a regular basis and comment or adjust status if the issue needs to be reprioritized.

Hi, is there a reason my issue is not being acknowledged?

@dianexjeong sorry about the lack of response, must have slipped through our team's radar. Apologies for that.

As for your question, the short answer is no, there is no "easy" way to convert from the JSON-based rich text format to markdown. "Easy" is subjective, though. In theory as long as you have a means of converting each individual rich text sub-elements (rich_text_section, rich_text_list, rich_text_quote, rich_text_preformatted as well as the "base" token elements like channel, user, group, link, emoji, etc.) to a markdown equivalent, it should be possible? Note that there is a recursive relationship: a rich_text_list can contain one or more rich_text_sections which can contain... etc.

Slack has no available tooling to do this conversion available. However, if you do end up writing something in this space, it would be great to know about it and share that with us!

In any case I will close this issue, but if you have further follow-ups, feel free to re-open or file a new issue.