LightAndLight / purescript-hubot

Hubot bindings for PureScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

purescript-hubot

Hubot bindings for PureScript.

Installation

$ bower install lightandlight/purescript-hubot

Usage

  1. Write a script

    -- <purescript_project_path>/src/MyHubotScript.purs
    
    module Main (script) where
    
    import Prelude (($), Unit)
    import Control.Monad.Aff (Aff, launchAff)
    import Control.Monad.Eff (Eff)
    import Control.Monad.Eff.Class (liftEff)
    import Control.Monad.Eff.Console (CONSOLE, log)
    import Control.Monad.Eff.Exception (EXCEPTION)
    import Data.Either (Either(..))
    import Data.String.Regex (Regex, noFlags, regex)
    
    import Hubot (HUBOT, Robot, hear, send)
    
    script' :: Robot -> Regex -> Aff (hubot :: HUBOT | e) Unit
    script' robot pat = do
        response <- hear pat robot
        liftEff $ send "polo" response
    
    script :: Robot -> Eff (err :: EXCEPTION, hubot :: HUBOT, console :: CONSOLE) Unit
    script robot = case regex "marco" noFlags of
        Left err -> liftEff $ log err
        Right pat -> do
            launchAff $ script' robot pat
            pure unit
  2. Build your module

    It's necessary to use browserify directly as pulp browserify doesn't have a --node flag yet

    $ pulp build &&
      cd output/Main/ &&
      browserify -o <hoobot_path>/scripts/lib/my_hubot_script.js -s MyHubotScript --node --no-bundle-external index.js &&
      cd ../../
  3. Add a Hubot script that calls the function you exported

    # <hubot_path>/scripts/my_hubot_script.coffee
    
    module.exports = (robot) -> require('./lib/my_hubot_script.js').script(robot)()

About

Hubot bindings for PureScript

License:MIT License


Languages

Language:PureScript 54.0%Language:JavaScript 46.0%