In this article, we take a look at bots, those programs-with-character that hang around in chat channels and amuse, help, and generally make the day a little more pleasant for those people who talk to them. We'll take a close look at ChatBot, beloved of the participants in the Jabber Developer's room "jdev", which is hosted on conference.jabber.org.
Despite the direction many OS's have taken in the past decade, towards a point-and-click experience (which is in many cases perfectly agreeable as a (G)UI), the command line, beloved by many a Unix hacker and perversely, by some MS Windows aficionados, is here to stay. Whether you're of the bash or C-shell or any other command-line environmental persuasion, the fact remains that a command prompt, where interaction with the computer is achieved through constructing sentences, like
find /haystack -exec grep -l needle \{} \; 2>/dev/null
is simple, powerful, and versatile. None of this mucking around with pointing and clicking, thank you very much.
|
Related Reading
|
Consider for a moment what this command line of the future might look like. More and more people are online. More and more people are permanently connected, whether it be through DSL, cable, or 802.11 technology. And more and more of these people are communicating. Talking. Having conversations. In addition to email and Internet Relay Chat, or IRC, the (relatively) new kid on the block, Instant messaging (IM), is playing a huge part in facilitating these conversations. And in the same way that it's common for us to have a command prompt or three sitting on our graphical desktop, it's also becoming common to have chat windows more or less permanently open on the desktop too.
But when thinking of IM, why stop at conversations with people? The person-to-application (P2A) world isn't the exclusive domain of the Web. Bots, applications or utilities that have their interface as a projection of a persona into the online chat world, are a great and fun way to bring people and applications together in a conversational way.
Interacting with a bot is the same as interacting with a person: type something to it and it replies. And what's more, because of the similarities between a classic command-line prompt and that of a chat window, where you're talking with a bot--both scenarios are text-based--interaction with a bot is scriptable. Furthermore, with voice-recognition software and text-to-speech translations, and a following wind, you could even interact with a bot over the phone! (With SMS (Short Message Service) this is, of course, already possible, and a lot easier to achieve) :-)
|
| |
Natural language processing is still not as widespread as it might be; until then, our conversations with bots, with the delightful exception of experimental programs like Eliza, are usually limited to short phrases that follow a certain pattern. Rather like those phrases that we utter without thinking in our command shells. So it's not unusual for us as people to adapt our mode of speech when talking to bots.
Indeed, why see that as a problem? Conversations in real life are most successful, most fruitful, when both parties are talking at the same level. A not insignificant part of the success of the 3Com Pilot is due to the fact that people learned to interact with it by "speaking" a new language that it could understand: Palm Graffiti. Let us humans, with the massive processing power of our brains, do the "hard" bit of talking the bot's language, and let the bots get on with the trivial, mundane but essential activities of providing us with useful services.
Interaction with a bot doesn't have to be a one-on-one affair. Here are a couple of examples where a bot exists as part of a community or group of people.
Example 1 shows purl, a well-loved "infobot" on the #perl IRC channel, where its a part of the community, volunteering useful information and quirky comments. (See the "Resources" box for more information on infobots.)
qmacro> anyone know where I can get hercules?
purl> someone said hercules was at http://www.conmicro.cx/hercules
qmacro> thanks, purl
purl> no problemo, qmacro
Example 1. purl, an infobot, on the IRC channel #perl |
Example 2 shows a fairly simple bot named frank, that understands a few commands and recognizes certain sentence formulas, to the extent that it can act as a useful assistant in online, chatroom-based meetings, organizing agenda points, and producing and publishing meeting notes.
...
dj> ok, where are we at?
piers> I think we're almost done.
piers> frank, review?
frank> --------------------------------------------------
frank> 1. Confirm problem priority
frank> 1.1. Get confirmation from key user
frank> Note: probably need to speak to Sarah on this
frank> 2. Estimate work
frank> 3. Implement solution
frank> --------------------------------------------------
dj> ok, hrm, I think we need to expand on the
implementation part
dj> 3.1 Confirm scope
dj> 3.5 develop
dj> 3.6 test
dj> 3.7 migration
piers> note on 3.6: need to get Tom involved
dj> frank, publish please
frank> ok, done. Url is http://apollo/plans/prob1.html
piers> thanks, frank
frank> de nada, piers
Example 2. frank, a meeting bot that helps with the mundane side of organizing and publishing meeting notes |
Example 3 shows a more-or-less permanent fixture in the Jabber developer conference room "jdev"--ChatBot, a bot written by Ryan Eatmon in Perl using the Net::Jabber libraries. Available in source code from the Jabber CVS repository, ChatBot is an accomplished and useful bot, providing jdev room participants with useful information such as when someone was last seen in the room, a definition-style glossary of information on various aspects of the Jabber development world, and so on.
%% qmacro has joined
<ChatBot> [qmacro] GUI? We don't need no stinkin' GUI!
<nawik> ?? Chatbot
<ChatBot> [chatbot]: Your friendly neighborhood Channel Bot. Lovingly
crafted in Perl and here for your enjoyment. Remember don't
feed it after midnight and don't ever get it wet.
<temas> !seen qmacro
<ChatBot> qmacro is in the channel right now
<nawik> ChatBot: how are you?
<ChatBot> nawik: does that question interest you?
Example 3. ChatBot in action in the jdev room |
Let's have a look at ChatBot's anatomy, how it works, and how we can interact with it. In the rest of this article we'll see what it takes to get ChatBot running in a conference room on your Jabber server, and control its features.
ChatBot is available from the download site at jabber.org. For the most recent version, 2.0, you'll need version 1.0023 of Net::Jabber and 1.0013 of XML::Stream. Make sure you have these two libraries first before you try to start up the bot.
Unpack the single tarball, and in the new directory chatbot/ that is created, you'll find a number of files, and a plugins/ directory. Here's an overview of the more important files and directory:
| chatbot | The main chatbot program. It's written in Perl, so if you're curious, dive in for a look around. |
| config.xml | The main configuration file. Here you can define various aspects of the bot's behavior: which Jabber server it connects to and how it manages that connection, where to find the code for the features it is to offer, and how those features are defined, and where to find a list of rooms, or channels (ChatBot refers to them as channels, so we will too from now on), it should join. |
| channels.xml | The list of channels the bot should join, and what features it should offer in each, by default. |
| plugins/ | This is the directory that contains the Perl code that provide ChatBot's individual features. |
There's also a PLUGIN_API.txt file that describes the plug-in architecture, new with version 2.0. We'll talk about the plug-ins later.
|
Related Reading
|
After making sure you have the right versions of Net::Jabber and XML::Stream installed, there's very little required to get ChatBot up and running and participating in one of your channels. The first thing to do is to tell ChatBot which Jabber server to connect to, and with which username, password, and resource. (If you already know something about the groupchat protocol, and you're wondering if the resource specified that will define ChatBot's nickname in each channel, don't worry, it's not. That's defined next.)
Use the <jabber> stanza in the config.xml file to specify these values.
On my local Jabber server (hostname localhost), I've created a user
called bot with a password of "pass," with which I can get ChatBot to
authenticate. Correspondingly, the stanza looks like this:
<jabber>
<server>localhost</server>
<username>bot</username>
<password>pass</password>
<resource>ChatBot</resource>
</jabber>
As we're just getting ChatBot to wake up for now, there's nothing else in the config.xml file that we have to modify.
Now we should define which channels ChatBot should join. In the channels.xml file, we can define any number of them; here we'll get him to join two--the kitchen, as "chef", and the study, as "frank":
|
Related Articles
A More Sensitive Mail Notifier |
<channels>
<channel>
<name>kitchen</name>
<server>conference.localhost</server>
<resource>chef</resource>
</channel>
<channel>
<name>study</name>
<server>conference.localhost</server>
<resource>frank</resource>
</channel>
</channels>
Each <channel> definition must contain a channel <name>, the <server> where the groupchat or conferencing service is to be reached (here it's a component connected to my Jabber server on localhost, called conference.localhost), and a nickname for the bot. Unlike people, ChatBot can be in more than one place at once.
OK, we're ready to wake up ChatBot. Start the chatbot script:
[dj@cicero chatbot]$ ./chatbot
and, as shown in Figure 1, we can see ChatBot enter the kitchen as "chef", to join me, "qmacro".
Let's put ChatBot through its paces. As we already know, ChatBot
offers a number of simple features out of the box, so to speak.
One of them is rolling dice to generate characters
for role-playing games, and is represented by the command chargen.
Availing yourself of this feature is simply a matter of invoking a
command that ChatBot recognizes:
!chargen
But it's very likely that if you've just started up ChatBot for the first time, nothing will happen. Don't worry. You can control whether features are available or not, on a channel basis, by using a special command to toggle them on and off. Before we do that, let's look at what features ChatBot has on offer. Entering the following command:
!flags flags
will get ChatBot to show you what features are available in the
channel, and whether they're turned on or off. Notice that the
command itself (!flags) is followed by a password (flags). Command
passwords are defined in the <plugins/> section of the config.xml file.
The password here comes from the <flags/> section:
<plugins>
...
<!-- Plugin to handle toggling the flags in a channel -->
<flags>
<password>flags</password>
</flags>
...
</plugins>
The passwords are there to prevent anyone and everyone from being able to dictate what ChatBot does. (If you're worried about interacting with ChatBot in a public channel, and showing these passwords to all and sundry, don't forget you can also talk to ChatBot directly in a one-on-one chat; many groupchat clients will allow you to do this sort of thing by clicking on a nickname in the list of room members.)
When you run the !flags command, ChatBot will return something like
this:
Here are the current flags for this channel:
dice -> off
eliza -> off
join -> off
last -> off
log -> off
log-private -> off
query -> off
seen -> off
The !chargen command is part of the "dice" feature, and as we can see,
the feature is currently switched off. To switch it on in this channel,
use the !toggle_flag command (or !tog for short). This command is part
of the "flags" feature, so it is governed by the same plug-in configuration
and has the same password:
!toggle_flag flags dice
ChatBot will respond thus:
Toggled flags:
dice -> on
Resources |
Now the dice feature is switched on, we can use the !chargen command:
!chargen
to which ChatBot will respond:
Generating new character: 10, 12, 18, 13, 15, 14
or something to that effect.
There are plenty of features that come with ChatBot that you can play
with. Each feature exists as a script in the plugins/ directory, and is
configured within the <plugins/> section of the config.xml file. Looking
at the response to the !flags command earlier, we can see that out of
the box, ChatBot supports all the features we know and love from the
Jabber Developers' conference room "jdev", running at conference.jabber.org:
eliza: The classic psychotherapist; ChatBot will respond when
addressed directly:
<qmacro> !tog flags eliza
<chef> Toggled flags:
eliza -> on
<qmacro> chef: I'm depressed
<chef> qmacro: I'm sure it's not pleasant to be
depressed.
join: Tracks when all users log in and out, and prints out
a join message if that user has one defined
last: Tracks the last X things a user says in a channel, and
allows you to get those things reported to you
log & log-private: Handles logging of the groupchat rooms
query: a simple mechanism for storing and maintaining information
on keywords
seen: Tracks when all users log in and out, and reports
back the time when they were last seen in the channel
|
However, that's not all. You can add new features to ChatBot using the API described in the PLUGIN_API.txt file. This entails adding a new file in the plugins/ directory and calling a few choice functions to register the new features.
In the next article, we'll look at adding a new feature to ChatBot to perform currency conversions for us. Until then, happy botting!
DJ Adams is the author of O'Reilly's Programming Jabber book.
O'Reilly & Associates recently released (January 2002) Programming Jabber.
Sample Chapter 5, Jabber Technology Basics, is available free online.
You can also look at the Table of Contents, the Index, and the Full Description of the book.
For more information, or to order the book, click here.
Copyright © 2007 O'Reilly Media, Inc.