<h1 id="hubot">Hubot</h1>
<h2 id="intro">Intro</h2>
<p><a href="https://hubot.github.com/">Hubot</a> is a chat-bot written by the folks at GitHub. It is a <a href="https://nodejs.org/">node.js</a> application written in <a href="https://coffeescript.org/">CoffeeScript</a>.</p>
<p>Hubot has a variety of <a href="https://hubot.github.com/docs/adapters/">adapters</a> that allow it to connect to a variety of chat platforms. These range from IRC to Slack. So, the platform
you are interested in probably already has an adapter available for it.</p>
<p>Hubot uses individual CoffeeScript scripts to provide chat-bot functionality. There are a slew of existing scripts available in the npm. Just search for <a href="https://www.npmjs.com/browse/keyword/hubot-scripts">hubot-scripts</a>.</p>
<p>You can also write your own in order to make sure that Hubot provides the functionality that you need.</p>
<h2 id="install">Install</h2>
<p>Hubot is available as an npm package. So, you will need to install node.js and npm on your system. I will leave this as an exercise for the listener.</p>
<p>I will however, throw out a tip for those of you using a Raspberry Pi for this. The node.js platform should be deployed on an ARM system using the armhf (ARM hard float) architecture. The nod
e.js stack needed to run Hubot will not properly install if you are using the armel (ARM soft float) architecture.</p>
<p>Once you have node.js and npm installed, you can install hubot and its dependencies with the following command.</p>
<pre><code>npm install -g hubot yo generator-hubot coffee-script</code></pre>
<p>You create your own instance of hubot by using <a href="https://yeoman.io/">yeoman</a> generator. You need to do this as a non-root user. When you create your bot, you will give it a name and
specify the adapter to use. These can be specified as command line flags, or the generator will prompt you for this information.</p>
<ul>
<li>Owner</li>
<li>Name</li>
<li>Description</li>
<li>Adapter</li>
</ul>
<p>Interactive</p>
<pre><code>yo hubot</code></pre>
<p>Providing the answers</p>
<pre><code>yo hubot --name mybot --description &quot;My Helpful Robot&quot; --adapter shell --defaults</code></pre>
<h2 id="running">Running</h2>
<p>Once hubot is installed, you can run it with the following. I will use the shell adapter, which provides an interactive shell from which to trigger hubot scripts.</p>
<pre><code>./bin/hubot --adapter shell</code></pre>
<p>Our Hubot instance is now active and ready to receive commands. We will start with a simple ping command.</p>
<pre><code>mybot&gt; mybot ping
mybot&gt; PONG</code></pre>
<p>We can see the available commands by asking Hubot for help</p>
<pre><code>mybot&gt; mybot help
mybot adapter - Reply with the adapter
mybot animate me &lt;query&gt; - The same thing as `image me`, except adds a few parameters to try to return an animated GIF instead.
mybot echo &lt;text&gt; - Reply back with &lt;text&gt;
mybot help - Displays all of the help commands that Hubot knows about.
mybot help &lt;query&gt; - Displays all help commands that match &lt;query&gt;.
mybot image me &lt;query&gt; - The Original. Queries Google Images for &lt;query&gt; and returns a random top result.
mybot map me &lt;query&gt; - Returns a map view of the area returned by `query`.
mybot mustache me &lt;url|query&gt; - Adds a mustache to the specified URL or query result.
mybot ping - Reply with pong
mybot pug bomb N - get N pugs
mybot pug me - Receive a pug
mybot the rules - Make sure hubot still knows the rules.
mybot time - Reply with current time
mybot translate me &lt;phrase&gt; - Searches for a translation for the &lt;phrase&gt; and then prints that bad boy out.
mybot translate me from &lt;source&gt; into &lt;target&gt; &lt;phrase&gt; - Translates &lt;phrase&gt; from &lt;source&gt; into &lt;target&gt;. Both &lt;source&gt; and &lt;target&gt; are optional
ship it - Display a motivation squirrel</code></pre>
<p>We will try a couple more.</p>
<pre><code>mybot&gt; mybot echo &quot;Hello world&quot;
&quot;Hello world&quot;
mybot&gt; mybot the rules
0. A robot may not harm humanity, or, by inaction, allow humanity to come to harm.
1. A robot may not injure a human being or, through inaction, allow a human being to come to harm.
2. A robot must obey any orders given to it by human beings, except where such orders would conflict with the First Law.
3. A robot must protect its own existence as long as such protection does not conflict with the First or Second Law.</code></pre>
<h2 id="adding-scripts">Adding Scripts</h2>
<h3 id="npm-scripts">npm scripts</h3>
<pre><code>npm install hubot-simpsons</code></pre>
<p>Add <code>hubot-simpsons</code> to the array in the <code>external-scripts.json</code> file.</p>
<pre><code>mybot&gt; mybot simpsons quote
mybot&gt; Disco Stuâ¦ likes disco.</code></pre>
<h3 id="writing-scripts">Writing scripts</h3>
<p>https://github.com/github/hubot/blob/master/docs/scripting.md</p>
<p>You can add your own custom scripts by adding them to the <code>scripts</code> directory. An <code>examples.coffee</code> script was included when Hubot was installed. It includes a variety of examples of things Hubot can do. I will illustrate by paring this down to a simple single script that responds to requests to open doors. Our simple script will open most doors, but will politely refuse to open the 'pod bay' doors.</p>
<p>The script uses the <code>respond</code> method on the <code>robot</code> module. This method takes a regex patten to respond to. It returns a result that contains a match array when the pattern has been detected. In our script we capture the group between 'onen the' and 'doors'. We then use this to determine which response to provide. The response is triggered with the robots <code>reply</code> method.</p>
<pre><code>module.exports = (robot) -&gt;

 robot.respond /open the (.*) doors/i, (res) -&gt;
   doorType = res.match[1]
   if doorType is &quot;pod bay&quot;
     res.reply &quot;I&#39;m afraid I can&#39;t let you do that.&quot;
   else
     res.reply &quot;Opening #{doorType} doors&quot;</code></pre>
