How to add Slack message button to open direct chat with a user?
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_linkorauthor_linkproperty.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).
slack slack-api botkit
add a comment |
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_linkorauthor_linkproperty.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).
slack slack-api botkit
add a comment |
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_linkorauthor_linkproperty.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).
slack slack-api botkit
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_linkorauthor_linkproperty.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).
slack slack-api botkit
slack slack-api botkit
edited Nov 15 '18 at 2:43
krsyoung
asked Nov 14 '18 at 15:11
krsyoungkrsyoung
586518
586518
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Adding to Adil's great answer about linking to a user profile
Here is how to provide a link to open a direct message between the current and another user:
You can use Slack's channel redirect feature to create a link that will open any channel for a user. This also works with direct message channels by providing the ID of the target user.
Example for user U12345678:
https://slack.com/app_redirect?channel=U12345678
You can provide this link via Link button or text link.
Note that this will always open a new browser tab/window though, even if the user is using a Slack native client (and no, there is no way to find out if the user it using a native client or the browser).
Another approach would be to just provide the user-mention in your message and let the user click on it to get a menu which includes "Direct Messages". This will work with every user and on every platform / client type:
Just include a standard user mention in your text with some instructions to the user:
<@U12345678>
1
Thanks! I think that confirms (unfortunately) that I'm going to be stuck launching a web session for the user even if they are in the desktop app :( . I'll try the feedback from you and Adil today and report back. Maybe the @mention will work without looking too ugly.
– krsyoung
Nov 14 '18 at 19:07
add a comment |
To create a link to a user's profile, try following the steps on this page:
Create the link by combining your Workspace URL with members’ User IDs. Here’s how:
The first part of the link is the Workspace URL. For example, https://acmeco.slack.com.
The second part of the link is the User ID. Multiple members' User IDs can be found using theusers.listAPI method. Or, an individual's User ID can be found by clicking the More actions icon in a member's profile, then choosing Copy member ID.
Append the User ID to the end of the Workspace URL. Here’s an example: https://acmeco.slack.com/team/U1H63D8SZ.
Using that same User ID, use the conversations.open API method to create a DM/multi-person message with the target user:
from slackclient import SlackClient
slack_token = os.environ["SLACK_API_TOKEN"]
sc = SlackClient(slack_token)
sc.api_call(
"conversations.open",
users=["W1234567890","U2345678901","U3456789012"]
)
1
Thanks for the ideas. The user profile link you suggested is exactly right, but the problem is if I reference the https:// ... in a message then the desktop Slack app will open a browser window (rather than just open the profile within the slack app). The suggestion works fine if web only. I'll dig into the second idea, multi-party chat is a great idea!
– krsyoung
Nov 14 '18 at 19:02
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303307%2fhow-to-add-slack-message-button-to-open-direct-chat-with-a-user%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Adding to Adil's great answer about linking to a user profile
Here is how to provide a link to open a direct message between the current and another user:
You can use Slack's channel redirect feature to create a link that will open any channel for a user. This also works with direct message channels by providing the ID of the target user.
Example for user U12345678:
https://slack.com/app_redirect?channel=U12345678
You can provide this link via Link button or text link.
Note that this will always open a new browser tab/window though, even if the user is using a Slack native client (and no, there is no way to find out if the user it using a native client or the browser).
Another approach would be to just provide the user-mention in your message and let the user click on it to get a menu which includes "Direct Messages". This will work with every user and on every platform / client type:
Just include a standard user mention in your text with some instructions to the user:
<@U12345678>
1
Thanks! I think that confirms (unfortunately) that I'm going to be stuck launching a web session for the user even if they are in the desktop app :( . I'll try the feedback from you and Adil today and report back. Maybe the @mention will work without looking too ugly.
– krsyoung
Nov 14 '18 at 19:07
add a comment |
Adding to Adil's great answer about linking to a user profile
Here is how to provide a link to open a direct message between the current and another user:
You can use Slack's channel redirect feature to create a link that will open any channel for a user. This also works with direct message channels by providing the ID of the target user.
Example for user U12345678:
https://slack.com/app_redirect?channel=U12345678
You can provide this link via Link button or text link.
Note that this will always open a new browser tab/window though, even if the user is using a Slack native client (and no, there is no way to find out if the user it using a native client or the browser).
Another approach would be to just provide the user-mention in your message and let the user click on it to get a menu which includes "Direct Messages". This will work with every user and on every platform / client type:
Just include a standard user mention in your text with some instructions to the user:
<@U12345678>
1
Thanks! I think that confirms (unfortunately) that I'm going to be stuck launching a web session for the user even if they are in the desktop app :( . I'll try the feedback from you and Adil today and report back. Maybe the @mention will work without looking too ugly.
– krsyoung
Nov 14 '18 at 19:07
add a comment |
Adding to Adil's great answer about linking to a user profile
Here is how to provide a link to open a direct message between the current and another user:
You can use Slack's channel redirect feature to create a link that will open any channel for a user. This also works with direct message channels by providing the ID of the target user.
Example for user U12345678:
https://slack.com/app_redirect?channel=U12345678
You can provide this link via Link button or text link.
Note that this will always open a new browser tab/window though, even if the user is using a Slack native client (and no, there is no way to find out if the user it using a native client or the browser).
Another approach would be to just provide the user-mention in your message and let the user click on it to get a menu which includes "Direct Messages". This will work with every user and on every platform / client type:
Just include a standard user mention in your text with some instructions to the user:
<@U12345678>
Adding to Adil's great answer about linking to a user profile
Here is how to provide a link to open a direct message between the current and another user:
You can use Slack's channel redirect feature to create a link that will open any channel for a user. This also works with direct message channels by providing the ID of the target user.
Example for user U12345678:
https://slack.com/app_redirect?channel=U12345678
You can provide this link via Link button or text link.
Note that this will always open a new browser tab/window though, even if the user is using a Slack native client (and no, there is no way to find out if the user it using a native client or the browser).
Another approach would be to just provide the user-mention in your message and let the user click on it to get a menu which includes "Direct Messages". This will work with every user and on every platform / client type:
Just include a standard user mention in your text with some instructions to the user:
<@U12345678>
answered Nov 14 '18 at 17:10
Erik KalkokenErik Kalkoken
12.9k32550
12.9k32550
1
Thanks! I think that confirms (unfortunately) that I'm going to be stuck launching a web session for the user even if they are in the desktop app :( . I'll try the feedback from you and Adil today and report back. Maybe the @mention will work without looking too ugly.
– krsyoung
Nov 14 '18 at 19:07
add a comment |
1
Thanks! I think that confirms (unfortunately) that I'm going to be stuck launching a web session for the user even if they are in the desktop app :( . I'll try the feedback from you and Adil today and report back. Maybe the @mention will work without looking too ugly.
– krsyoung
Nov 14 '18 at 19:07
1
1
Thanks! I think that confirms (unfortunately) that I'm going to be stuck launching a web session for the user even if they are in the desktop app :( . I'll try the feedback from you and Adil today and report back. Maybe the @mention will work without looking too ugly.
– krsyoung
Nov 14 '18 at 19:07
Thanks! I think that confirms (unfortunately) that I'm going to be stuck launching a web session for the user even if they are in the desktop app :( . I'll try the feedback from you and Adil today and report back. Maybe the @mention will work without looking too ugly.
– krsyoung
Nov 14 '18 at 19:07
add a comment |
To create a link to a user's profile, try following the steps on this page:
Create the link by combining your Workspace URL with members’ User IDs. Here’s how:
The first part of the link is the Workspace URL. For example, https://acmeco.slack.com.
The second part of the link is the User ID. Multiple members' User IDs can be found using theusers.listAPI method. Or, an individual's User ID can be found by clicking the More actions icon in a member's profile, then choosing Copy member ID.
Append the User ID to the end of the Workspace URL. Here’s an example: https://acmeco.slack.com/team/U1H63D8SZ.
Using that same User ID, use the conversations.open API method to create a DM/multi-person message with the target user:
from slackclient import SlackClient
slack_token = os.environ["SLACK_API_TOKEN"]
sc = SlackClient(slack_token)
sc.api_call(
"conversations.open",
users=["W1234567890","U2345678901","U3456789012"]
)
1
Thanks for the ideas. The user profile link you suggested is exactly right, but the problem is if I reference the https:// ... in a message then the desktop Slack app will open a browser window (rather than just open the profile within the slack app). The suggestion works fine if web only. I'll dig into the second idea, multi-party chat is a great idea!
– krsyoung
Nov 14 '18 at 19:02
add a comment |
To create a link to a user's profile, try following the steps on this page:
Create the link by combining your Workspace URL with members’ User IDs. Here’s how:
The first part of the link is the Workspace URL. For example, https://acmeco.slack.com.
The second part of the link is the User ID. Multiple members' User IDs can be found using theusers.listAPI method. Or, an individual's User ID can be found by clicking the More actions icon in a member's profile, then choosing Copy member ID.
Append the User ID to the end of the Workspace URL. Here’s an example: https://acmeco.slack.com/team/U1H63D8SZ.
Using that same User ID, use the conversations.open API method to create a DM/multi-person message with the target user:
from slackclient import SlackClient
slack_token = os.environ["SLACK_API_TOKEN"]
sc = SlackClient(slack_token)
sc.api_call(
"conversations.open",
users=["W1234567890","U2345678901","U3456789012"]
)
1
Thanks for the ideas. The user profile link you suggested is exactly right, but the problem is if I reference the https:// ... in a message then the desktop Slack app will open a browser window (rather than just open the profile within the slack app). The suggestion works fine if web only. I'll dig into the second idea, multi-party chat is a great idea!
– krsyoung
Nov 14 '18 at 19:02
add a comment |
To create a link to a user's profile, try following the steps on this page:
Create the link by combining your Workspace URL with members’ User IDs. Here’s how:
The first part of the link is the Workspace URL. For example, https://acmeco.slack.com.
The second part of the link is the User ID. Multiple members' User IDs can be found using theusers.listAPI method. Or, an individual's User ID can be found by clicking the More actions icon in a member's profile, then choosing Copy member ID.
Append the User ID to the end of the Workspace URL. Here’s an example: https://acmeco.slack.com/team/U1H63D8SZ.
Using that same User ID, use the conversations.open API method to create a DM/multi-person message with the target user:
from slackclient import SlackClient
slack_token = os.environ["SLACK_API_TOKEN"]
sc = SlackClient(slack_token)
sc.api_call(
"conversations.open",
users=["W1234567890","U2345678901","U3456789012"]
)
To create a link to a user's profile, try following the steps on this page:
Create the link by combining your Workspace URL with members’ User IDs. Here’s how:
The first part of the link is the Workspace URL. For example, https://acmeco.slack.com.
The second part of the link is the User ID. Multiple members' User IDs can be found using theusers.listAPI method. Or, an individual's User ID can be found by clicking the More actions icon in a member's profile, then choosing Copy member ID.
Append the User ID to the end of the Workspace URL. Here’s an example: https://acmeco.slack.com/team/U1H63D8SZ.
Using that same User ID, use the conversations.open API method to create a DM/multi-person message with the target user:
from slackclient import SlackClient
slack_token = os.environ["SLACK_API_TOKEN"]
sc = SlackClient(slack_token)
sc.api_call(
"conversations.open",
users=["W1234567890","U2345678901","U3456789012"]
)
edited Nov 14 '18 at 15:46
answered Nov 14 '18 at 15:40
Adil BAdil B
4,36592538
4,36592538
1
Thanks for the ideas. The user profile link you suggested is exactly right, but the problem is if I reference the https:// ... in a message then the desktop Slack app will open a browser window (rather than just open the profile within the slack app). The suggestion works fine if web only. I'll dig into the second idea, multi-party chat is a great idea!
– krsyoung
Nov 14 '18 at 19:02
add a comment |
1
Thanks for the ideas. The user profile link you suggested is exactly right, but the problem is if I reference the https:// ... in a message then the desktop Slack app will open a browser window (rather than just open the profile within the slack app). The suggestion works fine if web only. I'll dig into the second idea, multi-party chat is a great idea!
– krsyoung
Nov 14 '18 at 19:02
1
1
Thanks for the ideas. The user profile link you suggested is exactly right, but the problem is if I reference the https:// ... in a message then the desktop Slack app will open a browser window (rather than just open the profile within the slack app). The suggestion works fine if web only. I'll dig into the second idea, multi-party chat is a great idea!
– krsyoung
Nov 14 '18 at 19:02
Thanks for the ideas. The user profile link you suggested is exactly right, but the problem is if I reference the https:// ... in a message then the desktop Slack app will open a browser window (rather than just open the profile within the slack app). The suggestion works fine if web only. I'll dig into the second idea, multi-party chat is a great idea!
– krsyoung
Nov 14 '18 at 19:02
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53303307%2fhow-to-add-slack-message-button-to-open-direct-chat-with-a-user%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown