我做错了什么?到目前为止,在我的Slack应用程序中,还没有一个降价链接的例子。

我在我的Slack应用程序的聊天中粘贴了下面的例子。我从Slack markdown语法中得到了这个例子,它仍然将其视为Slack应用程序中的文字文本:

[like this](http://someurl)

所以我最终在Slack聊天中看到的不是“像这样”的链接。

或许上面的说法是错误的,在这种情况下,我的问题是如何在Slack中显式地创建链接?我想要一些文本,我指定可以点击到特定的URL(超链接)。


当前回答

我写了这段代码来转换markdown链接在一个文本体到链接格式slack期望:

// Pretty hacky, convert [sup](http://example.com) to <http://example.com|sup>
const reformatLinks = /\[(.*?)\]\((.*?)\)/g
const slackBody = body.replace(reformatLinks, (_m, text, url) => `<${url}|${text}>`)

据我所知,slack不支持文本内的图像链接。

其他回答

如果你正在使用Slack -bot或其他使用Slack API的东西,你就可以在你的消息中使用mrkdwn语法。

<http://www.example.com|This message is a link>

参考:https://api.slack.com/reference/surfaces/formatting

以下是spottedman的回答,我是如何让它在Javascript中工作的。注意,对于Firefox,用户需要启用一个标志才能使其工作。

a.addEventListener("click", function() {
    var textToDisplay = "foo";
    var url = "https://stackoverflow.com";
    var message = `<html><body>
    <!--StartFragment-->
    <a href="${url}">${textToDisplay}</a>
    <!--EndFragment-->
    </body></html>`;
    const htmlBlob = new Blob([message], {type : 'text/html'});
    const textBlob = new Blob(["sda"], {type : 'text/plain'});

    const cbi = new ClipboardItem({
        ['text/html']: htmlBlob,
        ['text/plain']: textBlob
    });
    navigator.clipboard.write([cbi]);
});

作为Slack Messages的替代品(Wilhem的回答中提到了),你可以通过API创建Slack Posts,并至少使用一些Markdown。这些都创建了<h2><a href="https://someurl">,如下所示</a></h2>:

curl -F filetype=post -F content="# [like this](https://someurl)" -F channels=C1.....7L -F token=xoxp-... https://slack.com/api/files.upload

或者交换content="…" for file=@post.md

curl -F filetype=post -F file=@post.md -F channels=C1.....7L -F token=xoxp-... https://slack.com/api/files.upload

这是使用files.upload。我认为尝试以自己的身份发布的最简单的方法是使用遗留令牌。从通道的URI获取通道ID。

我写了这段代码来转换markdown链接在一个文本体到链接格式slack期望:

// Pretty hacky, convert [sup](http://example.com) to <http://example.com|sup>
const reformatLinks = /\[(.*?)\]\((.*?)\)/g
const slackBody = body.replace(reformatLinks, (_m, text, url) => `<${url}|${text}>`)

据我所知,slack不支持文本内的图像链接。

当url涉及一个垂直栏|时,这种形式的降价有问题吗 用urltext解决了这个问题。替换(“|”、“% 7 c”)