0.0.6 • Published 7 years ago
demo-bot-plugin v0.0.6
demo-bot-plugin
Demo Bot Core Plugin functionality
Install
$ npm install --save demo-bot-plugin
Usage
const Plugin = require('demo-bot-plugin');
// create plugin
const plugin = new Plugin({
name: 'test',
questions: [{
type: 'list',
name: 'theme',
message: 'What do you want to do?',
choices: [
'Order a pizza',
'Make a reservation'
]
}],
handler: (answers) => {
console.log(answers);
}
})
// run plugin
plugin.run();
API
Plugin(config)
Returns a Plugin
instance.
config
name
Type: string
Required: true
Plugin nameentifier.
questions
Type: object[]
Default: []
Questions to be prompted (Inquerier Questions
)
handler
Type: Function
Default: answers => {}
Handler that gets called with answers after user answers questions.
before
Type: Function
Default: () => {}
Hook that gets called before. Makes it possible to perform any actions before questions, handler or run is called.
const plugin = new Plugin({
name: 'test',
questions: [{
type: 'list',
name: 'theme',
message: 'What do you want to do?',
choices: [
'Order a pizza',
'Make a reservation'
]
}],
before: () => {
// remove question
this.questions.pop();
},
handler: answers => {
console.log(answers);
}
})
Related
License
MIT © Jonathan Doherty