Custom validators
Create validators to be used in your messages.
Examples: E-mail, color picker, etc.
Define
bot.validators.define('email', {
validate: (expected, answer) => {
const isEmail = answer.indexOf('@') > 0;
return isEmail === expected;
},
warning: 'A friendly error message',
});
You can also define an asynchronous validation
bot.validators.define('external-dep', {
validate: async (externalAPI, answer) => {
return fetch(externalAPI).then(result => (answer === result));
},
warning: 'A friendly error message',
});
Usage
- message: Your e-mail
validators:
- email: true