Top Banner
1 / 26 Introduction Hubot Eueung Mulyana https://eueung.github.io/112016/hubot CodeLabs | Attribution-ShareAlike CC BY-SA
26

Chat bot-automation-hubot

Apr 16, 2017

Download

Technology

Eueung Mulyana
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Chat bot-automation-hubot

1 / 26

Introduction

HubotEueung Mulyana

https://eueung.github.io/112016/hubotCodeLabs | Attribution-ShareAlike CC BY-SA

Page 2: Chat bot-automation-hubot

Outline

Introduction

Quick Start

Hubot + Telegram

2 / 26

Page 3: Chat bot-automation-hubot

IntroductionA Customizable, Life Embetterment Robot

3 / 26

Page 4: Chat bot-automation-hubot

4 / 26

Page 5: Chat bot-automation-hubot

5 / 26

What isHubot?

...

Page 6: Chat bot-automation-hubot

6 / 26

Hubot?Well...

Hubot is yourcompany's robot.

Install him in yourcompany todramatically

improve and reduceemployee efficiency.

Page 7: Chat bot-automation-hubot

7 / 26

Nooo!!Seriously atuh

prens..

Page 8: Chat bot-automation-hubot

What can Hubot do?Hubot is shipped with a small group of core scripts:things like posting images, translating languages, andintegrating with Google Maps. There's also a repositoryof community Hubot scripts and an organization ofcommunity Hubot packages that you can add to your ownrobot.

The real fun happens when you add your own scripts. Besure to personalize your Hubot, too; your company'srobot should be a place full of inside jokes, customintegrations, and general merriment.

Ref: HUBOT

8 / 26

HubotGitHub, Inc., wrote the �rst version of Hubot to automatetheir company chat room. Hubot knew how to deploy thesite, automate a lot of tasks, and be a source of fun in the

company. Eventually he grew to become a formidable forcein GitHub. But he led a private, messy life. So he's then

rewritten.

Today's version of Hubot is open source, written in Co�eeScript on Node.js, and easilydeployed on platforms like Heroku. More importantly, Hubot is a standardized way to

share scripts between everyone's robots.

Page 9: Chat bot-automation-hubot

CoffeeScript?Kalem! Keine Angst! Stay Cool, Don't Panic! No Problemo.

9 / 26

Page 10: Chat bot-automation-hubot

CoffeeScript

fill = (container, liquid = "coffee") -> "Filling the #{container} with #{liquid}..."

Compiled JavaScript

var fill;

fill = function(container, liquid) { if (liquid == null) { liquid = "coffee"; } return "Filling the " + container + " with " + liquid + "...";};

Ref: Co�eeScript

10 / 26

CoffeeScriptCo�eeScript is a little language that

compiles into JavaScript. Co�eeScriptis an attempt to expose the good parts

of JavaScript in a simple way.

The golden rule of Co�eeScript is: "It's just JavaScript".The code compiles one-to-one into the equivalent JS,

and there is no interpretation at runtime. You can useany existing JavaScript library seamlessly from

Co�eeScript (and vice-versa). The compiled output isreadable and pretty-printed, will work in every

JavaScript runtime, and tends to run as fast or fasterthan the equivalent handwritten JavaScript.

Page 11: Chat bot-automation-hubot

Quick Start

11 / 26

Page 12: Chat bot-automation-hubot

_____________________________ / \ //\ | Extracting input for | ////\ _____ | self-replication process | //////\ /_____\ \ / ======= |[_/\_]| /---------------------------- | | _|___@@__|__ +===+/ /// \_\ | |_\ /// HUBOT/\\ |___/\// / \\ \ / +---+

? Owner [email protected]? Bot name ltkabot? Description A Bot for LTKA? Bot adapter telegram create bin/hubot ... _____________________________ _____ / \ \ \ | Self-replication process | | | _____ | complete... | |__\\| /_____\ \ Good luck with that. / |//+ |[_/\_]| /---------------------------- | | _|___@@__|__ +===+/ /// \_\ | |_\ /// HUBOT/\\ |___/\// / \\

[email protected] /home/em/ltkabot|-- [email protected] |-|-- [email protected]

12 / 26

Install & Scaffold$ node -vv6.9.1$ npm -v3.10.8

$ sudo npm install -g coffee-script yo generator-hubot

$ mkdir ltkabot && cd ltkabot && yo hubot

Page 13: Chat bot-automation-hubot

ltkabot$ cat package.json { "name": "ltkabot", "version": "0.0.0", "private": true, "author": "[email protected]", "description": "A Bot for LTKA", "dependencies": { "hubot": "2.19.0", "hubot-diagnostics": "0.0.1", "hubot-google-images": "0.2.6", "hubot-google-translate": "0.2.0", "hubot-help": "0.2.0", "hubot-heroku-keepalive": "1.0.2", "hubot-maps": "0.0.2", "hubot-pugme": "0.1.0", "hubot-redis-brain": "0.0.3", "hubot-rules": "0.1.1", "hubot-scripts": "2.17.2", "hubot-shipit": "0.2.0", "hubot-telegram": "0.1.2" }, "engines": { "node": "0.10.x" }}

ltkabot$ ll scripts/total 12drwxrwxr-x 2 em em 4096 Des 2 09:56 ./drwxrwxr-x 5 em em 4096 Des 2 09:56 ../-rw-r--r-- 1 em em 3360 Mei 20 2016 example.coffee

13 / 26

Check$ tree -L 1.|-- bin|-- external-scripts.json|-- hubot-scripts.json|-- node_modules|-- package.json|-- Procfile|-- README.md|-- scripts

3 directories, 5 files# -------------------------------------ltkabot$ cat external-scripts.json [ "hubot-diagnostics", "hubot-help", "hubot-heroku-keepalive", "hubot-google-images", "hubot-google-translate", "hubot-pugme", "hubot-maps", "hubot-redis-brain", "hubot-rules", "hubot-shipit"]

Page 14: Chat bot-automation-hubot

ltkabot$ bin/hubot ltkabot>

ltkabot> helpusage:history exit, \q - close shell and exithelp, \? - print this usageclear, \c - clear the terminal screen

ltkabot> ltkabot pingltkabot> PONG

ltkabot> ltkabot timeltkabot> Server time is: Sat Dec 03 2016 06:54:29 GMT+0700 (WIB)

ltkabot> ltkabot ship itltkabot> http://img70.imageshack.us/img70/9615/cutesquirrels15ac7.jpg

ltkabot> ltkabot the rulesltkabot> 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.

14 / 26

Run & TestShell Adapter

Page 15: Chat bot-automation-hubot

ltkabot> ltkabot helpltkabot> Shell: ltkabot adapter - Reply with the adapterltkabot animate me <query> - The same thing as image me, except adds a few parameters to try to ltkabot echo <text> - Reply back with <text>ltkabot help - Displays all of the help commands that Hubot knows about.ltkabot help <query> - Displays all help commands that match <query>.ltkabot image me <query> - The Original. Queries Google Images for <query> and returns a random top result.ltkabot map me <query> - Returns a map view of the area returned by query.ltkabot mustache me <url|query> - Adds a mustache to the specified URL or query result.ltkabot ping - Reply with pongltkabot pug bomb N - get N pugsltkabot pug me - Receive a pugltkabot the rules - Make sure hubot still knows the rules.ltkabot time - Reply with current timeltkabot translate me <phrase> - Searches for a translation for the <phrase> and then prints that bad boy out.ltkabot translate me from <source> into <target> <phrase> - Translates <phrase> from <source> into <target>. Both <ship it - Display a motivation squirrel

15 / 26

Run & Test

Page 16: Chat bot-automation-hubot

Hubot + Telegram

16 / 26

Page 17: Chat bot-automation-hubot

17 / 26

Page 18: Chat bot-automation-hubot

1. Create a new Telegram Bot, via BotFather2. If not previously installed with Yeoman, install the adapter:npm install --save hubot-telegram

3. Run Hubot with the adapter.

TELEGRAM_TOKEN=<token> bin/hubot -a telegram -n udjang

18 / 26

hubot-telegram

Page 19: Chat bot-automation-hubot

19 / 26

Page 20: Chat bot-automation-hubot

ltkabot$ TELEGRAM_TOKEN=123456789:CCOPd7weak7eyX-lmohZ8hZsYke5WPaaRMK bin/hubot -a[Sat Dec 03 2016 09:00:26 GMT+0700 (WIB)] INFO Telegram Adapter Bot 123456789:CCOPd7weak7eyX-lmohZ8hZsYke5WPaaRMK Loaded...[Sat Dec 03 2016 09:00:26 GMT+0700 (WIB)] INFO Telegram Adapter Started...[Sat Dec 03 2016 09:00:26 GMT+0700 (WIB)] WARNING Loading scripts from hubot-scripts.json is deprecated and will be removed

Your hubot-scripts.json is empty, so you just need to remove it.[Sat Dec 03 2016 09:00:26 GMT+0700 (WIB)] ERROR hubot-heroku-alive included, but missing HUBOT_HEROKU_KEEPALIVE_URL. heroku config:[Sat Dec 03 2016 09:00:26 GMT+0700 (WIB)] INFO hubot-redis-brain: Using default redis on localhost:6379[Sat Dec 03 2016 09:00:29 GMT+0700 (WIB)] INFO Telegram Bot Identified: LTKA Bot[Sat Dec 03 2016 09:00:29 GMT+0700 (WIB)] WARNING It is advised to use the same bot name as your Telegram Bot: ltka_bot[Sat Dec 03 2016 09:00:29 GMT+0700 (WIB)] WARNING Having a different bot name can result

[Sat Dec 03 2016 09:02:39 GMT+0700 (WIB)] INFO Receiving message_id: 1[Sat Dec 03 2016 09:02:49 GMT+0700 (WIB)] INFO Receiving message_id: 2[Sat Dec 03 2016 09:02:50 GMT+0700 (WIB)] INFO Reply message to room/message: 61999536/2[Sat Dec 03 2016 09:03:49 GMT+0700 (WIB)] INFO Receiving message_id: 4[Sat Dec 03 2016 09:03:50 GMT+0700 (WIB)] INFO Sending message to room: 61999536[Sat Dec 03 2016 09:04:39 GMT+0700 (WIB)] INFO Receiving message_id: 6[Sat Dec 03 2016 09:04:48 GMT+0700 (WIB)] INFO Sending message to room: 61999536[Sat Dec 03 2016 09:06:15 GMT+0700 (WIB)] INFO Receiving message_id: 8

20 / 26

Run & TestPolling via getUpdates()

Page 21: Chat bot-automation-hubot

21 / 26

Page 22: Chat bot-automation-hubot

22 / 26

Page 23: Chat bot-automation-hubot

ExerciseEdit external-scripts.json, delete all modules or include only those you want to

experiment withDo some experiments inside scripts/example.coffee

23 / 26

Page 24: Chat bot-automation-hubot

Refs

24 / 26

Page 25: Chat bot-automation-hubot

Refs1. HUBOT - A Customizable, Life Embetterment Robot2. HUBOT Documentation3. lukefx/hubot-telegram: Hubot adapter for Telegram4. Co�eeScript5. Bots: An introduction for developers

25 / 26

Page 26: Chat bot-automation-hubot

26 / 26

ENDEueung Mulyana

https://eueung.github.io/112016/hubotCodeLabs | Attribution-ShareAlike CC BY-SA