我们如何在使用 Slack 的 Block Kit Builder 时提及或标记某人?

发布于 2025-01-11 03:39:35 字数 1087 浏览 0 评论 0原文

我尝试创建 Slack 的块套件构建器,所需的设计实际上很好。但我不知道在哪里可以找到一个按钮,以便我们可以在上面标记某人。


我在这里尝试标记一个名为 john 的人,但不幸的是它只生成了纯文本,它没有通知该人,也没有变成与预期相同的设计(参见下面的图像结果) <一href="https://app.slack.com/block-kit-builder/T02HTGREMTJ#%7B%22blocks%22:%5B%7B%22type%22:%22section%22,%22text%22:%7 B%22type%22:%22mrkdwn%22,%22text%22:%22@juan%20%5Cn%5Cnis%20a%20mrkdwn%20section%20block%22%7D%7D,%7B%22type%22:%22imag e%22,%22title%22:%7B%22type%22:%22plain_text%22,%22text%22:%22I%20Need%20a%20Marg%22,%22emoji%22:true%7D,%22image_url% 22:%22https://assets3.thrillist.com/v1/image/1682388/size/tl-horizo​​ntal_main.jpg%22,%22alt_text%22:%22marg%22%7D%5D%7D" rel="nofollow noreferrer">查看 Playground

{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "@juan \n\nis a mrkdwn section block"
            }
        },
        .....
    ]
}

这是结果

在此处输入图像描述

I tried creating slack's block kit builder, the desired design were actually fine. But I don't know where to find a button so we can tag a someone on it.


I have here an attempt to tag a person named john but unfortunately it only generated a plain text, it did not notify the person nor became the same the design as expected (see image result below)
view playground

{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "@juan \n\nis a mrkdwn section block"
            }
        },
        .....
    ]
}

Here is the result

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

够运 2025-01-18 03:39:35

我从以下链接找到了解决方案。

https://api.slack.com/reference/surfaces/formatting#mentioning-users

  1. 获取用户的 id,
  2. 用左右箭头将其包裹起来,旁边带有“@”符号。语法 <@userId>

用法:

{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Hey <@802AWTP13BZ>, thanks for submitting your report!"
            }
        }
    ]
}

编辑: 以下是在您不知道的情况下获取用户 ID 的方法:

  1. 搜索此人。
  2. 单击他们的个人资料图片。
  3. 然后,单击“复制会员 ID”,如图所示。

输入图像描述这里

I found the solution from the following link.

https://api.slack.com/reference/surfaces/formatting#mentioning-users

  1. get the user's id
  2. wrap it with a left and right arrow with an "@" symbol beside it. syntax <@userId>

usage:

{
    "blocks": [
        {
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": "Hey <@802AWTP13BZ>, thanks for submitting your report!"
            }
        }
    ]
}

EDITED: Here's how to get a userID if you don't know:

  1. Search for the person.
  2. Click their profile picture.
  3. Then, click 'Copy member ID' like in the picture.

enter image description here

独﹏钓一江月 2025-01-18 03:39:35

接受的答案对我不起作用:用户的名称显示在通知中,但没有显示在消息本身中。

为了解开这个谜团,我使用 Slack Web 客户端发送了一条消息并检查了响应。

消息:

Some text.
@O...
test

响应:

"message": {
    "user": "...",
    "type": "message",
    "ts": "...",
    "client_msg_id": "...",
    "text": "Some text. <@U0...> test",
    "team": "...",
    "blocks": [
        {
            "type": "rich_text",
            "block_id": "f0DGh",
            "elements": [
                {
                    "type": "rich_text_section",
                    "elements": [
                        {
                            "type": "text",
                            "text": "Some text. "
                        },
                        {
                            "type": "user",
                            "user_id": "U0..."
                        },
                        {
                            "type": "text",
                            "text": " test"
                        }
                    ]
                }
            ]
        }
    ]
}

因此,我们需要围绕用户名拆分消息,并将用户名替换为带有相应用户 ID 的 user 元素类型。

The accepted answer does not work for me: the name of the user IS shown in the notification but it's not shown in the message itself.

To solve the mystery, I sent a message using the slack web client and checked the response.

Message:

Some text.
@O...
test

Response:

"message": {
    "user": "...",
    "type": "message",
    "ts": "...",
    "client_msg_id": "...",
    "text": "Some text. <@U0...> test",
    "team": "...",
    "blocks": [
        {
            "type": "rich_text",
            "block_id": "f0DGh",
            "elements": [
                {
                    "type": "rich_text_section",
                    "elements": [
                        {
                            "type": "text",
                            "text": "Some text. "
                        },
                        {
                            "type": "user",
                            "user_id": "U0..."
                        },
                        {
                            "type": "text",
                            "text": " test"
                        }
                    ]
                }
            ]
        }
    ]
}

So, it turns out we need to split the message around usernames and replace usernames with an element type of user with the id of the corresponding user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文