chatbotbase
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

ChatbotBase

A modular node.js framework to write chatbots for different platforms like Google Home and Amazon Alexa at once.

NPM Version NPM Downloads

Usage

In order to use this library you need to install the chatbotbase module and of cause the platforms you want to support. Currently are the following platforms supported:

If you want to support both platforms use this commands:

npm init
npm install chatbotbase chatbotbase-dialogflowplatform chatbotbase-alexaplatform

The next Step is to write your own chatbot by extending the VoiceAssistant class. The most important methods are:

  • loadPlatforms(), there you define the platforms you actually want to support
  • reply() where you get the input from the user and you return your answer
  • loadTranslations() where you define your translations
  • optional loadTracker() if you want to track the input of the user e.g. with chatbase

Basic example

Here is the full TypeScript code to write a skill/action supporting Alexa and the Google Assistant. This example welcomes you with a random phrase and gives the user the suggestion to say bye (on supported platforms here just Google Assistant). This example supports multiple languages here German and English.

import {Input, Output, VoiceAssistant, VoicePlatform, Translations} from 'chatbotbase';
import {Dialogflow} from 'chatbotbase-dialogflowplatform';
import {Alexa} from 'chatbotbase-alexaplatform';
 
export class MyChatBot extends VoiceAssistant {
    loadPlatforms(): VoicePlatform[] {
        return [new Dialogflow(), new Alexa()];
    }
 
    reply(input: Input): Output {
        const reply = input.reply();
        switch(input.intent) {
        case 'LaunchRequest':
        case 'Default Welcome Intent':
            reply.addReply(this.plainReply(this.t('WELCOME')));
            reply.addSuggestion(this.suggestion(this.t('BYE')));
            reply.setExpectAnswer(true);
            break;
        case 'Exit':
        case 'SessionEndedRequest':
            reply.addReply(this.plainReply(this.t('STOP_MESSAGE')));
            break;
        }
        return reply;
    }
 
    loadTranslations(): Translations {
        return {
            'de': {
                WELCOME: ['Hi', 'Hallo'],
                STOP_MESSAGE: ['Aufwiedersehen!', 'Bis bald.'],
                BYE: 'Tschüss'
            },
            'en': {
                WELCOME: ['Hi', 'Hello'],
                STOP_MESSAGE: ['Good bye!', 'See you soon.'],
                BYE: 'Bye'
            }
        };
    }
}

Tracking

The ChatbotBase also allows you to track the input of the user e.g. with chatbase. To use just just import the chatbaseplugin and overwrite the loadTracker() method like this:

loadTracker()TrackingProvider[] {
    return [new Chatbase('<your-api-key>', '<your-app-version>')];
}

Currently there are implementation the following tracker:

ToDos

  • Tests
  • Coverage
  • Wiki how to create own platforms/tracking provider
  • Integration of Konversation

License

Apache 2.0

Package Sidebar

Install

npm i chatbotbase

Weekly Downloads

4

Version

1.0.3

License

Apache-2.0

Unpacked Size

69.7 kB

Total Files

7

Last publish

Collaborators

  • rekire