Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add @ mention in response to slash commands in slack

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

like image 895
Diego Allen Avatar asked Apr 04 '16 23:04

Diego Allen


People also ask

How do I create a custom response on Slack?

Click the Slackbot tab, and you'll see an option to add new responses (provided your Slack administrator allows everyone to add new ones). You can put any text you like on the input side (what you type in a message) and output side (how Slackbot will respond).

How do you type a slash in Slack?

Slack has a lot of built-in slash commands that act as shortcuts for specific actions in Slack. You simply need to type the slash key (/) then followed by some keywords in any Slack channel or direct message to trigger specific actions in Slack (e.g. type /away to mark your status to “away” quickly).

How do I mention someone in Slack API?

Mentioning users in messages The user mentioning syntax <@W123|bronte> is now deprecated and will eventually be removed. Slack will use the "display name" when rendering all mentions. Use the simpler user ID-only form <@W123> instead. Using link_names when posting messages is also deprecated.


1 Answers

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

like image 184
Wilhelm Klopp Avatar answered Sep 18 '22 09:09

Wilhelm Klopp