Javascript SDK for building service module for elica.io
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
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.
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.
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.
npm i elica.js -S
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
};
}
Creates a bot instance with your configs, having multiple bot instance in the same application is supported
-
config (object)
- intents (array) array of your defined intents
- triggers (array) array of your triggers
- config (object) rest of configs for your service
- routePrefix (string) string if your service url is prefixed
- 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
});
Define a handler for a specific intent name
- intentRegex (string) defined a regex matching one or multiple intent
- handler (function) a function that returns a promise resolve to the response of the service
bot.intent('intent_name', intentHandler);
Define a handler for a specific session type
- sessionType (string) matching one session type
- handler (function) a function that returns a promise resolve to the response of the service
bot.session('LOCATION', updateLocation);
Return the auto configured endpoints for the service
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