Guide on how to implement link unfurling in slack
These instructions will guide you on controlling unfurling of links tied to your domain(s).
You'll need the following tools to setup your environment:
- Clone the repo
- Run
npm install
to install all the packages - Run
npm run-script run
to start up the node app - In a separate command console run
./ngrok http 1337
- Go to Step 1 - Your Apps page
- Click on Create New App
- Set the App Name and select the workspace to Develop the app
- Copy the Client ID, Client Secret and Signing Secret values to config.json file
- Click on Event Subscriptions
- Enable Events
- Set the Request URL to be ngrok's session url
- Subscribe to Link Shared event
- Add the domains you want to be notified of when shared
- Save the changes to Event Subscriptions, it should look like this:
- Click on Bot Users - Need this for the botkit library we are using to interface with Slack
- Fill out the bot user info
- Click on OAuth & Permissions to set up the Scopes and get Tokens
- Add the following to Permission Scopes:
- Click on Install App to Workspace to add the App to your workspace
- Verify the permissions request by the app and authorize the app
- Copy the OAuth Access Token and Bot User OAuth Access Token to the config.json file
- From your Slack channel (any!) type in http://example.com and see it unfurl!
- Now try passing http://example.com https://example.com
Currently in LinkSharedHandler.js the following block of code explicitly handles cases of one and two urls:
const unfurls = {};
unfurls[message.event.links[0].url] = {
'text': 'testing 1',
};
if (message.event.links.length > 1) {
unfurls[message.event.links[1].url] = {
'title': 'testing 2',
'title_link': 'https://example.com',
'text': 'testing 2',
'fields': [
{
'title': 'Testing 2',
'value': 10,
'short': true
}
],
'actions': [
{
'name': 'Testing',
'text': 'Testing 2',
'type': 'button',
'value': 'testing'
}
]
};
}
This is done purely to demonstrate sending back of simple text message for the first link and an interactive message for the second link if one is passed.
More often than not you'll have same format for urls matching specific domains so processing of the links can be done via map function.
Need to add testing! I have tried out botkit-mock but was unable to figure out how to set up track events :\
This project is licensed under the MIT License - see the LICENSE.md file for details