Code Monkey home page Code Monkey logo

Comments (6)

mdesousa avatar mdesousa commented on July 18, 2024 1

Actually, was able to write a bit of code to create blocks from mrkdwn with links... hope it helps others. The only issue is that it loses other mrkdwn formatting that aren't links...

import {
  RichTextBlock,
  RichTextElement,
  RichTextLink,
  RichTextText,
} from '@slack/bolt';

const toTextElement = (text: string): RichTextText => ({ type: 'text', text });
const toLinkElement = (url: string, text: string): RichTextLink => ({
  type: 'link',
  url,
  text,
});

const toElements = (md: string): RichTextElement[] => {
  const linkRegex = /<([^>]+)\|([^>]+)>/g; // match mrkdwn url <url|text>
  let parsed = 0;
  const elements: RichTextElement[] = [];

  for (;;) {
    const match = linkRegex.exec(md);
    if (!match) break;
    if (match.index > parsed) {
      const before = md.substring(parsed, match.index);
      elements.push(toTextElement(before));
    }
    elements.push(toLinkElement(match[1], match[2]));
    parsed = match.index + match[0].length;
  }

  if (parsed < md.length) elements.push(toTextElement(md.substring(parsed)));
  return elements;
};

export const toBlocks = (md: string): RichTextBlock[] => [
  {
    type: 'rich_text',
    elements: [{ type: 'rich_text_section', elements: toElements(md) }],
  },
];

from bolt-js.

seratch avatar seratch commented on July 18, 2024

Hi @mdesousa, we appreciate your time and effort in reporting this issue and apologize for the inconvenience you've experienced. This is indeed an issue on Slack's iOS app end and we're unable to provide a concrete timeline for its resolution. In the meantime, please consider the following workaround to deal with it:

const client = new WebClient(process.env.SLACK_BOT_TOKEN, { logLevel: "debug" });

(async () => {
  const repsonse = await client.chat.postMessage({
    channel: "<channel id>",
    text: "Click this: <https://www.google.com/search?hl=en&q=chocolate+chip+cookies|Search Google>",
    blocks: [
      {
        type: "rich_text",
        elements: [
          {
            type: "rich_text_section",
            elements: [
              { type: "text", text: "Click this: " },
              {
                type: "link",
                url: "https://www.google.com/search?hl=en&q=chocolate+chip+cookies",
                text: "Search Google",
              },
            ],
          },
        ],
      },
    ],
  });
  console.log(repsonse);
})();

I understand this could be frustrating but I hope this was helpful to you for the time being.

from bolt-js.

mdesousa avatar mdesousa commented on July 18, 2024

thanks @seratch. is there a repo for the iOS app where I can report this issue directly to them.
in the meantime, thanks for the workaround. i don't presume that you have a helper in the sdk (or sample code) to generate blocks from mtkdwn text? the example that I provided was a simple one... in reality, we may have text that has multiple links embedded in different places...

Search for different cookies: <https://www.google.com/search?hl=en&q=chocolate+chip+cookies|chocolate>, <https://www.google.com/search?hl=en&q=raisin+cookies|raisin>, or maybe <https://www.google.com/search?hl=en&q=macademia+nut+cookies|macademia nuts>. Enjoy!

from bolt-js.

filmaj avatar filmaj commented on July 18, 2024

is there a repo for the iOS app where I can report this issue directly to them.

sorry @mdesousa no such repo exists but I will raise this internally

from bolt-js.

filmaj avatar filmaj commented on July 18, 2024

Interestingly on my iPhone, the unfurled preview links correctly, but the actual linked markdown text is not linked.

from bolt-js.

github-actions avatar github-actions commented on July 18, 2024

👋 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.

from bolt-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.