Skip to content
This repository has been archived by the owner on May 10, 2022. It is now read-only.
/ rasa-client Public archive

Simple Node.js wrapper around the Rasa core HTTP server

License

Notifications You must be signed in to change notification settings

beevelop/rasa-client

Repository files navigation

Travis npm Release xo-code-style Status Badges Beevelop

Rasa Core HTTP Client for Node.js 🐦

⚠️ Still WIP: API is unstable and might change. Consider this a technical preview.

Simple Node.js wrapper around the Rasa core HTTP server.

Installation

Install via npm:

npm install --save rasa-client

Usage

const RasaClient = require('rasa-client')

// first param is the endpoint without trailing slash
// optionally the second parameter can be an authentication token
const rc = new RasaClient('http://localhost:5005')
rc.parse('Hello world').then((res) => console.log)
rc.getVersion().then((res) => console.log)

Examples

// Full example with the remotebot example (from the official Rasa core repo)

const SENDER_ID = 'anon'
// Greet the bot
const msg1 = 'hello'
rc.parse(msg1, SENDER_ID).then(reply => {
  return rc.continue({
    executed_action: 'greet'
  }, SENDER_ID)
}).then(cont1 => {
  // next_action is action_listen in this case
  // therefore we can initiate a new parse request

  // Send venues request
  const msg2 = 'Whats the next event'
  return rc.parse(msg2, SENDER_ID)
}).then(reply => {
  return rc.continue({
    executed_action: 'search_concerts',
    events: [{ event: 'slot', name: 'venues', value: [
      {name: "Big Arena", reviews: 4.5},
      {name: "Small Arena", reviews: 4.2}
    ]}]
  }, SENDER_ID)
}).then(cont2 => {
  // you get the point...
})