10

How can I make slack parse @someone mentions as links to the user instead of plaintext. I've been reading slack documentation on message formatting but still haven't figured it out. Here's an example of what I'm getting now:

{
  "text": "*username:* @alexis",
  "response_type": "ephemeral"
}

mention not parsed as link

Diego Allen
  • 4,623
  • 5
  • 30
  • 33
  • I have the same question with yours, and I think this will work. http://stackoverflow.com/questions/40771924/how-to-mention-user-in-slack-client/40774442#40774442 – Haipeng Su Nov 23 '16 at 21:33

3 Answers3

19

To make a proper "clickable" mention, you need to pass the unique user ID and not the plaintext name.

The format of the user ID is: U024BE7LHand a mention would look like this: <@U024BE7LH>

Ther user ID of the user that executed the slash command will be in the payload that slack sends to your endpoint. You can also look up user IDs by calling the users.list method, which will give you access to the user IDs of all the users in the team.

More information here

Wilhelm Klopp
  • 5,030
  • 2
  • 29
  • 37
3

Pass the username inside <> quotes like this <@someone>

Sample

{
  "text": "*username:* <@alexis>",
  "response_type": "ephemeral"
}

Also if instead of user you want to notify channel then use !channel, !group , !here , or !everyone instead of @username

For eg.

{
  "text": "*username:* <!channel>",
  "response_type": "ephemeral"
}
Kashif Siddiqui
  • 1,476
  • 14
  • 26
  • 2
    This answer is in part outdated. Slack is phasing out `@username` and developers should user @user-Id instead. More info here: https://api.slack.com/changelog/2017-09-the-one-about-usernames – Erik Kalkoken Nov 04 '18 at 15:38
0
slack_web_client.chat_postMessage(
    channel="channel_name",
    text="Hi! <@User_id>"
)

Place User ID in <> quotes and make sure that your app/bot has Scopes for commands.

Further details - https://api.slack.com/interactivity/slash-commands