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.
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).
Something like:
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
I'm stuck on a couple of issues:
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
slack://user?team=&id=..
ordomain.slack.com/team/{id}
approach? This is assuming I use either thetitle_link
orauthor_link
property.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.
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.
UPDATE
Thanks to comments from Adil and Erik I think I have the best possible solution. I ended up crafting a message attachment for each result as follows:
{
"fallback": `${user['name']} likes pizza`,
"text": `<@${user['uid']}>`,
"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']}`
}
]
}
This solution provides:
- 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).
- Link action button to open a direct message chat via
app_redirect
There are a couple of serious limitations:
- For native, the direct message link causes a browser to open and then (if the user decides) redirects back to the app.
- 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).