🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

chatbotbase

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chatbotbase

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

1.0.3
latest
Source
npm
Version published
Maintainers
1
Created
Source

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

Keywords

chatbotbase

FAQs

Package last updated on 31 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts