Code Monkey home page Code Monkey logo

hubot-rivescript's Introduction

Hubot: hubot-rivescript

Provides a RiveScript chatbot personality for Hubot, using the rivescript JS module.

RiveScript is a simple scripting language for chatbots. See RiveScript.com to learn more about it.

See src/rivescript.coffee for full documentation.

Installation

In your hubot project repo, run:

npm install --save hubot-rivescript

Then add hubot-rivescript to your external-scripts.json:

[
  "hubot-rivescript"
]

Configuration

Use the following environment variables to configure your RiveScript bot:

  • HUBOT_RIVESCRIPT_BRAIN (default ./brain)

    The path on disk to a directory containing RiveScript files (*.rive).

  • HUBOT_RIVESCRIPT_PREFIX (default blank)

    By default, this script responses to all messages directed at the bot (by mentioning its username). This can overlap with other scripts you may have configured; so you can set this variable to require an additional prefix. For example, with HUBOT_RIVESCRIPT_PREFIX="rs" a user must say "hubot rs hello" to get the RiveScript bot to respond.

  • HUBOT_RIVESCRIPT_UTF8 (default 0)

    Enable UTF-8 support within RiveScript. By default, all punctuation and symbols are stripped from the user's input message, and RiveScript triggers can't contain Unicode symbols. Enable UTF-8 mode to lift these restrictions if you want to support non-English users.

    Enable it with HUBOT_RIVESCRIPT_UTF8=1

  • HUBOT_RIVESCRIPT_SYNC (default 0)

    Use synchronous replies instead of async ones. By default, replies are async and you can change that by doing HUBOT_RIVESCRIPT_SYNC=1

    Under the hood, this is the difference between using rs.replyAsync() (default) and rs.reply(); in the latter mode, object macros aren't allowed to return promises but must return string results.

  • HUBOT_RIVESCRIPT_DEBUG (default 0)

    Set this variable to 1 to enable debug mode within RiveScript. This will log verbose internal information to the console and may be useful to help debug loading or matching errors within RiveScript.

Sample Interaction

user1> hubot hello bot
hubot> Hello human!

user1> hubot my name is Alice
hubot> Alice, I'll call you that from now on.

user2> hubot call me Bob
hubot> I'll remember that your name is Bob.

user1> hubot who am I?
hubot> Your name is Alice.

user2> hubot what's my name?
hubot> You told me your name is Bob.

NPM Module

https://www.npmjs.com/package/hubot-rivescript

Author

Noah Petherbridge, @kirsle

hubot-rivescript's People

Contributors

changhaitravis avatar kirsle avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

hubot-rivescript's Issues

Async Messages

The current source doesn't allow async msgs to be sent back from the brain scripts.

Changing the code for the coffee script to

RiveScript = require "rivescript"

module.exports = (robot) ->

  # Configuration parameters.
  brain  = process.env.HUBOT_RIVESCRIPT_BRAIN or "./brain"
  prefix = if process.env.HUBOT_RIVESCRIPT_PREFIX then "#{process.env.HUBOT_RIVESCRIPT_PREFIX}\\s+" else "\\s*"
  utf8   = "#{process.env.HUBOT_RIVESCRIPT_UTF8}" is "1" or false

  # The matcher regexp.
  regexp = new RegExp("#{prefix}(.*)", "i")

  # Initialize the RiveScript brain.
  @bot = new RiveScript({
    utf8: utf8
  })
  @bot.loadDirectory(brain, ->
    @bot.sortReplies()

    robot.respond regexp, (res) ->
      bot.replyAsync(res.message.user.name, res.match[1]).then (reply) ->
        res.send reply
        return

      #reply = bot.reply(res.message.user.name, res.match[1])
      #res.send reply
  , (err) ->
    console.error "Couldn't load RiveScript replies: #{err}"
  )

will allow async msgs to be sent back from the brain

uservars save to and load from hubot brain

I found that if you tell rivescript stuff about you it would remember, but this won't be persisted across reboots.

However, if getuservars and setuservars is exposed, we can use hubot.brain for persistence.

I'll be submitting a pull request with a thoroughly tested implementation of this over the weekend if it turns out to be possible/easy.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.