How to mention user in slack.client

前端 未结 2 1897
囚心锁ツ
囚心锁ツ 2020-12-28 13:18

This might be a simple question, but I can not get it work.

I am using Slack Python Api to mention a user in a channel, and I am referring to the document here, http

相关标签:
2条回答
  • 2020-12-28 13:52

    Posting an updated answer as this method no longer works since Slack updated their API. Now you have to discover the user's ID using users.list, or just looking it up in the Slack app on their profile.

    Then for a given userID, you mention them by setting the text as follows: <@userID>. The link_names argument is now irrelevant. So this would be the code to use now:

    message = sc.api_call(
      'chat.postMessage',
      channel='#channelname',
      text='<@userID> This is a test.'
      )
    

    HOWEVER, if you want to mention a usergroup, then the old method still applies - just @mention them and in that case do set link_names to true.

    0 讨论(0)
  • 2020-12-28 14:00

    After a little bit exploration, I got the solution which is quite simple. I don't know how I could miss it.

    message = sc.api_call(
      'chat.postMessage',
      link_names=1,
      channel='#channelname',
      text='@someone This is a test.'
      )
    

    use the option link_names=1 to link channels or user names automatically in the text message. This will do the trick.

    Thank you everyone.

    0 讨论(0)
提交回复
热议问题