Giter Site home page Giter Site logo

rasahq / chatroom Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scalableminds/chatroom

27.0 3.0 25.0 572 KB

React-based Chatroom Component for Rasa Stack

Home Page: https://npm-scalableminds.s3.eu-central-1.amazonaws.com/@scalableminds/chatroom@master/demo.html

License: GNU Affero General Public License v3.0

HTML 8.36% CSS 14.88% JavaScript 76.76%

chatroom's Introduction

This fork is under development to enable handing off from one bot to another. You will need to build chatroom locally to use this capability see section "Handoff to another bot/host"

React-based Chatroom Component for Rasa Stack

CircleCI

Demo

Watch a demo of our Chatroom in action

Features

  • React-based component
  • Supports Text with Markdown formatting, Images, and Buttons
  • Customizable with SASS variables
  • Generates a unique session id and keeps it in sessionStorage
  • Queues consecutive bot messages for better readability
  • Speech input (only in Chrome for now)
  • Text to Speech (only in Chrome for now)
  • Demo mode included (ideal for scripted screencasts)
  • Hosted on S3 for easy use
  • Simple setup. Works with Rasa's REST channel
  • Handoff to another bot/host

Usage

  1. Embed the chatroom.js in the HTML of your website and configure it to connect to your Rasa bot. Either use the S3 hosted version or build it yourself. (see below) You will have to build it yourself to use the handoff capability
<head>
  <link rel="stylesheet" href="http://127.0.0.1:8080/dist/Chatroom.css" />
</head>
<body>
  <div class="chat-container"></div>

  <script src="http://127.0.0.1:8080/dist/Chatroom.js"/></script>
  <script type="text/javascript">
    var chatroom = new window.Chatroom({
      host: "http://localhost:5005",
      title: "Chat with Mike",
      container: document.querySelector(".chat-container"),
      welcomeMessage: "Hi, I am Mike. How may I help you?",
      speechRecognition: "en-US",
      voiceLang: "en-US"
    });
    chatroom.openChat();
  </script>
</body>
  1. In your Rasa bot setup, make sure to include the Rasa REST channel in your credentials.yml file:
rest:
  # pass

Depending on your setup you might need to start the Rasa CLI / Rasa server with the right CORS headers, e.g. --cors "*".

Note, the version of the Chatroom's Javascript file is encoded in the URL. chatroom@master is always the latest version from the GitHub master branch. Use e.g. [email protected] to load a specific release. All Releases can be found here.

Chatroom Version Compatible Rasa Core Version
0.10.x 1.0
0.9.x (Deprecated) 0.11.4+, 0.13.7
0.8.x (Deprecated) 0.11.4+
0.7.8 (Deprecated) 0.10.4+

Note, versions prior to 0.10.x used a custom Python channel to connect the chatroom frontend with a Rasa bot backend. Upgrading, from version 0.9.x or below will require you to modify the credentials.yml and include the Rasa REST channel. (see installation instructions above)

Setting up handoff capability

This version of chatroom will switch hosts on demand when it receives a bot message with handoff_host given in a custom json payload in a bot message. You could use this either for a human handoff (you'd need to configure whichever channel the human was chatting on seperately) or a handoff to another bot. The examples below assume handoff to another bot.

Chatroom configuration for handoff

If you're happy with the defaults described below, no configuration of chatroom is required to make this work, but you will need to configure your bot(s) to send and handle the expected handoff messages.

The payload that will trigger a handoff can also include the title of the chat window for the new host (this is optional):

{
  "handoff_host":"http://localhost:5006",
  "title": "Handoff Bot"
}

By default, chatroom will send the following message to the handoff host upon receiving the handoff payload:

/handoff{"from_host":"<original host url>"}

You can configure which intent is sent to the handoff host by setting handoffIntent in the properties. e.g.

    var chatroom = new window.Chatroom({
...
      handoffIntent: "handoff_other",
...
    });

Regardless of the intent, {"from_host":"<original host url>"} will still be passed along with it.

Bot configuration for handoff

To trigger a handoff from a bot, the bot needs to send a message with the payload specified above. This could be sent from a custom action in a Rasa bot e.g.

    dispatcher.utter_message(json_message = {
        "handoff_host": "http://localhost:5006",
        "title": "Handoff Bot"
        })

or sent from a response template i.e. in domain.yml

responses:
  utter_handoff:
    custom:
      handoff_host: "http://localhost:5006"
      title: "Handoff Bot"

You should also make sure there is defined behaviour for whichever handoffIntent you define, so that the first response from the bot after handoff isn't a fallback or out of scope response.

You don't have to do anything with the from_host entity that is passed unless you want to. You would want to set a slot with it if any behaviour in your bot depends on whether a handoff has occurred or from where a handoff occurred.

A minimal example setup for handoff from a Rasa bot would look as follows in domain.yml:

intents:
- trigger_handoff:
    triggers: utter_handoff
- handoff:
    triggers: utter_welcome
responses:
  utter_handoff:
    custom:
      handoff_host: "http://localhost:5006"
      title: "Handoff Bot"
  utter_welcome:
    text: Welcome! I'm <bot description here>

Then if you were to enter /trigger_handoff or something that got classified as such in chatroom, the host would switch to http://localhost:5006.

Development

Install dependencies

yarn install

Continuously build the Chatroom component

yarn watch
yarn serve

Open http://localhost:8080/demo.html in your browser.

Build

yarn build

Distributable files will be created in folder dist.

License

AGPL v3

Made by scalable minds

chatroom's People

Contributors

btotharye avatar daniel-wer avatar dependabot[bot] avatar hotzenklotz avatar indam23 avatar jstriebel avatar netcarver avatar nicholasbulka avatar nicolepilsworth avatar normanrz avatar originleon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  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

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.