forked from node-vk-bot-api/node-vk-bot-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscene.js
34 lines (28 loc) · 803 Bytes
/
scene.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
const VkBot = require('../lib');
const Session = require('../lib/session');
const Stage = require('../lib/stage');
const Scene = require('../lib/scene');
const bot = new VkBot(process.env.TOKEN);
const session = new Session();
const scene = new Scene('meet',
(ctx) => {
ctx.scene.next();
ctx.reply('How old are you?');
},
(ctx) => {
ctx.session.age = +ctx.message.text;
ctx.scene.next();
ctx.reply('What is your name?');
},
(ctx) => {
ctx.session.name = ctx.message.text;
ctx.scene.leave();
ctx.reply(`Nice to meet you, ${ctx.session.name} (${ctx.session.age} years old)`);
});
const stage = new Stage(scene);
bot.use(session.middleware());
bot.use(stage.middleware());
bot.command('/meet', (ctx) => {
ctx.scene.enter('meet');
});
bot.startPolling();