Skip to content

sid77/irc-slack

 
 

Repository files navigation

IRC-to-Slack gateway

irc-slack is an IRC-to-Slack gateway. It is an IRC server that lets you connect to your Slack teams with your IRC client.

(That guy is me)

Slack has ended support for IRC and XMPP gateway on the 15th of May 2018. So what's left to do for people like me, who want to still be able to log in via IRC? Either you use wee-slack (but I don't use WeeChat), or you implement your own stuff.

The code quality is currently at the works-for-me level, but it's improving steadily.

NOTE: after Slack turned down their IRC gateway I got a lot of contacts from users of irc-slack asking me to fix and improve it. I didn't expect people to actually use it, but thanks to your feedback I'm now actively developing it again :-) Please keep reporting bugs and sending PRs!

How to use it

go get ./...  # download the dependencies, currently just github.com/slack-go/slack
go build
./irc-slack # by default on port 6666

Then configure your IRC client to connect to localhost:6666 and use one of the methods in the Tokens section to set the connection password.

You can also run it with Docker.

Encryption

irc-slack by default does not use encryption when communicating with your IRC client (but the communication between irc-slack and the Slack servers is encrypted). If you want to use TLS, you can use the -key and -cert command line parameters, and point them to a TLS certificate that you own. This is useful if you plan to connect to to irc-slack over the internet.

For example, you can generate a valid certificate with LetsEncrypt (adjust the relevant fields of course):

sudo certbot certonly \
    -n \
    -d your.domain.example.com \
    --test-cert \
    --standalone \
    -m your@email.example.com \
    --agree-tos

Then your key and certificate will be generated under /etc/letsencrypt/live/your.domain.example.com with the names privkey.pem and cert.pem respectively.

Authentication

To connect to Slack via irc-slack you need an authentication string. There are three possible methods:

  • User tokens with auth cookies (recommended)
  • Slack app tokens (if you can install apps on your slack team)
  • legacy tokens (soon to be deprecated)

These options are discussed in more detail below. Then just add -key <path/to/privkey.pem> -cert <path/to/cert.pem> to enable TLS on irc-slack, and enable TLS on your IRC client.

User tokens with auth cookie

This approach does not require legacy tokens nor installing any app, but in order to get the token there are a few manual steps to execute in your browser's console.

This type of token starts with xoxc-, and requires an auth cookie to be paired to it in order to work.

This is the same procedure as described in two similar projects, see:

But in short, log via browser on the Slack team, open the browser's network tab in the developer tools, and look for an XHR transaction. Then look for

  • the token (it starts with xoxc-) in the request data
  • the auth cookie, contained in the d key-value in the request cookies (it looks like d=XXXX;)

Then concatenate the token and the auth cookie using a | character, like this:

xoxc-XXXX|d=XXXX;

and use the above as your IRC password.

Alternatively, you can try autotoken.

Slack App tokens

As an alternative to legacy tokens, you can install the irc-slack app on your workspace, and use the token that it returns after you authorize it. The source code of the app is available in this repository, see below for details.

The token starts with xoxp-, and you can use it as your IRC password when connecting to irc-slack.

This is a Slack app with full user permissions, that is used to generate a Slack user token. Note that you need to install this app on every workspace you want to use it for, and the workspace owners may reject it.

Click on the button below to install the app:

Authorize irc-slack

Then copy the token from the resulting page (it starts with xoxp-).

This app exchanges your temporary authentication code with a permanent token. While the app does not log your token, you may rightfully not trust it or want to run your own. In order to do so, you need the two following steps:

  • create a Slack app using their v1 OauthV2 API (note: not their v2 version) at https://api.slack.com/apps
  • configure the redirect URL to your endpoint (in this case https://my-server/irc-slack/auth/)
  • run the web app under slackapp passing your app client ID and client secret, you can find them in the Basic Information tab at the link at the previous step

Legacy tokens

This is the easiest method, but it's deprecated and Slack will soon disable it. Slack has announced that they will stop issuing legacy tokens starting the 4th of May 2020, so this section will stay here for historical reasons.

Get you Slack legacy token at https://api.slack.com/custom-integrations/legacy-tokens , and set it as your IRC password when connecting to irc-slack.

Run it with Docker

Thanks to halkeye you can run irc-slack via Docker. The Dockerfile is published on https://hub.docker.com/r/insomniacslk/irc-slack and will by default listen on 0.0.0.0:6666. You can pull and run it with:

docker run --rm -p 6666:6666 insomniacslk/irc-slack

If you want to build it locally, just run:

docker build -f Dockerfile . -t insomniacslk/irc-slack

Connecting with irssi

/network add yourteam.slack.com
/server add -auto -network yourteam.slack.com localhost 6666 xoxp-<your-slack-token>
/connect yourteam.slack.com

Remember to add -tls to the /connect command if you're running irc-slack with TLS. Also remember to replace localhost with the name of the host you're connecting to, if different.

Connecting with WeeChat

/server add yourteam.slack.com localhost/6666
/set irc.server.yourteam.slack.com.password xoxp-<your-slack-token>
/connect yourteam.slack.com

To enable TLS, also run the following before the /connect command:

/set irc.server.yourteam.slack.com.ssl on
/set irc.server.yourteam.slack.com.ssl_verify on

Also remember to replace localhost with the name of the host you're connecting to, if different.

Gateway usage

There are a few options that you can pass to the server, e.g. to change the listener port, or the server name:

$ ./irc-slack -h
Usage of ./irc-slack:
  -D    Enable debug logging of the Slack API
  -H string
        IP address to listen on (default "127.0.0.1")
  -L string
        Log level. One of [none debug info warning error fatal] (default "info")
  -P int
        Pagination value for API calls. If 0 or unspecified, use the recommended default (currently 200). Larger values can help on large Slack teams
  -cert string
        TLS certificate for HTTPS server. Requires -key
  -chunk int
        Maximum size of a line to send to the client. Only works for certain reply types (default 512)
  -d string
        If set will download attachments to this location
  -key string
        TLS key for HTTPS server. Requires -cert
  -l string
        If set will overwrite urls to attachments with this prefix and local file name inside the path set with -d
  -p int
        Local port to listen on (default 6666)
  -s string
        IRC server name (i.e. the host name to send to clients)
  -u string
        User to drop privileges to after program setup

Deploying with Puppet

You can use the irc-slack module for Puppet by John Bond.

TODO

A lot of things. Want to help? Grep "TODO", "FIXME" and "XXX" in the code and send me a PR :)

This currently "works for me", but I published it in the hope that someone would use it so we can find and fix bugs.

BUGS

Plenty of them. I wrote this project while on a plane (like many other projects of mine) so this is hack-level quality - no proper design, no RFC compliance, no testing. I just fired up an IRC client until I could reasonably chat on a few Slack teams. Please report all the bugs you find on the Github issue tracker, or privately to me.

Authors

Thanks

Special thanks to

  • Stefan Stasik for helping me find, fix and troubleshoot a zillion of bugs :)
  • Mauro Codella for patiently reading and replying for two hours in a private conversation that I used to test the fix at pull/23 :D

About

IRC-to-Slack gateway

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 97.8%
  • Dockerfile 1.3%
  • Shell 0.9%