Instant messaging (IM) is one of the great time sinks of our age. Emacs-users, social butterflies as we are, of course want to take part in that -- preferrably from the comfort of our own environment.
There are various ways to use services like MS Live Messenger, Facebook Chat, GTalk, Yahoo etc. from within emacs – the one I use is called BitlBee. BitlBee is a program that presents all the various forms of IM as IRC-channels. In other words, while BitlBee knows all the details about communicating with these networks, all you need is an IRC-client to connect to BitlBee. This IRC-client does not have to be Emacs-based - any client can be used - but I am using ERC. Note, the below assumes you are somewhat familiar with it.
So, let's see how we can set up BitlBee on our system; there are public BitlBee-servers available online, but in the case of IM, I wouldn't necessarily want to trust them with my account data… so I'm using my own.
Setting up Bitlbee
So, how can we set this up? First, install BitlBee – many distributions have ready-made packages, otherwise you can build from source. In the examples below, I am assuming you are using Bitlbee version 3 or higher; if you use a different version, the details will vary a bit.
You can either run Bitlbee as a system-wide daemon, or just use it on your own. I am doing the former (for the latter, bitlbee.el is useful).
To connect ERC to the Bitlbee daemon, you can use something like the following:
(defun i-wanna-be-social () "Connect to IM networks using bitlbee." (interactive) (erc :server "localhost" :port 6667 :nick "user"))
I'm sure you can come up with a better nick than user
… Anyhow, with this
function in your ~/.emacs
, we can connect to bitlbee with:
M-x i-wanna-be-social RET
This should connect us to BitlBee; when all goes well, this will look something like this:
*** You have joined channel &bitlbee *** mindcrime has changed mode for &bitlbee to +t *** Users on &bitlbee: @user @root *** Topic for &bitlbee: Welcome to the control channel. Type help for help information. <root> Welcome to the BitlBee gateway! <root> <root> If you've never used BitlBee before, please do read the help information using the help command. Lots of FAQs are answered there. <root> If you already have an account on this server, just use the identify command to identify yourself. <root> The nick is (probably) not registered *** &bitlbee modes: +t <ERC>
Now, this first time, you will need to register yourself (this is only
needed once); use the same nick (user
in the example) that you used before:
<user> register user secretpassword <root> Account successfully created
We're registered! This means, that bitlbee knows about you, and will save your settings.
Re-entering bitlbee
Just to complete the bitlbee-connecting part: the next time you want to use
bitlbee
, use i-wanna-be-social
as before. However, now you need to
identify
yourself (rather than register
):
<user> identify user secretpassword <root> Password accepted, settings and accounts loaded
This can be automated by adding something like the following to your config:
(defun bitlbee-identify () (when (and (string= "localhost" erc-session-server) (string= "&bitlbee" (buffer-name))) (erc-message "PRIVMSG" (format "%s identify user secretpassword" (erc-default-target) djcb-bitlbee-password)))) (add-hook 'erc-join-hook 'bitlbee-identify)
Modify user
and secretpassword
as desired. If you don't want write out
your passwords in your emacs config files, take a look at keeping your secrets secret.
Adding accounts
Now, let's add some IM-accounts (just some examples here; also see Bitlbee Quickstart. Note, add any point during this, you can see your accounts with the command:
<user> account list
and using the numbers (or the accounts 'tag') you can switch an account on
(and off
):
<user> account 0 on
There are many other commands – use help
command the consult the built-in
documentation.
Connecting to IM networks
To connect to IM networks, you have to add the accounts to BitlBee. It will save them, so you only need to do that once. Let's do it - in each case, replace user and password with whatever you use for those.
You can see your combined logged-in buddy list using M-x erc-channel-names
(or C-c C-n
). Or use the blist
command (see help blist
).
After adding an account, it's a good idea to issue the save
command, to
ensure that bitlbee saves it.
Jabber
<user> account add jabber foobar@jabber.org mypassword <root> Account successfully added with tag jabber <user> account jabber on <root> jabber - Logging in: Connecting <root> jabber - Logging in: Connected to server, logging in <root> jabber - Logging in: Converting stream to TLS <root> jabber - Logging in: Connected to server, logging in <root> jabber - Logging in: Authentication finished <root> jabber - Logging in: Authenticated, requesting buddy list <root> jabber - Logging in: Logged in
(and of course, you can use other servers beside jabber.org
)
GoogleTalk
GoogleTalk (gtalk
) is implemented using XMPP (jabber), and it's
recommended to use oauth
for authentication. Note, the foobar
below is
just a placeholder (for a password); bitlbee wants us to put something
there, but since we'll be using oauth
, it's not actually used.
<user> account add jabber myaccount@gmail.com foobar <root> Account successfully added with tag gtalk <user> account gtalk set oauth on <root> oauth = `on' <user> account gtalk set nick_source full_name <root> nick_source = `full_name' <user> account gtalk on <root> gtalk - Logging in: Starting OAuth authentication
Now, a second window will open with a URL:
<jabber_oauth> Open this URL in your browser to authenticate: https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.\ com/auth/googletalk&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_i\ d=78312399893489.apps.googleusercontent.com <jabber_oauth> Respond to this message with the returned authorization token.
Follow this URL in your browser, and it will take you to some Google page for authentication. When that is completed, you will receive some string cookie, which you paste back into the newly opened window.
<user> 4/sIns904fdlkP5nudjCF4mBHF7Go_-E0g8 *** jabber_oauth is AWAY: Offline
Et voilĂ ! We're connected to Gtalk (don't worry about the Offline
-warning).
Apart from being a social website, Facebook can also be used for IM. You can
do this through the website, or you can use its jabber interface. It works
very similar to gtalk
; only important thing is that you get yourself a
Facebook username:
<user> account add jabber myusername0@chat.facebook.com <root> Account successfully added with tag fb <root> You can now use the /OPER command to enter the password <root> Alternatively, enable OAuth if the account supports it: account fb set oauth on <user> account fb set oauth on <root> oauth = `on' <user> account gtalk set nick_source full_name <root> nick_source = `full_name' <user> account fb on <root> fb - Logging in: Starting OAuth authentication
Then, go through the oath
-authentication steps (see the discussion about
adding Gtalk accounts above).
Once authenticated, you'll get something like this:
<root> fb - Logging in: Requesting OAuth access token <root> fb - Logging in: Connecting <root> fb - Logging in: Connected to server, logging in <root> fb - Logging in: Converting stream to TLS <root> fb - Logging in: Connected to server, logging in <root> fb - Logging in: Authentication finished <root> fb - Logging in: Server claims your JID is `-748234518@chat.facebook.com' instead of `myusername0@chat.facebook.com'. This mismatch may cause problems with groupchats and possibly other things. <root> fb - Logging in: Authenticated, requesting buddy list <root> fb - Logging in: Logged in
It's to now act upon the warning, so, we log out, change the user name and long back in:
<user> account fb off <root> fb - Signing off.. <user> account fb set username -748234518@chat.facebook.com <root> username = `-748234518@chat.facebook.com' <user> account fb on
MSN / Live Messenger
MSN uses its own protocol (although apparently they're also supporting XMPP
("jabber") now). Suppose you have an account there, user
partygirl89@hotmail.com
with password iamcute
:
<user> account add msn partygirl89@hotmail.com iamcute <root> Account successfully added <user> account msn on <root> msn - Logging in: Connecting <root> msn - Logging in: Connected to server, waiting for reply <root> msn - Logging in: Transferring to other server <root> msn - Logging in: Connected to server, waiting for reply <root> msn - Logging in: Authenticated, getting buddy list <root> msn - Login error: Error reported by MSN server: Invalid (non-existent) handle [12:17] <root> msn - Logging in: Logged in
The 'Error reported' does not seem to matter.
Other accounts
It's similarly easy to setup Twitter-accounts and Identi.ca-accounts; I've stopped using those though, as it turned out to be a little too easy for some typing in the wrong window to end op as a tweet… The risk is less with twittering-mode and identica-mode.
For ICQ/Yahoo/AIM see below – replace the username/password with your own.
- ICQ
<user> account add oscar ICQ-ID PASSWORD login.icq.com <root> ...
- AIM
<user> account add oscar AIM-NICK PASSWORD login.aol.oscar.com <root> ...
- Yahoo!
<user> account add yahoo YAHOO-NICK PASSWORD <root> ...
And I'm not even talking about combining bitlbee and Skype – yes, that is possible, too.
Chatting
Now, chatting is easy, following the normal ERC conventions (and
settings). When people talk to you, a window opens (or a frame – see
erc-auto-query
. And you can initiate conversations with people by using
/msg nick
, with nick
of course being the nickname of the person you want
to talk to.
ERC/Bitlbee also work together nicely with Sauron, the emacs event tracker.
Have fun! I have only scratched the surface here - you now have the full arsenal of Elisp and ERC power available for your chatting.