<p>Restart Hubot by...</p>
<p>Now we can use our new, useful Hubot script.</p>
<pre><code>mybot&gt; mybot open the french doors
mybot&gt; Shell: Opening french doors
mybot&gt; mybot open the pod bay doors
mybot&gt; Shell: I&#39;m afraid I can&#39;t let you do that.</code></pre>
<h2 id="aliases">Aliases</h2>
<p>A rose by any other name... If you would like your Hubot to respond to another name, you can assign your Hubot aliases to respond to. I really like this feature and I assign the '!' as my Hubot alias. This allows me to invoke Hubot with a single character.</p>
<pre><code>mybot&gt; ! open the pod bay doors
mybot&gt; Shell: I&#39;m afraid I can&#39;t let you do that.</code></pre>
<h2 id="adapters">Adapters</h2>
<p>Obviously the shell adapter is not very useful aside from allowing us to play with or develop Hubot scripts. Hubot comes with several adapters that allow it to integrate with existing chat systems. These include: * IRC * XMPP * Campfire * HipChat * Slack * IRC * IRC</p>
<h2 id="conclusion">Conclusion</h2>
<p>I hope this gives you a sense of what Hubot can do and how you can utilize it. Personally, I use Hubot in a variety of ways ranging from silly entertainment to useful communication tool. Using the eight-ball script, I can see if I will have a good day.</p>
<pre><code>mybot&gt; mybot eight-ball Will I have a good day?
mybot&gt; Shell: Most certainly!
mybot&gt; :-)</code></pre>
<p>Using a modified version of of the sms script, I can send text messages to my family members who are not available online.</p>
<pre><code>mybot&gt; mybot sms trinity   See you on the other side!
mybot&gt; Shell: Sent sms to 3125550690
mybot&gt; :-)</code></pre>
