Episode: 2048 Title: HPR2048: The Hubot chat-bot Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2048/hpr2048.mp3 Transcribed: 2025-10-18 13:42:53 --- This is HPR episode 2048 entitled The Huat Chatbot. It is hosted by John Huat and in about 22 minutes long, the summary is an introduction to The Huat Chatbot. This episode of HPR is brought to you by An Honesthost.com. Get 15% discount on all shared hosting with the offer code HPR15 that's HPR15. Get a web hosting that's Honest and Fair at An Honesthost.com. Hi, this is Ken Remindy, new to go over to podcastawards.com and vote for Hacker Public Radio. Every day this week, right up until Sunday, every vote counts. Thank you very much. Hello and welcome to another edition of Hacker Public Radio. My name is John DeWart and today I would like to talk to you about my current chatbot of choice, Huat. So there's tons of chatbots out there and I'm not saying that Huat is the greatest but it happens to be the one that I'm using currently so I thought I would share with the community a little bit about it. So one of its biggest differentiator is that unlike a lot of the chatbots that are geared specifically toward IRC. But has a slew of adapters. So it can run on anything from IRC to Skype Chat, to XMPP, to HIP Chat, to Slack and Mattermost and all those things. Pretty much anything you want to run it on, there's already an adapter for it and if there isn't, you can write your own. So it's written by the folks at GitHub in Node.js and the bits that you interact with to extend Huat to do your bidding are written in CoffeeScript. So Huat uses individual CoffeeScript scripts to provide the chatbot functionality and there's a slew of existing scripts available in the MPM which is the Node package management community. So you can just go to mpmjs.com and search for anything with the keyword, Huat-scripts in it and you're likely to find something that would interest you. You can also write your own in order to make sure that Huat can provide the functionality that you specifically are interested in. So let me start out with walking you through what it looks like to install Huat. So it's an available as an MPM package to install on top of Node.js or using Node.js. So you'll need to install Node.js and MPM first. I am not going to go through that install. There's either available in your package repos or you can go to the Node.js website to go check it out and download the latest and greatest one and install that on your system. However, having been through this myself, I will give you a cautionary bit of advice. If you are using an ARM-based processor such as that in the Raspberry Pi, you want to make sure that you are using a distribution that is using the ARM-HF or hard-float architecture rather than the ARM-softfloat architecture which is abbreviated as ARM-EL. So if you just look through your distribution packages and if they all contain the architecture ARM-HF, you're good to go. If your ARM-EL, then you're going to have some pain installing Node.js because my experience was that it's not fully supported there. But once you have Node.js and MPM installed, you can install Huat and its dependencies with just installing a generator script that GitHub includes as an MPM install. So you'll install the following MPM packages, Huat, Yo, that's YO, Generator, Dash, Huat and Coffee Script. So those are the dependencies and what that's going to do is install all the Huat dependencies and then it's going to kick off the Huat Generator as a human generator project. And I'll include the exact details in the show notes so you'll know what to type in there. So one of the other caveats is that you'll need to do this as a non-root user because the Generator also sort of deploys Huat as its own Git repository, a fresh Git repository that you can then add a remote to and push to your own remote Git server and manage it that way. You probably want to do it as a separate user with its own home directory that is not your every day user. So for this example, I'll use the user, I'll just create a user to do that in. When you fire off the Generator script, it will ask you for some information that Huat needs in order to build itself. There are four specific pieces of information that it needs, the owner, the name of the bot, a description of the bot and the adapter that you would like to use. And so those can either be added on the command line when you kick off the actual Huat human generator, which is done, sorry, so after you get all that stuff installed that I just talked about, you're going to run the human generator script itself with human. So that would be y-o, space, Huat. And you can just use that and go through the interactive install or you can add the answers for the owner, the native description of the adapter as command line flags to the Yo Huat command as well. So in my example, I will call my Huat, my bot. I will give it a description of my helpful robot. And for this example, I'll be using the shell adapter, which rather than hooking up to a specific chat infrastructure just to allow you to play with it at the command line. So then you can use, run the Huat command, it will dump you to a Huat shell, and then you can play with the various scripts provided, and then work on developing your own. You can then accept the rest of the answers as defaults with the dash-defaults flag on that command. So once you've got Huat installed with the human generator, so as I said, so if you've got a dedicated user, it's going to create all the necessary files at the root level of that user. It's going to create a git-ignore file. It's going to actually execute the initial git-comment. So I guess I should preface this before you actually run the Yo Huat command for that user. You should have git installed to get a clean experience, and you should also add the inappropriate user name and email for git to make sure the git is fully configured for that user before you kick off the Huat command. So once Huat is installed, as I said, so you've got a clean install. If you do a git status, it's going to say everything is clean. There's nothing to commit. If you do a git log, there'll be one commit for the initial commit, and that will allow you to manage your Huat, move it to another computer if you like. So this is very convenient. So if you have a more powerful machine that you want to do development on, and then push it to a Raspberry Pi, after you've committed those changes, it runs very well on the Raspberry Pi, but it is fairly slow to do development work on. I've also run it in a Docker container, it works well there as well. So to kick the thing off, after the human script is installed, it will also include a script to actually run Huat itself in a bin directory, which the generator also installed. So in the home directory of the user that you created, there'll be a bin directory, and there'll be a Huat command there, and you can give it the adapter that you'd like to use. So I think by default it uses Shell, but just to make this completely explicit, we'll go ahead and add the dash, dash, adapter flag to that command until it to use Shell. So that will actually walk the tree of all the installed RPM modules, build Huat and fire it up, and it'll be ready to go, and you'll get a Huat prompt. And at the Huat prompt, you're ready to start interacting with Huat. So essentially you could just use that prompt as a chat-based interface to start playing with it. And one of the sample commands that it comes with is a ping command to make sure it's up and running. So you can start with Mybot in order to make sure that you're addressing the bot specifically and give it the command ping. And then the bot will respond with the phrase Pong to let you know that it's up and running. So that's sort of the hello world. If everything went well, you get a prompt, you type in Mybot and SpacePing, you should get back a Pong. And now Huat is golden. So we can take a look at what other commands were installed by default by asking Huat for some help. So we'll type Mybot and SpaceHelp at the Shell prompt, and you'll get back a list of the various commands that Mybot won't respond to. So there's a better dozen of those that come out by default. So one of those is echo, where you'd give it the name of the bot, the echo command, and then some text, and the bot would respond by echoing back the text to you. So we can try that out with Mybot, echo, and then hello world. And then it comes back with hello images, response, hello world. That's that to the chat window. Another one is the rules, the rules for all bots. So you enter the name of the bot, Mybot, and then the phrase, the rules. And Huat will return the four rules, the Isaac Asma's rules for robotics. Let's see. So those are a good place to start and give you an idea of how the thing works. But the most exciting thing about Huat is the ability to add your own scripts. So you can add canned scripts. So if you go back to the NPM website and search for the Huat scripts, again, you'll come up with a ton of those. So I'll give you an example about how you install those. So once you find a Huat script that you like, or you think it would be useful to you, you can go back as that user that you designated for Huat and get out of the shell, you'd do this at the command line, and you'll execute an NPM install and then the name of the script. So I will do the example one of the Simpsons Huat plugin with NPM install, Huat-Simpsons. And then that will go ahead and install. So that installs the script, but it doesn't tell Huat itself that it's available for use. So the root of the home directory, you'll see a JSON file called external dash scripts. That contains a list of the NPM scripts that are available for it to use. And you can just add in the Huat-Simpsons script to that array. So once you add that in there, and you do, for curiosity, if you do a git status, you'll see a couple of files that are available to add for the NPM Simpsons module itself, as well as the changed file the external dash scripts.json that reflects the change that you made to add the Simpsons plugin. So at this point, the Simpsons plugin gives you a couple of different things. You can get a Simpsons image, or you can get a Simpsons quote. If you need help, again, you can do mybot help, and that'll give you all the commands, where you can do mybot help, and the specific command that you're interested in. So in this case, you can do mybot help Simpsons, it'll tell you what the interface is for the Simpsons plugin. So we'll go ahead and do mybot Simpsons quote, and the plugin goes out and slurps down Simpsons quote. The one that I got back was DiscoSto, likes Disco. So that's how to add pre-baked scripts. The other thing you can do is write your own. Hubot includes an example file that'll show you all the ways that you can architect your coffee script to interact with with Hubot itself. You add these to the scripts directory, and these are added automatically when you fire up Hubot. Any copy script that you add to the scripts directory, you do not have to touch another file. As soon as you relaunch Hubot, that will be available to you. So if you currently look in the scripts directory, you'll see an examples.coffeescript that was included on the install. There's a whole bunch of stuff in there. So I'm going to pluck out one little section of there for the Hal9000 that will respond to requests to open doors. We'll modify that a little bit. Just take that chunk, wrap it up into its own script. We'll call it Hal9000.coffees. And what it will do is if we happen to ask the bot to open French doors, it should respond. Happily respond, it will be able to do that. But if we ask it to open the pod bay doors, it should deny that request. So I'll have the copy script in the show notes. It's fairly simple. There's the two primary ways that Hubot interacts with stuff typed in the chat room is either directly by responding to something. So it uses the robot dot respond method. So if you use the call out your bot specifically, it will then respond to the rejects pattern as defined in the scripts. The other one is the here method, so robot dot here. In that case, it doesn't need to be called explicitly. Like if you type in something and don't talk about the bot at all, but it finds a phrase that it should be responding to, it will hear that and then perform an action appropriate to that particular input. So yeah, so here this is just a simple if statement, so it will respond to a rejects starting with open the and ending indoors, and then it will it has some conditional logic. If the matched group between open the and doors is pod pod bay, then it will not open the doors. And for any other door, it wouldn't gladly open that. So with the script written and put in the scripts directory, we'll restart hubot with the shell adapter that gets us back to the shell. We type in my bot, open the French doors, and hubot responds with opening the French doors. And then when we enter my bot, open the pod bay doors, hubot responds with I'm afraid I can't let you do that. Let's see. Oh, one of the, yeah, this is a minor feature, but it's super helpful. So obviously you don't want to give your bot a long name. If you're using a lot, you'll be typing that in. But one of the other cool things is that you can give your bot an alias. So instead of just, instead of typing out your bot's name, you can alias it to as little as a single character. So I alias mine to just the exclamation point. So that way if I want to address my bot rather than typing in my bot, I can just use the bang or exclamation point and execute the same command. So that's done. Also on the command line, when you fire out, you'll use the dash dash alias flag. And once that's up and running, you just go exclamation point, open the pod bay doors, and hubot responds to that alias, I'm afraid I can't let you do that. So I find that it saves you a lot of typing, super helpful. It's also easy for people to see in the chat window. Just that single odd character is actually easier to grok than a name that sort of gets lost in the rest of the text. Let's see here what else do I want to talk about. The adapters. Sure. So obviously you're not going to use the shell adapter. That's not very useful in production. But there are tons of them out there. If you want to use it in IRC, it's available. I personally am using the XMPP adapter with my EJ Aberdee server and just have a couple of different group chat rooms that I have added to the bot too. And then it just responds to commands. So I hope this sounds interesting to you. Please do check out the hubot project on the, I'll have a link to that project in the show notes. You can find it at github. So it's at hubot.github.com, again written by the github folks. You can do a bunch of different stuff with it, you know, as entertaining stuff like the Hal9000 script that we just went through, there's also a pre-packaged eight ball script, which is fun. You can ask the magic eight ball questions and it will respond. And there's also a Twilio plugin for it. So you can give it your Twilio credentials and then that allows you to do things like send text messages to numbers that you would enter in the chat room as well. So I've customized that myself to actually alias the, you know, my family members' names to their mobile numbers so that I can just send them SMS messages directly from the group chat rooms. And that's just as simple as a, you know, my bot SMS and then the person's name and the message that they want to send and then the bot will let you know that when it was able to send that correctly. And that's all I've got. Check it out. I hope you find it interesting. And you know, send in your own shows to HackerPublic Radio. Take care. Bye-bye. You've been listening to HackerPublic Radio at HackerPublicRadio.org. We are a community podcast network that releases shows every weekday Monday through Friday. Today's show, like all our shows, was contributed by an HPR listener like yourself. If you ever thought of recording a podcast, then click on our contribute link to find out how easy it really is. HackerPublic Radio was founded by the digital dog pound and the Infonomicon Computer Club and is part of the binary revolution at binrev.com. If you have comments on today's show, please email the host directly, leave a comment on the website or record a follow-up episode yourself. On this otherwise stated, today's show is released on the Creative Commons' Attribution