This article is written by a student studying JS instead of a memo. Don't expect the content.
This time it will be done on Ubuntu, so start the virtual environment with iTerm2.
Where it started
Move to the directory where Ubuntu is installed. vagrant up is a command to start Ubuntu installed on a virtual PC, and vagrant ssh connects to SSH with the Vagrant virtual machine set.
yo is a template creation tool called Yeoman. generator-hubot is a Yeoman generator (generator-hubot) for Hubot. Install coffeescript because it is necessary to handle hubot with JS.
The above content is to create a bot with the command yo hubot
, and after that, use slack as an adapter.
If you can answer multiple questions, your bot's project will be created.
Done in seconds.
If it comes out, it is a success.
'use strict';
module.exports = (rbot)=> {
rbot.hear(/hello>/i, msg => {
msg.send(`Hi`);
});
The first line is the description for using JS in strict mode.
The second line uses module.exports to store the value directly in a variable called rbot. module.exports allows you to read specified values from other js files and reuse them. The difference with exports, which is a bit similar, is that you can store the value directly without setting any properties. See below for the description method.
module.exports.Property name=value
The third and subsequent lines are module functions that return hi in response to the word hello. To react to a specific content, use the methods hear and respond (almost the same purpose) of the Robot class. See below for the description method.
(Regular expression you want to match,Callback function called when a regular expression is matched)
Also, use send and reply (almost the same purpose) to post a statement in a chat. See below for the description method.
```send(String
);
Source (https://gihyo.jp/dev/serial/01/hubot/0004)
# 4. Try moving hubot
Try moving the bot with the following command, and if it responds correctly to the character string specified earlier, it is successful. Thank you for your hard work!!!!
```bin/hubot
Quoted below (https://gihyo.jp/dev/serial/01/hubot/0001)
A program that resides in a chat tool and listens to and executes commands via chat, or speaks to a chat according to certain conditions and notifies chat participants is called a bot.
There are various frameworks in the world for creating bots for each development language and chat tool. For example, ikachan is famous for making IRC bots in Perl, and twittbot is famous for making Twitter bots in Web services. Hubot is a framework for creating and running bots with Node.js developed by GitHub and released under the MIT license. A major feature of Hubot is that it supports various chat tools. For example, ikachan, which I mentioned earlier, is a framework for creating bots for IRC, and cannot be used for the purpose of creating bots for Twitter. On the other hand, twittbot is for Twitter only, and you cannot make a bot for IRC. However, Hubot can connect to various chat tools by switching the "Adapter", which is a module that connects Hubot and chat tools.
The Adapter plays the role of inputting the chat status such as a statement input by someone to the Robot from the chat tool and transmitting the output created by the script to the chat tool. In the initial state, a shell adapter that can interact with Hubot on the shell and an Adapter called Campfire Adapter that connects to a chat tool called Campfire are included. There are a variety of Adapters available from third parties, so most of the time you'll find an Adapter for your chat tool.
Recommended Posts