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

吃可爱长大的小学妹 提交于 2019-12-10 13:05:37

问题


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


来源:https://stackoverflow.com/questions/36414427/how-to-add-mention-in-response-to-slash-commands-in-slack

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!