https://github.com/bottenderjs/bottender-form
An experimental package for handling conversational form with Bottender.
https://github.com/bottenderjs/bottender-form
Last synced: 7 months ago
JSON representation
An experimental package for handling conversational form with Bottender.
- Host: GitHub
- URL: https://github.com/bottenderjs/bottender-form
- Owner: bottenderjs
- License: mit
- Created: 2018-01-29T16:55:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-05T06:00:14.000Z (over 8 years ago)
- Last Synced: 2025-05-20T12:11:52.175Z (about 1 year ago)
- Language: JavaScript
- Size: 62.5 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# bottender-form
[](https://www.npmjs.com/package/bottender-form)
[](https://travis-ci.org/bottenderjs/bottender-form)
[](https://opensource.org/licenses/MIT)
> An experimental package for handling conversational form with [Bottender](https://github.com/Yoctol/bottender).
## Installation
```sh
npm install bottender-form
```
## Usage
```js
const { middleware } = require('bottender');
const form = require('bottender-form');
const handleForm = form({
name: 'user',
shouldStart: context => context.event.text === '/form',
steps: [
{
question: "What's your name?",
stateKey: 'user.name',
},
{
question: 'How old are you?',
validation: text => /\d+/.test(text),
map: numstr => +numstr,
stateKey: 'user.age',
},
],
});
bot.onEvent(
middleware([
handleForm,
async context => {
if (context.event.isMessage) {
await context.sendText(`user: ${JSON.stringify(context.state.user)}`);
}
},
])
);
```
## Options
### name
`text`
### shouldStart
Default: `() => false`.
### shouldStop
Default: `() => false`.
### retryMessage
Default: `Validation failed. Please try again.`.
### retryTimes
Default: `3`.
### didFinish
Default: `() => {}`.
### Step
#### question
`text | async context => void`
#### stateKey
`text`
#### validation
`text => boolean | async text => boolean`
#### map
`text => any`
## License
MIT © [Yoctol](https://github.com/bottenderjs/bottender-form)