Site icon The Ultimate Linux Newbie Guide

Use Slack in the Terminal using finch (or irc)

Corporations often use the chat client by Atlassian called Slack. If you are a Slack user, there’s a chance that you might work in software development, or work on the command line a lot. If you prefer to work using text-mode, then there is a libpurple plugin called slack-libpurple that allows you to do just that. Libpurple is a library that allows you to ‘plug-in’ to many different protocols, such as XMPP, IRC, Bonjour and Sametime.

The Slack libpurple plugin that we will be using can be obtained from the following git repository: https://github.com/dylex/slack-libpurple

NOTE: Before we begin, two-factor authentication for Slack is currently not supported by slack-libpurple, so you will need to disable it in your Account Settings if you currently have it enabled, press the ‘expand’ button next to “Two-factor authentication”:

Installing slack-libpurple

To install the slack-libpurple library and finch

sudo apt install libpurple-dev finch git

Clone the slack-libpurple repository by typing:

git clone https://github.com/dylex/slack-libpurple.git

then change directory into the slack-libpurple dir:

cd slack-libpurple

then build the application from the source code for all users:

sudo make install

(or if you prefer just to install it for yourself then make install-user).

Get your Slack details

You’ll need to get your Workspace URL and your member ID from https://app.slack.com/client/

There are two steps to this task: The first part is to get your workspace id. For example: a1marketing.slack.com. My one is a bit more obscure, it looks like a1marketing-9ut1x7141.slack.com. You can get the workspace URL by clicking on the dropdown of your company name (e.g. A1 Marketing) in the left hand side of the web UI, then click on Tools & Settings, then finally Workspace Settings. A new browser tab opens up and it will have the full workspace URL in it. If you use the URL, make sure you don’t keep the https:// and the “admin/settings/” part of the URL, i.e. all you want is a1marketing-9ut1x7141.slack.com

The second step is to get the user ID. An individual’s user ID can be found by clicking the More button in a member’s profile, then choosing Copy member ID. Multiple members’ user IDs can be found using the users.list API method.

To get your own user ID, click on your own profile in the Slack web UI, then click the small down arrow beside your name:

When you click the down arrow another side box comes up, click on ‘View Full Profile’.

Now click on the 3 dot button and click ‘Copy member ID’. This will give you something like U1234567890. This is your username.

Finch (and Pidgin)

Finch is the text mode client that uses ncurses. If you prefer, you can use an IRC client such as irssi or weechat, however you will need to use the bitlbee bridge to enable that. For a graphical client, Pidgin is your friend: https://pidgin.im. The following screenshot is what Slack looks like in Pidgin:

To start finch, simply type finch from the command line.

Account Configuration

Finch is built using the ncurses toolkit, which is a library designed especially to built text user interfaces. To navigate in a Finch window, use Tab to focus the next widget (option, tickbox, button), Shift+Tab to focus the previous one, Space in order to tick/untick an option, and Enter to ‘click’ a button. You will also need to press Esc to exit from menus such as the Actions menu.

The first time it starts, Finch automatically opens the accounts window (or if you need to get back to it, press Alt+A). To Add an account, press tab until you can select the Add button and press Enter. In the window that appears – New Account – use the arrows to select the Slack from the list of Protocols, and then use Tab to navigate to the next field, fill it in with your data, and so on:

The username is your email address that you use for Slack (e.g. bob@a1marketing.com). However, this didn’t work for me, so if you also get an “unknown_method” error, then you will need to use the member ID / user ID you got earlier from the Slack Web UI.

Host is the workspace ID you got earlier (eg a1marketing.slack.com).

Enable the relevant options you want and tab down to Save. Press enter. You will now see the Accounts dialogue with your Slack account. Enable the account by pressing space on the Slack account, an X will appear between the square parenthesis.

Press Alt+C to close the Accounts menu and you will now see your buddy list, you can move up and down with the cursor keys.

You may wish to enable the history plugin to see your previous messages. To do this, press Alt+A, then cursor down to Plugins, then in the Plugins menu, cursor down to GntHistory and press space to enable GntHistory. Press tab twice to go to Close and press Enter.

Navigating Finch

Alt+Q – quits Finch, getting back to bash

Alt+A – opens the Actions menu, which contains everything you need to configure Finch: accounts, buddy lists, file transfers, plugins, sounds, preferences and statuses; use the Esc key to close this menu when you’re done

Alt+C – closes the currently opened window

Alt+N – switch to the next window; you will need this to switch between chats, and other openend windows

Alt+P – switch to the previous window

Moving and resizing windows
There are two important shortcuts here, which will help you to:

