How to build bot using hubot?
In this tutorial, you’ll learn how to develop bot using Hubot.
What you’ll learn
- Build a basic chat bot using Hubot.
What you’ll need
- Node and npm
What is Hubot?
Hubot is your scriptable robot friend. Hubot is open source, written in CoffeeScript on Node.js
You can use Hubot to automate your tasks, deploy website, test your apis and a lot more.
Getting Started with Hubot
Step 1: Install node
Step 2: Install Hubot Generator
Open terminal and run the following:
% npm install -g yo generator-hubot
Step 3: Make a bot called ‘hodor’
% mkdir hodor
% cd hodor
% yo hubot
Now, you will be asked a few questions like who is creating the bot and adapter you want to use.
Ignore adapter part for now, will come to it in our next blog,“Integrate Hubot to your Slack”.
Step 4:Run the functional hubot inside “bin/hubot” folder
Hodor will reply with PONG.
Type hodor help to see the list of commands supported.
Now to the “hodor” folder in your system.
You can add your scripts inside “scripts” folder. Read more about coffeescript here.
Open “example.coffee” in editor.
Add the following after ‘module.exports = (robot) ->’
robot.hear /hi|hello|hey|/i, (res) ->
res.reply ‘hey, whats up’
robot.respond /what is your name/i, (res) ->
res.reply ‘Hodor Hodor Hodor’
Stop and run hubot again by % bin/hubot
In script, if you want hubot to reply to chat which is directed to him, use robot.respond
If you want hubot to reply even if it is not directed to him then use robot.hear
Type any of hi, hello, hey and Hubot will reply with “hey, whats up”
Type “hodor what is your name” and you will get the reply “Hodor Hodor Hodor”.
Congrats for building your first bot.
Next we will cover adapters and how to integrate bot with Slack.
Subscribe to our newsletter to learn more about bots.