Comments (6)
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.
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.
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.
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.
Interestingly on my iPhone, the unfurled preview links correctly, but the actual linked markdown text is not linked.
from bolt-js.
👋 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)
- Cannot access the files in the "app_mention" event with TypeScript HOT 3
- How to get search params in custom routes HOT 4
- appToken is not read in socketMode @3.18.0 HOT 4
- Add flag to `AwsLambdaReceiver` to disable Signature Verification HOT 1
- Events Subscription is continuously being turned off when we kill the process HOT 4
- Add reply_in_thread method HOT 1
- Run multiple replicas in k8s of bot app HOT 2
- Frequent disconnects in socket mode HOT 9
- Unable to upload a file in a direct message using files.completeUploadExternal HOT 7
- `too_many_websockets` causes Cannot read properties of undefined (reading 'event') HOT 5
- Cannot respond to incoming message events with `say` using the Bun runtime HOT 5
- Keep getting Error: Cannot write headers after they are sent to the client HOT 3
- How do I create a custom ConsoleLogger? HOT 1
- Better typing for block actions payload HOT 3
- How to access Company ID during OAuth for Slack App Installation HOT 2
- Add docs/sample for using browser cookies to pass custom app data during OAuth flow
- chat.postMessage returns channel name in the response HOT 4
- How do i update "messages_tab_read_only_enabled" to true/false programmatically HOT 4
- Update Ruby version for documentation generation (2.7.6 is end-of-life) HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bolt-js.