javascriptnode.jsslackslack-apislack-block-kit

How to Programmatically Mention/Tag a User in a Slack Canvas Using the API?


I'm trying to use the Slack API to mention/tag a user in a canvas so others can click the name to reach out (open profile or DM). Manually typing @UserName in the canvas UI works, creating a clickable mention, but I need to create or edit canvases dynamically using conversations.canvases.create or canvases.edit. I've tried using <@U1234567890> (the standard format for messages), but it renders as plain text in the canvas (e.g., "<@U1234567890>"). Other formats like @<U1234567890>, @[U1234567890], [@U1234567890], @UserName, ![user:U1234567890], and <user:U1234567890> also render as plain text. I also tried rich_text document_content, but got an invalid_arguments error.

My bot has a valid token with scopes like channels:write, users:read, canvases:write, and can tag users in channel messages without issue. The API accepts my payload, returning { "ok": true }, but the mention isn’t clickable, and is just the user ID in plain text. Here’s my JSON body for canvases.edit (using placeholder IDs):

{
    "canvas_id": "F1234567890",
    "changes": [
        {
            "operation": "replace",
            "document_content": {
                "type": "markdown",
                "markdown": "User: <@U1234567890>"
            }
        }
    ]
}

This is a POST request to https://slack.com/api/canvases.edit with headers: Content-Type: application/json;charset=utf-8. Without charset=utf-8, I get a missing_charset error. I’m using a Node.js app with @slack/web-api@7.9.2 (latest as of June 2025). The Slack Canvas API docs don’t mention user mention syntax.

Is there a supported format for programmatic user mentions in Slack canvases, or does the Canvas API Markdown parser not recognize mention syntax? Any insights or workarounds?


Solution

  • The Slack Canvas API docs don’t mention user mention syntax.

    This here appears to be the applicable part, https://api.slack.com/surfaces/canvases#markdown-formatting:

    For Slack-specific elements, the markdown syntax for canvases is a bit different. For example, a channel mention, where the channel ID is C123ABC456:

    Why not join ![](#C123ABC456)

    And a user mention, where the user ID is U123ABCDEFG:

    ![](@U123ABCDEFG)