1. Move windows in Finch
For this, use the Alt+M keyboard shortcut. This will highlight the currently selected window so you will be able to use the arrow keys in order to move it anywhere inside the terminal; use Esc to deselect it when you’re done.

2. Resize windows in Finch
Press Alt+R in order to highlight the currently selected window, then use the arrow keys to resize it; press Esc to deselect it when you’re done.

Advanced finch configuration

To configure Finch, press Alt+A, which will open the Actions menu. Here you can edit accounts, enable/disable plugins or configure general Finch preferences. For more information on how to configure Finch, type man finch from the command line.

The configuration files and the logs can be found inside the ~/.purple/ directory, where ~ is your home directory. Notice that .purple is a hidden directory.

The accounts.xml file contains all the slack account configuration items, however you shouldn’t need to edit this file directly.

The ~/.gntrc file
This file allows you to configure Finch in more detail, including colors for its interface, re-binding keys, change keys for various Finch actions, and even enable mouse support.

Here’s how to enable mouse support. Open up a text editor and edit (or create if it doesn’t already exist – and it probably won’t) the ~/.gntrc file:

nano ~/.gntrc # or gedit ~/.gntrc

Next, add the following lines in this file, then save it:

[general]
mouse = 1

Notice that if the file is already created, you should find the section [general] and set the mouse option to 1 (true).

Using IRC instead

If you prefer to use a terminal (or gui) IRC client instead, then no worries. Now that you have set up the basics, all you need to do is install bitlbee-libpurple and use that as your IRC gateway:

sudo apt install bitlbee-libpurple

Check to see if bitlbee has automatically started:

ps ax|grep bitlbee
 145974 ?        Ss     0:00 /usr/sbin/bitlbee -P /var/run/bitlbee.pid -F

The above shows bitlbee running. If it isn’t running. start up the bitlbee service:

sudo /etc/init.d/bitlbee start (or use sudo systemctl start bitlbee or whatever your system calls it)

Next, start up your IRC client of choice like irssi, weechat etc and point it to bitlbee running locally:

$ weechat

You can use weechat to automatically connect to your bitlbee server when you start up your bitlbee client by setting the server autoconnect option from weechat like follows (you can do similar in other irc clients):

/server add bitlbee localhost -notls -autoconnect

Next time you start up weechat, you should be shown a welcome screen from the bitlbee server. You can change the content of this in the /etc/bitlbee/motd.txt file.

Now we have to add your slack account into your bitlbee configuration. To do this, we need to move to the &bitlbee channel. In weechat you press Alt+RightArrow to move to the second window. In irssi, you type /win 2.

If you type help purple, you should see a list of account types that libpurple will support to through the bitlbee interface. Slack is on my list.

First up, we should register an identity with bitlbee, so that it doesn’t forget your account settings every time you quit irc. To do this, we use the register command:

register <password>

Naturally you should keep whatever you set as <password> secure, because this is like the master password for any account details you are going to set up with bitlbee, including Slack.

Next time you connect to your bitlbee server, simply type the following so you don’t have to set up your slack accounts all over again:

identify <password>

Ok, now it’s time to add your account. Enter the following in the &bitlbee chat channel:

account add slack U123456790%workspace.slack.com

Where the name U123456790 is your member ID from earlier, and workspace is your workspace ID. The slack-libpurple git page says to use “user@example.com%<workspace>.slack.com“. This may work for you if you can use your username@domain.com member ID, if not, forget that and just go for your U1234567890 member ID like I did.

Once you’ve got that set up, you’ll need to set the slack account password:

account slack set password slackpassword

Obviously replacing slackpassword with your own slack password.

Next, activate your account by typing:

account slack on

With any luck, you’ll see the following messages appear to indicate the connection has been successful:

@root │ slack - Logging in: Looking up team                                                                                     
@root │ slack - Logging in: Finding user                                                                                          @root │ slack - Logging in: Logging in                                                                                           @root │ slack - Logging in: Requesting RTM                                                                                         @root │ slack - Logging in: Connecting to RTM                                                                                      @root │ slack - Logging in: RTM Connected                                                                                         @root │ slack - Logging in: Loading Users                                                                                       
@root │ slack - Logging in: Loading conversations                                                                                @root │ slack - Logging in: Loading active conversations                                                                          @root │ slack - Logging in: Logged in

Finally, you can add common chat channels that you participate in, for example, if you are often a member of the channel #technical, then simply type:

chat add slack technical
/join #technical

The rest of the use of IRC is pretty standard, obviously the use of it differs slightly between IRC clients, but the standard stuff like messaging remains the same. For example – /msg <user> hello would initiate a DM/chat with <user> saying hello. It will open a new chat channel for direct messages.

And now, it’s time to /quit from this article! I hope you have found it helpful!

Exit mobile version