How to add @ mention in response to slash commands

2019-06-20 23:23发布

问题:

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"
}

回答1:

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



回答2:

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"
}