elica.js

0.2.2 • Public • Published

elica.js

Javascript SDK for building service module for elica.io

What is it?

elica.io is a extensible bot build using node.js and python. It provides a powerful paltform for developers to develop plugins for elica.io

How Elica works

Like all the chat bots, elica works by receiving messages from chat providers and provide response based on her configuration. One key difference for elica is elica is not designed to be human-like (that's google/microsoft's job), elica is designed to be useful so when you have something to ask, she will respond based on the available services configured for her.

How services works

Services in elica is a webserver that is able to host service configuration readable by elica and endpoint that can process messages posted by elica's main server. When a message arrives, if a specific service is required to complete the response, it will query the appoporiate service and send the response back to the user.

What's in this SDK?

Odds and ends, but mainly just a bot class that you will be able to hook up your own configuration and a middleware that is very simple to use.

Install

npm i elica.js -S

Usage

import Express				from 'express';
import Elica                            from 'elica.js';

const app = express(); // Create an express.js app

const bot = new Elica.Bot({
        intents: require('./intents.json'), // Define your intents
        triggers: require('./triggers.json'), // Define your triggers
        config: require('./config.json'), // Rest of your service config goes here
        routePrefix: '/weather', // Is your service prefixed a path
        key: process.env.API_KEY || 'apikey' // API key for your service
});

bot.intent('intent_name', intentHandler);

app.use(bot.handler.bind(bot)); // .bind() is essential

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})

function intentHandler(correlationId, conversation, session, analysis, service) {
	return {
		response: ['Hello World'],
		conversation
	};
}

Elica.bot(config)

Creates a bot instance with your configs, having multiple bot instance in the same application is supported

  1. config (object)

    1. intents (array) array of your defined intents
    2. triggers (array) array of your triggers
    3. config (object) rest of configs for your service
    4. routePrefix (string) string if your service url is prefixed
    5. key (string) api key for your service
const bot = new Elica.Bot({
        intents: require('./intents.json'), // Define your intents
        triggers: require('./triggers.json'), // Define your triggers
        config: require('./config.json'), // Rest of your service config goes here
        routePrefix: '/weather', // Is your service prefixed a path
        key: process.env.API_KEY || 'apikey' // API key for your service
});

bot.intent(intentRegex, handler)

Define a handler for a specific intent name

  1. intentRegex (string) defined a regex matching one or multiple intent
  2. handler (function) a function that returns a promise resolve to the response of the service
bot.intent('intent_name', intentHandler);

bot.session(sessionType, handler)

Define a handler for a specific session type

  1. sessionType (string) matching one session type
  2. handler (function) a function that returns a promise resolve to the response of the service
bot.session('LOCATION', updateLocation);

bot.endpoints()

Return the auto configured endpoints for the service

bot.handler

A function that is used as a express middleware

Note If you forgot to use .bind(), you will get errors like 'Can not resolve XXX from undefined

app.use(bot.handler.bind(bot)); // .bind() is essential

Readme

Keywords

none

Package Sidebar

Install

npm i elica.js

Weekly Downloads

15

Version

0.2.2

License

MIT

Last publish

Collaborators

  • r1cebank