Replies: 8 comments 1 reply
-
I think we should need to rewrite the |
Beta Was this translation helpful? Give feedback.
-
This at least rewrites the url to the correct one.
|
Beta Was this translation helpful? Give feedback.
-
Awesome! |
Beta Was this translation helpful? Give feedback.
-
Yes. Still haven't figured out how to get it to actually open Slack in a correct way. |
Beta Was this translation helpful? Give feedback.
-
Spent some time starting with what @ovelindstrom posted and modified it for my use case. Managed to get most links to work that I use (not sure about others). There didn't appear to be any documentation on how to translate deep linked messages here, but eventually figured out through trial and error how to format the message identifier. Below is the config that I use, but be sure to populate the org map with the proper subdomains and team identifiers:
Also, may be worth linking this response to another related issue: #158 |
Beta Was this translation helpful? Give feedback.
-
I wrote a more robust version of this which supports team hosts, enterprise hosts, and the generic
Note that I did not add support for
But deeplinks only support IDs rather than names, so only the first could actually be converted. It's possible a regex could be made to match only IDs, but I couldn't find much information about the endpoint or the ID formats it supports so I opted to ignore it. Also JavaScript isn't my language of choice, so there may be bugs and the code probably isn't optimal. module.exports = {
handlers: [
{
match: ({ url }) => url.protocol === "slack",
browser: "/Applications/Slack.app"
}
],
rewrite: [
{
match: [
'*.slack.com/*',
],
url: function({ url, urlString }) {
const subdomain = url.host.slice(0, -10)
const pathParts = url.pathname.split("/")
let team, patterns = {}
if (subdomain != 'app') {
switch (subdomain) {
case '<teamname>':
case '<corpname>.enterprise':
team = 'T00000000'
break
default:
finicky.notify(
`No Slack team ID found for ${url.host}`,
`Add the team ID to ~/.finicky.js to allow direct linking to Slack.`
)
return url
}
if (subdomain.slice(-11) == '.enterprise') {
patterns = {
'file': [/\/files\/\w+\/(?<id>\w+)/]
}
} else {
patterns = {
'file': [/\/messages\/\w+\/files\/(?<id>\w+)/],
'team': [/(?:\/messages\/\w+)?\/team\/(?<id>\w+)/],
'channel': [/\/(?:messages|archives)\/(?<id>\w+)(?:\/(?<message>p\d+))?/]
}
}
} else {
patterns = {
'file': [
/\/client\/(?<team>\w+)\/\w+\/files\/(?<id>\w+)/,
/\/docs\/(?<team>\w+)\/(?<id>\w+)/
],
'team': [/\/client\/(?<team>\w+)\/\w+\/user_profile\/(?<id>\w+)/],
'channel': [/\/client\/(?<team>\w+)\/(?<id>\w+)(?:\/(?<message>[\d.]+))?/]
}
}
for (let [host, host_patterns] of Object.entries(patterns)) {
for (let pattern of host_patterns) {
let match = pattern.exec(url.pathname)
if (match) {
let search = `team=${team || match.groups.team}`
if (match.groups.id) {
search += `&id=${match.groups.id}`
}
if (match.groups.message) {
let message = match.groups.message
if (message.charAt(0) == 'p') {
message = message.slice(1, 11) + '.' + message.slice(11)
}
search += `&message=${message}`
}
let output = {
protocol: "slack",
username: "",
password: "",
host: host,
port: null,
pathname: "",
search: search,
hash: ""
}
let outputStr = `${output.protocol}://${output.host}?${output.search}`
finicky.log(`Rewrote Slack URL ${urlString} to deep link ${outputStr}`)
return output
}
}
}
return url
}
}
]
} |
Beta Was this translation helpful? Give feedback.
-
Not sure if a finicky update caused this to stop working, but I fixed mine by returning let output = {
protocol: "slack",
username: "",
password: "",
host: host,
port: null,
pathname: "",
search: search,
hash: ""
}
let outputStr = `${output.protocol}://${output.host}?${output.search}`
finicky.log(`Rewrote Slack URL ${urlString} to deep link ${outputStr}`)
return output with let outputStr = `slack://${host}?${search}`
console.log(`Rewrote Slack URL ${urlString} to deep link ${outputStr}`)
return outputStr Note Note that a number of optional URL parameters were removed, and will need to be added to |
Beta Was this translation helpful? Give feedback.
-
Final working with v4, solved all warnings, I've updated the wiki. (Change default browser and browser name) // Based on @opalelement's answer https://github.com/johnste/finicky/issues/96#issuecomment-844571182
// Team ID can be found in the browser URL : https://slack.com/help/articles/221769328-Locate-your-Slack-URL-or-ID
// Free, Pro, and Business+ plans => Team or workspace ID starts with a T in https://app.slack.com/client/TXXXXXXX/CXXXXXXX
// Enterprise grid plans => Org ID starts with an E in https://app.slack.com/client/EXXXXXXX/CXXXXXXX
const workSlackTeamMapping = {
// 'subdomain': 'TXXXXXXX',
// 'acmecorp.enterprise': 'EXXXXXXX',
// 'acmecorp': 'EXXXXXXX',
};
const personalSlackMapping = {
// personal slacks
};
const slackSubdomainMapping = {
...workSlackTeamMapping,
...personalSlackMapping,
};
const slackRewriter = {
match: ["*.slack.com/*"],
url: function (urlObj) {
const subdomain = urlObj.host.slice(0, -10); // before .slack.com
const pathParts = urlObj.pathname.split("/");
let team,
patterns = {};
if (subdomain != "app") {
if (!Object.keys(slackSubdomainMapping).includes(subdomain)) {
console.log(
`No Slack team ID found for ${urlObj.host}`,
`Add a correct team ID to ~/.finicky.js to allow direct linking to Slack.`
);
return urlObj;
}
team = slackSubdomainMapping[subdomain];
if (subdomain.slice(-11) == ".enterprise") {
patterns = {
file: [/\/files\/\w+\/(?<id>\w+)/],
};
} else {
patterns = {
file: [/\/messages\/\w+\/files\/(?<id>\w+)/],
team: [/(?:\/messages\/\w+)?\/team\/(?<id>\w+)/],
channel: [
/\/(?:messages|archives)\/(?<id>\w+)(?:\/(?<message>p\d+))?/,
],
};
}
} else {
patterns = {
file: [
/\/client\/(?<team>\w+)\/\w+\/files\/(?<id>\w+)/,
/\/docs\/(?<team>\w+)\/(?<id>\w+)/,
],
team: [/\/client\/(?<team>\w+)\/\w+\/user_profile\/(?<id>\w+)/],
channel: [
/\/client\/(?<team>\w+)\/(?<id>\w+)(?:\/(?<message>[\d.]+))?/,
],
};
}
for (let [host, host_patterns] of Object.entries(patterns)) {
for (let pattern of host_patterns) {
let match = pattern.exec(urlObj.pathname);
if (match) {
let search = `team=${team || match.groups.team}`;
if (match.groups.id) {
search += `&id=${match.groups.id}`;
}
if (match.groups.message) {
let message = match.groups.message;
if (message.charAt(0) == "p") {
message = message.slice(1, 11) + "." + message.slice(11);
}
search += `&message=${message}`;
}
let outputStr = `slack://${host}?${search}`;
console.log(
`Rewrote Slack URL ${urlObj.href} to deep link ${outputStr}`
);
return new URL(outputStr);
}
}
}
return urlObj;
},
};
module.exports = {
defaultBrowser: "Arc",
rewrite: [slackRewriter],
handlers: [
{
match: ({ url }) => {
// Check for both 'slack:' and 'slack' since the property might not include the colon
return url.protocol === "slack:" || url.protocol === "slack";
},
browser: "Slack",
},
{
// Optional. If these work url cannot be converted, open them is work browser
// Login in work workspace unfortunately lands on the personal browser, just copy the link to the work browser
match: ({ url }) => {
const workDomains = Object.keys(workSlackTeamMapping).map(subdomain => subdomain + ".slack.com");
return workDomains.includes(url.host);
},
browser: "Arc", // your work browser
},
],
}; |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I was trying to use a handler to open the Slack links in the Slack.app client on mac but it didn't work. The app opens up but not on the right message. Any thoughts on how to achieve that?
Here is the code I used:
Beta Was this translation helpful? Give feedback.
All reactions