Merge pull request #36 from amovah/master

feat: customizable message for required params
This commit is contained in:
Mahdi Dibaiee 2017-09-12 20:34:26 +04:30 committed by GitHub
commit fe67118acb

View File

@ -117,7 +117,7 @@ export default class Bot extends EventEmitter {
* gets the update * gets the update
* @return {object} returns the bot object * @return {object} returns the bot object
*/ */
command(command, listener) { command(command, listener, customMessage = {}) {
const regex = /[^\s]+/; const regex = /[^\s]+/;
const cmd = command.match(regex)[0].trim(); const cmd = command.match(regex)[0].trim();
@ -125,7 +125,8 @@ export default class Bot extends EventEmitter {
this._userEvents.push({ this._userEvents.push({
pattern: new RegExp(`^/${cmd}`), pattern: new RegExp(`^/${cmd}`),
parse: argumentParser.bind(null, command), parse: argumentParser.bind(null, command),
listener listener,
customMessage
}); });
return this; return this;
@ -211,9 +212,12 @@ export default class Bot extends EventEmitter {
const bot = this; const bot = this;
function* getAnswer() { function* getAnswer() {
const customMessage = ev.customMessage;
for (const param of requiredParams) { for (const param of requiredParams) {
const ga = new Message().to(msg.chat.id) const ga = new Message()
.text(`Enter value for ${param}`); .to(msg.chat.id)
.text(customMessage[param] || `Enter value for ${param}`);
yield bot.send(ga).then(answer => { yield bot.send(ga).then(answer => {
args[param] = answer.text; args[param] = answer.text;
}); });