Skip to content

Instantly share code, notes, and snippets.

@carlosefonseca
Last active August 30, 2023 08:12
Show Gist options
  • Save carlosefonseca/10054847 to your computer and use it in GitHub Desktop.
Save carlosefonseca/10054847 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.

@xk4r00t
Copy link

xk4r00t commented Jun 1, 2019

Thanks !

This is to post a payload in channel by webhook :

xhr = new XMLHttpRequest();
xhr.open("POST", "https://hooks.slack.com/services/AAAAAA/ZZZZZZ/xxxxxxxxxxxxxxx", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xhr.send('payload={"text": "*This* is a line of text in a channel.\nAnd this is another line of text."}');

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