title: How to add Slack message button to open direct chat with a user?
body: <p>I have a Slack bot that needs to return a message that includes list of Slack users and a button to direct message each user.</p>
  
  <p>I want the engagement experience to stay consistent for the user.  If the user is interacting with the bot via a desktop Slack app then I want the user to stay within the app (not to be taken away to the web client -- where they likely aren't authenticated).</p>
  
  <p>Something like:</p>
  
  <pre><code>Results:
  
  User A - click link to view User A's profile in Slack
  [Message] - click button to open direct message with user A
  
  User B - click link to view User B's profile in Slack
  [Message] - click button to open direct message with user B
  </code></pre>
  
  <p>I'm stuck on a couple of issues:</p>
  
  <ol>
  <li><p>How to link to a user's profile because I don't know if they are using the Slack app or Slack web (thus how to decide between showing <code>slack://user?team=&amp;id=..</code> or <code>domain.slack.com/team/{id}</code> approach?  This is assuming I use either the <code>title_link</code> or <code>author_link</code> property.</p></li>
  <li><p>How to create a message button that will open a direct message to a user (and even better open it and pre-populate a message)? I've currently been playing with a link action but have not had any luck.</p></li>
  </ol>
  
  <p>I imagine I could workaround it by having the bot send the DM and then @mention the original user.  Not great from the UX perspective.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Thanks to comments from Adil and Erik I think I have the <em>best</em> possible solution.  I ended up crafting a message attachment for each result as follows:</p>
  
  <pre><code>    {
          "fallback": `${user['name']} likes pizza`,
          "text": `&lt;@${user['uid']}&gt;`,
          "actions": [
            {
              "type": "button",
              "text": "View Pizza Profile",
              "url": url(`/directory/${user['id']}`),
              "style": "primary"
            },
            {
              "type": "button",
              "text": "Order Pizza",
              "url": `https://slack.com/app_redirect?channel=${user['uid']}`
            }
          ]
      }
  </code></pre>
  
  <p>This solution provides:</p>
  
  <ul>
  <li>Text field which includes an @mention to the user (clicking it brings up the profile in the browser or native).  It uses the text as the message header (and drops the author and title fields).</li>
  <li>Link action button to open a direct message chat via <code>app_redirect</code></li>
  </ul>
  
  <p>There are a couple of serious limitations:</p>
  
  <ol>
  <li>For native, the direct message link causes a browser to open and then (if the user decides) redirects back to the app.</li>
  <li>The user MUST be using a browser window that is already authenticated to the same workspace as the native client (this is a huge problem for UX as many individuals have multiple workspaces open, in which case the redirect fails with a non-obvious error message).</li>
  </ol>