Skip to content

Instantly share code, notes, and snippets.

@azadag
Forked from carlosefonseca/Post to Slack.md
Last active August 29, 2015 14:14
Show Gist options
  • Save azadag/3944432dc3d8821ee768 to your computer and use it in GitHub Desktop.
Save azadag/3944432dc3d8821ee768 to your computer and use it in GitHub Desktop.

Bookmarklet to Post to Slack


Please note that this has a little problem: It posts the links as Slack Bot and not as yourself. You could add your name to the message but doesn't look right.


I've created a little bookmarklet that posts the url of the current webpage to a Slack channel. You have to set your token and the channel name manually but it's all fun and profit from there.

The readable code:

xhr = new XMLHttpRequest();
//                         ---v---                                          --v--            --v--
xhr.open("POST", "https://TEAM_NAME.slack.com/services/hooks/slackbot?token=TOKEN&channel=%23general", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xhr.send(window.location.href);

To get your url/token, go to the Add Slack Integration page, scroll to the bottom and select the Slackbot integration, then change to the tab Remote Controls. Copy the url (or the team name and token) and replace in the code.

Replace general with the channel you want to post to.

I used Bookmarkleter to neatly convert the code to a bookmarklet. Just copy and paste the code there, change it and generate your link.

I have a couple of these on my bookmarks bar, one for each channel I regularly post links to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment