Upgrade to Pro — share decks privately, control downloads, hide ads and more …

hubot introduction

hubot introduction

Introduction to Hubot for Custom Chat Bot and Automation

https://eueung.github.io/112016/hubot

Eueung Mulyana

December 03, 2016
Tweet

More Decks by Eueung Mulyana

Other Decks in Technology

Transcript

  1. 6 / 26 Hubot? Well... Hubot is your company's robot.

    Install him in your company to dramatically improve and reduce employee efficiency.
  2. What can Hubot do? Hubot is shipped with a small

    group of core scripts: things like posting images, translating languages, and integrating with Google Maps. There's also a repository of community Hubot scripts and an organization of community Hubot packages that you can add to your own robot. The real fun happens when you add your own scripts. Be sure to personalize your Hubot, too; your company's robot should be a place full of inside jokes, custom integrations, and general merriment. Ref: HUBOT 8 / 26 Hubot GitHub, Inc., wrote the rst version of Hubot to automate their company chat room. Hubot knew how to deploy the site, automate a lot of tasks, and be a source of fun in the company. Eventually he grew to become a formidable force in 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 easily deployed on platforms like Heroku. More importantly, Hubot is a standardized way to share scripts between everyone's robots.
  3. CoffeeScript f i l l = ( c o n

    t a i n e r , l i q u i d = " c o f f e e " ) - > " F i l l i n g t h e # { c o n t a i n e r } w i t h # { l i q u i d } . . . " Compiled JavaScript v a r f i l l ; f i l l = f u n c t i o n ( c o n t a i n e r , l i q u i d ) { i f ( l i q u i d = = n u l l ) { l i q u i d = " c o f f e e " ; } r e t u r n " F i l l i n g t h e " + c o n t a i n e r + " w i t h " + l i q u i d + " . . . " ; } ; Ref: Co eeScript 10 / 26 CoffeeScript Co eeScript is a little language that compiles into JavaScript. Co eeScript is 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 use any existing JavaScript library seamlessly from Co eeScript (and vice-versa). The compiled output is readable and pretty-printed, will work in every JavaScript runtime, and tends to run as fast or faster than the equivalent handwritten JavaScript.
  4. _ _ _ _ _ _ _ _ _ _

    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ / \ / / \ | E x t r a c t i n g i n p u t f o r | / / / / \ _ _ _ _ _ | s e l f - r e p l i c a t i o n p r o c e s s | / / / / / / \ / _ _ _ _ _ \ \ / = = = = = = = | [ ^ _ / \ _ ] | / - - - - - - - - - - - - - - - - - - - - - - - - - - - - | | _ | _ _ _ @ @ _ _ | _ _ + = = = + / / / / \ _ \ | | _ \ / / / H U B O T / \ \ | _ _ _ / \ / / / \ \ \ / + - - - + ? O w n e r e u e u n g @ g m a i l . c o m ? B o t n a m e l t k a b o t ? D e s c r i p t i o n A B o t f o r L T K A ? B o t a d a p t e r t e l e g r a m c r e a t e b i n / h u b o t . . . _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ / \ \ \ | S e l f - r e p l i c a t i o n p r o c e s s | | | _ _ _ _ _ | c o m p l e t e . . . | | _ _ \ \ | / _ _ _ _ _ \ \ G o o d l u c k w i t h t h a t . / | / / + | [ ^ _ / \ _ ] | / - - - - - - - - - - - - - - - - - - - - - - - - - - - - | | _ | _ _ _ @ @ _ _ | _ _ + = = = + / / / / \ _ \ | | _ \ / / / H U B O T / \ \ | _ _ _ / \ / / / \ \ l t k a b o t @ 0 . 0 . 0 / h o m e / e m / l t k a b o t | - - h u b o t @ 2 . 1 9 . 0 | - | - - a s y n c @ 0 . 9 . 2 12 / 26 Install & Scaffold $ n o d e - v v 6 . 9 . 1 $ n p m - v 3 . 1 0 . 8 $ s u d o n p m i n s t a l l - g c o f f e e - s c r i p t y o g e n e r a t o r - h u b o t $ m k d i r l t k a b o t & & c d l t k a b o t & & y o h u b o t
  5. l t k a b o t $ c a

    t p a c k a g e . j s o n { " n a m e " : " l t k a b o t " , " v e r s i o n " : " 0 . 0 . 0 " , " p r i v a t e " : t r u e , " a u t h o r " : " e u e u n g @ g m a i l . c o m " , " d e s c r i p t i o n " : " A B o t f o r L T K A " , " d e p e n d e n c i e s " : { " h u b o t " : " ^ 2 . 1 9 . 0 " , " h u b o t - d i a g n o s t i c s " : " 0 . 0 . 1 " , " h u b o t - g o o g l e - i m a g e s " : " ^ 0 . 2 . 6 " , " h u b o t - g o o g l e - t r a n s l a t e " : " ^ 0 . 2 . 0 " , " h u b o t - h e l p " : " ^ 0 . 2 . 0 " , " h u b o t - h e r o k u - k e e p a l i v e " : " ^ 1 . 0 . 2 " , " h u b o t - m a p s " : " 0 . 0 . 2 " , " h u b o t - p u g m e " : " ^ 0 . 1 . 0 " , " h u b o t - r e d i s - b r a i n " : " 0 . 0 . 3 " , " h u b o t - r u l e s " : " ^ 0 . 1 . 1 " , " h u b o t - s c r i p t s " : " ^ 2 . 1 7 . 2 " , " h u b o t - s h i p i t " : " ^ 0 . 2 . 0 " , " h u b o t - t e l e g r a m " : " ^ 0 . 1 . 2 " } , " e n g i n e s " : { " n o d e " : " 0 . 1 0 . x " } } l t k a b o t $ l l s c r i p t s / t o t a l 1 2 d r w x r w x r - x 2 e m e m 4 0 9 6 D e s 2 0 9 : 5 6 . / d r w x r w x r - x 5 e m e m 4 0 9 6 D e s 2 0 9 : 5 6 . . / - r w - r - - r - - 1 e m e m 3 3 6 0 M e i 2 0 2 0 1 6 e x a m p l e . c o f f e e 13 / 26 Check $ t r e e - L 1 . | - - b i n | - - e x t e r n a l - s c r i p t s . j s o n | - - h u b o t - s c r i p t s . j s o n | - - n o d e _ m o d u l e s | - - p a c k a g e . j s o n | - - P r o c f i l e | - - R E A D M E . m d | - - s c r i p t s 3 d i r e c t o r i e s , 5 f i l e s # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - l t k a b o t $ c a t e x t e r n a l - s c r i p t s . j s o n [ " h u b o t - d i a g n o s t i c s " , " h u b o t - h e l p " , " h u b o t - h e r o k u - k e e p a l i v e " , " h u b o t - g o o g l e - i m a g e s " , " h u b o t - g o o g l e - t r a n s l a t e " , " h u b o t - p u g m e " , " h u b o t - m a p s " , " h u b o t - r e d i s - b r a i n " , " h u b o t - r u l e s " , " h u b o t - s h i p i t " ]
  6. l t k a b o t $ b i

    n / h u b o t l t k a b o t > l t k a b o t > h e l p u s a g e : h i s t o r y e x i t , \ q - c l o s e s h e l l a n d e x i t h e l p , \ ? - p r i n t t h i s u s a g e c l e a r , \ c - c l e a r t h e t e r m i n a l s c r e e n l t k a b o t > l t k a b o t p i n g l t k a b o t > P O N G l t k a b o t > l t k a b o t t i m e l t k a b o t > S e r v e r t i m e i s : S a t D e c 0 3 2 0 1 6 0 6 : 5 4 : 2 9 G M T + 0 7 0 0 ( W I B ) l t k a b o t > l t k a b o t s h i p i t l t k a b o t > h t t p : / / i m g 7 0 . i m a g e s h a c k . u s / i m g 7 0 / 9 6 1 5 / c u t e s q u i r r e l s 1 5 a c 7 . j p g l t k a b o t > l t k a b o t t h e r u l e s l t k a b o t > 0 . A r o b o t m a y n o t h a r m h u m a n i t y , o r , b y i n a c t i o n , a l l o w h u m a n i t y t o c o m e t o h a r m . 1 . A r o b o t m a y n o t i n j u r e a h u m a n b e i n g o r , t h r o u g h i n a c t i o n , a l l o w a h u m a n b e i n g t o c o m e t o h a r m . 2 . A r o b o t m u s t o b e y a n y o r d e r s g i v e n t o i t b y h u m a n b e i n g s , e x c e p t w h e r e s u c h o r d e r s w o u l d c o n f l i c 3 . A r o b o t m u s t p r o t e c t i t s o w n e x i s t e n c e a s l o n g a s s u c h p r o t e c t i o n d o e s n o t c o n f l i c t w i t h t h e F i r 14 / 26 Run & Test Shell Adapter
  7. l t k a b o t > l t

    k a b o t h e l p l t k a b o t > S h e l l : l t k a b o t a d a p t e r - R e p l y w i t h t h e a d a p t e r l t k a b o t a n i m a t e m e < q u e r y > - T h e s a m e t h i n g a s ` i m a g e m e ` , e x c e p t a d d s a f e w p a r a m e t e r s t o t r y t o l t k a b o t e c h o < t e x t > - R e p l y b a c k w i t h < t e x t > l t k a b o t h e l p - D i s p l a y s a l l o f t h e h e l p c o m m a n d s t h a t H u b o t k n o w s a b o u t . l t k a b o t h e l p < q u e r y > - D i s p l a y s a l l h e l p c o m m a n d s t h a t m a t c h < q u e r y > . l t k a b o t i m a g e m e < q u e r y > - T h e O r i g i n a l . Q u e r i e s G o o g l e I m a g e s f o r < q u e r y > a n d r e t u r n s a r a n d o m t o p l t k a b o t m a p m e < q u e r y > - R e t u r n s a m a p v i e w o f t h e a r e a r e t u r n e d b y ` q u e r y ` . l t k a b o t m u s t a c h e m e < u r l | q u e r y > - A d d s a m u s t a c h e t o t h e s p e c i f i e d U R L o r q u e r y r e s u l t . l t k a b o t p i n g - R e p l y w i t h p o n g l t k a b o t p u g b o m b N - g e t N p u g s l t k a b o t p u g m e - R e c e i v e a p u g l t k a b o t t h e r u l e s - M a k e s u r e h u b o t s t i l l k n o w s t h e r u l e s . l t k a b o t t i m e - R e p l y w i t h c u r r e n t t i m e l t k a b o t t r a n s l a t e m e < p h r a s e > - S e a r c h e s f o r a t r a n s l a t i o n f o r t h e < p h r a s e > a n d t h e n p r i n t s t h a t b a l t k a b o t t r a n s l a t e m e f r o m < s o u r c e > i n t o < t a r g e t > < p h r a s e > - T r a n s l a t e s < p h r a s e > f r o m < s o u r c e > i n t o s h i p i t - D i s p l a y a m o t i v a t i o n s q u i r r e l 15 / 26 Run & Test
  8. 1. Create a new Telegram Bot, via BotFather 2. If

    not previously installed with Yeoman, install the adapter: n p m i n s t a l l - - s a v e h u b o t - t e l e g r a m 3. Run Hubot with the adapter. T E L E G R A M _ T O K E N = < t o k e n > b i n / h u b o t - a t e l e g r a m - n u d j a n g 18 / 26 hubot-telegram
  9. l t k a b o t $ T E

    L E G R A M _ T O K E N = 1 2 3 4 5 6 7 8 9 : C C O P d 7 w e a k 7 e y X - l m o h Z 8 h Z s Y k e 5 W P a a R M K b i n / h u b o t - a [ S a t D e c 0 3 2 0 1 6 0 9 : 0 0 : 2 6 G M T + 0 7 0 0 ( W I B ) ] I N F O T e l e g r a m A d a p t e r B o t 1 2 3 4 5 6 7 8 9 : C C O P d 7 [ S a t D e c 0 3 2 0 1 6 0 9 : 0 0 : 2 6 G M T + 0 7 0 0 ( W I B ) ] I N F O T e l e g r a m A d a p t e r S t a r t e d . . . [ S a t D e c 0 3 2 0 1 6 0 9 : 0 0 : 2 6 G M T + 0 7 0 0 ( W I B ) ] W A R N I N G L o a d i n g s c r i p t s f r o m h u b o t - s c r i p t s Y o u r h u b o t - s c r i p t s . j s o n i s e m p t y , s o y o u j u s t n e e d t o r e m o v e i t . [ S a t D e c 0 3 2 0 1 6 0 9 : 0 0 : 2 6 G M T + 0 7 0 0 ( W I B ) ] E R R O R h u b o t - h e r o k u - a l i v e i n c l u d e d , b u t m i s [ S a t D e c 0 3 2 0 1 6 0 9 : 0 0 : 2 6 G M T + 0 7 0 0 ( W I B ) ] I N F O h u b o t - r e d i s - b r a i n : U s i n g d e f a u l t r e d i [ S a t D e c 0 3 2 0 1 6 0 9 : 0 0 : 2 9 G M T + 0 7 0 0 ( W I B ) ] I N F O T e l e g r a m B o t I d e n t i f i e d : L T K A B o t [ S a t D e c 0 3 2 0 1 6 0 9 : 0 0 : 2 9 G M T + 0 7 0 0 ( W I B ) ] W A R N I N G I t i s a d v i s e d t o u s e t h e s a m e b o t [ S a t D e c 0 3 2 0 1 6 0 9 : 0 0 : 2 9 G M T + 0 7 0 0 ( W I B ) ] W A R N I N G H a v i n g a d i f f e r e n t b o t n a m e c a n r e [ S a t D e c 0 3 2 0 1 6 0 9 : 0 2 : 3 9 G M T + 0 7 0 0 ( W I B ) ] I N F O R e c e i v i n g m e s s a g e _ i d : 1 [ S a t D e c 0 3 2 0 1 6 0 9 : 0 2 : 4 9 G M T + 0 7 0 0 ( W I B ) ] I N F O R e c e i v i n g m e s s a g e _ i d : 2 [ S a t D e c 0 3 2 0 1 6 0 9 : 0 2 : 5 0 G M T + 0 7 0 0 ( W I B ) ] I N F O R e p l y m e s s a g e t o r o o m / m e s s a g e : 6 1 9 9 9 5 [ S a t D e c 0 3 2 0 1 6 0 9 : 0 3 : 4 9 G M T + 0 7 0 0 ( W I B ) ] I N F O R e c e i v i n g m e s s a g e _ i d : 4 [ S a t D e c 0 3 2 0 1 6 0 9 : 0 3 : 5 0 G M T + 0 7 0 0 ( W I B ) ] I N F O S e n d i n g m e s s a g e t o r o o m : 6 1 9 9 9 5 3 6 [ S a t D e c 0 3 2 0 1 6 0 9 : 0 4 : 3 9 G M T + 0 7 0 0 ( W I B ) ] I N F O R e c e i v i n g m e s s a g e _ i d : 6 [ S a t D e c 0 3 2 0 1 6 0 9 : 0 4 : 4 8 G M T + 0 7 0 0 ( W I B ) ] I N F O S e n d i n g m e s s a g e t o r o o m : 6 1 9 9 9 5 3 6 [ S a t D e c 0 3 2 0 1 6 0 9 : 0 6 : 1 5 G M T + 0 7 0 0 ( W I B ) ] I N F O R e c e i v i n g m e s s a g e _ i d : 8 20 / 26 Run & Test Polling via getUpdates()
  10. Exercise Edit e x t e r n a l

    - s c r i p t s . j s o n , delete all modules or include only those you want to experiment with Do some experiments inside s c r i p t s / e x a m p l e . c o f f e e 23 / 26
  11. Refs 1. HUBOT - A Customizable, Life Embetterment Robot 2.

    HUBOT Documentation 3. lukefx/hubot-telegram: Hubot adapter for Telegram 4. Co eeScript 5. Bots: An introduction for developers 25 / 26