forked from mullwar/telebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule-ask.js
50 lines (34 loc) · 942 Bytes
/
module-ask.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
const TeleBot = require('../');
const bot = new TeleBot('-PASTEYOURTELEGRAMBOTAPITOKENHERE-');
// Use ask module
bot.use(require('../modules/ask.js'));
// On start command
bot.on('/start', msg => {
const id = msg.from.id;
// Ask user name
return bot.sendMessage(id, 'What is your name?', { ask: 'name' });
});
// Ask name event
bot.on('ask.name', msg => {
const id = msg.from.id
const name = msg.text;
// Ask user age
return bot.sendMessage(
id, `Nice to meet you, ${ name }! How old are you?`, { ask: 'age' }
);
});
// Ask age event
bot.on('ask.age', msg => {
const id = msg.from.id;
const age = Number(msg.text);
// If incorrect age, ask again
if (!age) {
return bot.sendMessage(
id, 'Incorrect age. Please, try again!', { ask: 'age' }
);
}
// Last message (don't ask)
return bot.sendMessage(id, `You are ${ age } years old. Great!`);
});
bot.connect();