[LINUX] I tried using Hubot

Introduction

This article is written by a student studying JS instead of a memo. Don't expect the content.

1. Open a virtual environment

This time it will be done on Ubuntu, so start the virtual environment with iTerm2.

Where it started

  1. Virtual Box 2.Vagrant I use Ubuntu in a virtual environment that uses two software. cd ~/vagrant/ubuntu vagrant up vagrant ssh

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.

2. Install the modules needed to make a bot

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.

3. Make a bot

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.

3. Write a program to run Hubot


'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)

What is a bot

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.

What is hubot

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.

What is an adapter

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

I tried using Hubot
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using aiomysql
I tried using Summpy
I tried using Pipenv
I tried using matplotlib
I tried using ESPCN
I tried using openpyxl
I tried using Ipython
I tried using PyCaret
I tried using cron
I tried using ngrok
I tried using face_recognition
I tried using Jupyter
I tried using PyCaret
I tried using Heapq
I tried using doctest
I tried using folium
I tried using jinja2
I tried using folium
I tried using time-window
[I tried using Pythonista 3] Introduction
I tried using easydict (memo).
I tried face recognition using Face ++
I tried using Random Forest
I tried using BigQuery ML
I tried using Amazon Glacier
I tried using git inspector
[Python] I tried using OpenPose
I tried using magenta / TensorFlow
I tried using AWS Chalice
I tried using Slack emojinator
I tried using Rotrics Dex Arm
I tried using GrabCut of OpenCV
I tried using Thonny (Python / IDE)
I tried server-client communication using tmux
I tried reinforcement learning using PyBrain
I tried deep learning using Theano
Somehow I tried using jupyter notebook
[Kaggle] I tried undersampling using imbalanced-learn
I tried shooting Kamehameha using OpenPose
I tried using the checkio API
[Python] I tried using YOLO v3
I tried asynchronous processing using asyncio
I tried scraping
I tried PyQ
I tried AutoKeras
I tried papermill
I tried django-slack
I tried Django
I tried spleeter
I tried cgo
I tried using Amazon SQS with django-celery
I tried using Azure Speech to Text.
I tried using Twitter api and Line api
I tried playing a ○ ✕ game using TensorFlow
I tried using YOUTUBE Data API V3
I tried using Selenium with Headless chrome
I tried drawing a line using turtle