root 420fc96bd2 240813-1146-Kim hace 3 meses
..
README 420fc96bd2 240813-1146-Kim hace 3 meses
build 420fc96bd2 240813-1146-Kim hace 3 meses
docs 420fc96bd2 240813-1146-Kim hace 3 meses
examples 420fc96bd2 240813-1146-Kim hace 3 meses
src 420fc96bd2 240813-1146-Kim hace 3 meses
LICENSE 420fc96bd2 240813-1146-Kim hace 3 meses
README.md 420fc96bd2 240813-1146-Kim hace 3 meses
build.js 420fc96bd2 240813-1146-Kim hace 3 meses
package-lock.json 420fc96bd2 240813-1146-Kim hace 3 meses
package.json 420fc96bd2 240813-1146-Kim hace 3 meses

README.md

ChatUI

ChatUI

A javascript chatbot library for frontend / UI development

ChatUI

Introduction

There are already many javascript chatbot libraries on the market. Why another one? Most chatbot libraries and frameworks mix MVC patterns. Many libraries for example already inlcude some kind of logic to organize and handle the conversation with the user. This makes it difficult to implement them if you have your own ideas for handling the input and maybe even already your own logic module. Therefore, we decided to completely separate frontend (view) and logic (controller, model). ChatUI is simply helping you get your chat UI going.

Try it out:

Usage

More details can be found in the docs.

Select a container element (e.g. div) and send it to the constructor. Make sure set the height for that element (see examples/d3.html).

var chat = chatUI(d3.select('#chatbot'));

After initialising, you can activate the input module. The whole library strongly builds upon callbacks.

chat.showInput(function(input){
  //This function is called when input is submitted by the user
}, function(input){
  //This function is called when the user inputs text
});

The second function is optional.

Beyond the text input, the core of the library are different bubble types. There are two types build in, other types can be added (see next section). addBubble always returns an ID for the added bubble.

//Text Bubble
chat.addBubble({
  //type of bubble (text or select)
  type: 'text',
  //text for the bubble (text or html)
  value: 'Hi there!',
  //speaker (bot or human)
  class: 'bot',
  //show typing bubbles (0-n ms)
  delay: 1000 
}, function(){
  //callback is called after delay is over
});
//Select Bubble
chat.addBubble({
  //type of bubble (text or select)
  type: 'select',
  //array of objects for the select (only the label attribute is required)
  value: [
    {
      label:'yes',
      value:1
    },
    {
      label:'no',
      value:0
    }
  ],
  //speaker (bot or human)
  class: 'bot'
}, function(selection){
  //callback is called after user selects something, the selection is the selected object from the value array
});

Extending ChatUI

The chat.types object can be freely extended.

chat.types.image = function(bubble, options, callback){
  //bubble is a d3 selection of the current container
  //options is the object passed to addBubble
  //callback is the function passed to addBubble
};
var hw = 0;
cb.type.hello = function(bubble, options, callback){
  hw++;
  bubble.append('p').text('Hello World ('+hw+')');
};

cb.addBubble({type:'hello', class:'bot'});
cb.addBubble({type:'hello', class:'human'});

An example for an extension is provided in examples/extend.html

Styling

Most of the things you will likely want to change you can find in the src/css/variables.scss. All ChatUI classes and ids use the namespace 'cb-' Most importantly the icons for human and bot can be changed from build/assets/...

Other useful Functions

Hide the input module

chat.hideInput();

Remove a bubble by ID

module.removeBubble(ID);

Remove all bubbles until ID is reached

module.removeBubbles(ID);

Get a selection of the bubble with ID

module.getBubble(ID);

Scroll chat to start or end

module.scrollTo('start'||'end');

Flavors

The library comes in three flavors:

Underlying dependencies are not inlcuded.

We build this system for a D3 project. In order to make it easier for others to include we added the two other flavors.

Difference between flavors

Beyond the internal differences between the flavors, there are two important differences for implementing different flavors:

1. Initialisation

//jquery
var chat = chatUI($('#chatbot'));

//d3
var chat = chatUI(d3.select('#chatbot'));

2. Building Objects

About the project

SVIFT

ChatUI is part of the SVIFT project, a novel system for quickly and easily creating data visualisations for the web, print and video. SVIFT is being developed by Sebastian Meier, Alsino Skowronnek and Hans Hack.

The project is being supported by http://www.miz-babelsberg.de

MIZ