Giter Club home page Giter Club logo

botkit-rasa's Introduction

Botkit / Rasa NLU plugin

This plugin provides Botkit developers a way to use the Rasa NLU open source, self hosted natural language API.

Setup in your project

Install the plugin using the npm package

npm i --save botkit-rasa

Make your bot aware of the plugin:

var rasa = require('botkit-rasa')({rasa_uri: 'http://localhost:5000'});
controller.middleware.receive.use(rasa.receive);

controller.hears(['my_intent'],'message_received', rasa.hears, function(bot, message) {

    console.log('Intent:', message.intent);
    console.log('Entities:', message.entities);    

});

Example Slack bot

In the example directory there's a fully functional Slack bot sample.

This bot demonstrates some core features of Botkit leveraging Rasa NLU plugin:

  • Connect to Slack using the real time API
  • Receive messages based on "spoken" patterns
  • Reply to messages

Prerequisites

Run the example bot

Get Rasa NLU up and running by checking out their repository and following the instructions to setup a Rasa NLU instance. At this point you should have a Rasa NLU instance up and running.

Now get a Bot token from Slack (you will need this later when launching the bot from the command line):

Clone this repository and move into the example directory:

  • git clone https://github.com/sohlex/botkit-rasa.git

Open another terminal and from the example directory, run the commands (TOKEN is the one that you got before from the slack website):

  • npm install
  • slack_token=<TOKEN> node bot.js

Use the bot

Find your bot inside Slack to send it a direct message.

Say: "Hello"

The bot should reply "Hello!" If it didn't, there's a problem with Rasa NLU configuration, check the bot and Rasa console for errors.

Make sure to invite your bot into other channels using /invite @!

Extend the bot

If this middleware doesn't satisfy your needs, you can use it as inspiration for your implementations or contribute to this project! Furthermore, Botkit has many features for building cool and useful bots!

Read all about it here.

What this middleware does

Using this Rasa NLU middleware plugin for Botkit causes every message that is sent to your bot to be first sent to Rasa NLU for processing. The results of the call to Rasa NLU are added into the incoming message as message.intents and message.entities.

Using the Rasa NLU hears middleware tells Botkit to look for Rasa NLU intents information, and match them using this information instead of the built in pattern matching function.

You must create an intent in the understandings area of Rasa NLU and train it to register certain expressions.

More informations are available in the Rasa NLU documentation

botkit-rasa's People

Contributors

sohlex avatar terrytran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

botkit-rasa's Issues

Recognize Bot's messages

Hi!

In order to not sent to rasa the bot reply, this could be added just after

 if (!message.text || message.is_echo) {
        next()
        return
}

we can simply identify whether the message comes from a bot:

if( message.bot_id != null ){
        console.log('\t\t[own_debug]  bot response, not processing')
        next()
        return
}

Hope it helps. Regards

Compatibility with rasa NLU v0.9x

Hi, it seems that there is some problems when using this middleware with rasa NLU >0.7
Whenever you interact with the rasa server, the following error appears:

Unhandled rejection StatusCodeError: 404 - {"error":"Invalid parse parameter specified"}

This error appears after calling the nodeJS program with:
slack_token=XXXXX node bot.js

Rasa is installed using pip, and botkit using npm after cloning the main repository.

Kind regards

LOG

Initializing Botkit v0.5.4
info: ** No persistent storage method specified! Data may be lost when process shuts down.
debug: Setting up a handler for spawned
debug: Setting up a handler for heard_trigger
debug: Setting up a handler for command_triggered
debug: Setting up a handler for remote_command_end
info: ** Setting up custom handlers for processing Slack messages
debug: Setting up a handler for message_received
debug: rtm.connect { token: 'XXXXX' }
info: ** API CALL: https://slack.com/api/rtm.connect
{ receive: [Function: receive], hears: [Function: hears] }
debug: Setting up a handler for direct_message
debug: Setting up a handler for direct_mention
debug: Setting up a handler for mention
debug: Got response null {"ok":true,"url":"wss:\/\/mpmulti-s1ou.slack-msgs.com\/websocketXXXXXXXXXXX=","team":{"id":"XXXXXXXXXX","name":"Slack test","domain":"XXXX-test"},"self":{"id":"U5W5ZP7HC","name":"XXXX-test-bot"}}
notice: ** BOT ID: XXXXXXXXXX-bot ...attempting to connect to RTM!
notice: RTM websocket opened
Unhandled rejection StatusCodeError: 404 - {"error":"Invalid parse parameter specified"}
    at new StatusCodeError (~/example/test_rasa_nlu/botkit-rasa/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (~/example/test_rasa_nlu/botkit-rasa/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (~/example/test_rasa_nlu/botkit-rasa/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (~/example/test_rasa_nlu/botkit-rasa/node_modules/request/request.js:188:22)
    at emitTwo (events.js:125:13)
    at Request.emit (events.js:213:7)
    at Request.<anonymous> (~/example/test_rasa_nlu/botkit-rasa/node_modules/request/request.js:1171:10)
    at emitOne (events.js:115:13)
    at Request.emit (events.js:210:7)
    at IncomingMessage.<anonymous> (~/example/test_rasa_nlu/botkit-rasa/node_modules/request/request.js:1091:12)
    at Object.onceWrapper (events.js:312:19)
    at emitNone (events.js:110:20)
    at IncomingMessage.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1045:12)
    at _combinedTickCallback (internal/process/next_tick.js:102:11)
    at process._tickCallback (internal/process/next_tick.js:161:9)

Unhandled rejection StatusCodeError: 404 - {"error":"Invalid parse parameter specified"}
    at new StatusCodeError (~/example/test_rasa_nlu/botkit-rasa/node_modules/request-promise-core/lib/errors.js:32:15)
    at Request.plumbing.callback (~/example/test_rasa_nlu/botkit-rasa/node_modules/request-promise-core/lib/plumbing.js:104:33)
    at Request.RP$callback [as _callback] (~/example/test_rasa_nlu/botkit-rasa/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at Request.self.callback (~/example/test_rasa_nlu/botkit-rasa/node_modules/request/request.js:188:22)
    at emitTwo (events.js:125:13)
    at Request.emit (events.js:213:7)
    at Request.<anonymous> (~/example/test_rasa_nlu/botkit-rasa/node_modules/request/request.js:1171:10)
    at emitOne (events.js:115:13)
    at Request.emit (events.js:210:7)

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.