📦 Trailpack to create chatbot under your Trails projects
With yo :
npm install -g yo generator-trails
yo trails:trailpack trailpack-chatbot
With npm (you will have to create config file manually) :
npm install --save trailpack-chatbot
This Trailpack is compatible with Sequelize trailpack-sequelize.
Load in your trailpack config.
// config/main.js
module.exports = {
// ...
packs: [
require('trailpack-core'),
// ...
require('trailpack-cache'),
require('trailpack-chatbot')
]
}
In order to work you need to install and configure trailpack-cache with a memory store
It's needed to keep in cache the last answer of the user and his context to calculate the next action
Setup your bots.
// config/chatbot.js
module.exports = {
bots: {}, // put you bots definitions here (see example below)
allowAnonymousUsers: false, // allow to use basic chatbot command (no nested states for unlogged user
defaultAnswer: (app, data) => { // set a default answer when no bot recognize the sentence
data.action = 'UNKNOWN'
return Promise.resolve(data)
},
hooks: {} // set some hooks on bot states to add/modify the bot response
}
// config/caches.js minimum config
module.exports = {
stores: [
{
name: 'chatbot',
type: 'memory',
ttl: 0
}
]
}
Default config here
Full example of bot here
We love contributions! Please check out our Contributor's Guide for more information on how our projects are organized and how to get started.