Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Messages #1

Closed
codeiain opened this issue Jan 5, 2017 · 1 comment · Fixed by #4
Closed

Async Messages #1

codeiain opened this issue Jan 5, 2017 · 1 comment · Fixed by #4

Comments

@codeiain
Copy link

codeiain commented Jan 5, 2017

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

@kirsle
Copy link
Member

kirsle commented Apr 30, 2017

I've published hubot-rivescript v0.1.1 which incorporates this change.

Async replies are on by default, and can be disabled with HUBOT_RIVESCRIPT_SYNC=1

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants