Skip to content

Latest commit

 

History

History
99 lines (78 loc) · 3.24 KB

README.md

File metadata and controls

99 lines (78 loc) · 3.24 KB

trailpack-chatbot

📦 Trailpack to create chatbot under your Trails projects

Gitter Known Vulnerabilities NPM version Linux + OSX Build Status Code Climate Follow @trailsjs on Twitter

Intallation

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

Compatibility

This Trailpack is compatible with Sequelize trailpack-sequelize.

Usage

Load in your trailpack config.

// config/main.js
module.exports = {
  // ...
  packs: [
    require('trailpack-core'),
    // ...
    require('trailpack-cache'),
    require('trailpack-chatbot')
  ]
}

Dependencies

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

Config

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

Contributing

We love contributions! Please check out our Contributor's Guide for more information on how our projects are organized and how to get started.

License

MIT